Metarika has asked for the wisdom of the Perl Monks concerning the following question:

Hi. I have seen examples of printf("\e[%d;%dH", $y, $x); to move the cursor to an absolute column and row or left or right. Does anyone know of a list of available codes or how to figure them out aside from stabbing in the dark? I need to insert text (moving the rest of it to the right) without doing that in code and a few other vi-like commands. Thanks.

Replies are listed 'Best First'.
Re: Printing Escape Characters
by pc88mxer (Vicar) on Feb 15, 2008 at 17:33 UTC
    You'll want to check out the Curses package. It consults a database to look up the appropriate escape codes for your terminal. Also, it'll allow you to deal with screen drawing at a much higher level api.
Re: Printing Escape Characters
by Fletch (Bishop) on Feb 15, 2008 at 17:35 UTC

    You don't want to hardcode them. At the least you want to use a module like Term::Cap to lookup the specific sequences by a capability name; more likely you'd want to use something like Curses which will give you a higher level drawing API and handle the grunt work for you.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Printing Escape Characters
by BrowserUk (Patriarch) on Feb 15, 2008 at 18:17 UTC
      I was trying to have vi command-line functionality within my script (not by launching vi with a temporary file), and after following a suggestion about the Term::ReadLine::Gnu, but I found that it didn't work exactly the way I wanted, or I didn't know how to use it. However, this is exactly what I want and I'm using it correctly -> Term::ReadLine::Zoid All vi functionality including an automatic history buffer is contained in it. Thanks guys.
Re: Printing Escape Characters
by kyle (Abbot) on Feb 15, 2008 at 17:36 UTC

    That's sort of a raw, hardcoded (and unreliable) way of doing what probably ought to be done with Curses. What it's doing is printing terminal control codes without much regard for what the terminal is. Nearly every terminal today responds to most of the same codes, so it probably won't break much, but using a library to handle those functions will be easier to read and more reliable anyway.

Re: Printing Escape Characters
by locked_user sundialsvc4 (Abbot) on Feb 19, 2008 at 16:52 UTC

    Yes, definitely curses. This is a package that was specifically designed to handle TTY terminals or their equivalent, allowing you to express what you want to do, at a fairly high level, and have curses do it.