我正在构建node.js CLI,希望显示ASCII艺术徽标。但根据终端的背景颜色,我想更改我的徽标的颜色。有可能这样做吗?如果是怎么做的?谢谢您。
最佳答案
你要找的是:
https://stackoverflow.com/a/30540928/5110035
在这里:
http://www.linuxquestions.org/questions/programming-9/%2Ash-script-to-detect-default-background-color-of-a-terminal-731196/
#!/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/]\+$//'
关于linux - 是否可以确定linux机器中终端的背景色?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43931304/