Skip to content

Instantly share code, notes, and snippets.

@rene-d
Last active March 24, 2024 12:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rene-d/b5370efb61db005d7de0ad47959cd46c to your computer and use it in GitHub Desktop.
Save rene-d/b5370efb61db005d7de0ad47959cd46c to your computer and use it in GitHub Desktop.
Show ANSI color sequences in a terminal
#!/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
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