Addressing the cursor of a VT100 style terminal emulator using perl

J

Jeff Silverman

I am working on a perl program which uses VT100 style escape codes and
runs in gnome-terminal or konsole or rxterm or xterm or similar.

I want to know if there is a way to sent an escape sequence to the
terminal emulator which queries for the current size of the screen and
gets a report back. I am assuming that the user can resize the
terminal. I plan to query the terminal size at the end of each pass.
If the user resizes the terminal in the middle of pass - well - he's
going to be confused.

Does anybody know how to do this? I have looked at Term::Cap but I
don't see where that queries the current terminal size. Ditto for
Term::ANSIColor.


Many thanks,


Jeff Silverman
 
S

Samwyse

Jeff said:
I am working on a perl program which uses VT100 style escape codes and
runs in gnome-terminal or konsole or rxterm or xterm or similar.

I want to know if there is a way to sent an escape sequence to the
terminal emulator which queries for the current size of the screen and
gets a report back. I am assuming that the user can resize the
terminal. I plan to query the terminal size at the end of each pass.
If the user resizes the terminal in the middle of pass - well - he's
going to be confused.

Does anybody know how to do this? I have looked at Term::Cap but I
don't see where that queries the current terminal size. Ditto for
Term::ANSIColor.

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
call 'getch()', the library will return KEY_RESIZE to let you know what
happened. Typically, you repaint the entire screen at that point.

Googling the terms in all caps should tell you more.
 
T

Thomas Dickey

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top