Writing a “real” interactive terminal program like vim, htop, … in C/C++ without ncurses

前端 未结 3 419
一整个雨季
一整个雨季 2021-01-30 02:34

No, I don\'t want to use ncurses, because I want to learn how the terminal works and have fun programming it on my own. :) It doesn\'t have t

3条回答
  •  误落风尘
    2021-01-30 02:47

    I'm a bit confused. You speak of a “terminal application”, like vim; terminal applications don't get mouse events, and don't respond to the mouse.

    If you're talking about real terminal applications, which run in an xterm, the important thing to note is that many of the portability issues concern the terminal, and not the OS. The terminal is controlled by sending different escape sequences. Which ones do what depend on the terminal; the ANSI escape codes are now fairly widespread, however, see http://en.wikipedia.org/wiki/ANSI_escape_code. These are generally understood by xterm, for example.

    You may have to output an additional sequence at the start and at the end to enter and leave “full screen” mode; this is necessary for xterm.

    Finally, you'll have to do something special at the input/output level to ensure that your output driver doesn't add any characters (e.g. convert a simple LF into a CRLF), and ensure that input doesn't echo, is transparent, and returns immediately. Under Linux, this is done using ioctl. (Again, don't forget to restore it when you finish.)

提交回复
热议问题