Terminal colours

Pick a colour for the text, one for the background, and some attributes: the tool writes the ANSI escape sequence, ready for printf, echo -e, tput or a bash prompt.

Colours
Attributes

Preview

$

The exact shades depend on your terminal’s theme, especially for the 16 basic colours.

To paste

SGR codes:

printf (recommended)

    
      
echo -e

    
      
printf, portable form (\033, also in sh)

    
      
In a script, as variables

    
      
In PS1 (the prompt): between \[ and \]

    
      
tput (reads the terminal’s capabilities)

    
  

See your terminal’s real colours

Paste this into your terminal: it prints the 16 and the 256 colours as your terminal draws them, then a gradient that stays smooth only with true colour.

bash

  

Transparency

The sequences are computed in your browser, by the scripts listed below. Nothing you choose leaves this page.

Enforced by your browser
This page's Content Security Policy allows a single destination, the site's audience measurement (connect-src https://stats.r-no.fr, see below), and forbids any form submission (form-action 'none'), so even a bug could not send what you type anywhere. You can read the policy at the top of the page source.
Audience measurement
Like every page of the site, this one counts its visit with Umami, installed on R-no’s own server (stats.r-no.fr). It receives the address of the page, without parameters or anchor, the site you came from (its domain only), your browser, system, language and screen size, and the country, region and city deduced from your IP address, which is not kept. It never receives what you type, nor the result of the tool. No cookie, nothing stored in your browser; if your browser asks not to be tracked (Do Not Track), nothing is measured. The data is erased after 25 months.
  • /commun/mesure.js: the filter applied before each sending, written for R-no Toolbox. 1.4 kB
    SHA-256 225eec74fd12623d82fc05ee7d222be629ce454d081c129e8d1e249ed37ee716
  • https://stats.r-no.fr/m.js: Umami’s tracker, open source (MIT), served by the measurement server. Its fingerprint is not shown here: it changes with each version of Umami, and you cannot check from your browser that it is the published code. For that part, you have to trust R-no.
What is stored
No cookie, and nothing in the address. What you type is never stored: it disappears when you reload or close the page. Your language is given by the address itself (/en/ or /fr/): nothing is stored to remember it. Like any website, the server records the download of the page and its files in its access logs (IP address, date and time, address requested, browser name). It never receives what you type.
Code that runs here
  • app.js: the colour tables and the writing of the sequences, written for R-no Toolbox. Not minified, no third-party library. 13.7 kB
    SHA-256 ecef13414684ac539bc5be54f90830da3346f5056c8886f51abfea094fb0f613
  • textes.js: the French messages of the tool, shown by its script (the rest of the French page is written into its HTML when the site is built). It only defines texts, with no logic. 6.8 kB
    SHA-256 3f05f035ea8cfa140ac6a0c44e8a05a515bcd02a460fa84ebdc17a965b5bfdf3
  • /commun/langue.js: the language helper, the same on every page of the site. It reads the language of the page and gives the tool its messages in that language. It stores nothing. 1.6 kB
    SHA-256 80f76f69773ef628d36d09bf8387cfedebda4529210d7120649b6f5603310631
Before you paste
This page only writes text: it runs nothing, neither here nor on your machine. What you paste into a terminal or a configuration file runs with your rights, so read it first. The code it writes downloads nothing and calls no outside service.
Where the values come from
The codes are the SGR sequences of ECMA-48, the standard behind ANSI colours (30–37, 90–97, 38;5;n, 38;2;r;g;b). The preview uses xterm’s default shades; the 256-colour cube and greys are the same in every terminal. The printf, echo and tput lines were run through bash 5.2 to check the bytes they print.
Check it yourself
Download a script and compare its fingerprint with the one above:
curl -s https://r-no.fr/bash/colors/app.js | shasum -a 256
Limits
What a terminal really shows depends on it: italic, blink, strikethrough and true colour are not supported everywhere (Terminal.app on macOS has no true colour), and the 16 basic colours follow its theme. Always end a coloured text with \e[0m, or the colour carries on. Outside a terminal (a file, a pipe), these codes are just noise: test [ -t 1 ] before using them.