本文介绍了如何确定终端的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有任何方法可以确定终端的背景颜色?

I'd like to know if there is any way to determine a terminal's background color ?

就我而言,使用 gnome-terminal.
这可能很重要,因为完全取决于终端应用程序来绘制其窗口的背景,甚至可能不是纯色.

In my case, using gnome-terminal.
It might matter, since it's entirety up to the terminal application to draw the background of its windows, which may even be something else than a plain color.

推荐答案

我想出了以下几点:

#!/bin/sh
#
# Query a property from the terminal, e.g. background color.
#
# XTerm Operating System Commands
#     "ESC ] Ps;Pt ST"

oldstty=$(stty -g)

# What to query?
# 11: text background
Ps=${1:-11}

stty raw -echo min 0 time 0
# stty raw -echo min 0 time 1
printf "\033]$Ps;?\033\\"
# xterm needs the sleep (or "time 1", but that is 1/10th second).
sleep 0.00000001
read -r answer
# echo $answer | cat -A
result=${answer#*;}
stty $oldstty
# Remove escape at the end.
echo $result | sed 's/[^rgb:0-9a-f/]\+$//'

来源/Repo/Gist:https://gist.github.com/blueyed/c8470c2aad3381c33ea3

Source/Repo/Gist: https://gist.github.com/blueyed/c8470c2aad3381c33ea3

这篇关于如何确定终端的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 08:49