Skip to content

Instantly share code, notes, and snippets.

@jdunham22
Forked from webstandardcss/ANSI-Test.sh
Last active August 15, 2022 08:15
Show Gist options
  • Save jdunham22/3cf4e8671ad21a83c6673d4aaf9954d0 to your computer and use it in GitHub Desktop.
Save jdunham22/3cf4e8671ad21a83c6673d4aaf9954d0 to your computer and use it in GitHub Desktop.
Shell script to test support of ANSI color and style codes
#!/bin/sh
# some terminals need echo -e, others don't understand it
_ECHO_OPT=""
#_ECHO_OPT="-e"
# another terminal doesn't understand \x1b but \033 works
#_ESC="\x1b"
_ESC="\033"
# ANSI Start Codes
# Styles.
Normal="$_ESC[0m"
Bold="$_ESC[1m"
Faint="$_ESC[2m"
Italic="$_ESC[3m"
Underline="$_ESC[4m"
Blink_Slow="$_ESC[5m"
Blink_Rapid="$_ESC[6m"
Inverse="$_ESC[7m"
Conceal="$_ESC[8m"
Crossed_Out="$_ESC[9m"
# Text colors.
Black="$_ESC[30m"
Red="$_ESC[31m"
Green="$_ESC[32m"
Yellow="$_ESC[33m"
Blue="$_ESC[34m"
Magenta="$_ESC[35m"
Cyan="$_ESC[36m"
White="$_ESC[37m"
# Background colors.
Bg_Black="$_ESC[40m"
Bg_Red="$_ESC[41m"
Bg_Green="$_ESC[42m"
Bg_Yellow="$_ESC[43m"
Bg_Blue="$_ESC[44m"
Bg_Magenta="$_ESC[45m"
Bg_Cyan="$_ESC[46m"
Bg_White="$_ESC[47m"
# High-intensity colors.
HiBlack="$_ESC[90m"
HiRed="$_ESC[91m"
HiGreen="$_ESC[92m"
HiYellow="$_ESC[93m"
HiBlue="$_ESC[94m"
HiMagenta="$_ESC[95m"
HiCyan="$_ESC[96m"
HiWhite="$_ESC[97m"
# Resets
NoStyle="$_ESC[0m"
NoUnderline="$_ESC[24m"
NoInverse="$_ESC[27m"
NoColor="$_ESC[39m"
Colors1="None $Black""Black""$NoColor $Red""Red""$NoColor $Green""Green""$NoColor $Yellow""Yellow""$NoColor"
Colors2="$Blue""Blue""$NoColor $Magenta""Magenta""$NoColor $Cyan""Cyan""$NoColor $White""White""$NoColor"
AllColors="$Colors1 $Colors2 $NoStyle"
Bg_Black_All="$Bg_Black$AllColors"
Bg_Red_All="$Bg_Red$AllColors"
Bg_Green_All="$Bg_Green$AllColors"
Bg_Yellow_All="$Bg_Yellow$AllColors"
Bg_Blue_All="$Bg_Blue$AllColors"
Bg_Magenta_All="$Bg_Magenta$AllColors"
Bg_Cyan_All="$Bg_Cyan$AllColors"
Bg_White_All="$Bg_White$AllColors"
HiColors1="None $HiBlack""Black""$NoColor $HiRed""Red""$NoColor $HiGreen""Green""$NoColor $HiYellow""Yellow""$NoColor"
HiColors2="$HiBlue""Blue""$NoColor $HiMagenta""Magenta""$NoColor $HiCyan""Cyan""$NoColor $HiWhite""White""$NoColor"
AllHiColors="$HiColors1 $HiColors2 $NoStyle"
Bg_Black_AllHi="$Bg_Black$AllHiColors"
Bg_Red_AllHi="$Bg_Red$AllHiColors"
Bg_Green_AllHi="$Bg_Green$AllHiColors"
Bg_Yellow_AllHi="$Bg_Yellow$AllHiColors"
Bg_Blue_AllHi="$Bg_Blue$AllHiColors"
Bg_Magenta_AllHi="$Bg_Magenta$AllHiColors"
Bg_Cyan_AllHi="$Bg_Cyan$AllHiColors"
Bg_White_AllHi="$Bg_White$AllHiColors"
# Test Table
echo $_ECHO_OPT "Background: | Style: | Text Colors:"
echo $_ECHO_OPT "------------|-------------|----------------------------------------------------"
echo $_ECHO_OPT " | Normal | "$Normal$AllColors
echo $_ECHO_OPT " | Bold | "$Bold$AllColors
echo $_ECHO_OPT " | Faint | "$Faint$AllColors
echo $_ECHO_OPT " | Italic | "$Italic$AllColors
echo $_ECHO_OPT " | Underline | "$Underline$AllColors
echo $_ECHO_OPT " | Blink_Slow | "$Blink_Slow$AllColors
echo $_ECHO_OPT " | Blink_Rapid | "$Blink_Rapid$AllColors
echo $_ECHO_OPT " | Inverse | "$Inverse$AllColors
echo $_ECHO_OPT " | Conceal | "$Conceal$AllColors
echo $_ECHO_OPT " | Crossed_Out | "$Crossed_Out$AllColors
echo $_ECHO_OPT "BG Black | Normal | "$Normal$Bg_Black_All
echo $_ECHO_OPT "BG Black | Bold | "$Bold$Bg_Black_All
echo $_ECHO_OPT "BG BlackHi | Normal | "$Normal$Bg_Black_AllHi
echo $_ECHO_OPT "BG BlackHi | Bold | "$Bold$Bg_Black_AllHi
echo $_ECHO_OPT "BG Red | Normal | "$Normal$Bg_Red_All
echo $_ECHO_OPT "BG Red | Bold | "$Bold$Bg_Red_All
echo $_ECHO_OPT "BG RedHi | Normal | "$Normal$Bg_Red_AllHi
echo $_ECHO_OPT "BG RedHi | Bold | "$Bold$Bg_Red_AllHi
echo $_ECHO_OPT "BG Green | Normal | "$Normal$Bg_Green_All
echo $_ECHO_OPT "BG Green | Bold | "$Bold$Bg_Green_All
echo $_ECHO_OPT "BG GreenHi | Normal | "$Normal$Bg_Green_AllHi
echo $_ECHO_OPT "BG GreenHi | Bold | "$Bold$Bg_Green_AllHi
echo $_ECHO_OPT "BG Yellow | Normal | "$Normal$Bg_Yellow_All
echo $_ECHO_OPT "BG Yellow | Bold | "$Bold$Bg_Yellow_All
echo $_ECHO_OPT "BG YellowHi | Normal | "$Normal$Bg_Yellow_AllHi
echo $_ECHO_OPT "BG YellowHi | Bold | "$Bold$Bg_Yellow_AllHi
echo $_ECHO_OPT "BG Blue | Normal | "$Normal$Bg_Blue_All
echo $_ECHO_OPT "BG Blue | Bold | "$Bold$Bg_Blue_All
echo $_ECHO_OPT "BG BlueHi | Normal | "$Normal$Bg_Blue_AllHi
echo $_ECHO_OPT "BG BlueHi | Bold | "$Bold$Bg_Blue_AllHi
echo $_ECHO_OPT "BG Magenta | Normal | "$Normal$Bg_Magenta_All
echo $_ECHO_OPT "BG Magenta | Bold | "$Bold$Bg_Magenta_All
echo $_ECHO_OPT "BG MagentaHi| Normal | "$Normal$Bg_Magenta_AllHi
echo $_ECHO_OPT "BG MagentaHi| Bold | "$Bold$Bg_Magenta_AllHi
echo $_ECHO_OPT "BG Cyan | Normal | "$Normal$Bg_Cyan_All
echo $_ECHO_OPT "BG Cyan | Bold | "$Bold$Bg_Cyan_All
echo $_ECHO_OPT "BG CyanHi | Normal | "$Normal$Bg_Cyan_AllHi
echo $_ECHO_OPT "BG CyanHi | Bold | "$Bold$Bg_Cyan_AllHi
echo $_ECHO_OPT "BG White | Normal | "$Normal$Bg_White_All
echo $_ECHO_OPT "BG White | Bold | "$Bold$Bg_White_All
echo $_ECHO_OPT "BG WhiteHi | Normal | "$Normal$Bg_White_AllHi
echo $_ECHO_OPT "BG WhiteHi | Bold | "$Bold$Bg_White_AllHi
@jdunham22
Copy link
Author

jdunham22 commented Aug 15, 2022

Next: add High background colors codes 100-107

see also https://stackoverflow.com/questions/4842424/list-of-ansi-color-escape-sequences

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment