#!/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() { if [ -z "$TERM" ] || (($(tput colors) != 256)); then return 1 fi printf '\033[0;0m'; return 0 } pb_fg() { if [ -z "$TERM" ] || (($(tput colors) != 256)); then return 1 fi if [ -z "$1" ] || (("$1" > 255)) || ! pb_isuint "$1" ; then return 1 fi printf %s "\033[38;5;$1m" return 0 } pb_bg() { if [ -z "$TERM" ] || (($(tput colors) != 256)); then return 1 fi 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