bin: make color index more readable
Use white text for darker colors and black text for lighter colors. Also, now the `colors256` script became redundant, so it's removed.
This commit is contained in:
parent
82979b2153
commit
d7b6938a74
2 changed files with 18 additions and 42 deletions
24
bin/colors
24
bin/colors
|
@ -22,7 +22,6 @@ bg_256() { printf '\e[48;5;%sm' "$1"; }
|
|||
fg_rgb() { printf '\e[38;2;%s;%s;%sm' "$1" "$2" "$3"; }
|
||||
bg_rgb() { printf '\e[48;2;%s;%s;%sm' "$1" "$2" "$3"; }
|
||||
|
||||
|
||||
rgb_from_hex() {
|
||||
echo "$1" | awk '{
|
||||
r="0x"substr($0, 2, 2)
|
||||
|
@ -41,41 +40,53 @@ reset() { printf '\e[0m'; }
|
|||
fg_reset() { printf '\e[39m'; }
|
||||
bg_reset() { printf '\e[49m'; }
|
||||
|
||||
indent() { printf ' '; }
|
||||
indent() { printf ' '; }
|
||||
newline() { printf '%b\n' '\e[0m'; }
|
||||
|
||||
|
||||
indexed_16() {
|
||||
echo "16 indexed colors:"
|
||||
|
||||
black=0
|
||||
white=15
|
||||
|
||||
for i in 0 1; do
|
||||
[ "$i" -eq 0 ] && fg="$white" || fg="$black"
|
||||
indent
|
||||
for j in $(seq 0 7); do
|
||||
n=$((8*i + j))
|
||||
bg_16 "$n"; fg_16 0; printf ' %2d ' "$n"
|
||||
bg_16 "$n"; fg_16 "$fg"; printf ' %2d ' "$n"
|
||||
done
|
||||
newline
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
indexed_256() {
|
||||
echo "256 indexed colors:"
|
||||
|
||||
black=232
|
||||
white=255
|
||||
|
||||
# 16 standard colors
|
||||
for i in 0 1; do
|
||||
[ "$i" -eq 0 ] && fg="$white" || fg="$black"
|
||||
indent
|
||||
for j in $(seq 0 7); do
|
||||
n=$((8*i + j))
|
||||
bg_256 "$n"; fg_16 0; printf ' %3d ' "$n"
|
||||
bg_256 "$n"; fg_256 "$fg"; printf ' %3d ' "$n"
|
||||
done
|
||||
newline
|
||||
done
|
||||
|
||||
# 216 colors
|
||||
for i in 0 18; do
|
||||
[ "$i" -eq 0 ] && fg="$white" || fg="$black"
|
||||
for j in $(seq 0 5); do
|
||||
indent
|
||||
for k in $(seq $i $(( i + 17 ))); do
|
||||
n=$((16 + 36*j + k))
|
||||
bg_256 "$n"; fg_16 0; printf '%3d ' "$n"
|
||||
bg_256 "$n"; fg_256 "$fg"; printf '%3d ' "$n"
|
||||
done
|
||||
newline
|
||||
done
|
||||
|
@ -84,9 +95,10 @@ indexed_256() {
|
|||
# 24 grayscale colors
|
||||
for i in 0 1; do
|
||||
indent
|
||||
[ "$i" -eq 0 ] && fg="$white" || fg="$black"
|
||||
for j in $(seq 0 11); do
|
||||
n=$((232 + 12*i + j))
|
||||
bg_256 "$n"; fg_16 0; printf ' %3d ' "$n"
|
||||
bg_256 "$n"; fg_256 "$fg"; printf ' %3d ' "$n"
|
||||
done
|
||||
newline
|
||||
done
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Print all 256 colors
|
||||
|
||||
black="\e[38;5;232m"
|
||||
white="\e[38;5;255m"
|
||||
|
||||
# 16 standard colors -> 0...15
|
||||
|
||||
for i in $(seq 0 15); do
|
||||
[ $i -lt 8 ] && fg="$white" || fg="$black"
|
||||
bg="\e[48;5;${i}m"
|
||||
printf '%b%b %2d ' "$fg" "$bg" "$i"
|
||||
done
|
||||
printf '%b\n' '\e[0m'
|
||||
|
||||
# 216 colors -> 16...231
|
||||
|
||||
for i in $(seq 0 5); do
|
||||
for j in $(seq 0 35); do
|
||||
n=$(( 16 + 36 * i + j ))
|
||||
[ $j -lt 18 ] && fg="$white" || fg="$black"
|
||||
bg="\e[48;5;${n}m"
|
||||
printf '%b%b%4d' "$fg" "$bg" "$n"
|
||||
done
|
||||
printf '%b\n' '\e[0m'
|
||||
done
|
||||
|
||||
# 24 grayscale colors -> 232...255
|
||||
|
||||
for i in $(seq 0 23); do
|
||||
n=$(( 232 + i ))
|
||||
[ $i -lt 12 ] && fg="$white" || fg="$black"
|
||||
bg="\e[48;5;${n}m"
|
||||
printf '%b%b%4d ' "$fg" "$bg" "$n"
|
||||
done
|
||||
printf '%b\n' '\e[0m'
|
Loading…
Add table
Reference in a new issue