diff options
author | Philip Wittamore <philip@wittamore.com> | 2025-05-17 09:04:10 +0200 |
---|---|---|
committer | Philip Wittamore <philip@wittamore.com> | 2025-05-17 09:04:10 +0200 |
commit | 6c1ff8fe7947266e4c8e47a55f73542ce88b6fe9 (patch) | |
tree | 7c505f5dcfcf93168079c772656292433d8bf29e /pb_colour | |
parent | de9249cc1b768687daa2a41e6a05455759890129 (diff) | |
download | bashlib-6c1ff8fe7947266e4c8e47a55f73542ce88b6fe9.tar.gz bashlib-6c1ff8fe7947266e4c8e47a55f73542ce88b6fe9.tar.bz2 bashlib-6c1ff8fe7947266e4c8e47a55f73542ce88b6fe9.zip |
update
Diffstat (limited to 'pb_colour')
-rwxr-xr-x | pb_colour | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/pb_colour b/pb_colour new file mode 100755 index 0000000..89f6354 --- /dev/null +++ b/pb_colour @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +#--- 256 colour functions +# requires pb_number +# usage: +# source ./pb +# printf %b "$(pb_bg 196)$(pb_fg 254) RED $(pb_nc)\n" + +pb_nc() { + printf '\033[0;0m'; + exit; +} + +pb_fg() { + + if [ -z "$1" ] || ! pb_isuint "$1" ; then + return 1 + fi + + local x + x=$(tput colors) + + if (("$1" < 256)) && (("$x" > 255)); then + printf %s "\033[38;5;$1m" + fi + + return 0 + +} + +pb_bg() { + + if [ -z "$1" ] || ! pb_isuint "$1" ; then + return 1 + fi + + local x + x=$(tput colors) + + if (("$1" < 256)) && (("$x" > 255)); then + printf %s "\033[48;5;$1m" + fi + + return 0 +} + +# end 256 colour functions |