summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/vyatta-show-interfaces.pl16
1 files changed, 14 insertions, 2 deletions
diff --git a/scripts/vyatta-show-interfaces.pl b/scripts/vyatta-show-interfaces.pl
index abc9ec6..3a9f1cc 100755
--- a/scripts/vyatta-show-interfaces.pl
+++ b/scripts/vyatta-show-interfaces.pl
@@ -24,6 +24,7 @@
#
use lib "/opt/vyatta/share/perl5/";
+require 'sys/ioctl.ph';
use Vyatta::Interface;
use Vyatta::Misc;
@@ -49,13 +50,22 @@ my %action_hash = (
my $clear_stats_dir = '/var/run/vyatta';
my $clear_file_magic = 'XYZZYX';
-my ($term_height, $term_width) = split ' ', `stty size`;
-
my @rx_stat_vars =
qw/rx_bytes rx_packets rx_errors rx_dropped rx_over_errors multicast/;
my @tx_stat_vars =
qw/tx_bytes tx_packets tx_errors tx_dropped tx_carrier_errors collisions/;
+sub get_terminal_width {
+ my $winsize = '';
+ open(my $TTY, '>', '/dev/tty');
+ # undefined if output not going to terminal
+ return unless (ioctl($TTY, &TIOCGWINSZ, $winsize));
+ close($TTY);
+
+ my ($rows, $cols, undef, undef) = unpack('S4', $winsize);
+ return $cols;
+}
+
sub get_intf_description {
my $name = shift;
my $description = interface_description($name);
@@ -239,6 +249,8 @@ sub conv_brief_code {
sub conv_descriptions {
my $description = pop @_;
my @descriptions;
+ my $term_width = get_terminal_width;
+ $term_width = 80 if (!defined($term_width));
my $desc_len = $term_width - 56;
my $line = '';
foreach my $elem (split(' ', $description)){