暂时为Linux终端前景和背景文本着色

时间:2017-06-26 23:00:46

标签: linux colors terminal

如何暂时设置Linux终端的颜色?我希望添加一个脚本,一个颜色设置,以便我记得几分钟后运行合作伙伴脚本。颜色更改将在一个脚本中设置,在另一个脚本中删除,并将作为一个明显的提示给我。

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

我的终端是GNOME Terminal 2.31.3

1 个答案:

答案 0 :(得分:0)

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

  • “ANSI颜色”逃脱(对你来说没用,因为许多程序会重置那些)
  • 使用非ANSI 动态颜色更改文本前景和背景(重置者很少见)
  • 更改调色板(同样,重置者很少见)

后两者记录于XTerm Control Sequences Operating System Commands 部分:

OSC Ps ; Pt BEL
OSC Ps ; Pt ST

给出控制序列的形式,例如 escape ] PS ; 的Pt BEL

动态颜色在此描述:

      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.