aboutsummaryrefslogtreecommitdiff
path: root/pb_colour
diff options
context:
space:
mode:
Diffstat (limited to 'pb_colour')
-rwxr-xr-xpb_colour61
1 files changed, 38 insertions, 23 deletions
diff --git a/pb_colour b/pb_colour
index 0012205..5fe6240 100755
--- a/pb_colour
+++ b/pb_colour
@@ -1,49 +1,64 @@
#!/usr/bin/env bash
-#--- 256 colour functions
-# requires pb_number
+#--- 88/256 colour functions
# usage:
# source ./pb
# printf %b "$(pb_bg 196)$(pb_fg 254) RED $(pb_nc)\n"
-pb_nc() {
+pb_ctest() {
- if [ -z "$TERM" ] || (($(tput colors) != 256)); then
- return 1
+ if [ -z "$TERM" ] ; then
+ return 0
+ fi
+
+ case $1 in '' | *[!0-9]* ) return 0;; esac
+
+ local x
+ x=$(tput colors)
+
+ if [ -z "$1" ] || (("$1" > "$x")) ; then
+ return 0
fi
- printf '\033[0;0m';
- return 0
+ return 1
}
-pb_fg() {
+pb_terminfo() {
+ local x
+ x=$(tput colors)
+ echo "TERM = $TERM : $x colours supported"
+}
+
+pb_nc() {
- if [ -z "$TERM" ] || (($(tput colors) != 256)); then
+ if eval pb_ctest ; then
+ printf '\033[0;0m'
+ return 0
+ else
return 1
- fi
+ fi
+}
- if [ -z "$1" ] || (("$1" > 255)) || ! pb_isuint "$1" ; then
+pb_fg() {
+
+ if eval pb_ctest ; then
+ printf %s "\033[38;5;$1m"
+ return 0
+ else
return 1
fi
- printf %s "\033[38;5;$1m"
- return 0
-
}
pb_bg() {
- if [ -z "$TERM" ] || (($(tput colors) != 256)); then
+ if eval pb_ctest ; then
+ printf %s "\033[48;5;$1m"
+ return 0
+ else
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() {
@@ -65,7 +80,7 @@ pb_ef() {
return 0
;;
- "underscore")
+ "underline")
printf %s "\033[4m"
return 0
;;