Chapter 21. The Linux Console

   


The Linux console normally imitates a serial terminal. By writing special character sequences to the console device, you control all aspects of the screen presentation. You will usually use S-Lang, curses, or some other screen-drawing library to draw to the screen; they use these escape sequences. The console can also be read and modified through an alternative full-screen interface, which is particularly useful for some specialized programs.

DOS programmers introduced for the first time to Linux programming often are dismayed to find that writing characters to the screen is not a simple matter of initializing a pointer to the address of the screen in memory and writing blindly through it. Some complain loudly about this "backwards" system that forces them to pretend that they are writing to a serial terminal, writing escape sequences in between the characters that are written to the screen to control cursor movement, color, screen clearing, and so on.

There are several good reasons to treat the console as a fancy serial terminal. Not the least is that when the program is being run on a serial terminal, it still works. More important in these Internet-conscious times the program runs correctly across networks and in these GUI-conscious times the program runs correctly in a terminal emulator window under X or any other GUI. Furthermore, programs that are run remotely, either via a network or a serial connection, display properly on your console.

Furthermore, you will find that the escape codes are a reasonable low-level interface to the screen, and they are a good base on which to build higher-level primitives, such as curses, documented in Programming with curses [Strang, 1991A]. This is no accident; serial terminals are a venerable technology, fine-tuned over the years in response to programmers' real needs. The Linux console is based on the most popular family of serial terminals, the descendants of the DEC VT100.

Most escape sequences use the ANSI escape character, which has no convenient printed representation. We follow the termcap and terminfo libraries in using ^[ to denote the ANSI escape character; be aware when reading them that they sometimes refer to the same character as \E. As elsewhere in this book, as well as in termcap and terminfo, ^C indicates the Control-C character.


       
    top
     


    Linux Application Development
    Linux Application Development (paperback) (2nd Edition)
    ISBN: 0321563220
    EAN: 2147483647
    Year: 2003
    Pages: 168

    Similar book on Amazon

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net