Twitter Updates

    follow me on Twitter

    G-AVLN in front of her home

    G-AVLN in front of her home

    Mostly Unix and Linux topics. But flying might get a mention too.

    Friday, September 16, 2005

    Terminal capabilities

    I remember going back years and years, having to use an application which was meant to be displayed on a Prestel terminal. Prestel is a simple screen protocol, of 40 columns x 24 rows, still used in some places (mostly in Europe). It's got some interesting features, such as fixed colours for certain facilities. Can't remember much of the detail anymore, but I'm sure that, for example, the background colour is like choosing an old Ford - any colour you want, as long as it is black. Quite peculiar.

    This was the project, however, that tought me a lot about terminfo database and tools associated with creating and manipulating the terminal capability files. The terminfo database is in fact a collection of hundreds of individual files, each containing a description of one terminal type. These are data files, you can't 'touch' them with cat or more, but feel free (as root) to convert it into text with:

    # infocmp /usr/share/terminfo/v/vt100 > /tmp/vt100.txt

    If you needed to create a new terminal file, you'd pick up the most suitable (similar) existing one, modify it (using data from the hardware manual provided with your new terminal) and submit it into the terminfo system with the tic command (terminfo compiler).

    These days one gets 'drivers' for every screen one can think of (and few more), but understanding of the terminfo still helps - as you can then implement scripts, menus, etc, using some of the more advanced screen control techniques.

    For example, many people know of the tput command, that allows to manipulate the screen on an ad hoc bases. This command uses the capabilities file indicated by your TERM variable. To check, type:

    $ echo $TERM

    If you are looged into Linux, that is very likely xterm, and the file used is /usr/share/terminfo/x/xterm.

    If you've never seen tput in action, log onto any Unix or Linux box, open any terminal session and type:

    $ tput bold; echo hello world; tput rev; echo and again; tput rsg0

    The fun starts when you begin to utilise some of the more obscure features, such a colour or placement control. Try the following:

    $ red=$(tput setf 4)
    $ echo "${red}$(tput cup 10 20)hello world"

    The setf argument allows to control the character colour, whereas cup x y will send the cursor to column x row y of your screen.

    To find out more about the screen capabiliites and arguments to tput look at the manual pages for terminfo, as well as tput. There is a lot more useful stuff there, for example there is an explanation of why setf 4 might mean red on one ocassion but green on another!

    No comments:

    Blog Archive