-
codes ANSI
- Build your own Command Line with ANSI escape codes
- bash-hackers: Terminal Codes (ANSI/VT100) introduction
- Scrolling:
\033[S
: Scroll the screen up.\033[T
: Scroll the screen down.
- Save/Restore Cursor Position:
\033[s
: Save the cursor position.\033[u
: Restore the cursor position.
- Changing Text Attributes:
\033[0m
: Reset all attributes (color, style).\033[1m
: Bold or increased intensity.\033[2m
: Faint or decreased intensity.\033[3m
: Italic (if supported).\033[4m
: Underline.\033[5m
: Blink (slow).\033[6m
: Blink (rapid).\033[7m
: Reverse video.\033[8m
: Concealed.
- Changing Text Color:
\033[38;2;<r>;<g>;<b>m
: Set text color using RGB values.\033[38;5;<color_code>m
: Set text color using a 256-color palette.\033[39m
: Default text color.
ESC
BASH :
\033PYTHON:
\033Langage C :
\eCtrl-Key :
^[Octal :
\033Unicode :
\u001bHexadecimal :
\x1BDecimal :
27CONTRÔLE DU CURSEUR
ESC[#;#HorESC[#;#fdéplace le curseur à la ligne #, colonne #ESC[Hdéplace le curseur à 0,0ESC[#Adéplace le curseur en haut de # lignes (ESC[Apour 1 seule ligne)ESC[#Bdéplace le curseur en bas de # lignes (ESC[Bpour 1 seule ligne)ESC[#Cdéplace le curseur à droite de # espaces (ESC[Cpour 1 seule ligne)ESC[#Ddéplace le curseur à gauche de # espaces (ESC[Dpour 1 seule ligne)ESC[#;#Renregistre la position courante du curseur (line & column)ESC[senregistre la position actuelle du curseur pour un rappel recall later (SCO)ESC[uretourne le curseur à la position enregistrée peécédemment (SCO)ESC[#Emoves cursor to beginning of next line, # lines downESC[#Fmoves cursor to beginning of previous line, # lines upESC[#Gmoves cursor to column #ESC[6nrequest cursor position (reports as ESC[#;#R)ESC Mmoves cursor one line up, scrolling if neededESC 7save cursor position (DEC)ESC 8restores the cursor to the last saved position (DEC)NOTE: It is recommended to use DEC sequences.
EFFACEMENT & SUPPRESSION
ESC[JouESC[0Jefface du curseur jusqu'à la fin de l'écranESC[1Jefface du début de l'écran jusdu'au curseurESC[2Jefface tout l'écran et place le curseur à 0,0ESC[3Jefface saved lines (scrollback buffer)ESC[KouESC[0Kefface du curseur jusquà la fin de la ligneESC[1Kefface du début de la ligne jusqu'au curseurESC[2Kefface toute la ligneNOTE: Supprimer une ligne ne déplace pas le curseur. Utiliser \r après avoir effacer la ligne pour que le curseur revienne au début de la ligne.
COULEUR ET FORMATAGE DU TEXTE
ESC[#(;#)mPour avoir plusieurs formatages : espacer avec;et terminer avecmoù#peut avoir comme valeur :0normal -1bold -4underline (mono only) -5blink on -7reverse video on -8nondisplayed (invisible)couleurs foreground :
30noir -31rouge -32vert -33jaune -34bleu -35magenta -36cyan -37blanccouleurs background :
40noir -41rouge -42vert -43jaune -44bleu -45magenta -46cyan -47blancCode Reset Description
ESC[1;34;{...}mgraphics modes for cell, separated by semicolon (;).ESC[0mreset tous les modes (styles et couleur)ESC[1m ESC[22mbold mode.ESC[2m ESC[22mdim/faint mode.ESC[3m ESC[23mitalic mode.ESC[4m ESC[24munderline mode.ESC[5m ESC[25mblinking modeESC[7m ESC[27minverse/reverse modeESC[8m ESC[28mhidden/invisible modeESC[9m ESC[29mstrikethrough mode.ESC[21mdouble underline work in some terminals and is reset withESC[24m.Most terminals, apart from the basic set of 8 colors, also support the "bright" or "bold" colors. These have their own set of codes, mirroring the normal colors, but with an additional ;1 in their codes:
\x1b[1;31mHello # bold, red foreground \x1b[2;37;41mWorld # dimmed white foreground with red background
Terminals that support the aixterm specification provides bright versions of the ISO colors, without the need to use the bold modifier:
Nom Foreground Background
Bright Black
90 100Bright Red
91 101Bright Green
92 102Bright Yellow
93 103Bright Blue
94 104Bright Magenta
95 105Bright Cyan
96 106Bright White
97 107256 Colors
The following escape codes tells the terminal to use the given color ID ( 0 à 255) :
ESC[38;5;{ID}mforeground colorESC[48;5;{ID}mbackground colorThe table starts with the original 16 colors (0-15).
The final 24 colors (232-255) are grayscale starting from a shade slighly lighter than black, ranging up to shade slightly darker than white.
RGB Colors
More modern terminals supports Truecolor (24-bit RGB), which allows you to set foreground and background colors using RGB.
ESC[38;2;{r};{g};{b}mSet foreground color as RGB.ESC[48;2;{r};{g};{b}mSet background color as RGB.Note that ;38 and ;48 corresponds to the 16 color sequence and is interpreted by the terminal to set the foreground and background color respectively. Whereas ;2 and ;5 sets the color format.
ÉCRAN
ESC[=#;7houESC[=houESC[=0houESC[?7hput screen in indicated mode where # is:040 x 25 black & white140 x 25 color280 x 25 b&w380 x 25 color4320 x 200 color graphics5320 x 200 b&w graphics6640 x 200 b&w graphics7to wrap at end of line (enables line wrapping)13320 x 200 color (graphics)14640 x 200 color (16-color graphics)15640 x 350 monochrome (2-color graphics)16640 x 350 color (16-color graphics)17640 x 480 monochrome (2-color graphics)18640 x 480 color (16-color graphics)19320 x 200 color (256-color graphics)ESC[=#;7louESC[=louESC[=0louESC[?7lresets mode # set with above commandESC[={value}lResets the mode by using the same values that Set Mode uses, except for 7, which disables line wrapping. (L minuscule).These are some examples of private modes, which are not defined by the specification, but are implemented in most terminals.
ESC[?25lmake cursor invisibleESC[?25hmake cursor visibleESC[?47lrestore screenESC[?47hsave screenESC[?1049henables the alternative bufferESC[?1049ldisables the alternative bufferXTerm Control Sequences for a more in-depth list of private modes defined by XTerm.
EXEMPLES
Purple
\e[0;35mCLAVIER Strings
ESC[{code};{string};{...}p
Redefines a keyboard key to a specified string.
The parameters for this escape sequence are defined as follows:
- code is one or more of the values listed in the following table. These values represent keyboard keys and key combinations. When using these values in a command, you must type the semicolons shown in this table in addition to the semicolons required by the escape sequence. The codes in parentheses are not available on some keyboards. ANSI.SYS will not interpret the codes in parentheses for those keyboards unless you specify the /X switch in the DEVICE command for ANSI.SYS.
- string is either the ASCII code for a single character or a string contained in quotation marks. Ex, both 65 and "A" can be used to represent an uppercase A.
IMPORTANT: Some of the values in the following table are not valid for all computers. Check your computer's documentation for values that are different.
List of keyboard strings
Key Code SHIFT+code CTRL+code ALT+code F1 0;59 0;84 0;94 0;104 F2 0;60 0;85 0;95 0;105 F3 0;61 0;86 0;96 0;106 F4 0;62 0;87 0;97 0;107 F5 0;63 0;88 0;98 0;108 F6 0;64 0;89 0;99 0;109 F7 0;65 0;90 0;100 0;110 F8 0;66 0;91 0;101 0;111 F9 0;67 0;92 0;102 0;112 F10 0;68 0;93 0;103 0;113 F11 0;133 0;135 0;137 0;139 F12 0;134 0;136 0;138 0;140 HOME (num keypad) 0;71 55 0;119 -- UP ARROW (num keypad) 0;72 56 (0;141) -- PAGE UP (num keypad) 0;73 57 0;132 -- LEFT ARROW (num keypad) 0;75 52 0;115 -- RIGHT ARROW (num keypad) 0;77 54 0;116 -- END (num keypad) 0;79 49 0;117 -- DOWN ARROW (num keypad) 0;80 50 (0;145) -- PAGE DOWN (num keypad) 0;81 51 0;118 -- INSERT (num keypad) 0;82 48 (0;146) -- DELETE (num keypad) 0;83 46 (0;147) -- HOME (224;71) (224;71) (224;119) (224;151) UP ARROW (224;72) (224;72) (224;141) (224;152) PAGE UP (224;73) (224;73) (224;132) (224;153) LEFT ARROW (224;75) (224;75) (224;115) (224;155) RIGHT ARROW (224;77) (224;77) (224;116) (224;157) END (224;79) (224;79) (224;117) (224;159) DOWN ARROW (224;80) (224;80) (224;145) (224;154) PAGE DOWN (224;81) (224;81) (224;118) (224;161) INSERT (224;82) (224;82) (224;146) (224;162) DELETE (224;83) (224;83) (224;147) (224;163) PRINT SCREEN -- -- 0;114 -- PAUSE/BREAK -- -- 0;0 -- BACKSPACE 8 8 127 (0) ENTER 13 -- 10 (0 TAB 9 0;15 (0;148) (0;165) NULL 0;3 -- -- -- A 97 65 1 0;30 B 98 66 2 0;48 C 99 66 3 0;46 D 100 68 4 0;32 E 101 69 5 0;18 F 102 70 6 0;33 G 103 71 7 0;34 H 104 72 8 0;35 I 105 73 9 0;23 J 106 74 10 0;36 K 107 75 11 0;37 L 108 76 12 0;38 M 109 77 13 0;50 N 110 78 14 0;49 O 111 79 15 0;24 P 112 80 16 0;25 Q 113 81 17 0;16 R 114 82 18 0;19 S 115 83 19 0;31 T 116 84 20 0;20 U 117 85 21 0;22 V 118 86 22 0;47 W 119 87 23 0;17 X 120 88 24 0;45 Y 121 89 25 0;21 Z 122 90 26 0;44 1 49 33 -- 0;120 2 50 64 0 0;121 3 51 35 -- 0;122 4 52 36 -- 0;123 5 53 37 -- 0;124 6 54 94 30 0;125 7 55 38 -- 0;126 8 56 42 -- 0;126 9 57 40 -- 0;127 0 48 41 -- 0;129 - 45 95 31 0;130 = 61 43 --- 0;131 [ 91 123 27 0;26 ] 93 125 29 0;27 92 124 28 0;43 ; 59 58 -- 0;39 ‘ 39 34 -- 0;40 , 44 60 -- 0;51 . 46 62 -- 0;52 / 47 63 -- 0;53 ` 96 126 -- (0;41) ENTER (keypad) 13 -- 10 (0;166) / (keypad) 47 47 (0;142) (0;74) * (keypad) 42 (0;144) (0;78) -- - (keypad) 45 45 (0;149) (0;164) + (keypad) 43 43 (0;150) (0;55) 5 (keypad) (0;76) 53 (0;143) -- Resources
https://github.com/hinell/palette-print.bash