UNPKG

9.34 kBJavaScriptView Raw
1/*
2 Terminal Kit
3
4 Copyright (c) 2009 - 2020 Cédric Ronvel
5
6 The MIT License (MIT)
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in all
16 copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 SOFTWARE.
25*/
26
27"use strict" ;
28
29
30
31// Control char (not escape sequence)
32exports.control = {
33 '\\x07': { event: 'bell' } ,
34
35 // Looks like it just moves to the left
36 //'\\x08': { event: 'edit' , subType: 'backDelete' , extraArgs: [ 1 ] } ,
37 '\\x08': { event: 'cursor' , subType: 'left' , extraArgs: [ 1 ] } ,
38
39 '\\x09': { event: 'cursor' , subType: 'tab' } ,
40 '\\x0a': { event: 'cursor' , subType: 'lineFeed' } ,
41 '\\x0d': { event: 'cursor' , subType: 'carriageReturn' } ,
42
43 // Looks like it does nothing at all
44 //'\\x7f': { event: 'edit' , subType: 'delete' , extraArgs: [ 1 ] } ,
45 '\\x7f': { event: 'none' }
46} ;
47
48
49
50// ESC (simple ESC + char sequence)
51exports.ESC = {
52 '7': { event: 'cursor' , subType: 'save' } ,
53 '8': { event: 'cursor' , subType: 'restore' } ,
54 'c': { event: 'reset' } ,
55 'M': { event: 'edit' , subType: 'reverseLineFeed' }
56} ;
57
58
59
60// CSI tree (Control Sequence Introducer)
61exports.CSI = {
62 A: { event: 'cursor' , subType: 'up' , defaultExtraArgs: [ 1 ] } ,
63 B: { event: 'cursor' , subType: 'down' , defaultExtraArgs: [ 1 ] } ,
64 C: { event: 'cursor' , subType: 'right' , defaultExtraArgs: [ 1 ] } ,
65 D: { event: 'cursor' , subType: 'left' , defaultExtraArgs: [ 1 ] } ,
66 E: { event: 'cursor' , subType: 'nextLine' , defaultExtraArgs: [ 1 ] } ,
67 F: { event: 'cursor' , subType: 'previousLine' , defaultExtraArgs: [ 1 ] } ,
68 G: { event: 'cursor' , subType: 'column' } ,
69 H: { event: 'cursor' , subType: 'moveToYX' , defaultExtraArgs: [ 1 , 1 ] } ,
70
71 J: {
72 event: 'edit' ,
73 subType: 'eraseDisplay' ,
74 arg: 'after' ,
75 subTree: {
76 '0': { arg: 'after' } ,
77 '1': { arg: 'before' } ,
78 '2': { arg: 'display' }
79 }
80 } ,
81
82 K: {
83 event: 'edit' ,
84 subType: 'eraseLine' ,
85 arg: 'after' ,
86 subTree: {
87 '0': { arg: 'after' } ,
88 '1': { arg: 'before' } ,
89 '2': { arg: 'line' }
90 }
91 } ,
92
93 L: { event: 'edit' , subType: 'insertLine' , defaultExtraArgs: [ 1 ] } ,
94 M: { event: 'edit' , subType: 'deleteLine' , defaultExtraArgs: [ 1 ] } ,
95
96 P: { event: 'edit' , subType: 'delete' , defaultExtraArgs: [ 1 ] } ,
97 S: { event: 'edit' , subType: 'vScrollUp' , defaultExtraArgs: [ 1 ] } ,
98 T: { event: 'edit' , subType: 'vScrollDown' , defaultExtraArgs: [ 1 ] } ,
99 X: { event: 'edit' , subType: 'erase' , defaultExtraArgs: [ 1 ] } ,
100
101 d: { event: 'cursor' , subType: 'row' } ,
102
103 '?h': {
104 event: 'device' ,
105 arg: true ,
106 subTree: {
107 '1000': { subType: 'mouseButton' , continue: true } ,
108 '1002': { subType: 'mouseDrag' , continue: true } ,
109 '1003': { subType: 'mouseMotion' , continue: true } ,
110 '1004': { subType: 'focusEvent' , continue: true } ,
111 '1006': { event: 'none' , continue: true } // we only support SGR anyway
112 }
113 } ,
114 '?l': {
115 // This is the "turn off" counter-part of '?h' type, the subTree is copied from '?h' after the current assignment
116 event: 'device' ,
117 arg: false ,
118 subTree: null
119 } ,
120
121 n: {
122 // Device status report
123 event: 'device' ,
124 subTree: {
125 '6': { subType: 'cursorLocation' }
126 }
127 } ,
128 '?n': {
129 // Device status report (again)
130 event: 'device' ,
131 subTree: {
132 '6': { subType: 'cursorLocation' , arg: true }
133 }
134 } ,
135
136 m: {
137 // Known as SGR (Select Graphic Rendition)
138 event: 'attr' ,
139 subType: 'reset' , // if empty, it is usually a reset
140 subTree: {
141 '0': { subType: 'reset' , continue: true } ,
142
143 '1': { subType: 'bold' , arg: true , continue: true } ,
144 '2': { subType: 'dim' , arg: true , continue: true } ,
145 '3': { subType: 'italic' , arg: true , continue: true } ,
146 '4': { subType: 'underline' , arg: true , continue: true } ,
147 '5': { subType: 'blink' , arg: true , continue: true } ,
148 '7': { subType: 'inverse' , arg: true , continue: true } ,
149 '8': { subType: 'hidden' , arg: true , continue: true } ,
150 '9': { subType: 'strike' , arg: true , continue: true } ,
151
152 '21': { subType: 'bold' , arg: false , continue: true } ,
153 '22': { subType: 'noDimNoBold' , continue: true } ,
154 '23': { subType: 'italic' , arg: false , continue: true } ,
155 '24': { subType: 'underline' , arg: false , continue: true } ,
156 '25': { subType: 'blink' , arg: false , continue: true } ,
157 '27': { subType: 'inverse' , arg: false , continue: true } ,
158 '28': { subType: 'hidden' , arg: false , continue: true } ,
159 '29': { subType: 'strike' , arg: false , continue: true } ,
160
161 '30': { subType: 'color' , arg: 'black' , continue: true } ,
162 '31': { subType: 'color' , arg: 'red' , continue: true } ,
163 '32': { subType: 'color' , arg: 'green' , continue: true } ,
164 '33': { subType: 'color' , arg: 'yellow' , continue: true } ,
165 '34': { subType: 'color' , arg: 'blue' , continue: true } ,
166 '35': { subType: 'color' , arg: 'magenta' , continue: true } ,
167 '36': { subType: 'color' , arg: 'cyan' , continue: true } ,
168 '37': { subType: 'color' , arg: 'white' , continue: true } ,
169 '38': {
170 subTree: {
171 '2': { subType: 'colorRgb' } ,
172 '5': { subType: 'color256' }
173 }
174 } ,
175 '39': { subType: 'color' , arg: 'default' , continue: true } ,
176
177 '40': { subType: 'bgColor' , arg: 'black' , continue: true } ,
178 '41': { subType: 'bgColor' , arg: 'red' , continue: true } ,
179 '42': { subType: 'bgColor' , arg: 'green' , continue: true } ,
180 '43': { subType: 'bgColor' , arg: 'yellow' , continue: true } ,
181 '44': { subType: 'bgColor' , arg: 'blue' , continue: true } ,
182 '45': { subType: 'bgColor' , arg: 'magenta' , continue: true } ,
183 '46': { subType: 'bgColor' , arg: 'cyan' , continue: true } ,
184 '47': { subType: 'bgColor' , arg: 'white' , continue: true } ,
185 '48': {
186 subTree: {
187 '2': { subType: 'bgColorRgb' } ,
188 '5': { subType: 'bgColor256' }
189 }
190 } ,
191 '49': { subType: 'bgColor' , arg: 'default' , continue: true } ,
192
193 '90': { subType: 'color' , arg: 'gray' , continue: true } ,
194 '91': { subType: 'color' , arg: 'brightRed' , continue: true } ,
195 '92': { subType: 'color' , arg: 'brightGreen' , continue: true } ,
196 '93': { subType: 'color' , arg: 'brightYellow' , continue: true } ,
197 '94': { subType: 'color' , arg: 'brightBlue' , continue: true } ,
198 '95': { subType: 'color' , arg: 'brightMagenta' , continue: true } ,
199 '96': { subType: 'color' , arg: 'brightCyan' , continue: true } ,
200 '97': { subType: 'color' , arg: 'brightWhite' , continue: true } ,
201
202 '100': { subType: 'bgColor' , arg: 'gray' , continue: true } ,
203 '101': { subType: 'bgColor' , arg: 'brightRed' , continue: true } ,
204 '102': { subType: 'bgColor' , arg: 'brightGreen' , continue: true } ,
205 '103': { subType: 'bgColor' , arg: 'brightYellow' , continue: true } ,
206 '104': { subType: 'bgColor' , arg: 'brightBlue' , continue: true } ,
207 '105': { subType: 'bgColor' , arg: 'brightMagenta' , continue: true } ,
208 '106': { subType: 'bgColor' , arg: 'brightCyan' , continue: true } ,
209 '107': { subType: 'bgColor' , arg: 'brightWhite' , continue: true }
210 }
211 } ,
212
213 r: { event: 'edit' , subType: 'vScrollingRegion' } ,
214 t: {
215 event: 'device' ,
216 subTree: {
217 '18': { subType: 'screenSize' }
218 }
219 }
220} ;
221
222exports.CSI['?l'].subTree = exports.CSI['?h'].subTree ;
223
224
225
226// OSC tree (OS Command)
227exports.OSC = {
228 '0': { event: 'system' , subType: 'setWindowTitle' } ,
229 '1': { event: 'system' , subType: 'setIconName' } ,
230 '2': { event: 'system' , subType: 'setWindowTitle' } ,
231 '4': { event: 'palette' , subType: 'setColor' } ,
232 '4?': { event: 'palette' , subType: 'getColor' } ,
233 '7': { event: 'system' , subType: 'setCwd' } ,
234 '9': { event: 'system' , subType: 'notify' } , // iTerm2 growl notification, only a body argument
235 '10': { event: 'palette' , subType: 'setDefaultColor' } ,
236 '11': { event: 'palette' , subType: 'setDefaultBgColor' } ,
237 '12': { event: 'cursorAttr' , subType: 'setColor' } ,
238 '17': { event: 'palette' , subType: 'setHighlightBgColor' } ,
239 '50': { event: 'cursorAttr' , subType: 'setShape' } ,
240 '104': { event: 'palette' , subType: 'resetColor' } ,
241 '110': { event: 'palette' , subType: 'resetDefaultColor' } ,
242 '111': { event: 'palette' , subType: 'resetDefaultBgColor' } ,
243 '112': { event: 'cursorAttr' , subType: 'resetColor' } ,
244 '117': { event: 'palette' , subType: 'resetHighlightBgColor' } ,
245 '777': { // rxvt/urxvt module, only support notifications
246 event: 'system' ,
247 subTree: {
248 'notify': { subType: 'notify' } // notify with a title and body arguments
249 }
250 }
251} ;
252