I'd like to know if there is any way to determine a terminal's background color ?
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.
“tput setaf” sets foreground color, “tput setab” sets background color, and “tput sgr0” resets all the settings to terminal default. There are 8 standard colors encoded in numbers from 0 to 7 (in order: black, red, green, yellow, blue, magenta, cyan, white).
Answer. Press "Windows," type "Paint" and click "Paint" to launch the Paintprogram. ... Click the image's background colorand note that Paint changes the color of the "Color 1" square to match that color. ... Move to the Colors section and click the color you'd like to use to replace the existing background color.
There's an xterm control sequence for this:
\e]11;?\a
(\e
and \a
are the ESC and BEL characters, respectively.)
Xterm-compatible terminals should reply with the same sequence, with the question mark replaced by an X11 color name, e.g. rgb:0000/0000/0000
for black.
I've came up with the following:
#!/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/]\+$//'
Source/Repo/Gist: https://gist.github.com/blueyed/c8470c2aad3381c33ea3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With