UNPKG

8.14 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// Used when there is no terminal (e.g.: pipe)
32
33
34
35const esc = {
36
37 /* Common sequences */
38
39 // Reset the terminal
40 reset: { on: '' } ,
41
42 /* Cursor sequences */
43
44 saveCursor: { on: '' } ,
45 restoreCursor: { on: '' } ,
46
47 up: { on: '%D' } ,
48 down: { on: '%D' } ,
49 right: { on: '%D' } ,
50 left: { on: '%D' } ,
51 nextLine: { on: '%D' } ,
52 previousLine: { on: '%D' } ,
53
54 //column: { on: '%D' } ,
55 column: {
56 on: '%[column:%a]F' ,
57 handler: x => {
58 if ( typeof x !== 'number' || ! x || x <= 1 || x === Infinity ) { return '' ; }
59 return ' '.repeat( x - 1 ) ;
60 }
61 } ,
62 row: { on: '%D' } ,
63 moveTo: { on: '%D%D' , optimized: () => '' } ,
64 //moveToBottomLeft: { on: '' } , // Not widely supported
65 hideCursor: { on: '' , off: '' } ,
66
67 tabSet: { on: '' } , // HTS
68 tabClear: { on: '' } , // TBC
69 tabClearAll: { on: '' } , // TBC
70 forwardTab: { on: '%D' } , // CHT
71 backwardTab: { on: '%D' } , // CBT
72
73 // Cursor styles
74 blockCursor: { on: '' } ,
75 blinkingBlockCursor: { on: '' } ,
76 underlineCursor: { on: '' } ,
77 blinkingUnderlineCursor: { on: '' } ,
78 beamCursor: { on: '' } ,
79 blinkingBeamCursor: { on: '' } ,
80
81 /* Editing sequences */
82
83 clear: { on: '' } ,
84 eraseDisplayBelow: { on: '' } ,
85 eraseDisplayAbove: { on: '' } ,
86 eraseDisplay: { on: '' } ,
87 eraseSavedLine: { on: '' } ,
88 eraseLineAfter: { on: '' } ,
89 eraseLineBefore: { on: '' } ,
90 eraseLine: { on: '' } ,
91 insertLine: { on: '%D' } ,
92 deleteLine: { on: '%D' } ,
93 insert: { on: '%D' } , // insert char
94 'delete': { on: '%D' } , // delete char
95 backDelete: { on: '' } , // Backspace-like, left(1) followed by delete(1)
96 scrollUp: { on: '%D' } , // scroll up n lines, new lines are added at the bottom
97 scrollDown: { on: '%D' } , // scroll down n lines, new lines are added at the top
98 scrollingRegion: { on: '%D%D' } , // top line, bottom line, scrolling affect only this region,
99 resetScrollingRegion: { on: '' } ,
100
101 // This set the alternate screen buffer, do not work on many term, due to this titeInhibit shit...
102 alternateScreenBuffer: { on: '' , off: '' } ,
103
104 /* Misc sequences */
105
106 beep: { on: '' } , // Deprecated -- use bell instead
107 bell: { on: '' } , // Emit an audible bell
108
109 /* Style sequences */
110
111 styleReset: { on: '' } ,
112
113 bold: { on: '' , off: '' } , // here we use the dim.off code (22) that have a better support than (21), for God-only known reason...
114 dim: { on: '' , off: '' } , // dim: darker, 'off' remove removes also bold/bright
115 italic: { on: '' , off: '' } ,
116 underline: { on: '' , off: '' } ,
117 blink: { on: '' , off: '' } ,
118 inverse: { on: '' , off: '' } ,
119 hidden: { on: '' , off: '' } , // invisible, but can be copy/paste'd
120 strike: { on: '' , off: '' } ,
121
122 // Foreground color
123 defaultColor: { on: '' } ,
124 black: { on: '' , off: '' } ,
125 red: { on: '' , off: '' } ,
126 green: { on: '' , off: '' } ,
127 yellow: { on: '' , off: '' } ,
128 blue: { on: '' , off: '' } ,
129 magenta: { on: '' , off: '' } ,
130 cyan: { on: '' , off: '' } ,
131 white: { on: '' , off: '' } ,
132 darkColor: { on: '%D' , off: '' } , // should be called with a 0..7 integer
133 brightBlack: { on: '' , off: '' } ,
134 brightRed: { on: '' , off: '' } ,
135 brightGreen: { on: '' , off: '' } ,
136 brightYellow: { on: '' , off: '' } ,
137 brightBlue: { on: '' , off: '' } ,
138 brightMagenta: { on: '' , off: '' } ,
139 brightCyan: { on: '' , off: '' } ,
140 brightWhite: { on: '' , off: '' } ,
141 brightColor: { on: '%D' , off: '' } , // should be called with a 0..7 integer
142
143 // Background color
144 bgDefaultColor: { on: '' } ,
145 bgBlack: { on: '' , off: '' } ,
146 bgRed: { on: '' , off: '' } ,
147 bgGreen: { on: '' , off: '' } ,
148 bgYellow: { on: '' , off: '' } ,
149 bgBlue: { on: '' , off: '' } ,
150 bgMagenta: { on: '' , off: '' } ,
151 bgCyan: { on: '' , off: '' } ,
152 bgWhite: { on: '' , off: '' } ,
153 bgDarkColor: { on: '%D' , off: '' } , // should be called with a 0..7 integer
154 bgBrightBlack: { on: '' , off: '' } ,
155 bgBrightRed: { on: '' , off: '' } ,
156 bgBrightGreen: { on: '' , off: '' } ,
157 bgBrightYellow: { on: '' , off: '' } ,
158 bgBrightBlue: { on: '' , off: '' } ,
159 bgBrightMagenta: { on: '' , off: '' } ,
160 bgBrightCyan: { on: '' , off: '' } ,
161 bgBrightWhite: { on: '' , off: '' } ,
162 bgBrightColor: { on: '%D' , off: '' } , // should be called with a 0..7 integer
163
164 /* Input / Output sequences */
165
166 // Request terminal ID
167 // requestTerminalId: { on: '' } ,
168
169 // Terminal will send the cursor coordinate only one time
170 requestCursorLocation: { on: '' , na: true } ,
171
172 // Terminal will send the cursor coordinate only one time
173 requestScreenSize: { on: '' } ,
174
175 // Terminal will send the rgb color for a register
176 requestColor: { on: '%D' , na: true } ,
177
178 // Terminal will send event on button pressed with mouse position
179 mouseButton: { on: '' , off: '' } ,
180
181 // Terminal will send position of the column hilighted
182 mouseHilight: { on: '' , off: '' } ,
183
184 // Terminal will send event on button pressed and mouse motion as long as a button is down, with mouse position
185 mouseDrag: { on: '' , off: '' } ,
186
187 // Terminal will send event on button pressed and motion
188 mouseMotion: { on: '' , off: '' } ,
189
190 // Another mouse protocol that extend coordinate mapping (without it, it supports only 223 rows and columns)
191 mouseSGR: { on: '' , off: '' } ,
192
193 // Terminal will send event when it gains and loses focus
194 focusEvent: { on: '' , off: '' } ,
195
196 // Should allow keypad to send different code than 0..9 keys but it does not works on some setup
197 applicationKeypad: { on: '' , off: '' } ,
198
199 /* OSC - OS Control sequences: may be unavailable on some context */
200
201 // Set the title of an xterm-compatible window
202 windowTitle: { on: '%D' } ,
203 iconName: { on: '%D' } ,
204 cwd: { on: '%D' } ,
205 notify: { on: '%D%D' } ,
206
207 // Those sequences accept either #%x%x%x or rgb:%d/%d/%d
208 // Sometime rgb:%d/%d/%d should be encoded into the 0..65535 range, so #%x%x%x is more reliable
209 setCursorColorRgb: { on: '%D%D%D' } , // it want rgb as parameter, like rgb:127/0/32
210 resetCursorColorRgb: { on: '' } ,
211 setDefaultColorRgb: { on: '%D%D%D' } , // not widely supported
212 resetDefaultColorRgb: { on: '' } ,
213 setDefaultBgColorRgb: { on: '%D%D%D' } , // not widely supported
214 resetDefaultBgColorRgb: { on: '' } ,
215 setHighlightBgColorRgb: { on: '%D%D%D' } , // not widely supported
216 resetHighlightBgColorRgb: { on: '' } ,
217 setColorLL: { on: '%D%D%D%D' } , // LL= Low Level
218 resetColorLL: { on: '%D' } ,
219
220 setClipboardLL: { na: true } ,
221 requestClipboard: { na: true } ,
222
223 setFont: { on: '%D' } , // ->|TODOC|<- rarely supported
224 color24bits: { on: '%D%D%D' , na: true } , // not capable
225 bgColor24bits: { on: '%D%D%D' , na: true } , // not capable
226
227 /* Functions */
228
229 color256: { on: '%D' , off: '' } ,
230 bgColor256: { on: '%D' , off: '' } ,
231 setCursorColor: { on: '%D%D' , off: '' }
232} ;
233
234
235
236const handler = {} ;
237const keymap = {} ;
238
239
240
241module.exports = {
242 esc: esc ,
243 keymap: keymap ,
244 handler: handler ,
245 support: {
246 deltaEscapeSequence: false ,
247 "256colors": false ,
248 "24bitsColors": false , // DEPRECATED
249 "trueColor": false
250 } ,
251 // Whatever...
252 colorRegister: require( '../colorScheme/linux.json' )
253} ;
254