jonathanstowe / TermReadKey

Character mode terminal access for Perl
12 stars 27 forks source link

GetTerminalSize() call looks for too many arguments #8

Closed nemws1 closed 7 years ago

nemws1 commented 9 years ago

I'm working on a program that does a call to GetTerminalSize() in Term::ReadKey. Usually the output goes to the terminal, but sometimes it may be redirected. Regardless of the case, I want to grab my terminal dimensions, including the pixel sizes. This is easily done by just looking at /dev/tty instead of STDOUT. However, Term::ReadKey doesn't work the way I would expect when trying to pass a filehandle to GetTerminalSize. From the documentation, I would think I could do this:

use Term::ReadKey;
open(TTY, "/dev/tty");
my($wchar, $hchar, $wpixels, $hpixels) = GetTerminalSize(TTY);
close(TTY);

But it doesn't work. Looking at the module, it's expecting the filehandle to be the 2nd argument to GetTerminalSize:

my ($file) = normalizehandle( ( @_ > 1 ? $_[1] : \*STDOUT ) );

Shouldn't this be:

my ($file) = normalizehandle( ( @_ > 0 ? $_[0] : \*STDOUT ) );

In order to get my program to work, I had to just pass a value (which looks to be ignored) before I pass the filehandle:

open(TTY, "/dev/tty");
my($wchar, $hchar, $wpixels, $hpixels) = GetTerminalSize("some junk", TTY);
close(TTY);
nemws1 commented 7 years ago

Thank you!!! :)