Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
ANSI escape code
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Examples == {{code|CSI 2 J}} β This clears the screen and, on some devices, locates the cursor to the y,x position 1,1 (upper left corner). {{code|CSI 32 m}} β This makes text green. The green may be a dark, dull green, so you may wish to enable Bold with the sequence {{code|CSI 1 m}} which would make it bright green, or combined as {{code|CSI 32 ; 1 m}}. Some implementations use the Bold state to make the character Bright. {{code|CSI 0 ; 6 8 ; "DIR" ; 13 p}} β This reassigns the key F10 to send to the keyboard buffer the string "DIR" and ENTER, which in the DOS command line would display the contents of the current directory. (MS-DOS ANSI.SYS only) This was sometimes used for [[ANSI bomb]]s. This is a private-use code (as indicated by the letter p), using a non-standard extension to include a string-valued parameter. Following the letter of the standard would consider the sequence to end at the letter D. {{code|CSI s}} β This saves the cursor position. Using the sequence {{code|CSI u}} will restore it to the position. Say the current cursor position is 7(y) and 10(x). The sequence {{code|CSI s}} will save those two numbers. Now you can move to a different cursor position, such as 20(y) and 3(x), using the sequence {{code|CSI 20 ; 3 H}} or {{code|CSI 20 ; 3 f}}. Now if you use the sequence CSI u the cursor position will return to 7(y) and 10(x). Some terminals require the DEC sequences {{code|ESC 7}} / {{code|ESC 8}} instead which is more widely supported. === In shell scripting === ANSI escape codes are often used in [[UNIX]] and UNIX-like [[virtual console|terminals]] to provide [[syntax highlighting]]. For example, on compatible terminals, the following ''[[ls|list]]'' command color-codes file and directory names by type. ls --color Users can employ escape codes in their scripts by including them as part of ''[[standard output]]'' or ''[[stderr|standard error]]''. For example, the following GNU ''[[sed]]'' command embellishes the output of the ''[[make (software)|make]]'' command by displaying lines containing words starting with "WARN" in [[reverse video]] and words starting with "ERR" in bright yellow on a dark red background ([[letter case]] is ignored). The representations of the codes are highlighted.<ref>{{cite web |url=http://www.debian.org/doc/manuals/debian-reference/ch09.en.html#_colorized_shell_echo |title=Chapter 9. System tips|work=debian.org}}</ref> <span style="white-space:pre-wrap;">make 2>&1 | sed -e 's/.*\bWARN.*/<span style="border:1px solid grey;border-radius:5px;color:white;background:black;font-weight:bolder;">\x1b[7m</span>&<span style="border:1px solid grey;border-radius:5px;">\x1b[0m</span>/i' -e 's/.*\bERR.*/<span style="border:1px solid grey;border-radius:5px;color:yellow;background:maroon;font-weight:bolder;">\x1b[93;41m</span>&<span style="border:1px solid grey;border-radius:5px;">\x1b[0m</span>/i'</span> The following [[Bash (Unix shell)|Bash]] function flashes the terminal (by alternately sending reverse and normal video mode codes) until the user presses a key.<ref>{{cite web |title=VT100.net: Digital VT100 User Guide |url=http://vt100.net/docs/vt100-ug/chapter3.html |access-date=2015-01-19}}</ref> flasher () { while true; do printf <span style="border:1px solid grey;border-radius:5px;color:white;background:black;font-weight:bolder;">\\e[?5h</span>; sleep 0.1; printf <span style="border:1px solid grey;border-radius:5px;font-weight:bolder;">\\e[?5l</span>; read -s -n1 -t1 && break; done; } This can be used to alert a programmer when a lengthy command terminates, such as with {{code|make ; flasher}}{{thin space}}.<ref>{{cite web |title=bash β How to get a notification when my commands are done β Ask Different |url=http://apple.stackexchange.com/questions/9412/how-to-get-a-notification-when-my-commands-are-done |access-date=2015-01-19}}</ref> printf \\033c This will reset the console, similar to the command {{code|reset}} on modern Linux systems; however it should work even on older Linux systems and on other (non-Linux) UNIX variants. === In C === This following program creates a table of numbers from 0 to 109, each of which is displayed in the format specified by the [[#SGR|Select Graphic Rendition]] escape sequence using that number as the graphic rendition code. [[File:ANSI sample program output.png|right|thumb|Output of example program on [[Gnome Terminal]]]]<syntaxhighlight lang="c" line="1"> #include <stdio.h> int main(void) { int i, j, n; for (i = 0; i < 11; i++) { for (j = 0; j < 10; j++) { n = 10 * i + j; if (n > 108) break; printf("\033[%dm %3d\033[m", n, n); } printf("\n"); } return 0; } </syntaxhighlight>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
ANSI escape code
(section)
Add topic