escape-sekvenser.xmlDenna kod är public domain. Om ni hittar fel eller vill ändra något i koden blir jag jätteglad om ni skickar dessa ändringar till jesper [at] fantasi [punkt] se.
<?xml version="1.0"?>
<article category="software" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="article.xsd">
<keyword>Escape-sekvenser</keyword>
<topic>ANSI:s Escape-sekvenser</topic>
<ingress>
I många terminaler och emulatorer kan man ändra
färg och flytta markören genom att skicka
escape-sekvenser till dem. Den mest spridda standarden för
dessa sekvenser är definierad av ANSI och den följs
bland annat av VT100 som är en av de vanligast
förekommande terminalerna.
</ingress>
<text>
Beroende på hur man kommunicerar med terminalen finns det
naturligtvis olika sätt att skicka dessa koder till den, men
om vi antar att vi vill göra det från ett program
så skickas escape-sekvenserna på samma sätt som
man skriver ut vanlig text till terminalen, dvs med till exempel
printf (C/C++), System.out.println, (Java) eller echo (olika
script). På <a href="source.php">kodsidan</a> finns exempel
på hur escape-koderna kan användas i olika program.
</text>
<text>
Nedan följer ett utdrag ur ANSI:s tabell av escape-sekvenser.
<code><lt />esc<gt /></code> står för ASCII-koden
för "escape", 0x1B. Värden inom måsvingar är
variabler, dvs <code>{ROW}</code> byts ut mot ett radnummer.
</text>
<table start="-1" header="Namn-+-Esc-sekvens-+-Beskrivning"
style="l-+-lt-+-l">
<row data="Cursor Up-+-&amp;lt;esc&amp;gt;[{N}A-+-Flytta markören uppåt N rader, stanna vid terminalens kant. N = 1 om inget annat anges." />
<row data="Cursor Down-+-&amp;lt;esc&amp;gt;[{N}B-+-Flytta markören nedåt N rader, stanna vid terminalens kant. N = 1 om inget annat anges." />
<row data="Cursor Right-+-&amp;lt;esc&amp;gt;[{N}C-+-Flytta markören åt höger N kolumner, stanna vid terminalens kant. N = 1 om inget annat anges." />
<row data="Cursor Left-+-&amp;lt;esc&amp;gt;[{N}D-+-Flytta markören åt vänster N kolumner, stanna vid terminalens kant. N = 1 om inget annat anges." />
<row data="Cursor Home-+-&amp;lt;esc&amp;gt;[{ROW};{COLUMN}H-+-Flytta markören till rad {ROW} och kolumn {COLUMN}. Om rad och kolumn inte anges (&lt;code&gt;&amp;lt;esc&amp;gt;[H&lt;/code&gt;), kommer markören att flyttas till terminalens övre vänstra hörn." />
<row data="Move Cursor-+-&amp;lt;esc&amp;gt;[{ROW}{COLUMN}f-+-Samma som Cursor Home." />
<row data="Next Line-+-&amp;lt;esc&amp;gt;E-+-Flytta markören till början av nästa rad. Rulla texten uppåt om markören är på nedersta raden." />
<row data="Index-+-&amp;lt;esc&amp;gt;D-+-Flytta markören nedåt en rad. Rulla texten uppåt om markören är på nedersta raden." />
<row data="Reverse Index-+-&amp;lt;esc&amp;gt;M-+-Flytta markören uppåt en rad. Rulla texten nedåt om markören är på översta raden." />
<row data="Save Cursor-+-&amp;lt;esc&amp;gt;[s-+-Spara nuvarande markörposition." />
<row data="Unsave Cursor-+-&amp;lt;esc&amp;gt;[u-+-Återställ markörpositionen till senast sparade." />
<row data="Query Cursor Position-+-&amp;lt;esc&amp;gt;[6n-+-Begär 'Report Cursor Position' från terminalen." />
<row data="Report Cursor Position-+-&amp;lt;esc&amp;gt;[{ROW};{COLUMN}R-+-Genereras av terminalen som svar på 'Query Cursor Position' och innehåller nuvarande markörposition." />
<row data="Save Cursor + Attrs-+-&amp;lt;esc&amp;gt;7-+-Spara nuvarande markörposition och attribut." />
<row data="Restore Cursor + Attrs-+-&amp;lt;esc&amp;gt;8-+-Återställ markörposition och attribut till senast sparade." />
<row data="Scroll Screen-+-&amp;lt;esc&amp;gt;[r-+-Slå på textrullning för hela terminalen." />
<row data="Scroll Screen-+-&amp;lt;esc&amp;gt;[{start};{end}r-+-Slå på textrullning från rad {start} till rad {end}." />
<row data="Scroll Down-+-&amp;lt;esc&amp;gt;D-+-Rulla texten nedåt en rad." />
<row data="Scroll Up-+-&amp;lt;esc&amp;gt;M-+-Rulla texten uppåt en rad." />
<row data="Set smooth scrolling-+-&amp;lt;esc&amp;gt;[?4h-+-Mjuk textrullning." />
<row data="Set jump scrolling-+-&amp;lt;esc&amp;gt;[?4l-+-Hoppig textrullning." />
<row data="Erase End of Line-+-&amp;lt;esc&amp;gt;[K-+-Radera texten från markörpositionen till slutet av raden." />
<row data="Erase End of Line-+-&amp;lt;esc&amp;gt;[0K-+-Radera texten från markörpositionen till slutet av raden." />
<row data="Erase Start of Line-+-&amp;lt;esc&amp;gt;[1K-+-Radera texten från markörpositionen till början av raden." />
<row data="Erase Line-+-&amp;lt;esc&amp;gt;[2K-+-Radera hela raden som markören står på." />
<row data="Erase Down-+-&amp;lt;esc&amp;gt;[J-+-Radera alla rader från nuvarande till botten av terminalen." />
<row data="Erase Down-+-&amp;lt;esc&amp;gt;[0J-+-Radera alla rader från nuvarande till botten av terminalen." />
<row data="Erase Up-+-&amp;lt;esc&amp;gt;[1J-+-Radera alla rader från nuvarande till toppen av terminalen." />
<row data="Erase Screen-+-&amp;lt;esc&amp;gt;[2J-+-Radera hela terminalen med bibehållen bakgrundsfärg och flytta markören till övre vänstra hörnet." />
<row data="Set Attribute Mode-+-&amp;lt;esc&amp;gt;[{attr 1};...;{attr n}m-+-
Sätt visuella attribut enligt tabellen nedan&lt;br&gt;&lt;br&gt;
&lt;table class=&quot;fitable&quot;&gt;&lt;tr&gt;&lt;td class=&quot;fcolumn&quot; width=&quot;40%&quot;&gt;
&lt;table width=&quot;100%&quot;&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt; &lt;/td&gt;&lt;td class=&quot;small&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot; valign=&quot;top&quot;&gt;0&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Återställ alla attribut&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;1&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Ljus&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;2&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Skuggad&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;4&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Understruken&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;5&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Blinkande&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;7&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Spegelvänd&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;8&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Dold&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;&lt;td class=&quot;fcolumn&quot; width=&quot;30%&quot;&gt;
&lt;table width=&quot;100%&quot;&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot; colspan=&quot;2&quot;&gt;Textfärg&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot; width=&quot;50%&quot;&gt;30&lt;/td&gt;&lt;td class=&quot;small&quot; width=&quot;50%&quot;&gt;Svart&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;31&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Röd&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;32&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Grön&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;33&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Gul&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;34&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Blå&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;35&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Lila&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;36&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Cyan&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;37&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Vit&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;&lt;td class=&quot;fcolumn&quot; width=&quot;30%&quot;&gt;
&lt;table width=&quot;100%&quot;&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot; colspan=&quot;2&quot;&gt;Bakgrunsfärg&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot; width=&quot;50%&quot;&gt;40&lt;/td&gt;&lt;td class=&quot;small&quot; width=&quot;50%&quot;&gt;Svart&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;41&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Röd&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;42&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Grön&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;43&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Gul&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;44&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Blå&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;45&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Lila&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;46&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Cyan&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;small&quot;&gt;47&lt;/td&gt;&lt;td class=&quot;small&quot;&gt;Vit&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;" />
<row data="Font Set G0-+-&amp;lt;esc&amp;gt;(-+-Använd standardtypsnitt." />
<row data="Font Set G1-+-&amp;lt;esc&amp;gt;)-+-Använd alternativt typsnitt (fetstil/kursiv etc)." />
<!-- row data="-+-&amp;lt;esc&amp;gt;(A-+-" />
<row data="-+-&amp;lt;esc&amp;gt;)A-+-" />
<row data="-+-&amp;lt;esc&amp;gt;(B-+-" />
<row data="-+-&amp;lt;esc&amp;gt;)B-+-" />
<row data="Set G0 special chars. and line set-+-&amp;lt;esc&amp;gt;(0-+-" />
<row data="Set G1 special chars. and line set-+-&amp;lt;esc&amp;gt;)0-+-" />
<row data="Set G0 alternate character ROM-+-&amp;lt;esc&amp;gt;(1-+-" />
<row data="Set G1 alternate character ROM-+-&amp;lt;esc&amp;gt;)1-+-" />
<row data="Set G0 alt char ROM and spec. graphics-+-&amp;lt;esc&amp;gt;(2-+-" />
<row data="Set G1 alt char ROM and spec. graphics-+-&amp;lt;esc&amp;gt;)2-+-" / -->
<row data="Double-height top half-+-&amp;lt;esc&amp;gt;#3-+-Ändra aktuell rad till dubbel höjd, övre halvan." />
<row data="Double-height bottom half-+-&amp;lt;esc&amp;gt;#4-+-Ändra aktuell rad till dubbel höjd, nedre halvan." />
<row data="Normal size-+-&amp;lt;esc&amp;gt;#5-+-Ändra aktuell rad till normal bredd och höjd." />
<row data="Double-width-+-&amp;lt;esc&amp;gt;#6-+-Ändra aktuell rad till dubbel bredd." />
<row data="Leds-+-&amp;lt;esc&amp;gt;[1;...;4q-+-Tänd en eller fler programmerbara lysdioder (1-4). " />
<row data="Leds-+-&amp;lt;esc&amp;gt;[q-+-Släck alla programmerbara lysdioder. " />
<row data="Set Tab-+-&amp;lt;esc&amp;gt;H-+-Sätt en tab på nuvarande kolumn." />
<row data="Clear Current Tab-+-&amp;lt;esc&amp;gt;[g-+-Ta bort tab från nuvarande kolumn." />
<row data="Clear Current Tab-+-&amp;lt;esc&amp;gt;[0g-+-Ta bort tab från nuvarande kolumn." />
<row data="Clear All Tabs-+-&amp;lt;esc&amp;gt;[3g-+-Ta bort alla tabbar." />
<row data="Enable Line Wrap-+-&amp;lt;esc&amp;gt;[7h-+-Slå på automatisk radbrytning." />
<row data="Disable Line Wrap-+-&amp;lt;esc&amp;gt;[7l-+-Slå av automatisk radbrytning." />
<row data="Reverse video-+-&amp;lt;esc&amp;gt;[?5h-+-Invertera färgerna i terminalen." />
<row data="Normal video-+-&amp;lt;esc&amp;gt;[?5l-+-Återställ färgerna i terminalen." />
<row data="Set Key Definition-+-&amp;lt;esc&amp;gt;[{key};&amp;quot;{string}&amp;quot;p-+-Associera en text med en tangent ({key} = tangentens decimala ASCII-värde)." />
<row data="Reset Device-+-&amp;lt;esc&amp;gt;c-+-Återställ alla terminalinställningar till standardvärden." />
<!--
MODES
ESC[20h Linefeed
ESC[20l Cursor key mode Application
ESC[?1h Cursor
ESC[?1l ANSII/VT52 mode ANSII
ESC[?2l Column mode 132 col.
ESC[?3h 80 col.
ESC[?3l Scrolling mode Smooth
ESC[?4h Jump
ESC[?4l Screen video mode Black on wht
ESC[?5h White on blk
ESC[?5l Origin mode Relative
ESC[?6h Absolute
ESC[?6l Wraparound On
ESC[?7h Off
ESC[?7l Auto key repeat On
ESC[?8h Off
ESC[?8l Interlaced video On
ESC[?9h Off
ESC[?9l Graphic proc. option On
ESC1 Off
ESC2 Keypad mode Application
ESC= Numeric
-->
<row data="E Test-+-&amp;lt;esc&amp;gt;#8-+-Fyll terminalen med bokstaven E." />
<row data="Power up Test-+-&amp;lt;esc&amp;gt;[2;1y-+-Utför startuptest (ROM, RAM, NVR, tangentbord och AVO)." />
<row data="Data loop-back Test-+-&amp;lt;esc&amp;gt;[2;2y-+-Utför data loop-back-test. Kabel krävs." />
<row data="EIA modem control-+-&amp;lt;esc&amp;gt;[2;4y-+-Kabel krävs." />
<row data="Repeat test-+-&amp;lt;esc&amp;gt;[2;8y-+-Upprepa testet tills dess att det misslyckas." />
</table>
<!--
Esc5n Device status report DSR
Esc0n Response: terminal is OK DSR
Esc3n Response: terminal is not OK DSR
VT100 Special Key Codes
These are sent from the terminal back to the computer when the particular key is pressed. Note that the numeric keypad keys send different codes in numeric mode than in alternate mode. See escape codes above to change keypad mode.
Function Keys:
EscOP PF1
EscOQ PF2
EscOR PF3
EscOS PF4
Arrow Keys:
Reset Set
up EscA EscOA
down EscB EscOB
right EscC EscOC
left EscD EscOD
Numeric Keypad Keys:
EscOp 0
EscOq 1
EscOr 2
EscOs 3
EscOt 4
EscOu 5
EscOv 6
EscOw 7
EscOx 8
EscOy 9
EscOm -(minus)
EscOl ,(comma)
EscOn .(period)
EscOM ^M
Printing:
Esc[i Print Screen Print the current screen
Esc[1i Print Line Print the current line
Esc[4i Stop Print Log Disable log
Esc[5i Start Print Log Start log; all received text is echoed to a printer
REPORTS
Report Query Response Cursor position
<ESC>[6n
<ESC>[Pl;PcR Status report
<ESC>[c
<ESC>[?1;Psc or 'what are you' Status report
<ESC>[0c
<ESC>[?1;Psc
Where Pl is line number, Pc is column no. Ps is status word
Ps = 0 Basic VT100, no options 1 VT100 with processor option (STP) 2 VT100 with advanced video (AVO) 4 VT100 with graphic processor (GPO)
3 STP & AVO 5 STP & GPO 6 AVO & GPO 7 STP, AVO & GPO
VT52
VT52 COMPATIBLE MODE
<ESC>F Select graphics characters (VT100 set not the same as VT52)
<ESC>G Select ASCII set
<ESC>I Reverse linefeed
<ESC>YPlPc Direct cursor address Pl - line, Pc - column
<ESC>Z Identify - response is <ESC>/Z
<ESC>= Enter keypad application mode
<ESC>> Enter keypad numeric mode
<ESC>< Enter ANSII mode
-->
</article>
|