【问题标题】:Temporarily colour Linux Terminal foreground and background text临时为 Linux 终端前景和背景文本着色
【发布时间】:2017-06-26 23:00:45
【问题描述】:

如何临时设置 Linux 终端的颜色?我希望在脚本中添加颜色设置,以便我记得在几分钟后运行合作伙伴脚本。颜色更改将在一个脚本中设置,并在另一个脚本中删除,这对我来说是一个可见的提醒。

所以颜色变化需要在终端启动后应用,并且需要在随后的所有输入中保持不变,直到它被另一个等效命令删除。

我的终端是 GNOME 终端 2.31.3

【问题讨论】:

  • Stack Overflow 是一个编程和开发问题的网站。这个问题似乎离题了,因为它与编程或开发无关。请参阅帮助中心的What topics can I ask about here。也许Super UserUnix & Linux Stack Exchange 会是一个更好的提问地点。
  • 我很抱歉。我在这里发现了很多非常相似的问题,带有相同的标签,但没有一个能完全解决我想要做的事情,所以我也在这里发布了我的问题。我没有意识到这是不合适的。

标签: linux colors terminal


【解决方案1】:

改变颜色的方法不止一种。 VTE(GNOME 终端中的实际终端)实现了这些功能(通常来自xterm):

  • “ANSI 颜色”转义(这对您来说毫无用处,因为许多程序会重置这些)
  • 使用非 ANSI 动态颜色更改文本前景和背景(重置器很少见)
  • 更改调色板(同样,重置器很少见)

后两个记录在XTerm Control Sequences,在Operating System Commands部分:

OSC Ps ; Pt BEL
OSC Ps ; Pt ST

给出控制序列的形式,例如,escape]Ps;PtBEL

动态颜色描述如下:

      The 10 colors (below) which may be set or queried using 1 0
      through 1 9  are denoted dynamic colors, since the correspond-
      ing control sequences were the first means for setting xterm's
      colors dynamically, i.e., after it was started.  They are not
      the same as the ANSI colors.  These controls may be disabled
      using the allowColorOps resource.  At least one parameter is
      expected for Pt.  Each successive parameter changes the next
      color in the list.  The value of Ps tells the starting point
      in the list.  The colors are specified by name or RGB specifi-
      cation as per XParseColor.

这里还有其他颜色:

        Ps = 4 ; c; spec -> Change Color Number c to the color spec-
      ified by spec.  This can be a name or RGB specification as per
      XParseColor.  Any number of c/spec pairs may be given.  The
      color numbers correspond to the ANSI colors 0-7, their bright
      versions 8-15, and if supported, the remainder of the 88-color
      or 256-color table.

【讨论】:

  • 非常感谢您努力编写看似全面的答案。我很抱歉说我不明白。您是否可以添加一个示例,说明我将在终端中键入的内容以更改前景。我不是一个特别有经验的 Linux 用户。
猜你喜欢
  • 2023-03-18
  • 2011-04-27
  • 1970-01-01
  • 1970-01-01
  • 2012-08-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多