I'm trying to wrap my head how shells move the screen cursor around (Moving around input the arrow keys and such).

I've been doing a lot of testing, and I haven't found any system call that allows for movement of the screen cursor in a terminal. Is this done using specific terminal extensions? If so, is there any documentation as to how this is achieved for, say, xterm?

This has been driving me crazy, any light you can shed on this is appreciated.


There is no such system call, or set of system calls. It's all done by convention.

Back in the old days, when a "terminal" was a large clunky piece of equiment linked to a computer via a cable, "smart terminals" would do things like move the cursor, or draw a line, or fill in a polygon with colors. The smart terminal usually did this via "escape sequenes". A program issued a special sequence of byte values, usually beginning with ASCII 0x1b, 'ESC', to move a cursor, or color a word, or some special thing other than imitating a teletypewriter.

That's the "convention". Nowadays, a "terminal" is almost always just one window among many on a bitmapped screen, xterm, rxvt, etc etc. It's up to xterm (or rxvt or whatever) to read the bytes coming from "the program" running in it, and interpret those bytes according to a given convention. I just typed this in one of my xterm windows:

6 % echo $TERM 

But I know that old, old xterms used to say "vt100" in that case. Any program that "moves the cursor" has to output escape sequences for the "xterm" convention to move the cursor in an xterm instance.

You could do man curses and man terminfo for more information.


People have done whole windowing systems with escape sequences. See MGR as an example.


Checkout tput. It is a wrapper around ANSI Escape sequences that are supported (the amount of support differs a lot) by almost all terminal emulators.

tput will only output the sequence if it is supported by the terminal, therefore you don't have to worry about the support. Or at least you don't have to worry about strange characters being printed in the terminal :-)


I know this is not the exact answer to your question but the curses library is the stuff you need to do some tui dev. If you're a programmer, looking at its source (available in all open-source unix distributions) will show you how it's done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.