Help! I need a _reliable_ way to determine the current terminal window size when my Perl program is being piped data to it. It is being run under HP-UX 11.11 under both hpterm and xterm terminals (separately, of course) :)
At issue is the fact that when I run my program with no parameters or piped-in data, I can grab the output from `stty -a` and parse it for the "rows=" and "columns=" values. HOWEVER when you are piping data to a program like this: cat passwd | ./myprog then STDIN is no longer "real", meaning that your Perl program no longer knows anything about the terminal, since its whole world is now a stream of data which has no "boundaries". If you don't believe me, try this:
#!/usr/local/bin/perl -w
my $stuff=`stty -a 2>/dev/null`;
print "\$stuff=$stuff\n";
Now run this by itself, then run it again but cat some data to it: cat ./myprog | ./myprog and you will see that $stuff is empty when having something piped to it.
Note #1: must use only standard (default) Perl installation, so no CPAN modules (such as Term::ReadKey) allowed!
Note #2: curses is unavailable in this installation (don't ask...)
Note #3: I don't consider environment variables to be reliable due to them being so volatile, so $LINES and $COLUMNS are out of the picture.
Now, after all of these are tossed, I'm thinking that there must be a POSIX escape code to read the current cursor position, so I can set the cursor position to (200,200) and read it and if it wrapped then the window isn't that big so drop the column width down and do it again, ad nauseum. However, I cannot find it after days of searching. Also, there might be a simple POSIX escape sequence that simply reads the current cursor position, but I was unable to find that either!
I sure hope someone with lots of low-level terminal experience can help me!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.