Bergnaum Patch 🚀

List of ANSI color escape sequences

April 15, 2025

List of ANSI color escape sequences

Including a splash of colour to your bid-formation interface tin importantly better readability and brand accusation base retired. ANSI flight sequences supply a standardized manner to accomplish this, permitting you to power matter colour, inheritance colour, and equal use results similar bolding oregon underlining. This blanket usher dives into the planet of ANSI colour flight sequences, offering you with the cognition and instruments to heighten your terminal output.

Knowing ANSI Flight Sequences

ANSI flight sequences are particular quality codes that instruct the terminal to execute a circumstantial act. They statesman with an flight quality (ASCII codification 27, represented arsenic \033 oregon \e) adopted by a series of characters that specify the desired consequence. Deliberation of them arsenic concealed codes that unlock your terminal’s styling capabilities. These sequences are wide supported crossed assorted terminal emulators and working programs, guaranteeing accordant colour rendering.

These sequences are peculiarly utile for highlighting crucial accusation, differentiating betwixt antithetic information varieties, and mostly making the terminal output much visually interesting. Ideate debugging a analyzable book – colour-coded output tin rapidly pinpoint errors and prevention you invaluable clip. Furthermore, they tin beryllium included into ammunition scripts and bid-formation instruments to make interactive and person-affable interfaces.

Basal Colour Codes

The center of ANSI colour codes lies successful manipulating foreground and inheritance colours. The basal construction of a colour flight series is \033[<em>kind;foreground;inheritance</em>m, wherever kind represents matter formatting (e.g., daring, underline), foreground is the matter colour, and inheritance units the inheritance colour. For case, \033[31m units the matter colour to reddish, piece \033[42m units the inheritance colour to greenish. Combining these codes, \033[1;31;42m would food daring reddish matter connected a greenish inheritance.

Present’s a speedy mention for generally utilized colour codes:

  • Achromatic: 30 (foreground), forty (inheritance)
  • Reddish: 31 (foreground), forty one (inheritance)
  • Greenish: 32 (foreground), forty two (inheritance)
  • Yellowish: 33 (foreground), forty three (inheritance)
  • Bluish: 34 (foreground), forty four (inheritance)
  • Magenta: 35 (foreground), forty five (inheritance)
  • Cyan: 36 (foreground), forty six (inheritance)
  • Achromatic: 37 (foreground), forty seven (inheritance)

Retrieve to usage \033[0m to reset the styling to default last making use of colour adjustments. This prevents consequent matter from inheriting unintended formatting.

Precocious ANSI Flight Sequences

Past basal colours, ANSI flight codes message additional customization choices. You tin use kinds similar daring (1), underline (four), blink (5 – usage sparingly!), and inverse (7). For illustration, \033[four;32m produces underlined greenish matter. Combining these types with colour codes permits for a broad scope of ocular variations.

256-colour manner expands the palette importantly, offering entree to a richer spectrum of colours. The format is \033[38;5;<em>color_code</em>m for foreground and \033[forty eight;5;<em>color_code</em>m for inheritance, wherever color_code ranges from zero to 255. Actual colour (24-spot) gives equal finer power, permitting you to specify exact RGB values. The flight series format is \033[38;2;<em>R;G;B</em>m and \033[forty eight;2;<em>R;G;B</em>m for foreground and inheritance, respectively, with R, G, and B representing reddish, greenish, and bluish values (zero-255).

Applicable Functions and Examples

Implementing ANSI colour codes is simple. Successful ammunition scripts, you tin straight embed the flight sequences into echo instructions. For illustration: echo -e "\033[31mThis matter is reddish\033[0m". Galore programming languages besides activity ANSI flight codes, enabling you to adhd colour to your programme’s output.

See a book that screens scheme assets. Utilizing colour codes, you might show CPU utilization successful greenish if beneath a threshold and reddish if exceeding it, offering an contiguous ocular cue. Likewise, successful log information, antithetic log ranges (e.g., mistake, informing, data) might beryllium assigned antithetic colours, making it simpler to place captious points. These are conscionable a fewer examples of however ANSI flight sequences tin heighten accusation position and better person education.

  1. Place the matter you privation to colour.
  2. Take the desired colour and kind codes.
  3. Prepend the matter with the due flight series.
  4. Append \033[0m to reset the styling.

For much elaborate accusation connected ANSI flight sequences and their functions, mention to these assets:

Infographic Placeholder: A ocular cooperation of communal ANSI colour codes and their corresponding flight sequences.

ANSI flight sequences empower you to change your terminal from a monotonous partition of matter into a vibrant and informative show. By knowing and using these codes, you tin importantly heighten the readability and usability of your bid-formation interface, making it simpler to construe information, debug codification, and work together with your scheme. Commencement experimenting with these codes present and detect the powerfulness of colour successful your terminal. Larn much astir enhancing your terminal education.

FAQ

Q: Bash each terminals activity ANSI flight codes?

A: About contemporary terminals activity ANSI flight codes. Nevertheless, any older oregon specialised terminals mightiness not person afloat activity.

Question & Answer :
Connected about terminals it is imaginable to colorize output utilizing the \033 ANSI flight series.

I’m wanting for a database of each supported colours and choices (similar agleam and blinking).

Arsenic location are most likely variations betwixt the terminals supporting them, I’m chiefly curious successful sequences supported by xterm-appropriate terminals.

The ANSI flight sequences you’re wanting for are the Choice Graphic Rendition subset. Each of these person the signifier

\033[XXXm 

wherever XXX is a order of semicolon-separated parameters.

To opportunity, brand matter reddish, daring, and underlined (we’ll discourse galore another choices beneath) successful C you mightiness compose:

printf("\033[31;1;4mHello\033[0m"); 

Successful C++ you’d usage

std::cout<<"\033[31;1;4mHello\033[0m"; 

Successful Python3 you’d usage

mark("\033[31;1;4mHello\033[0m") 

and successful Bash you’d usage

echo -e "\033[31;1;4mHello\033[0m" 

wherever the archetypal portion makes the matter reddish (31), daring (1), underlined (four) and the past portion clears each this (zero).

Arsenic described successful the array beneath, location are a ample figure of matter properties you tin fit, specified arsenic boldness, font, underlining, &c.

Font Results

| Codification | Consequence | Line | |---|---|---| | zero | Reset / Average | each attributes disconnected | | 1 | Daring oregon accrued strength | | | 2 | Faint (decreased strength) | Not wide supported. | | three | Italic | Not wide supported. Typically handled arsenic inverse. | | four | Underline | | | 5 | Dilatory Blink | little than one hundred fifty per infinitesimal | | 6 | Fast Blink | Sclerosis-DOS ANSI.SYS; one hundred fifty+ per infinitesimal; not wide supported | | 7 | \[\[reverse video\]\] | swap foreground and inheritance colours | | eight | Conceal | Not wide supported. | | 9 | Crossed-retired | Characters legible, however marked for deletion. Not wide supported. | | 10 | Capital(default) font | | | eleven–19 | Alternate font | Choice alternate font `n-10` | | 20 | Fraktur | barely always supported | | 21 | Daring disconnected oregon Treble Underline | Daring disconnected not wide supported; treble underline barely always supported. | | 22 | Average colour oregon strength | Neither daring nor faint | | 23 | Not italic, not Fraktur | | | 24 | Underline disconnected | Not singly oregon doubly underlined | | 25 | Blink disconnected | | | 27 | Inverse disconnected | | | 28 | Uncover | conceal disconnected | | 29 | Not crossed retired | | | 30–37 | Fit foreground colour | Seat colour array beneath | | 38 | Fit foreground colour | Adjacent arguments are `5;` oregon `2;;;`, seat beneath | | 39 | Default foreground colour | implementation outlined (in accordance to modular) | | forty–forty seven | Fit inheritance colour | Seat colour array beneath | | forty eight | Fit inheritance colour | Adjacent arguments are `5;` oregon `2;;;`, seat beneath | | forty nine | Default inheritance colour | implementation outlined (in accordance to modular) | | fifty one | Framed | | | fifty two | Encircled | | | fifty three | Overlined | | | fifty four | Not framed oregon encircled | | | fifty five | Not overlined | | | 60 | ideogram underline | barely always supported | | sixty one | ideogram treble underline | barely always supported | | sixty two | ideogram overline | barely always supported | | sixty three | ideogram treble overline | barely always supported | | sixty four | ideogram emphasis marking | barely always supported | | sixty five | ideogram attributes disconnected | reset the results of each of 60-sixty four | | ninety–ninety seven | Fit agleam foreground colour | aixterm (not successful modular) | | one hundred–107 | Fit agleam inheritance colour | aixterm (not successful modular) |
2-spot Colors =============

You’ve received this already!

four-spot Colors

The requirements implementing terminal colors started with constricted (four-spot) choices. The array beneath lists the RGB values of the inheritance and foreground colors utilized for these by a assortment of terminal emulators:

Table of ANSI colours implemented by various terminal emulators

Utilizing the supra, you tin brand reddish matter connected a greenish inheritance (however wherefore?) utilizing:

\033[31;42m 

eleven Colors (An Interlude)

Successful their publication “Basal Colour Status: Their Universality and Development”, Brent Berlin and Paul Kay utilized information collected from 20 antithetic languages from a scope of communication households to place eleven imaginable basal colour classes: achromatic, achromatic, reddish, greenish, yellowish, bluish, brownish, purple, pinkish, orangish, and grey.

Berlin and Kay recovered that, successful languages with less than the most eleven colour classes, the colours adopted a circumstantial evolutionary form. This form is arsenic follows:

  1. Each languages incorporate status for achromatic (chill colors) and achromatic (agleam colors).
  2. If a communication accommodates 3 status, past it accommodates a word for reddish.
  3. If a communication accommodates 4 status, past it accommodates a word for both greenish oregon yellowish (however not some).
  4. If a communication accommodates 5 status, past it comprises status for some greenish and yellowish.
  5. If a communication accommodates six status, past it comprises a word for bluish.
  6. If a communication incorporates 7 status, past it accommodates a word for brownish.
  7. If a communication accommodates 8 oregon much status, past it incorporates status for purple, pinkish, orangish oregon grey.

This whitethorn beryllium wherefore narrative Beowulf lone incorporates the colors achromatic, achromatic, and reddish. Homer’s Odyssey incorporates achromatic about 200 occasions and achromatic astir a hundred occasions. Reddish seems 15 instances, piece yellowish and greenish look lone 10 occasions. (Much accusation present)

Variations betwixt languages are besides absorbing: line the profusion of chiseled color phrases utilized by Nation vs. Island. Nevertheless, digging deeper into these languages exhibits that all makes use of color successful chiseled methods. (Much accusation)

Chinese vs English colour names. Image adapted from “muyueh.com”

Mostly talking, the naming, usage, and grouping of colors successful quality languages is fascinating. Present, backmost to the entertainment.

eight-spot (256) colors

Application precocious, and tables of 256 pre-chosen colors turned disposable, arsenic proven beneath.

256-bit colour mode for ANSI escape sequences

Utilizing these supra, you tin brand pinkish matter similar truthful:

\033[38;5;206m #That is, \033[38;5;<FG Colour>m 

And brand an aboriginal-greeting bluish inheritance utilizing

\033[forty eight;5;57m #That is, \033[forty eight;5;<BG Colour>m 

And, of class, you tin harvester these:

\033[38;5;206;forty eight;5;57m 

The eight-spot colors are organized similar truthful:

| Scope | Statement | |---|---| | 0x00-0x07 | modular colours (aforesaid arsenic the four-spot colors) | | 0x08-0x0F | advanced strength colours | | 0x10-0xE7 | 6 × 6 × 6 dice (216 colours): sixteen + 36 × r + 6 × g + b (zero ≤ r, g, b ≤ 5) | | 0xE8-0xFF | grayscale from achromatic to achromatic successful 24 steps |
Each THE Colors ===============

Present we are surviving successful the early, and the afloat RGB spectrum is disposable utilizing:

\033[38;2;<r>;<g>;<b>m #Choice RGB foreground colour \033[forty eight;2;<r>;<g>;<b>m #Choice RGB inheritance colour 

Truthful you tin option pinkish matter connected a brownish inheritance utilizing

\033[38;2;255;eighty two;197;forty eight;2;one hundred fifty five;106;0mHello 

Activity for “actual colour” terminals is listed present.

Overmuch of the supra is drawn from the Wikipedia leaf “ANSI flight codification”.

A Useful Book to Prompt Your self

Since I’m frequently successful the assumption of attempting to retrieve what colors are what, I person a useful book referred to as: ~/bin/ansi_colours:

#!/usr/bin/env python3 for i successful scope(30, 37 + 1): mark("\033[%dm%d\t\t\033[%dm%d" % (i, i, i + 60, i + 60)) mark("\033[39m\\033[49m - Reset colour") mark("\\033[2K - Broad Formation") mark("\\033[<L>;<C>H oregon \\033[<L>;<C>f - Option the cursor astatine formation L and file C.") mark("\\033[<N>A - Decision the cursor ahead N strains") mark("\\033[<N>B - Decision the cursor behind N strains") mark("\\033[<N>C - Decision the cursor guardant N columns") mark("\\033[<N>D - Decision the cursor backward N columns\n") mark("\\033[2J - Broad the surface, decision to (zero,zero)") mark("\\033[Ok - Erase to extremity of formation") mark("\\033[s - Prevention cursor assumption") mark("\\033[u - Reconstruct cursor assumption\n") mark("\\033[4m - Underline connected") mark("\\033[24m - Underline disconnected\n") mark("\\033[1m - Daring connected") mark("\\033[21m - Daring disconnected") 

This prints

Simple ANSI colours