我试图给一个由李贝迪驱动的应用程序的提示符着色,但是我的颜色根本没有显示出来。知道我在这里做错什么了吗?
#include <iostream>
#include <histedit.h>
char* prompt(EditLine *e)
{
static char p[] = "\1\033[36m\1:::\1\033[0m\1 ";
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不幸的是,只显示了以下未着色的提示符:
::: 发布于 2014-01-20 17:57:07
\1用作停止/启动文字字符,因此这似乎是正确的行为。
\1\033[36m\1:::\1\033[0m\1
| | | |
| | |_Start |_Stop
| |
|_Start |_StopEL_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\033[36m:::\033[0m\1因为\1可能会终止颜色的使用,而\[ ... \]则是bash中的正常终止符。
发布于 2015-02-21 16:09:52
'esc[0m‘重置所有属性,因此显示的颜色将立即消失,最好将属性设置为不同的颜色,例如白色的'esc[47m’
有关更全面的属性列表,请参见http://www.termsys.demon.co.uk/vtansi.htm
https://stackoverflow.com/questions/21240181
复制相似问题