diff options
author | Philip Wittamore <philip@wittamore.com> | 2025-05-17 15:37:08 +0200 |
---|---|---|
committer | Philip Wittamore <philip@wittamore.com> | 2025-05-17 15:37:08 +0200 |
commit | 1a81432a550f5f4a0d638a6ef22fe6d922f71326 (patch) | |
tree | 3c315836ffd0fa659847f6c47a064cca9dfbc7c7 /pb_colour | |
parent | 7151df8f8cd23993c67e6bfa7eb7d4ced7870f06 (diff) | |
download | bashlib-1a81432a550f5f4a0d638a6ef22fe6d922f71326.tar.gz bashlib-1a81432a550f5f4a0d638a6ef22fe6d922f71326.tar.bz2 bashlib-1a81432a550f5f4a0d638a6ef22fe6d922f71326.zip |
update
Diffstat (limited to 'pb_colour')
-rwxr-xr-x | pb_colour | 85 |
1 files changed, 69 insertions, 16 deletions
@@ -3,45 +3,98 @@ #--- 256 colour functions # requires pb_number # usage: -# source ./pb -# printf %b "$(pb_bg 196)$(pb_fg 254) RED $(pb_nc)\n" +# source ./pb +# printf %b "$(pb_bg 196)$(pb_fg 254) RED $(pb_nc)\n" pb_nc() { + + if [ -z "$TERM" ] || (($(tput colors) != 256)); then + return 1 + fi + printf '\033[0;0m'; - exit; + return 0 } pb_fg() { - if [ -z "$1" ] || ! pb_isuint "$1" ; then + if [ -z "$TERM" ] || (($(tput colors) != 256)); then return 1 fi - - local x - x=$(tput colors) - if (("$1" < 256)) && (("$x" > 255)); then - printf %s "\033[38;5;$1m" + if [ -z "$1" ] || (("$1" > 255)) || ! pb_isuint "$1" ; then + return 1 fi + printf %s "\033[38;5;$1m" return 0 } pb_bg() { - if [ -z "$1" ] || ! pb_isuint "$1" ; then + if [ -z "$TERM" ] || (($(tput colors) != 256)); then return 1 fi - local x - x=$(tput colors) - - if (("$1" < 256)) && (("$x" > 255)); then - printf %s "\033[48;5;$1m" + if [ -z "$1" ] || (("$1" > 255)) || ! pb_isuint "$1" ; then + return 1 fi + printf %s "\033[48;5;$1m" return 0 + } - + +pb_ef() { + + case $1 in + + "bold") + printf %s "\033[1m" + return 0 + ;; + + "dim") + printf %s "\033[2m" + return 0 + ;; + + "italic") + printf %s "\033[3m" + return 0 + ;; + + "underscore") + printf %s "\033[4m" + return 0 + ;; + + "blink") + printf %s "\033[5m" + return 0 + ;; + + "reverse") + printf %s "\033[7m" + return 0 + ;; + + "hidden") + printf %s "\033[8m" + return 0 + ;; + + "strikethrough") + printf %s "\033[9m" + return 0 + ;; + + *) + return 1 + ;; +esac + +} + # end 256 colour functions |