diff options
author | John Southworth <john.southworth@vyatta.com> | 2012-05-08 15:58:26 -0700 |
---|---|---|
committer | John Southworth <john.southworth@vyatta.com> | 2012-05-08 15:58:26 -0700 |
commit | e21661af7de05c33e62b819f1590675de6660f64 (patch) | |
tree | 32661a4372c3133f304c1ebbdcb547b4b2b4f889 /scripts | |
parent | 8ce2f42e1d5f5aceb82347b0ccfcf94e277e4686 (diff) | |
download | vyatta-op-e21661af7de05c33e62b819f1590675de6660f64.tar.gz vyatta-op-e21661af7de05c33e62b819f1590675de6660f64.zip |
Use native perl code to figure othe the terminal width
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/vyatta-show-interfaces.pl | 16 |
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)){ |