bashcols: add background support
This commit is contained in:
23
bashcols
23
bashcols
@@ -2,6 +2,15 @@
|
||||
|
||||
reset_esc='\e[0m'
|
||||
|
||||
# bgcol <color> <command>
|
||||
# Use the specified color as background
|
||||
function bgcol {
|
||||
_bashcols_bgcol_conditionalsuffix=bg
|
||||
"$@"
|
||||
_bashcols_bgcol_conditionalsuffix=
|
||||
}
|
||||
|
||||
|
||||
# applies the given color id, executes the command, then resets the color
|
||||
function colout() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
@@ -11,7 +20,11 @@ function colout() {
|
||||
|
||||
local color="$1"
|
||||
shift
|
||||
tput setaf "$color"
|
||||
if [[ -z $_bashcols_bgcol_conditionalsuffix ]]; then
|
||||
tput setaf "$color"
|
||||
else
|
||||
tput setab "$color"
|
||||
fi
|
||||
"$@"
|
||||
tput sgr0
|
||||
}
|
||||
@@ -39,8 +52,8 @@ function dispcollist() {
|
||||
local idx=0
|
||||
for colid in {1..256}; do
|
||||
colout $colid printf "%3s " $colid
|
||||
idx=$(($idx+1))
|
||||
if [[ $(($idx % $width)) -eq 0 ]]; then
|
||||
let "idx++" || true
|
||||
if ! (( $idx % $width )); then
|
||||
printf "\n"
|
||||
fi
|
||||
done
|
||||
@@ -49,7 +62,7 @@ function dispcollist() {
|
||||
function colthis {
|
||||
local name="$1"
|
||||
shift
|
||||
eval "printf \"%s\" \"\${${name}_esc}$@$reset_esc\""
|
||||
eval "printf \"%s\" \"\${${name}_esc${_bashcols_bgcol_conditionalsuffix}}$@$reset_esc\""
|
||||
}
|
||||
|
||||
# default colors
|
||||
@@ -70,3 +83,5 @@ defcol cyanl 14
|
||||
defcol whitel 15
|
||||
defcol black 16
|
||||
|
||||
_bashlib_bashcols=1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user