Question

I want to understand how programs like vim or man work in a shell. How do they let the user scroll, refresh the display and such?

They seem to interact with some console library and hence manipulate what we see. What's really happening?

Was it helpful?

Solution

The terminal has what is called a terminal driver. This isn't a driver in the sense of an interface to hardware, but rather it interprets certain character sequences that cause it to perform operations such as scrolling, text attributes, and so on.

The character sequences are stored in the terminfo database. A library called curses (or its modern equivalent, ncurses) reads the terminfo database and emits the various character sequences based on the functions called.

Separating out the terminfo database from the terminal driver itself allows programs to support a number of terminals such as xterm, the text console, network clients, even remote dumb terminals connected via a serial line.

OTHER TIPS

Here's a great how-to:

You probably want to take a look at chapter 17 - Using the Terminal.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top