Skip to content

Instantly share code, notes, and snippets.

@rene-d
Created January 16, 2024 06:13
Show Gist options
  • Save rene-d/543e084f99838059b8777912a7cb3777 to your computer and use it in GitHub Desktop.
Save rene-d/543e084f99838059b8777912a7cb3777 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# https://en.wikipedia.org/wiki/ANSI_escape_code
print_colors()
{
# Print column headers.
printf "%-4s " '' ${bgs[@]}
echo
# Print rows.
for bold in ${bolds[@]}; do
for fg in ${fgs[@]}; do
# Print row header
printf "%s;%s " $bold $fg
# Print cells.
for bg in ${bgs[@]}; do
# Print cell.
printf "\e[%s;%s;%sm%s\e[0m " $bold $fg $bg " text "
done
echo
done
done
}
# Print standard colors.
bolds=( 0 1 )
fgs=( 3{0..7} )
bgs=( 4{0..7} )
# print_colors
# Print vivid colors.
bolds=( 0 1 ) # Bold vivid is the same as bold normal.
fgs=( 9{0..7} )
bgs=( 10{0..7} )
# print_colors
python3 <<'EOF'
print(r"256-color mode — foreground: \033[38;5;{n}m background: \033[48;5;{n}m")
print(" ".join(f"\033[97;48;5;{n}m {n:2} \033[0m" for n in range(0,8))+"\033[0m"+
" "+
" ".join(f"\033[30;48;5;{n}m {n:2} \033[0m" for n in range(8,16))+"\033[0m")
for i in range(16,232,18):
f="30" if ((i-16)//18)%2==1 else "97"
print("".join(f"\033[{f};48:5:{n}m {n:3} \033[0m" for n in range(i,i+18)))
print(r"RGB - foreground: \033[38;2;{r};{g};{b}m background: \033[48;2;{r};{g};{b}m")
EOF
echo -e "0 \033[0mreset, normal\033[0m"
echo -e "1 \033[1mbold\033[0m"
echo -e "2 \033[2mfaint\033[0m"
echo -e "3 \033[3mitalic\033[0m"
echo -e "4 \033[4munderline\033[0m"
echo -e "5 \033[5mslow blink\033[0m"
echo -e "6 \033[6mrapid blink\033[0m"
echo -e "7 \033[7mreverse video\033[0m"
echo -e "8 \033[8mconceal\033[0m (conceal)"
echo -e "9 \033[9mcrossed-out\033[0m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment