如何为编辑线应用程序的提示着色
How to colorize the prompt of an editline application
我正在尝试使libedit供电的应用程序提示着色,但是我根本不会出现颜色。有什么想法我在这里做错了什么?
#include <iostream>
#include <histedit.h>
char* prompt(EditLine *e)
{
static char p[] = "1 33[36m1:::1 33[0m1 ";
return p;
}
int main(int argc, char* argv[])
{
EditLine* el = el_init(argv[0], stdin, stdout, stderr);
el_set(el, EL_PROMPT_ESC, &prompt, '1');
el_set(el, EL_EDITOR, "vi");
while (1)
{
int count;
char const* line = el_gets(el, &count);
if (count > 0)
std::cout << line;
}
el_end(el);
return 0;
}
用
编译clang++ editline.cc -ledit && ./a.out
不幸的是仅显示:
的未颜色提示:::
编辑线不支持颜色提示。有一个补丁实现它们。
有趣的是,在屏幕更新期间,Editline在内存缓冲区中首先呈现图像,并在上一个帧中差异,然后发出命令以修复差异。命令是moveto(x,y)
,delete(n)
,insert(text)
。
此设计允许更简单的代码。例如,在编辑器中插入命令可以并且实际上对整个屏幕进行重新绘制,但是终端绘制命令的结果序列很小。
不幸的是,由于文本在到达终端之前经历了复杂的转换,因此在翻译中丢失了一些信息,例如颜色。
1 用作停止/启动字面字符,因此这似乎是正确的行为。
1 33[36m1:::1 33[0m1
| | | |
| | |_Start |_Stop
| |
|_Start |_Stop
el_prompt_esc,char *( *f)(editline *),char c 与EL_PROMPT相同,但C参数指示 启动/停止字面提示字符。
If a start/stop literal character is found in the prompt, the
character itself is not printed, but characters after it are
printed directly to the terminal without affecting the state
of the current line. A subsequent second start/stop literal
character ends this behavior. This is typically used to
embed literal escape sequences that change the color/style of
the terminal in the prompt. 0 unsets it.
男人页面使用0
来阐明颜色,但尚不清楚它们的含义。
也许尝试这样的逃生序列:
1 33[36m::: 33[0m1
由于1
可能从使用中终止颜色,而[ ... ]
将是bash中的普通终结者。
'esc [0m'重置所有属性,因此显示的颜色将立即消失,最好将属性设置为其他颜色,例如,示例为白色'ESC [47m'
请参阅http://www.termsys.demon.co.uk/vtansi.htm有关属性的更全面列表
相关文章:
- 试图在visual studio上用C++创建一个桌面应用程序
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 在C应用程序中运行C++(带有STL)函数
- 使用VerQueryValue检索应用程序的文件描述
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 使用调试/崩溃报告将应用程序部署到客户端
- C++控制台应用程序阻止退出
- 码头化的C++应用程序是否向后兼容早期的内核版本
- 将应用程序从32位移植到64位时出现问题
- 如何改变c++应用程序的视觉效果
- WM_CTLCOLORSTATIC从未在WIN32应用程序中触发
- PC中的程序和PHONE中的本机描述应用程序之间的数据连接
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 示例外壳应用程序显示的 V8 "segmentation fault (core dumped)"错误
- phytec phyBOARD iMX-6在从闪存而不是SD卡运行qt5 opengles应用程序时表现不佳(FPS减半
- 为什么导入Mixed native/CLR lib.dll的本机C++应用程序没有在Mixed lib.dll中的外部变
- 如何为编辑线应用程序的提示着色
- 安装盾,安装应用程序后,系统会提示用户安装程序
- c++ /CLI提示“应用程序无法启动”
- 在不提示UAC权限的情况下从c++应用程序运行NSIS安装程序