-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbase16test.sh
More file actions
executable file
·54 lines (46 loc) · 1.6 KB
/
base16test.sh
File metadata and controls
executable file
·54 lines (46 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
set -Eeufo pipefail
trap 'echo >&2 "$0:$LINENO [$?]: $BASH_COMMAND"' ERR
readonly w=12
ansi_fg() {
if [[ "$1" -lt 8 ]]; then
echo $(( 30 + $1 ))
elif [[ "$1" -lt 16 ]]; then
echo $(( 90 + $1 - 8 ))
else
echo "38;5;$1"
fi
}
ansi_bg() {
if [[ "$1" -lt 8 ]]; then
echo $(( 40 + $1 ))
elif [[ "$1" -lt 16 ]]; then
echo $(( 100 + $1 - 8 ))
else
echo "48;5;$1"
fi
}
show() {
b16_hex=$1
shift
fg_fg=$(ansi_fg "$2")
fg_bg=
[[ $# -ge 3 ]] && fg_bg=";$(ansi_bg "$3")"
bg_bg=$(ansi_bg "$2")
bg_fg=
[[ $# -ge 4 ]] && bg_fg=";$(ansi_fg "$4")"
printf "\x1b[90m(%02d:%s)\x1b[0m " "$2" "$b16_hex"
printf "\x1b[${fg_fg}${fg_bg}m %-${w}s \x1b[0m " "$1"
printf "\x1b[${bg_bg}${bg_fg}m %-${w}s \x1b[0m" "$1"
}
gap() {
printf " "
}
show "0" "background" 0 18 7; gap; show "3" "comment" 8 0 0; gap; show "9" "directive" 16 0 0; echo
show "8" "error/-" 1 0 0 ; gap; show "8" "error/-" 9 0 0; gap; show "f" "special" 17 0 0; echo
show "b" "keyword/+" 2 0 0 ; gap; show "b" "keyword/+" 10 0 0; gap; show "1" "highlight" 18 0 7; echo
show "a" "identifier" 3 0 0 ; gap; show "a" "identifier" 11 0 0; gap; show "2" "selection" 19 0 7; echo
show "d" "function" 4 0 0 ; gap; show "d" "function" 12 0 0; gap; show "4" "subtle" 20 0 0; echo
show "e" "type/other" 5 0 0 ; gap; show "e" "type/other" 13 0 0; gap; show "6" "emphasis" 21 0 0; echo
show "c" "constant" 6 0 0 ; gap; show "c" "constant" 14 0 0; gap; echo
show "5" "foreground" 7 0 0 ; gap; show "7" "inverse bg" 15 0 0; gap; echo