【问题标题】:How do I add colour to a QNX terminal?如何为 QNX 终端添加颜色?
【发布时间】:2012-05-22 07:57:05
【问题描述】:

我正在使用 PuTTY 0.62 通过 SSH 连接到 QNX Neutrino。

我已启用“允许终端指定 ASCI 颜色”和“允许终端使用 xterm 256 色模式”。

如何让我的终端 (qansi-m) 为输出文本添加颜色?

【问题讨论】:

  • 有人能解释一下为什么它跑题了吗?这个问题与“程序员常用的软件工具”有关,是一个“编程行业独有的实用、可回答的问题”(来自常见问题解答)。

标签: colors ksh qnx-neutrino


【解决方案1】:

您可以在使用echo时通过以下方式手动添加颜色:

图形渲染代码如下:

Number  Meaning
0       All attributes off (except charset (10, 11, 12))
1       Bold
2       Half intensity (default to cyan on color screen)
4       Underline (default to red on color screen)
5       Blink
7       Reverse
9       Invisible
10      Exit alternate char set (GR & GL are restored)
11      Enter PC-lower char set (GR & GL are ASCII; C0 & C1 are PC_LO except for ESC)
12      Enter PC-higher char set (GR, C1 & GL, C0 are PC_HI except for ESC)
21      Normal intensity (un-Bold)
22      Normal intensity (un-Half intensity)
24      Disable underline
25      Disable blink
27      Disable reverse
29      Visible
30-37   Set foreground color (30+color_number, see below)
39      Set foreground to saved
40-47   Set background color (40+color_number, see below)
49      Set background to saved

颜色代码如下:

colour_num  Description
0           Black
1           Red
2           Green
3           Brown
4           Blue
5           Violet
6           Cyan
7           White

语法:

{CSI}<setting1>;<setting2>m

八进制的 CSI 是 \0233,因此要打印带有红色前景 (31) 的粗体文本 (1),您可以:

echo "\023331;1m"

Reference

【讨论】:

    【解决方案2】:

    您需要配置在 Neutrino 上运行的程序(包括 shell)以发送必要的 ANSI 转义序列。 sshd无法拦截修改终端输出。

    【讨论】:

    • 感谢您的回答。我不认为我使用的外壳被设计成彩色的,我认为我最好使用转义序列手动添加颜色。我修改了问题的范围。
    • 如果你想让你的 shell 提示丰富多彩,你可以将相关的转义序列添加到你的PS1
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-21
    • 2014-07-04
    • 2010-09-09
    • 1970-01-01
    • 1970-01-01
    • 2013-08-18
    • 2019-11-01
    相关资源
    最近更新 更多