diff options
author | Philip Wittamore <philip@wittamore.com> | 2025-05-18 19:01:12 +0200 |
---|---|---|
committer | Philip Wittamore <philip@wittamore.com> | 2025-05-18 19:01:12 +0200 |
commit | 36dfcdfe1c26f38e66ad4c3b086cc5a0d388bd8f (patch) | |
tree | a6d1c37ee73219ec45e8bf423781a12f7a438f8b /pb_colour | |
parent | 61026973046b4afa6b57d01f33df7910695f3300 (diff) | |
download | bashlib-36dfcdfe1c26f38e66ad4c3b086cc5a0d388bd8f.tar.gz bashlib-36dfcdfe1c26f38e66ad4c3b086cc5a0d388bd8f.tar.bz2 bashlib-36dfcdfe1c26f38e66ad4c3b086cc5a0d388bd8f.zip |
update
Diffstat (limited to 'pb_colour')
-rwxr-xr-x | pb_colour | 24 |
1 files changed, 11 insertions, 13 deletions
@@ -1,6 +1,8 @@ #!/usr/bin/env bash -#--- 88/256 colour functions +#--- colour functions +# tested on 16/88/256/truecolor TERM definitions +# limited to 256 colours # usage: # source ./pb # printf %b "$(pb_bg 196)$(pb_fg 254) RED $(pb_nc)\n" @@ -8,19 +10,19 @@ pb_ctest() { if [ -z "$TERM" ] ; then - return 0 + return 1 fi - case $1 in '' | *[!0-9]* ) return 0;; esac + case $1 in '' | *[!0-9]* ) return 1;; esac local x x=$(tput colors) if [ -z "$1" ] || (("$1" > "$x")) ; then - return 0 + return 1 fi - - return 1 + + return 0 } pb_terminfo() { @@ -31,17 +33,13 @@ pb_terminfo() { pb_nc() { - if eval pb_ctest ; then printf '\033[0;0m' - return 0 - else - return 1 - fi + } pb_fg() { - if eval pb_ctest ; then + if pb_ctest $1; then printf %s "\033[38;5;$1m" return 0 else @@ -52,7 +50,7 @@ pb_fg() { pb_bg() { - if eval pb_ctest ; then + if pb_ctest $1; then printf %s "\033[48;5;$1m" return 0 else |