Skip to content

Instantly share code, notes, and snippets.

@rene-d
Last active May 23, 2020 10:19
Show Gist options
  • Save rene-d/81c0cd9103e3a0996c943add688470e5 to your computer and use it in GitHub Desktop.
Save rene-d/81c0cd9103e3a0996c943add688470e5 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.
echo -ne "\033[0m"
printf "%-4s " '' ${bgs[@]}
echo
# Print rows.
for bold in ${bolds[@]}; do
for fg in ${fgs[@]}; do
# Print row header
printf "\033[0m%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 -e "\033[0m"
done
done
}
# Print standard colors.
bolds=( 0 )
fgs=( {30..37} {90..97} )
bgs=( {40..47} 10{0..7} )
print_colors
# Print vivid colors.
bolds=( 1 )
fgs=( {30..37} ) # Bold vivid is the same as bold normal.
bgs=( {40..47} 10{0..7} )
print_colors
# Print effects.
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