Addressing the cursor of a VT100 style terminal emulator using perl

Discussion in 'Perl Misc' started by Jeff Silverman, Dec 29, 2005.

  1. 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
    Jeff Silverman, Dec 29, 2005
    #1
    1. Advertising

  2. Jeff Silverman

    Samwyse Guest

    Re: Addressing the cursor of a VT100 style terminal emulator usingperl

    Jeff Silverman <"Remove the letters in all caps" wrote:
    > 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.
    Samwyse, Dec 29, 2005
    #2
    1. Advertising

  3. Samwyse <> wrote:
    >> 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


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

    --
    Thomas E. Dickey
    http://invisible-island.net
    ftp://invisible-island.net
    Thomas Dickey, Dec 29, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Captain Dondo

    Pattern matching for a terminal emulator

    Captain Dondo, Apr 19, 2007, in forum: C Programming
    Replies:
    7
    Views:
    316
    David Thompson
    May 21, 2007
  2. dmaziuk
    Replies:
    3
    Views:
    574
    Chris Gonnerman
    Jan 25, 2011
  3. Eric

    Terminal emulator

    Eric, Feb 14, 2006, in forum: Perl Misc
    Replies:
    4
    Views:
    133
    Veli-Pekka Tätilä
    Feb 15, 2006
  4. Lakshmipathi.G
    Replies:
    0
    Views:
    88
    Lakshmipathi.G
    Aug 6, 2013
  5. dieter
    Replies:
    0
    Views:
    88
    dieter
    Aug 7, 2013
Loading...

Share This Page