Term::Screen - A Simple all perl Term::Cap based screen positioning module |
Term::Screen - A Simple all perl Term::Cap based screen positioning module
require Term::Screen;
$scr = new Term::Screen; unless ($scr) { die " Something's wrong \n"; } $scr->clrscr(); $scr->at(5,3); $scr->puts("this is some stuff"); $scr->at(10,10)->bold()->puts("hi!")->normal(); # you can concatenate many calls (not getch) $c = $scr->getch(); # doesn't need Enter key ... if ($scr->key_pressed()) { print "ha you hit a key!"; }
Term::Screen is a very simple screen positioning module that should
work wherever Term::Cap
does. It is set up for Unix using stty's but
these dependences are isolated by evals in the new
constructor. Thus
you may create a child module implementing Screen with MS-DOS, ioctl,
or other means to get raw and unblocked input. This is not a replacement
for Curses -- it has no memory. This was written so that it could be
easily changed to fit nasty systems, and to be available first thing.
The input functions getch, key_pressed, echo, and noecho are implemented so as to work under a fairly standard Unix system. They use 'stty' to set raw and no echo modes and turn on auto flush. All of these are 'eval'ed so that this class can be inherited for new definitions easily.
Term::Screen was designed to be ``required'', then used with object syntax as shown above. One quirk (which the author was used to so he didn't care) is that for function key translation, no delay is set. So for many terminals to get an esc character, you have to hit another char after it, generally another esc.
Term::Screen has a very minimal set of of fixed character terminal position and character reading commands:
new()
term(term)
rows(rows)
cols(cols)
at(row,col)
resize(r,c)
normal()
bold()
reverse()
clrscr()
clreol()
clreos()
il()
dl()
ic_exists()
ic()
dc_exists()
dc()
The following are the I/O functions. They provide standard useful single character reading values. getch returns either a single char or the name of a function key when a key is pressed. The only exception is when you hit a character that is the start of a function key sequence. In this case getch keeps waiting for the next char to see if it is fn key. Generally this is the escape key, and why you need to hit esc twice. To get a stright char, just use the regular 'gets' perl function. You will need to echo it yourself if you want.
puts(str)
$scr-
at(10,0)->puts(``Hi!'')->at(0,0);>. You can just use
print if you want.
getch()
get_fn_keys
function for what a lot of the names are. This will wait
for next char if in a possible fn key string, so you would need to type
'esc' 'esc' most likely to get out of getch, since 'esc' is usually the
leading char for function keys. You can use perl's getc, to go 'underneath'
getch if you want. See the table in Screen::get_fn_keys() for more
information.
key_pressed([sec])
echo()
noecho()
flush_input()
stuff_input(str)
getch
method buffer, the underlying getc stuff
is not touched.
Term::Screen.pm by Mark Kaehny (kaehny@execpc.com) Currently maintained by Jonathan Stowe <jns@gellyfish.com>
Please see the README file in the distribution kit for the license details for this module.
Term::Cap, termcap, curses, stty, select
Term::Screen - A Simple all perl Term::Cap based screen positioning module |