Skip to content

Instantly share code, notes, and snippets.

@o-az
Last active November 26, 2023 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save o-az/b803c60091685f6b16cfde390d66bdbb to your computer and use it in GitHub Desktop.
Save o-az/b803c60091685f6b16cfde390d66bdbb to your computer and use it in GitHub Desktop.
ANSI color codes in various file formats (.sh, .json, .ts)
ansi colors demo
command to print the above [click to expand]
echo -e "   ${BLACK}Black Text${RESET}"
echo -e "      ${RED}Red Text${RESET}"
echo -e "         ${RED_BOLD}Red Bold Text${RESET}"
echo -e "            ${GREEN}Green Text${RESET}"
echo -e "               ${GREEN_BOLD}Green Bold Text${RESET}"
echo -e "                  ${YELLOW}Yellow Text${RESET}"
echo -e "                     ${YELLOW_BOLD}Yellow Bold Text${RESET}"
echo -e "                        ${BLUE}Blue Text${RESET}"
echo -e "                           ${BLUE_BOLD}Blue Bold Text${RESET}"
echo -e "                              ${MAGENTA}Magenta Text${RESET}"
echo -e "                                 ${MAGENTA_BOLD}Magenta Bold Text${RESET}"
echo -e "                                    ${CYAN}Cyan Text${RESET}"
echo -e "                                       ${CYAN_BOLD}Cyan Bold Text${RESET}"
echo -e "                                          ${WHITE}White Text${RESET}"
echo -e "                                             ${WHITE_BOLD}White Bold Text${RESET}"
#!/bin/sh

BLACK=\x1b[0;30m
BLACK_BOLD=\x1b[1;30m
RED=\x1b[0;31m
RED_BOLD=\x1b[1;31m
GREEN=\x1b[0;32m
GREEN_BOLD=\x1b[1;32m
YELLOW=\x1b[0;33m
YELLOW_BOLD=\x1b[1;33m
BLUE=\x1b[0;34m
BLUE_BOLD=\x1b[1;34m
MAGENTA=\x1b[0;35m
MAGENTA_BOLD=\x1b[1;35m
CYAN=\x1b[0;36m
CYAN_BOLD=\x1b[1;36m
WHITE=\x1b[0;37m
WHITE_BOLD=\x1b[1;37m
{
  "black": "\\x1b[0;30m",
  "black_bold": "\\x1b[1;30m",
  "red": "\\x1b[0;31m",
  "red_bold": "\\x1b[1;31m",
  "green": "\\x1b[0;32m",
  "green_bold": "\\x1b[1;32m",
  "yellow": "\\x1b[0;33m",
  "yellow_bold": "\\x1b[1;33m",
  "blue": "\\x1b[0;34m",
  "blue_bold": "\\x1b[1;34m",
  "magenta": "\\x1b[0;35m",
  "magenta_bold": "\\x1b[1;35m",
  "cyan": "\\x1b[0;36m",
  "cyan_bold": "\\x1b[1;36m",
  "white": "\\x1b[0;37m",
  "white_bold": "\\x1b[1;37m"
}
export const ansiColorCodes = {
  black: '\x1b[0;30m',
  black_bold: '\x1b[1;30m',
  red: '\x1b[0;31m',
  red_bold: '\x1b[1;31m',
  green: '\x1b[0;32m',
  green_bold: '\x1b[1;32m',
  yellow: '\x1b[0;33m',
  yellow_bold: '\x1b[1;33m',
  blue: '\x1b[0;34m',
  blue_bold: '\x1b[1;34m',
  magenta: '\x1b[0;35m',
  magenta_bold: '\x1b[1;35m',
  cyan: '\x1b[0;36m',
  cyan_bold: '\x1b[1;36m',
  white: '\x1b[0;37m',
  white_bold: '\x1b[1;37m'
}
{
"black": "\\x1b[0;30m",
"black_bold": "\\x1b[1;30m",
"red": "\\x1b[0;31m",
"red_bold": "\\x1b[1;31m",
"green": "\\x1b[0;32m",
"green_bold": "\\x1b[1;32m",
"yellow": "\\x1b[0;33m",
"yellow_bold": "\\x1b[1;33m",
"blue": "\\x1b[0;34m",
"blue_bold": "\\x1b[1;34m",
"magenta": "\\x1b[0;35m",
"magenta_bold": "\\x1b[1;35m",
"cyan": "\\x1b[0;36m",
"cyan_bold": "\\x1b[1;36m",
"white": "\\x1b[0;37m",
"white_bold": "\\x1b[1;37m"
}
#!/bin/sh
BLACK=\x1b[0;30m
BLACK_BOLD=\x1b[1;30m
RED=\x1b[0;31m
RED_BOLD=\x1b[1;31m
GREEN=\x1b[0;32m
GREEN_BOLD=\x1b[1;32m
YELLOW=\x1b[0;33m
YELLOW_BOLD=\x1b[1;33m
BLUE=\x1b[0;34m
BLUE_BOLD=\x1b[1;34m
MAGENTA=\x1b[0;35m
MAGENTA_BOLD=\x1b[1;35m
CYAN=\x1b[0;36m
CYAN_BOLD=\x1b[1;36m
WHITE=\x1b[0;37m
WHITE_BOLD=\x1b[1;37m
export const ansiColorCodes = {
black: '\x1b[0;30m',
black_bold: '\x1b[1;30m',
red: '\x1b[0;31m',
red_bold: '\x1b[1;31m',
green: '\x1b[0;32m',
green_bold: '\x1b[1;32m',
yellow: '\x1b[0;33m',
yellow_bold: '\x1b[1;33m',
blue: '\x1b[0;34m',
blue_bold: '\x1b[1;34m',
magenta: '\x1b[0;35m',
magenta_bold: '\x1b[1;35m',
cyan: '\x1b[0;36m',
cyan_bold: '\x1b[1;36m',
white: '\x1b[0;37m',
white_bold: '\x1b[1;37m'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment