#!/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