diff options
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 |