bashcols: add background support

This commit is contained in:
2021-07-28 00:23:28 +02:00
parent cfcb399d20
commit 4a96947caf
2 changed files with 21 additions and 5 deletions

View File

@@ -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

View File

@@ -1,4 +1,4 @@
#!/usr/bin/bash
#!/hint/bash
declare -A __params
@@ -20,3 +20,4 @@ function set_param {
}
_bashlib_bashparam=1