以程式方式存取目前 xterm 顏色

以程式方式存取目前 xterm 顏色

在下面的線程中

以程式方式存取目前的 xterm 背景顏色?

Alex North-Keys 提供了一個有用的 bash 腳本,它會傳回目前 xterm 的背景顏色。我想使用此腳本的輸出在更改後(例如,登入遠端系統後)重設背景顏色。

例如,他的腳本可能會傳回類似的內容

rgb:e0e0/ffff/ffff

不幸的是我用來設定背景顏色的轉義序列

echo -ne "\033]11;!*\007"

似乎只有當我給它一種命名顏色(例如像牙色)時才有效。

有沒有辦法修改這個指令,以便它將像 e0e0/ffff/ffff 這樣的參數作為參數?

謝謝!

答案1

複製並貼上到 Emacs 或 Vim 中。刪除 #?其中一行的開頭。該行是包含“^[”的 sed 語句。這是 2 個字元的文本,需要用 1 個字元 ESC (^[) 替換。在 Vim 中,輸入 C+v ESC。在 Emacs 中,輸入 C+q ESC。

# filename: OSC_11_Pt_ST.sh
echo -e "\e[7m Reverse the FG/BG colors on this terminal as a visual aid. \e[0m"
y='\' # Add to end of $result (\e]11;rgb:??/??/??\e) to complete ST terminating
# OSC sequence.
# Query the background color using ST (string terminate) vice BEL (^G).Replies
# with a control sequence in RGB specification format using same terminator as
# the query (in this case, ST): "^[]11;rgb:4242/2525/5353^[\" (see file
# ctlseqs.txt). "^[" is ESC (\e); "^[]" is OSC; "^[\" is ST.
echo -en "\e]11;?\e\\"
# Read line from the standard input & assign to variable CSPEC (color specifi-
# cation as indicated by ctlseqs.txt). Do not echo input coming from terminal
# (-s); raw (-r); delimiter \ (-d).
read -s -r -d '\' CSPEC
#?????result=$(echo $CSPEC | sed 's/^[/\\\e/g')
# Set BG to "WebGrey" (decimal 128 128 128).
echo 'Set BG to "Webgrey" in 5 seconds...'
sleep 5
echo -en "\e]11;rgb:80/80/80\007"
echo "Return to original BG ($result$y) in 5 seconds..."
sleep 5
echo -en "$result$y"

相關內容