summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChloe Kudryavtsev <toast@toast.cafe>2022-07-31 13:41:03 -0400
committerChloe Kudryavtsev <toast@toast.cafe>2022-07-31 13:41:03 -0400
commite4cbecd3f655ef3f69a9a962e22e346581a83f25 (patch)
treeb13e70c819b6c301dc6fe8bcc87b6b04fe07ffc5
parent047bad473a742a2e28b4c79af1f0cf4e338a62a4 (diff)
create a demo scriptv2
-rwxr-xr-xcolors/demo.sh43
1 files changed, 43 insertions, 0 deletions
diff --git a/colors/demo.sh b/colors/demo.sh
new file mode 100755
index 0000000..19278eb
--- /dev/null
+++ b/colors/demo.sh
@@ -0,0 +1,43 @@
+#!/bin/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"
+ if [ $# -gt 1 ]; then
+ bold
+ printf 'bold '
+ fi
+ # 9 is the length of brmagenta
+ printf '%-9s' "$1"
+ reset
+}
+
+demo() {
+ for col in black red green yellow blue magenta cyan white; do
+ printf '%b %b | %b %b\n' "$(demopart $col)" "$(demopart br$col)" \
+ "$(demopart $col bold)" "$(demopart br$col bold)"
+ done
+}
+
+. ./colors.sh
+demo