![]() |
|
Perl-Sensitive Sunglasses | |
PerlMonks |
How do I get the screen size?by faq_monk (Initiate) |
on Oct 08, 1999 at 00:29 UTC ( [id://713]=perlfaq nodetype: print w/replies, xml ) | Need Help?? |
Current Perl documentation can be found at perldoc.perl.org. Here is our local, out-dated (pre-5.6) version: If you have Term::ReadKey module installed from CPAN, you can use it to fetch the width and height in characters and in pixels:
use Term::ReadKey; ($wchar, $hchar, $wpixels, $hpixels) = GetTerminalSize(); This is more portable than the raw ioctl, but not as illustrative:
require 'sys/ioctl.ph'; die "no TIOCGWINSZ " unless defined &TIOCGWINSZ; open(TTY, "+</dev/tty") or die "No tty: $!"; unless (ioctl(TTY, &TIOCGWINSZ, $winsize='')) { die sprintf "$0: ioctl TIOCGWINSZ (%08x: $!)\n", &TIOCGWINSZ; } ($row, $col, $xpixel, $ypixel) = unpack('S4', $winsize); print "(row,col) = ($row,$col)"; print " (xpixel,ypixel) = ($xpixel,$ypixel)" if $xpixel || $ypixel; print "\n";
|
|