I am building a node.js CLI and I want to display an ASCII art logo. But depending on the background color of the terminal, I want to change the color of my logo. Is it possible to do this? If yes how? Thank you.
Asked
Active
Viewed 1,284 times
1 Answers
2
What you are looking for is here:
AND here:
#!/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/]\+$//'

Community
- 1
- 1

MichaelMMeskhi
- 659
- 8
- 26
-
2Please consider including the solution itself in your answer (as per SO guidelines) or flag the question as duplicate if you think it is. – werediver May 12 '17 at 07:34