diff --git a/bashcols b/bashcols index fb0adc1..8dddbfe 100755 --- a/bashcols +++ b/bashcols @@ -2,6 +2,15 @@ reset_esc='\e[0m' +# bgcol +# 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 + diff --git a/bashparam b/bashparam index 4aabd61..41a4e08 100644 --- a/bashparam +++ b/bashparam @@ -1,4 +1,4 @@ -#!/usr/bin/bash +#!/hint/bash declare -A __params @@ -20,3 +20,4 @@ function set_param { } +_bashlib_bashparam=1