如何做ncurses等。 et al。工作? [英] How Do ncurses et. al. Work?

查看:190
本文介绍了如何做ncurses等。 et al。工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有几个类似 ncurses 的库可协助制作命令行GUI。



简单地说,它们是如何工作的?



我的第一个想法是,ncurses截取所有键盘输入,它一行一行。然而,仔细检查揭示每个新帧将覆盖前一个。它如何修改已经输出的行?此外,它如何处理颜色?



编辑:同样的问题适用于任何具有花式界面,如 vim 例如将光标移动到屏幕上的特定位置,插入字符,删除行等。



每个终端类型不同,并且有自己的命令序列。 ncurses有一个数据库(有关详情,请参阅 terminfo



内部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。工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆