Question

I have a program that uses a terminal in raw mode and I want to move the cursor around. Where can I find the escape sequence for this and how can I send it to the terminal from inside my c program?

Here's what I currently have:

char code[4];
code[0] = 27;
code[1] = 91;
code[2] = '*';
code[3] = 'D';
write(1, code, 4);
Was it helpful?

Solution

If you want control of the full screen then you should look at the ncurses library. This is a simple library for full screen console programs that contains among other things

  • Full screen positioning of text
  • Use of the full keyboard including function keys, insert/delete etc
  • Use of attributes for colouring, highlighting of text etc

OTHER TIPS

You want to use termcap to get this information, as it varies, depending on what sort of terminal the user is at.

I would suggest you look hard at the curses or ncurses libraries, and plan to use one or the other rather than roll your own. You should aim to use the terminfo system of terminal descriptions rather than the older termcap system. See also the O'Reilly books "Termcap and Terminfo" and my favourite title (mainly because I seem to spend a lot of time cursing when programming) "Progamming With Curses". (However, that book is ancient - 1986 - and there are other more recent books on the same subject which would probably be better choices; I still love the title, though.)

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