<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://aznot.com/index.php?action=history&amp;feed=atom&amp;title=ANSI_Color</id>
	<title>ANSI Color - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://aznot.com/index.php?action=history&amp;feed=atom&amp;title=ANSI_Color"/>
	<link rel="alternate" type="text/html" href="https://aznot.com/index.php?title=ANSI_Color&amp;action=history"/>
	<updated>2026-05-07T06:31:47Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://aznot.com/index.php?title=ANSI_Color&amp;diff=6142&amp;oldid=prev</id>
		<title>Kenneth: Created page with &quot;== ANSI Color ==  == 256 color mode of xterm ANSI ==  [http://www.frexx.de/xterm-256-notes/ The 256 color mode of xterm]  a small bash script which prints a table of escape se...&quot;</title>
		<link rel="alternate" type="text/html" href="https://aznot.com/index.php?title=ANSI_Color&amp;diff=6142&amp;oldid=prev"/>
		<updated>2022-12-09T15:58:50Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== ANSI Color ==  == 256 color mode of xterm ANSI ==  [http://www.frexx.de/xterm-256-notes/ The 256 color mode of xterm]  a small bash script which prints a table of escape se...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== ANSI Color ==&lt;br /&gt;
&lt;br /&gt;
== 256 color mode of xterm ANSI ==&lt;br /&gt;
&lt;br /&gt;
[http://www.frexx.de/xterm-256-notes/ The 256 color mode of xterm]&lt;br /&gt;
&lt;br /&gt;
a small bash script which prints a table of escape sequences: colortable16.sh:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
# prints a color table of 8bg * 8fg * 2 states (regular/bold)&lt;br /&gt;
echo&lt;br /&gt;
echo Table for 16-color terminal escape sequences.&lt;br /&gt;
echo Replace ESC with \\033 in bash.&lt;br /&gt;
echo&lt;br /&gt;
echo &amp;quot;Background | Foreground colors&amp;quot;&lt;br /&gt;
echo &amp;quot;---------------------------------------------------------------------&amp;quot;&lt;br /&gt;
for((bg=40;bg&amp;lt;=47;bg++)); do&lt;br /&gt;
	for((bold=0;bold&amp;lt;=1;bold++)) do&lt;br /&gt;
		echo -en &amp;quot;\033[0m&amp;quot;&amp;quot; ESC[${bg}m   | &amp;quot;&lt;br /&gt;
		for((fg=30;fg&amp;lt;=37;fg++)); do&lt;br /&gt;
			if [ $bold == &amp;quot;0&amp;quot; ]; then&lt;br /&gt;
				echo -en &amp;quot;\033[${bg}m\033[${fg}m [${fg}m  &amp;quot;&lt;br /&gt;
			else&lt;br /&gt;
				echo -en &amp;quot;\033[${bg}m\033[1;${fg}m [1;${fg}m&amp;quot;&lt;br /&gt;
			fi&lt;br /&gt;
		done&lt;br /&gt;
		echo -e &amp;quot;\033[0m&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
	echo &amp;quot;--------------------------------------------------------------------- &amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
echo&lt;br /&gt;
echo&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
256colors2.pl:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/perl&lt;br /&gt;
# Author: Todd Larason &amp;lt;jtl@molehill.org&amp;gt;&lt;br /&gt;
# $XFree86: xc/programs/xterm/vttests/256colors2.pl,v 1.2 2002/03/26 01:46:43 dickey Exp $&lt;br /&gt;
&lt;br /&gt;
# use the resources for colors 0-15 - usually more-or-less a&lt;br /&gt;
# reproduction of the standard ANSI colors, but possibly more&lt;br /&gt;
# pleasing shades&lt;br /&gt;
&lt;br /&gt;
# colors 16-231 are a 6x6x6 color cube&lt;br /&gt;
for ($red = 0; $red &amp;lt; 6; $red++) {&lt;br /&gt;
    for ($green = 0; $green &amp;lt; 6; $green++) {&lt;br /&gt;
	for ($blue = 0; $blue &amp;lt; 6; $blue++) {&lt;br /&gt;
	    printf(&amp;quot;\x1b]4;%d;rgb:%2.2x/%2.2x/%2.2x\x1b\\&amp;quot;,&lt;br /&gt;
		   16 + ($red * 36) + ($green * 6) + $blue,&lt;br /&gt;
		   ($red ? ($red * 40 + 55) : 0),&lt;br /&gt;
		   ($green ? ($green * 40 + 55) : 0),&lt;br /&gt;
		   ($blue ? ($blue * 40 + 55) : 0));&lt;br /&gt;
	}&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# colors 232-255 are a grayscale ramp, intentionally leaving out&lt;br /&gt;
# black and white&lt;br /&gt;
for ($gray = 0; $gray &amp;lt; 24; $gray++) {&lt;br /&gt;
    $level = ($gray * 10) + 8;&lt;br /&gt;
    printf(&amp;quot;\x1b]4;%d;rgb:%2.2x/%2.2x/%2.2x\x1b\\&amp;quot;,&lt;br /&gt;
	   232 + $gray, $level, $level, $level);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# display the colors&lt;br /&gt;
&lt;br /&gt;
# first the system ones:&lt;br /&gt;
print &amp;quot;System colors:\n&amp;quot;;&lt;br /&gt;
for ($color = 0; $color &amp;lt; 8; $color++) {&lt;br /&gt;
    print &amp;quot;\x1b[48;5;${color}m  &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
print &amp;quot;\x1b[0m\n&amp;quot;;&lt;br /&gt;
for ($color = 8; $color &amp;lt; 16; $color++) {&lt;br /&gt;
    print &amp;quot;\x1b[48;5;${color}m  &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
print &amp;quot;\x1b[0m\n\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# now the color cube&lt;br /&gt;
print &amp;quot;Color cube, 6x6x6:\n&amp;quot;;&lt;br /&gt;
for ($green = 0; $green &amp;lt; 6; $green++) {&lt;br /&gt;
    for ($red = 0; $red &amp;lt; 6; $red++) {&lt;br /&gt;
	for ($blue = 0; $blue &amp;lt; 6; $blue++) {&lt;br /&gt;
	    $color = 16 + ($red * 36) + ($green * 6) + $blue;&lt;br /&gt;
	    print &amp;quot;\x1b[48;5;${color}m  &amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
	print &amp;quot;\x1b[0m &amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    print &amp;quot;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# now the grayscale ramp&lt;br /&gt;
print &amp;quot;Grayscale ramp:\n&amp;quot;;&lt;br /&gt;
for ($color = 232; $color &amp;lt; 256; $color++) {&lt;br /&gt;
    print &amp;quot;\x1b[48;5;${color}m  &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
print &amp;quot;\x1b[0m\n&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Referenced from: [http://plug.org/pipermail/plug/2008-March/029944.html The 90s called; they want their 256 colors back]&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
* ANSI escape code - http://en.wikipedia.org/wiki/ANSI_escape_code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Colored Bash ==&lt;br /&gt;
&lt;br /&gt;
 echo -e &amp;quot;\033[31mHI&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 echo &amp;quot;^[[0;31;40mIn Color&amp;quot;&lt;br /&gt;
 &amp;lt;ESC&amp;gt;[{attr};{fg};{bg}m&lt;br /&gt;
&lt;br /&gt;
Color test:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#/bin/sh&lt;br /&gt;
# Show all the colors of the rainbow, should be run under bash&lt;br /&gt;
for STYLE in 0 1 2 3 4 5 6 7; do&lt;br /&gt;
  for FG in 30 31 32 33 34 35 36 37; do&lt;br /&gt;
    for BG in 40 41 42 43 44 45 46 47; do&lt;br /&gt;
      CTRL=&amp;quot;\033[${STYLE};${FG};${BG}m&amp;quot;&lt;br /&gt;
      echo -en &amp;quot;${CTRL}&amp;quot;&lt;br /&gt;
      echo -n &amp;quot;${STYLE};${FG};${BG}&amp;quot;&lt;br /&gt;
      echo -en &amp;quot;\033[0m&amp;quot;&lt;br /&gt;
    done&lt;br /&gt;
    echo&lt;br /&gt;
  done&lt;br /&gt;
  echo&lt;br /&gt;
done&lt;br /&gt;
# Reset&lt;br /&gt;
echo -e &amp;quot;\033[0m&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;m&amp;quot; character following the number code 31 (Indicating that you want to print in red) completes the instantiation of the color. Without it, your text would remain whatever color it already was. The incorrect echo statement may also have other bizarre side effects, like repositioning your cursor or resetting your terminal. The final &amp;quot;m&amp;quot; is very important :)&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
*[http://linuxshellaccount.blogspot.com/2008/03/using-color-in-linux-or-unix-shell.html The Linux and Unix Menagerie: Using Color In The Linux Or Unix Shell]&lt;br /&gt;
*[http://linuxshellaccount.blogspot.com/2008/04/script-for-simple-menu-using-tput-and.html The Linux and Unix Menagerie: Script For A Simple Menu Using Tput And ANSI Color]&lt;br /&gt;
*[http://linuxtidbits.wordpress.com/2008/08/11/output-color-on-bash-scripts/ Output color on bash scripts « Helpful Linux Tidbits]&lt;br /&gt;
*[http://www.linuxjournal.com/article/8603 So You Like Color--The Mysterious ^[[ Characters]&lt;br /&gt;
*[http://tldp.org/LDP/abs/html/colorizing.html Colorizing Scripts]&lt;br /&gt;
*[http://edoceo.com/liber/linux-bash-shell The Bash Shell - Edoceo, Inc.]&lt;br /&gt;
&lt;br /&gt;
=== Python ANSI Color ===&lt;br /&gt;
&lt;br /&gt;
* ANSI escape code - http://en.wikipedia.org/wiki/ANSI_escape_code&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
unicode - Print in terminal with colors using Python? - Stack Overflow - https://stackoverflow.com/questions/287871/print-in-terminal-with-colors-using-python&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class bcolors:&lt;br /&gt;
    HEADER = &amp;#039;\033[95m&amp;#039;&lt;br /&gt;
    OKBLUE = &amp;#039;\033[94m&amp;#039;&lt;br /&gt;
    OKGREEN = &amp;#039;\033[92m&amp;#039;&lt;br /&gt;
    WARNING = &amp;#039;\033[93m&amp;#039;&lt;br /&gt;
    FAIL = &amp;#039;\033[91m&amp;#039;&lt;br /&gt;
    ENDC = &amp;#039;\033[0m&amp;#039;&lt;br /&gt;
    BOLD = &amp;#039;\033[1m&amp;#039;&lt;br /&gt;
    UNDERLINE = &amp;#039;\033[4m&amp;#039;&lt;br /&gt;
&lt;br /&gt;
print bcolors.WARNING + &amp;quot;Warning: No active frommets remain. Continue?&amp;quot; + bcolors.ENDC&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class colors:&lt;br /&gt;
  black = 0&lt;br /&gt;
  red = 1&lt;br /&gt;
  green = 2&lt;br /&gt;
  yellow = 3&lt;br /&gt;
  blue = 4&lt;br /&gt;
  magenta = 5&lt;br /&gt;
  cyan = 6&lt;br /&gt;
  white = 7&lt;br /&gt;
  fg = 30  # foreground add&lt;br /&gt;
  bg = 40  # background add&lt;br /&gt;
  bfg = 90  # bold foreground add&lt;br /&gt;
  bbg = 100  # bold background add&lt;br /&gt;
&lt;br /&gt;
print &amp;#039;\033[%dm red foreground \033[0m&amp;#039; % (colors.red + colors.fg)&lt;br /&gt;
print &amp;#039;\033[%dm bold red foreground \033[0m&amp;#039; % (colors.red + colors.bfg)&lt;br /&gt;
print &amp;#039;\033[%dm blue background \033[0m&amp;#039; % (colors.blue + colors.bg)&lt;br /&gt;
print &amp;#039;\033[%dm bold blue background \033[0m&amp;#039; % (colors.blue + colors.bbg)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
Before you start spouting escape sequences, you should check that stdout is a tty. You can do this with sys.stdout.isatty()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sys.stdout.isatty()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def hilite(string, status, bold):&lt;br /&gt;
    attr = []&lt;br /&gt;
    if status:&lt;br /&gt;
        # green&lt;br /&gt;
        attr.append(&amp;#039;32&amp;#039;)&lt;br /&gt;
    else:&lt;br /&gt;
        # red&lt;br /&gt;
        attr.append(&amp;#039;31&amp;#039;)&lt;br /&gt;
    if bold:&lt;br /&gt;
        attr.append(&amp;#039;1&amp;#039;)&lt;br /&gt;
    return &amp;#039;\x1b[%sm%s\x1b[0m&amp;#039; % (&amp;#039;;&amp;#039;.join(attr), string)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Python | change text color in shell - Stack Overflow - https://stackoverflow.com/questions/2330245/python-change-text-color-in-shell&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
For reference, a small bash script which prints a table of escape sequences: colortable16.sh: ([http://www.frexx.de/xterm-256-notes/ The 256 color mode of xterm], [http://plug.org/pipermail/plug/2008-March/016821.html The 90s called; they want their 256 colors back])&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
# prints a color table of 8bg * 8fg * 2 states (regular/bold)&lt;br /&gt;
echo&lt;br /&gt;
echo Table for 16-color terminal escape sequences.&lt;br /&gt;
echo Replace ESC with \\033 in bash.&lt;br /&gt;
echo&lt;br /&gt;
echo &amp;quot;Background | Foreground colors&amp;quot;&lt;br /&gt;
echo &amp;quot;---------------------------------------------------------------------&amp;quot;&lt;br /&gt;
for((bg=40;bg&amp;lt;=47;bg++)); do&lt;br /&gt;
	for((bold=0;bold&amp;lt;=1;bold++)) do&lt;br /&gt;
		echo -en &amp;quot;\033[0m&amp;quot;&amp;quot; ESC[${bg}m   | &amp;quot;&lt;br /&gt;
		for((fg=30;fg&amp;lt;=37;fg++)); do&lt;br /&gt;
			if [ $bold == &amp;quot;0&amp;quot; ]; then&lt;br /&gt;
				echo -en &amp;quot;\033[${bg}m\033[${fg}m [${fg}m  &amp;quot;&lt;br /&gt;
			else&lt;br /&gt;
				echo -en &amp;quot;\033[${bg}m\033[1;${fg}m [1;${fg}m&amp;quot;&lt;br /&gt;
			fi&lt;br /&gt;
		done&lt;br /&gt;
		echo -e &amp;quot;\033[0m&amp;quot;&lt;br /&gt;
	done&lt;br /&gt;
	echo &amp;quot;--------------------------------------------------------------------- &amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
echo&lt;br /&gt;
echo&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Python version: (modified by me)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
# prints a color table of 8bg * 8fg * 2 states (regular/bold)&lt;br /&gt;
print&lt;br /&gt;
print &amp;quot;Table for 16-color terminal escape sequences.&amp;quot;&lt;br /&gt;
print &amp;quot;Replace ESC with \\033 in bash.&amp;quot;&lt;br /&gt;
print&lt;br /&gt;
print &amp;quot;Background | Foreground colors&amp;quot;&lt;br /&gt;
print &amp;quot;---------------------------------------------------------------------&amp;quot;&lt;br /&gt;
for bg in range(40, 47+1):&lt;br /&gt;
  for bold in range(0, 1+1):&lt;br /&gt;
                sys.stdout.write(&amp;quot;\033[0m&amp;quot;&amp;quot; ESC[{bg}m   | &amp;quot;.format(bg=bg))&lt;br /&gt;
                for fg in range(30, 37+1):&lt;br /&gt;
                        if bold == 0:&lt;br /&gt;
                                sys.stdout.write(&amp;quot;\033[{bg}m\033[{fg}m [{fg}m  &amp;quot;.format(bg=bg, fg=fg))&lt;br /&gt;
                        else:&lt;br /&gt;
                                sys.stdout.write(&amp;quot;\033[{bg}m\033[1;{fg}m [1;{fg}m&amp;quot;.format(bg=bg, fg=fg))&lt;br /&gt;
                sys.stdout.write(&amp;quot;\033[0m\n&amp;quot;)&lt;br /&gt;
  print &amp;quot;--------------------------------------------------------------------- &amp;quot;&lt;br /&gt;
&lt;br /&gt;
print&lt;br /&gt;
print&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== keywords ==&lt;br /&gt;
&lt;br /&gt;
ANSI Color&lt;/div&gt;</summary>
		<author><name>Kenneth</name></author>
	</entry>
</feed>