in reply to handling terminal window resizing

Here's a little test program I built a while back to try this out. Run it in a terminal window such xterm and it will report the terminal size as you change it.

use strict; use warnings; use feature qw{ say }; $SIG{ WINCH } = \ &winch; winch(); while ( 1 ) { sleep 200; } sub winch { my( $rows, $cols ) = getRowsCols(); say qq{Rows = $rows - Columns = $cols}; } sub getRowsCols { my $sttyOut = do { open my $sttyFH, q{-|}, qw{ /bin/stty size } or die qq{fork: /bin/stty size: $!\n}; local $/; <$sttyFH>; }; die qq{/bin/stty size: Unexpected output: $sttyOut} unless $sttyOut =~ m{^(\d+)\s+(\d+)$}; return $1, $2; }

I hope this is helpful.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^2: handling terminal window resizing
by morgon (Priest) on Dec 30, 2016 at 14:11 UTC
    I would write your getRowsCols-sub like this:
    sub getRowsCols { qx|/bin/stty size| =~ /(\d+)\s+(\d+)/; }
    Is there anything gained in your (more complicated imho) way?
      > Is there anything gained in your (more complicated imho) way?

      Well he has 2 points of error handling.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!