Re: Addressing the cursor of a VT100 style terminal emulator using perl



Thomas Dickey wrote:
Samwyse <samwyse@xxxxxxxxx> wrote:

Actually, when a terminal is resized, your app gets a SIGWINCH signal. You should then issue an ioctl to get the new size:
struct winsize size;
ioctl(fileno(stdout), TIOCGWINSZ, &size);
This way, you don't have to query the terminal and worry about the user hitting a key at the wrong time. The ncurses library handles all of this for you, I suppose that Term::Cap does as well. The next time you

I don't belive Term::Cap does this since it doesn't have a getch() method. (likewise Term::AnsiColor).

Well, what good is it, then? ;-)

OK, http://www.google.com/search?q=perl+KEY_RESIZE tells us about Term::Visual, which notes that it handles KEY_RESIZE by repainting the screen. This looks like a useful high-level package for all sort of ncurses-like functionality. While I assume that it uses ncurses, there's no actual mention of how it gets that keystroke, but reading a module's source is always a fun way to spend the dead time between Xmas and New Year's.

http://www.google.com/search?q=perl+TIOCGWINSZ turns up nothing that seems useful at first glance.

http://www.google.com/search?q=perl+KEY_SIGWINCH turns up the fact that Term::ReadKey has a method for this type of stuff, and it works across both *NIX and Win32. If you don't/can't use Term::Visual for some reason, maybe it will be helpful.

=====
GetTerminalSize [Filehandle]

Returns either an empty array if this operation is unsupported, or a four element array containing: the width of the terminal in characters, the height of the terminal in character, the width in pixels, and the height in pixels. (The pixel size will only be valid in some environments.)

Under Windows, this function must be called with an "output" filehandle, such as STDOUT, or a handle opened to CONOUT$.
.



Quantcast