问题描述
有几个类似的库可协助制作命令行GUI。
简单地说,它们是如何工作的?
我的第一个想法是,ncurses截取所有键盘输入,它一行一行。然而,仔细检查揭示每个新帧将覆盖前一个。它如何修改已经输出的行?此外,它如何处理颜色?
编辑:同样的问题适用于任何具有花式界面,如例如将光标移动到屏幕上的特定位置,插入字符,删除行等。
每个终端类型不同,并且有自己的命令序列。 ncurses有一个数据库(有关详情,请参阅)
内部ncurses维护屏幕的2个视图:当前内容和应用当前暂挂更改后屏幕应该是什么样子。一旦程序请求屏幕重画,ncurses计算一个有效的方式更新屏幕看起来像所需的视图。输出的确切字符/命令序列取决于使用的终端类型。
There are several libraries like ncurses that assist in making command-line GUIs.
Simply put, how do they work?
My first thought was that ncurses intercepts all keyboard input, and draws each "frame" by outputting it line-by-line normally. Closer inspection, however, reveals that each new frame overwrites the previous one. How does it modify lines that have already been outputted? Furthermore, how does it handle color?
EDIT: The same question applies to anything with a "fancy" interface, like vim and emacs.
Text terminals have command sequences that do things like move the cursor to a particular position on the screen, insert characters, delete lines etc.
Each terminal type is different and has its own set of command sequences. ncurses has a databse (see terminfo for details)
Internally ncurses maintains 2 views of the screen: the current contents and what the screen should look like after the current pending changes are applied. Once the program requests a screen redraw, ncurses calculates an efficient way to update the screen to look like the desired view. The exact characters/command sequences output depend on what terminal type is in use.
这篇关于如何做ncurses等。 et al。工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!