linux - 临时为 Linux 终端前景和背景文本着色

标签 linux colors terminal

如何临时设置 Linux 终端的颜色?我想在脚本中添加颜色设置,以便我记得在几分钟后运行合作伙伴脚本。颜色变化将在一个脚本中设置,在另一个脚本中移除,这将作为对我的可见提醒。

因此,需要在终端启动后应用颜色更改,并且需要保留所有后续输入,直到它被另一个等效命令删除。

我的终端是 GNOME Terminal 2.31.3

最佳答案

改变颜色的方法不止一种。 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 - 临时为 Linux 终端前景和背景文本着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44769868/

相关文章:

复杂数组初始化

android - 如何为Material Design App创建具有自定义颜色的自定义调色板?

javascript - 使用 jQuery 获取点击颜色的十六进制值

regex - 在 Linux 终端中使用带有 egrep 的正则表达式查找数字

firebase - 如何在正确的目录中初始化firebase?

c - 数据包分层传输

linux - linux中符号^\是什么意思

javascript - HTML/CSS/JavaScript 是否定义代表系统主题颜色的常量?

python代码错误(linux,网络抓取)奇怪的错误

Linux Shell 脚本,用于提取已发送电子邮件的数据并将邮件发回给管理员