Closed excalibur1234 closed 7 years ago
i have just tried this using the following definitions of colors:
# Text attributes variables for all sorts of terminals (originally taken from http://mywiki.wooledge.org/BashFAQ/037)
[[ -t 2 ]] && {
dim=$( tput dim || tput mh ) # Start dim (this is default behavior)
bold=$( tput bold || tput md ) # Start bold
stout=$( tput smso || tput so ) # Start stand-out
estout=$( tput rmso || tput se ) # End stand-out
under=$( tput smul || tput us ) # Start underline
eunder=$( tput rmul || tput ue ) # End underline
italic=$( tput sitm || tput ZH ) # Start italic
eitalic=$( tput ritm || tput ZR ) # End italic
reset=$( tput sgr0 || tput me ) # Reset all attributes
[[ $TERM != *-m ]] && {
red=$( tput setaf 1 || tput AF 1 ) # set color of foreground (i.e. text)
green=$( tput setaf 2 || tput AF 2 ) # set color of foreground (i.e. text)
yellow=$( tput setaf 3 || tput AF 3 ) # set color of foreground (i.e. text)
blue=$( tput setaf 4 || tput AF 4 ) # set color of foreground (i.e. text)
magenta=$( tput setaf 5 || tput AF 5 ) # set color of foreground (i.e. text)
cyan=$( tput setaf 6 || tput AF 6 ) # set color of foreground (i.e. text)
redB=$( tput setab 1 || tput AB 1 ) # set color of background
greenB=$( tput setab 2 || tput AB 2 ) # set color of background
yellowB=$( tput setab 3 || tput AB 3 ) # set color of background
blueB=$( tput setab 4 || tput AB 4 ) # set color of background
magentaB=$( tput setab 5 || tput AB 5 ) # set color of background
cyanB=$( tput setab 6 || tput AB 6 ) # set color of background
}
black=$( tput setaf 0 || tput AF 0 ) # set color of foreground (i.e. text)
white=$( tput setaf 7 || tput AF 7 ) # set color of foreground (i.e. text)
blackB=$( tput setab 0 || tput AB 0 ) # set color of background
whiteB=$( tput setab 7 || tput AB 7 ) # set color of background
default=$( tput op )
} 3>&2 2>/dev/null ||:
# 3>&2 2>/dev/null ||: this code silences all errors
but i have difficulties when text color of other applications (such as expac, awk, less, etc.) have to be changed. in most cases, they do not support executing variables such as ${red}
and print that code instead of red colored text. but in most cases, these applications are able to do ANSI escapes!
if anybody knows a solution to that problem (which works for all/most applications), please reopen this issue.
i want pacui's bash code to be as easy to read as possible. using ANSI escape sequences (which do not always work!) is quite bad for code readability.
the bash code readability could be improved using a different method for changing terminal text colors (while using a more robust and compatible method at the same time) as described in the manjaro forum here: https://forum.manjaro.org/t/get-kernel-version-from-commandline/28937/11