Chapter 5

Terminals

In this chapter, you take a look at some improvements you might like to make to your basic application from Chapter 2. Perhaps the most obvious failing is the user interface; it’s functional, but not very elegant. Here, you look at how to take more control of the user’s terminal; that is, both keyboard input and screen output. More than this though, you learn how to “guarantee” that the programs you write can get input from the user, even in the presence of input redirection, and ensure that the output goes to the right place on the screen.

Though the reimplemented CD database application won’t see the light of day until the end of Chapter 7, you’ll do much of the groundwork for that chapter here. Chapter 6 is on curses, which is not some ancient malediction, but rather a library of functions that provide a higher level of code to control the terminal screen display. Along the way, you’ll examine a little more of the thinking of the early UNIX meisters by introducing you to some philosophy of Linux and UNIX and the concept of terminal input and output. The low-level access presented here might be just what you’re looking for. Most of what we cover applies equally well to programs running in a console window, such as KDE’s Konsole, GNOME’s gnome-terminal, or the standard X11 xterm.

Specifically, in this chapter, you learn about

  • Reading and writing to the terminal
  • Terminal drivers and the General Terminal Interface
  • termios
  • Terminal output and terminfo
  • Detecting ...

Get Beginning Linux Programming, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.