1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | "use strict" ;
|
28 |
|
29 |
|
30 |
|
31 | const tree = require( 'tree-kit' ) ;
|
32 | const string = require( 'string-kit' ) ;
|
33 | const xterm = require( './xterm.js' ) ;
|
34 | const gpm = require( '../gpm.js' ) ;
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | const bold = '\x1b[1m' ;
|
40 | const noBold = '\x1b[22m' ;
|
41 | const blink = '\x1b[5m' ;
|
42 | const noBlink = '\x1b[25m' ;
|
43 | const defaultColor = noBold + '\x1b[39m' ;
|
44 | const bgDefaultColor = noBold + '\x1b[49m' ;
|
45 |
|
46 |
|
47 |
|
48 | const fgCursorTable = [
|
49 | 0 , 3 , 5 , 1 , 6 , 2 , 4 , 7 ,
|
50 | 8 , 11 , 13 , 9 , 14 , 10 , 12 , 15
|
51 | ] ;
|
52 |
|
53 | const bgCursorTable = [
|
54 | 0 , 4 , 2 , 6 , 1 , 5 , 3 , 7 ,
|
55 | 8 , 12 , 10 , 14 , 9 , 13 , 11 , 15
|
56 | ] ;
|
57 |
|
58 |
|
59 |
|
60 | const esc = tree.extend( null , Object.create( xterm.esc ) , {
|
61 |
|
62 | clear: { on: '\x1b[H\x1b[J' } ,
|
63 |
|
64 |
|
65 | defaultColor: { on: defaultColor } ,
|
66 | black: { on: noBold + '\x1b[30m' , off: defaultColor } ,
|
67 | red: { on: noBold + '\x1b[31m' , off: defaultColor } ,
|
68 | green: { on: noBold + '\x1b[32m' , off: defaultColor } ,
|
69 | yellow: { on: noBold + '\x1b[33m' , off: defaultColor } ,
|
70 | blue: { on: noBold + '\x1b[34m' , off: defaultColor } ,
|
71 | magenta: { on: noBold + '\x1b[35m' , off: defaultColor } ,
|
72 | cyan: { on: noBold + '\x1b[36m' , off: defaultColor } ,
|
73 | white: { on: noBold + '\x1b[37m' , off: defaultColor } ,
|
74 | darkColor: { on: noBold + '\x1b[3%um' , off: defaultColor } ,
|
75 | brightBlack: { on: bold + '\x1b[30m' , off: defaultColor } ,
|
76 | brightRed: { on: bold + '\x1b[31m' , off: defaultColor } ,
|
77 | brightGreen: { on: bold + '\x1b[32m' , off: defaultColor } ,
|
78 | brightYellow: { on: bold + '\x1b[33m' , off: defaultColor } ,
|
79 | brightBlue: { on: bold + '\x1b[34m' , off: defaultColor } ,
|
80 | brightMagenta: { on: bold + '\x1b[35m' , off: defaultColor } ,
|
81 | brightCyan: { on: bold + '\x1b[36m' , off: defaultColor } ,
|
82 | brightWhite: { on: bold + '\x1b[37m' , off: defaultColor } ,
|
83 | brightColor: { on: bold + '\x1b[3%um' , off: defaultColor } ,
|
84 |
|
85 |
|
86 | bgDefaultColor: { on: bgDefaultColor } ,
|
87 | bgBlack: { on: noBlink + '\x1b[40m' , off: bgDefaultColor } ,
|
88 | bgRed: { on: noBlink + '\x1b[41m' , off: bgDefaultColor } ,
|
89 | bgGreen: { on: noBlink + '\x1b[42m' , off: bgDefaultColor } ,
|
90 | bgYellow: { on: noBlink + '\x1b[43m' , off: bgDefaultColor } ,
|
91 | bgBlue: { on: noBlink + '\x1b[44m' , off: bgDefaultColor } ,
|
92 | bgMagenta: { on: noBlink + '\x1b[45m' , off: bgDefaultColor } ,
|
93 | bgCyan: { on: noBlink + '\x1b[46m' , off: bgDefaultColor } ,
|
94 | bgWhite: { on: noBlink + '\x1b[47m' , off: bgDefaultColor } ,
|
95 | bgDarkColor: { on: noBlink + '\x1b[4%um' , off: bgDefaultColor } ,
|
96 | bgBrightBlack: { on: blink + '\x1b[40m' , off: bgDefaultColor } ,
|
97 | bgBrightRed: { on: blink + '\x1b[41m' , off: bgDefaultColor } ,
|
98 | bgBrightGreen: { on: blink + '\x1b[42m' , off: bgDefaultColor } ,
|
99 | bgBrightYellow: { on: blink + '\x1b[43m' , off: bgDefaultColor } ,
|
100 | bgBrightBlue: { on: blink + '\x1b[44m' , off: bgDefaultColor } ,
|
101 | bgBrightMagenta: { on: blink + '\x1b[45m' , off: bgDefaultColor } ,
|
102 | bgBrightCyan: { on: blink + '\x1b[46m' , off: bgDefaultColor } ,
|
103 | bgBrightWhite: { on: blink + '\x1b[47m' , off: bgDefaultColor } ,
|
104 | bgBrightColor: { on: blink + '\x1b[4%um' , off: bgDefaultColor } ,
|
105 |
|
106 |
|
107 | dim: { on: bold + '\x1b[30m' , off: defaultColor } ,
|
108 | underline: { on: blink + '\x1b[40m' , off: bgDefaultColor } ,
|
109 | italic: { on: '\x1b[1m' , off: '\x1b[22m' } ,
|
110 | hidden: { on: '\x1b[40m\x1b[30m' , off: '\x1b[49m\x1b[39m' } ,
|
111 | strike: { on: bold + '\x1b[30m' , off: defaultColor } ,
|
112 |
|
113 |
|
114 | hideCursor: { on: '\x1b[?1c' , off: '\x1b[?0c' } ,
|
115 | blockCursor: { on: '\x1b[?16;0;16c' } ,
|
116 | blinkingBlockCursor: { on: '\x1b[?6c' } ,
|
117 | underlineCursor: { on: '\x1b[?2c' } ,
|
118 | blinkingUnderlineCursor: { on: '\x1b[?2c' } ,
|
119 | beamCursor: { on: '' , na: true } ,
|
120 | blinkingBeamCursor: { on: '' , na: true } ,
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | windowTitle: { on: '%D' , na: true } ,
|
126 | iconName: { on: '%D' , na: true } ,
|
127 | cwd: { on: '%D' , na: true } ,
|
128 | notify: { on: '%D%D' , na: true } ,
|
129 |
|
130 | setDefaultColorRgb: { on: '\x1b]P7%x%x%x' } ,
|
131 | resetDefaultColorRgb: { on: '' , na: true } ,
|
132 | setDefaultBgColorRgb: { on: '\x1b]P0%x%x%x' } ,
|
133 | resetDefaultBgColorRgb: { on: '' , na: true } ,
|
134 | setHighlightBgColorRgb: { on: '%D%D%D' , na: true } ,
|
135 | resetHighlightBgColorRgb: { on: '' , na: true } ,
|
136 | setColorLL: { on: '\x1b]P%h%x%x%x' } ,
|
137 | resetColorLL: { on: '%D' , na: true } ,
|
138 | setFont: { on: '%D' , na: true } ,
|
139 | requestColor: { on: '%D' , na: true } ,
|
140 |
|
141 |
|
142 |
|
143 | color256: {
|
144 | on: '%[color256:%a]F' ,
|
145 | off: defaultColor ,
|
146 | fb: true ,
|
147 | handler: function( register ) {
|
148 | if ( typeof register !== 'number' ) { return '' ; }
|
149 | if ( register < 0 || register > 255 ) { return '' ; }
|
150 |
|
151 |
|
152 | if ( register > 15 ) {
|
153 | register = this.root.registerForRgb( this.root.rgbForRegister( register ) , 0 , 15 ) ;
|
154 | }
|
155 |
|
156 |
|
157 | return this.root.escHandler.color( register ) ;
|
158 | }
|
159 | } ,
|
160 |
|
161 | bgColor256: {
|
162 | on: '%[bgColor256:%a]F' ,
|
163 | off: bgDefaultColor ,
|
164 | fb: true ,
|
165 | handler: function( register ) {
|
166 | if ( typeof register !== 'number' ) { return '' ; }
|
167 | if ( register < 0 || register > 255 ) { return '' ; }
|
168 |
|
169 |
|
170 | if ( register > 15 ) {
|
171 | register = this.root.registerForRgb( this.root.rgbForRegister( register ) , 0 , 15 ) ;
|
172 | }
|
173 |
|
174 |
|
175 | return this.root.escHandler.bgColor( register ) ;
|
176 | }
|
177 | } ,
|
178 |
|
179 | setCursorColor: {
|
180 | on: '%[setCursorColor:%a%a]F' ,
|
181 | handler: function( bg , fg ) {
|
182 | if ( typeof fg !== 'number' || typeof bg !== 'number' ) { return '' ; }
|
183 |
|
184 | fg = Math.floor( fg ) ;
|
185 | bg = Math.floor( bg ) ;
|
186 |
|
187 | if ( fg < 0 || fg > 255 || bg < 0 || bg > 255 ) { return '' ; }
|
188 |
|
189 |
|
190 | if ( fg > 15 ) { fg = this.root.registerForRgb( this.root.rgbForRegister( fg ) , 0 , 15 ) ; }
|
191 | if ( bg > 15 ) { bg = this.root.registerForRgb( this.root.rgbForRegister( bg ) , 0 , 15 ) ; }
|
192 |
|
193 |
|
194 |
|
195 | fg = fgCursorTable[ fg ] ;
|
196 | bg = bgCursorTable[ bg ] ;
|
197 |
|
198 | return string.format( '\x1b[?16;%u;%uc' , fg , bg * 16 ) ;
|
199 | }
|
200 | } ,
|
201 |
|
202 |
|
203 | setCursorColorRgb: {
|
204 | on: '%[setCursorColorRgb:%a%a%a]F' ,
|
205 | handler: function( r , g , b ) {
|
206 | if ( typeof r !== 'number' || typeof g !== 'number' || typeof b !== 'number' ) { return '' ; }
|
207 |
|
208 | r = Math.floor( r ) ;
|
209 | g = Math.floor( g ) ;
|
210 | b = Math.floor( b ) ;
|
211 |
|
212 | if ( r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255 ) { return '' ; }
|
213 |
|
214 | var register = this.root.registerForRgb( r , g , b , 0 , 15 ) ;
|
215 |
|
216 |
|
217 |
|
218 | return this.root.str.setCursorColor( register , 0 ) ;
|
219 | }
|
220 | } ,
|
221 |
|
222 | |
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 | mouseButton: {
|
233 | on: '%[mouseButton]F' ,
|
234 | off: '%[mouseButton_off]F' ,
|
235 | handler: function() { gpmMouse.call( this , 'button' ) ; return '' ; } ,
|
236 | offHandler: function() { gpmMouse.call( this , false ) ; return '' ; }
|
237 | } ,
|
238 |
|
239 |
|
240 | mouseDrag: {
|
241 | on: '%[mouseDrag]F' ,
|
242 | off: '%[mouseDrag_off]F' ,
|
243 | handler: function() { gpmMouse.call( this , 'drag' ) ; return '' ; } ,
|
244 | offHandler: function() { gpmMouse.call( this , false ) ; return '' ; }
|
245 | } ,
|
246 |
|
247 |
|
248 | mouseMotion: {
|
249 | on: '%[mouseMotion]F' ,
|
250 | off: '%[mouseMotion_off]F' ,
|
251 | handler: function() { gpmMouse.call( this , 'motion' ) ; return '' ; } ,
|
252 | offHandler: function() { gpmMouse.call( this , false ) ; return '' ; }
|
253 | } ,
|
254 |
|
255 | mouseHilight: { on: '' , off: '' } ,
|
256 | mouseSGR: { on: '' , off: '' } ,
|
257 | focusEvent: { on: '' , off: '' }
|
258 | } ) ;
|
259 |
|
260 |
|
261 |
|
262 |
|
263 | function gpmMouse( mode ) {
|
264 | if ( this.root.gpmHandler ) {
|
265 | this.root.gpmHandler.close() ;
|
266 | this.root.gpmHandler = undefined ;
|
267 | }
|
268 |
|
269 | if ( ! mode ) {
|
270 |
|
271 | return ;
|
272 | }
|
273 |
|
274 | this.root.gpmHandler = gpm.createHandler( { stdin: this.root.stdin , raw: false , mode: mode } ) ;
|
275 |
|
276 |
|
277 |
|
278 |
|
279 | this.root.gpmHandler.on( 'mouse' , ( name , data ) => {
|
280 | this.root.emit( 'mouse' , name , data ) ;
|
281 | } ) ;
|
282 | this.root.gpmHandler.on( 'error' , ( ) => {
|
283 |
|
284 | } ) ;
|
285 | }
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 | const keymap = tree.extend( null , Object.create( xterm.keymap ) , {
|
295 | F1: '\x1b[[A' ,
|
296 | F2: '\x1b[[B' ,
|
297 | F3: '\x1b[[C' ,
|
298 | F4: '\x1b[[D' ,
|
299 | F5: '\x1b[[E' ,
|
300 |
|
301 | SHIFT_F1: '\x1b[25~' ,
|
302 | SHIFT_F2: '\x1b[26~' ,
|
303 | SHIFT_F3: '\x1b[28~' ,
|
304 | SHIFT_F4: '\x1b[29~' ,
|
305 | SHIFT_F5: '\x1b[31~' ,
|
306 | SHIFT_F6: '\x1b[32~' ,
|
307 | SHIFT_F7: '\x1b[33~' ,
|
308 | SHIFT_F8: '\x1b[34~' ,
|
309 |
|
310 |
|
311 |
|
312 | KP_NUMLOCK: '\x1bOP' ,
|
313 | KP_DIVIDE: '\x1bOQ' ,
|
314 | KP_MULTIPLY: '\x1bOR' ,
|
315 | KP_MINUS: '\x1bOS' ,
|
316 | KP_0: '\x1bOp' ,
|
317 | KP_1: '\x1bOq' ,
|
318 | KP_2: '\x1bOr' ,
|
319 | KP_3: '\x1bOs' ,
|
320 | KP_4: '\x1bOt' ,
|
321 | KP_5: '\x1bOu' ,
|
322 | KP_6: '\x1bOv' ,
|
323 | KP_7: '\x1bOw' ,
|
324 | KP_8: '\x1bOx' ,
|
325 | KP_9: '\x1bOy' ,
|
326 | KP_PLUS: '\x1bOl' ,
|
327 | KP_DELETE: '\x1bOn' ,
|
328 | KP_ENTER: '\x1bOM'
|
329 |
|
330 | } ) ;
|
331 |
|
332 |
|
333 |
|
334 | module.exports = {
|
335 | esc: esc ,
|
336 | keymap: keymap ,
|
337 | handler: Object.create( xterm.handler ) ,
|
338 | support: {
|
339 | deltaEscapeSequence: false ,
|
340 | "256colors": false ,
|
341 | "24bitsColors": false ,
|
342 | "trueColor": false
|
343 | } ,
|
344 |
|
345 |
|
346 |
|
347 | colorRegister: require( '../colorScheme/linux.json' )
|
348 | } ;
|
349 |
|