aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcolors/ansi.sh19
-rwxr-xr-xcolors/demo.sh19
2 files changed, 23 insertions, 15 deletions
diff --git a/colors/ansi.sh b/colors/ansi.sh
new file mode 100755
index 0000000..e0334f9
--- /dev/null
+++ b/colors/ansi.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+# utilities for outputting ansi escape codes
+# including ansi colors and truecolor
+
+# low level output coding
+acol() { printf '%b[%dm' '\033' "$@"; }
+pcol() { printf '%b[%d;2;%d;%d;%dm' '\033' "$1" "$2" "$3" "$4"; }
+pcolx() { pcol "$1" 0x"$2" 0x"$3" 0x"$4"; }
+fg() { pcol 38 "$@"; }
+fgx() { pcolx 38 "$@"; }
+bg() { pcol 48 "$@"; }
+bgx() { pcolx 48 "$@"; }
+bold() { acol 1 "$@"; }
+reset() { acol 0; }
+
+# logical input processing
+colsep() { echo $* | fold -w2; }
+fgc() { fgx $(colsep $1); }
+bgc() { bgx $(colsep $1); }
diff --git a/colors/demo.sh b/colors/demo.sh
index 19278eb..4bb9f70 100755
--- a/colors/demo.sh
+++ b/colors/demo.sh
@@ -1,25 +1,11 @@
#!/bin/sh
+. ./ansi.sh
# demo as in starlight.png
# requires truecolor
# for every color:
# color, bright color | bold color, bright bold color
-# low level output coding
-pcol() { printf '%b[%d;2;%d;%d;%dm' '\033' "$1" "$2" "$3" "$4"; }
-pcolx() { pcol "$1" 0x"$2" 0x"$3" 0x"$4"; }
-fg() { pcol 38 "$@"; }
-fgx() { pcolx 38 "$@"; }
-bg() { pcol 48 "$@"; }
-bgx() { pcolx 48 "$@"; }
-bold() { printf '%b[1m' '\033'; }
-reset() { printf '%b[0m' '\033'; }
-
-# logical input processing
-colsep() { echo $* | fold -w2; }
-fgc() { fgx $(colsep $1); }
-bgc() { bgx $(colsep $1); }
-
# loop
demopart() {
eval fgc '$'"$1"
@@ -30,6 +16,7 @@ demopart() {
# 9 is the length of brmagenta
printf '%-9s' "$1"
reset
+ bgc $background
}
demo() {
@@ -40,4 +27,6 @@ demo() {
}
. ./colors.sh
+bgc $background
demo
+reset