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