如何让在bash当前终端颜色对 [英] how to get current terminal color pair in bash

查看:239
本文介绍了如何让在bash当前终端颜色对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查询和存储在BASH例如当前终端颜色对:

 #!/斌/庆典#some AN​​SI颜色转义序列
红色=\\ 033 [0;31米
GRN =\\ 033 [0;32米
蓝光=\\ 033 [0;34米DEF =\\ 033 [0;00米#默认回声-e更改为$ {}红冲至$ {DEF}默认为$ {}蓝光蓝色的。#现在存储当前的颜色(这恰好是蓝色的),例如:CUR = ????回声-e更改为$ {} GRN绿色,回到了我之前$ {过} CUR
回声-e这将是蓝色的,如果变量Cur包含例如为:0;34米。
回声-e回到默认$ {DEF}
退出0

这是逃避我的答案是如何捕捉当前颜色

  CUR = ????


解决方案

问题是关于当前的颜色的,而不是光标的位置

两者都是非标准(尽管后者,光标位置报告是由任何具有合法索赔VT100模拟器执行)。

不过,xterm中实现了一组被称为的动态颜色的,其中preDATE的ANSI颜色功能转义序列。这些设置工作颜色,包括文本前景和背景。我修改这 2002 以允许应用程序与发送的顺序?而不是一个彩色告诉xterm中以返回颜色值,如,

  OSC 1 1? ST

使用的XTerm控制序列给出

符号

I would like to query and store the current terminal color pair in BASH e.g.:

#!/bin/bash

#some ANSI colour escape sequences
red="\033[0;31m"
grn="\033[0;32m"
blu="\033[0;34m"

def="\033[0;00m" # default

echo -e "Change to ${red} red to ${def} default to ${blu} blue."

# now store the current color (which happens to be blue) e.g.:

cur=????

echo -e "Change to ${grn} green and back to what I had before ${cur}"
echo -e "This would be in blue if variable cur contained e.g.: 0;34m."
echo -e "Back to default${def}"
exit 0

The answer that eludes me is how to capture the current color

cur=????

解决方案

The question was about the current color, not the cursor position.

Both are "nonstandard" (though the latter, cursor position report is implemented by anything which has a valid claim to "VT100 emulator").

However, xterm implements a set of escape sequences referred to as dynamic colors, which predate the ANSI color functionality. Those set the working colors including text foreground and background. I modified this in 2002 to allow an application to send the sequence with a "?" rather than a color to tell xterm to return the color value, e.g.,

OSC 1 1 ? ST

using the notation given in XTerm Control Sequences

这篇关于如何让在bash当前终端颜色对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆