diff options
author | John Southworth <john.southworth@vyatta.com> | 2012-05-09 08:50:11 -0700 |
---|---|---|
committer | John Southworth <john.southworth@vyatta.com> | 2012-05-09 08:50:11 -0700 |
commit | dde86895d4a66c78bb5198c09b16ac99589bce71 (patch) | |
tree | d5c8bd203ecb5b1831dd926fbf534b702bf9ab5d /lib/Vyatta | |
parent | 1d6c1f38d708c3b612a2fabb234148d99390d8d3 (diff) | |
download | vyatta-cfg-dde86895d4a66c78bb5198c09b16ac99589bce71.tar.gz vyatta-cfg-dde86895d4a66c78bb5198c09b16ac99589bce71.zip |
Add functions to get calling terminal size to Vyatta::Misc
Diffstat (limited to 'lib/Vyatta')
-rwxr-xr-x | lib/Vyatta/Misc.pm | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/Vyatta/Misc.pm b/lib/Vyatta/Misc.pm index 6579da7..61ce029 100755 --- a/lib/Vyatta/Misc.pm +++ b/lib/Vyatta/Misc.pm @@ -23,12 +23,15 @@ package Vyatta::Misc; use strict; require Exporter; +require 'sys/ioctl.ph'; + our @ISA = qw(Exporter); our @EXPORT = qw(getInterfaces getIP getNetAddIP get_sysfs_value is_address_enabled is_dhcp_enabled get_ipaddr_intf_hash isIpAddress is_ip_v4_or_v6 interface_description is_local_address is_primary_address get_ipnet_intf_hash - isValidPortNumber); + isValidPortNumber get_terminal_size get_terminal_height + get_terminal_width ); our @EXPORT_OK = qw(generate_dhclient_intf_files getInterfacesIPadresses getPortRuleString @@ -522,4 +525,28 @@ sub interface_description { return $description; } +# returns (rows, columns) for terminal size +sub get_terminal_size { + 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 ($rows, $cols); +} + +# return only terminal width +sub get_terminal_width { + my ($rows, $cols) = get_terminal_size; + return $cols; +} + +# return only terminal height +sub get_terminal_height { + my ($rows, $cols) = get_terminal_size; + return $rows; +} + 1; |