@socketsecurity/cli-with-sentry 0.14.94 → 0.14.95

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/dist/constants.js +3 -3
  2. package/dist/constants.js.map +1 -1
  3. package/dist/instrument-with-sentry.js +2 -2
  4. package/dist/instrument-with-sentry.js.map +1 -1
  5. package/dist/module-sync/cli.js +176 -156
  6. package/dist/module-sync/cli.js.map +1 -1
  7. package/dist/module-sync/shadow-bin.js +3 -14
  8. package/dist/module-sync/shadow-bin.js.map +1 -1
  9. package/dist/module-sync/shadow-npm-inject.js +68 -59
  10. package/dist/module-sync/shadow-npm-inject.js.map +1 -1
  11. package/dist/module-sync/shadow-npm-paths.js +16 -29
  12. package/dist/module-sync/shadow-npm-paths.js.map +1 -1
  13. package/dist/module-sync/vendor.d.ts +0 -0
  14. package/dist/module-sync/vendor.js +85829 -12598
  15. package/dist/module-sync/vendor.js.map +1 -1
  16. package/dist/require/cli.js +158 -137
  17. package/dist/require/cli.js.map +1 -1
  18. package/dist/require/shadow-bin.d.ts +5 -0
  19. package/dist/require/shadow-bin.js +108 -1
  20. package/dist/require/shadow-bin.js.map +1 -0
  21. package/dist/require/shadow-npm-inject.d.ts +1 -0
  22. package/dist/require/shadow-npm-inject.js +2335 -1
  23. package/dist/require/shadow-npm-inject.js.map +1 -0
  24. package/dist/require/shadow-npm-paths.d.ts +29 -0
  25. package/dist/require/shadow-npm-paths.js +454 -1
  26. package/dist/require/shadow-npm-paths.js.map +1 -0
  27. package/package.json +29 -29
  28. package/dist/blessed/lib/alias.js +0 -521
  29. package/dist/blessed/lib/blessed.js +0 -34
  30. package/dist/blessed/lib/colors.js +0 -492
  31. package/dist/blessed/lib/events.js +0 -197
  32. package/dist/blessed/lib/gpmclient.js +0 -247
  33. package/dist/blessed/lib/helpers.js +0 -172
  34. package/dist/blessed/lib/keys.js +0 -514
  35. package/dist/blessed/lib/program.js +0 -4532
  36. package/dist/blessed/lib/tput.js +0 -3113
  37. package/dist/blessed/lib/unicode.js +0 -914
  38. package/dist/blessed/lib/widget.js +0 -62
  39. package/dist/blessed/lib/widgets/ansiimage.js +0 -175
  40. package/dist/blessed/lib/widgets/bigtext.js +0 -172
  41. package/dist/blessed/lib/widgets/box.js +0 -36
  42. package/dist/blessed/lib/widgets/button.js +0 -64
  43. package/dist/blessed/lib/widgets/checkbox.js +0 -97
  44. package/dist/blessed/lib/widgets/element.js +0 -2873
  45. package/dist/blessed/lib/widgets/filemanager.js +0 -225
  46. package/dist/blessed/lib/widgets/form.js +0 -303
  47. package/dist/blessed/lib/widgets/image.js +0 -73
  48. package/dist/blessed/lib/widgets/input.js +0 -36
  49. package/dist/blessed/lib/widgets/layout.js +0 -251
  50. package/dist/blessed/lib/widgets/line.js +0 -61
  51. package/dist/blessed/lib/widgets/list.js +0 -654
  52. package/dist/blessed/lib/widgets/listbar.js +0 -454
  53. package/dist/blessed/lib/widgets/listtable.js +0 -267
  54. package/dist/blessed/lib/widgets/loading.js +0 -90
  55. package/dist/blessed/lib/widgets/log.js +0 -84
  56. package/dist/blessed/lib/widgets/message.js +0 -147
  57. package/dist/blessed/lib/widgets/node.js +0 -315
  58. package/dist/blessed/lib/widgets/overlayimage.js +0 -796
  59. package/dist/blessed/lib/widgets/progressbar.js +0 -168
  60. package/dist/blessed/lib/widgets/prompt.js +0 -129
  61. package/dist/blessed/lib/widgets/question.js +0 -131
  62. package/dist/blessed/lib/widgets/radiobutton.js +0 -64
  63. package/dist/blessed/lib/widgets/radioset.js +0 -38
  64. package/dist/blessed/lib/widgets/screen.js +0 -2487
  65. package/dist/blessed/lib/widgets/scrollablebox.js +0 -417
  66. package/dist/blessed/lib/widgets/scrollabletext.js +0 -37
  67. package/dist/blessed/lib/widgets/table.js +0 -385
  68. package/dist/blessed/lib/widgets/terminal.js +0 -454
  69. package/dist/blessed/lib/widgets/text.js +0 -37
  70. package/dist/blessed/lib/widgets/textarea.js +0 -378
  71. package/dist/blessed/lib/widgets/textbox.js +0 -81
  72. package/dist/blessed/lib/widgets/video.js +0 -132
  73. package/dist/blessed/usr/fonts/AUTHORS +0 -1
  74. package/dist/blessed/usr/fonts/LICENSE +0 -94
  75. package/dist/blessed/usr/fonts/README +0 -340
  76. package/dist/blessed/usr/fonts/ter-u14b.json +0 -17826
  77. package/dist/blessed/usr/fonts/ter-u14n.json +0 -17826
  78. package/dist/blessed/usr/linux +0 -0
  79. package/dist/blessed/usr/windows-ansi +0 -0
  80. package/dist/blessed/usr/xterm +0 -0
  81. package/dist/blessed/usr/xterm-256color +0 -0
  82. package/dist/blessed/usr/xterm.termcap +0 -243
  83. package/dist/blessed/usr/xterm.terminfo +0 -1977
  84. package/dist/blessed/vendor/tng.js +0 -1878
@@ -1,4532 +0,0 @@
1
- 'use strict'
2
-
3
- /**
4
- * program.js - basic curses-like functionality for blessed.
5
- * Copyright (c) 2013-2015, Christopher Jeffrey and contributors (MIT License).
6
- * https://github.com/chjj/blessed
7
- */
8
-
9
- /**
10
- * Modules
11
- */
12
-
13
- const EventEmitter = require('node:events').EventEmitter,
14
- StringDecoder = require('node:string_decoder').StringDecoder,
15
- cp = require('node:child_process'),
16
- util = require('node:util'),
17
- fs = require('node:fs')
18
-
19
- const Tput = require('./tput'),
20
- colors = require('./colors'),
21
- slice = Array.prototype.slice
22
-
23
- const nextTick = global.setImmediate || process.nextTick.bind(process)
24
-
25
- /**
26
- * Program
27
- */
28
-
29
- function Program(options) {
30
- const self = this
31
-
32
- if (!(this instanceof Program)) {
33
- return new Program(options)
34
- }
35
-
36
- Program.bind(this)
37
-
38
- EventEmitter.call(this)
39
-
40
- if (!options || Object.getPrototypeOf(options) !== Object.prototype) {
41
- options = {
42
- input: arguments[0],
43
- output: arguments[1]
44
- }
45
- }
46
-
47
- this.options = options
48
- this.input = options.input || process.stdin
49
- this.output = options.output || process.stdout
50
-
51
- options.log = options.log || options.dump
52
- if (options.log) {
53
- this._logger = fs.createWriteStream(options.log)
54
- if (options.dump) {
55
- this.setupDump()
56
- }
57
- }
58
-
59
- this.zero = options.zero !== false
60
- this.useBuffer = options.buffer
61
-
62
- this.x = 0
63
- this.y = 0
64
- this.savedX = 0
65
- this.savedY = 0
66
-
67
- this.cols = this.output.columns || 1
68
- this.rows = this.output.rows || 1
69
-
70
- this.scrollTop = 0
71
- this.scrollBottom = this.rows - 1
72
-
73
- this._terminal =
74
- options.terminal ||
75
- options.term ||
76
- process.env.TERM ||
77
- (process.platform === 'win32' ? 'windows-ansi' : 'xterm')
78
-
79
- this._terminal = this._terminal.toLowerCase()
80
-
81
- // OSX
82
- this.isOSXTerm = process.env.TERM_PROGRAM === 'Apple_Terminal'
83
- this.isiTerm2 =
84
- process.env.TERM_PROGRAM === 'iTerm.app' || !!process.env.ITERM_SESSION_ID
85
-
86
- // VTE
87
- // NOTE: lxterminal does not provide an env variable to check for.
88
- // NOTE: gnome-terminal and sakura use a later version of VTE
89
- // which provides VTE_VERSION as well as supports SGR events.
90
- this.isXFCE = /xfce/i.test(process.env.COLORTERM)
91
- this.isTerminator = !!process.env.TERMINATOR_UUID
92
- this.isLXDE = false
93
- this.isVTE =
94
- !!process.env.VTE_VERSION || this.isXFCE || this.isTerminator || this.isLXDE
95
-
96
- // xterm and rxvt - not accurate
97
- this.isRxvt = /rxvt/i.test(process.env.COLORTERM)
98
- this.isXterm = false
99
-
100
- this.tmux = !!process.env.TMUX
101
- this.tmuxVersion = (function () {
102
- if (!self.tmux) {
103
- return 2
104
- }
105
- try {
106
- const version = cp.execFileSync('tmux', ['-V'], { encoding: 'utf8' })
107
- return +/^tmux ([\d.]+)/i.exec(version.trim().split('\n')[0])[1]
108
- } catch (e) {
109
- return 2
110
- }
111
- })()
112
-
113
- this._buf = ''
114
- this._flush = this.flush.bind(this)
115
-
116
- if (options.tput !== false) {
117
- this.setupTput()
118
- }
119
-
120
- this.listen()
121
- }
122
-
123
- Program.global = null
124
-
125
- Program.total = 0
126
-
127
- Program.instances = []
128
-
129
- Program.bind = function (program) {
130
- if (!Program.global) {
131
- Program.global = program
132
- }
133
-
134
- if (!~Program.instances.indexOf(program)) {
135
- Program.instances.push(program)
136
- program.index = Program.total
137
- Program.total++
138
- }
139
-
140
- if (Program._bound) {
141
- return
142
- }
143
- Program._bound = true
144
-
145
- unshiftEvent(
146
- process,
147
- 'exit',
148
- (Program._exitHandler = function () {
149
- Program.instances.forEach(function (program) {
150
- // Potentially reset window title on exit:
151
- // if (program._originalTitle) {
152
- // program.setTitle(program._originalTitle);
153
- // }
154
- // Ensure the buffer is flushed (it should
155
- // always be at this point, but who knows).
156
- program.flush()
157
- // Ensure _exiting is set (could technically
158
- // use process._exiting).
159
- program._exiting = true
160
- })
161
- })
162
- )
163
- }
164
-
165
- Object.setPrototypeOf(Program.prototype, EventEmitter.prototype)
166
-
167
- Program.prototype.type = 'program'
168
-
169
- Program.prototype.log = function () {
170
- return this._log('LOG', util.format.apply(util, arguments))
171
- }
172
-
173
- Program.prototype.debug = function () {
174
- if (!this.options.debug) {
175
- return
176
- }
177
- return this._log('DEBUG', util.format.apply(util, arguments))
178
- }
179
-
180
- Program.prototype._log = function (pre, msg) {
181
- if (!this._logger) {
182
- return
183
- }
184
- return this._logger.write(pre + ': ' + msg + '\n-\n')
185
- }
186
-
187
- Program.prototype.setupDump = function () {
188
- const self = this,
189
- write = this.output.write,
190
- decoder = new StringDecoder('utf8')
191
-
192
- function stringify(data) {
193
- return caret(
194
- data.replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/\t/g, '\\t')
195
- ).replace(/[^ -~]/g, function (ch) {
196
- if (ch.charCodeAt(0) > 0xff) {
197
- return ch
198
- }
199
- ch = ch.charCodeAt(0).toString(16)
200
- if (ch.length > 2) {
201
- if (ch.length < 4) {
202
- ch = '0' + ch
203
- }
204
- return '\\u' + ch
205
- }
206
- if (ch.length < 2) {
207
- ch = '0' + ch
208
- }
209
- return '\\x' + ch
210
- })
211
- }
212
-
213
- function caret(data) {
214
- return data.replace(/[\0\x80\x1b-\x1f\x7f\x01-\x1a]/g, function (ch) {
215
- switch (ch) {
216
- case '\0':
217
- case '\x80':
218
- ch = '@'
219
- break
220
- case '\x1b':
221
- ch = '['
222
- break
223
- case '\x1c':
224
- ch = '\\'
225
- break
226
- case '\x1d':
227
- ch = ']'
228
- break
229
- case '\x1e':
230
- ch = '^'
231
- break
232
- case '\x1f':
233
- ch = '_'
234
- break
235
- case '\x7f':
236
- ch = '?'
237
- break
238
- default:
239
- ch = ch.charCodeAt(0)
240
- // From ('A' - 64) to ('Z' - 64).
241
- if (ch >= 1 && ch <= 26) {
242
- ch = String.fromCharCode(ch + 64)
243
- } else {
244
- return String.fromCharCode(ch)
245
- }
246
- break
247
- }
248
- return '^' + ch
249
- })
250
- }
251
-
252
- this.input.on('data', function (data) {
253
- self._log('IN', stringify(decoder.write(data)))
254
- })
255
-
256
- this.output.write = function (data) {
257
- self._log('OUT', stringify(data))
258
- return write.apply(this, arguments)
259
- }
260
- }
261
-
262
- Program.prototype.setupTput = function () {
263
- if (this._tputSetup) {
264
- return
265
- }
266
- this._tputSetup = true
267
-
268
- const self = this,
269
- options = this.options,
270
- write = this._write.bind(this)
271
-
272
- const tput = (this.tput = new Tput({
273
- terminal: this.terminal,
274
- padding: options.padding,
275
- extended: options.extended,
276
- printf: options.printf,
277
- termcap: options.termcap,
278
- forceUnicode: options.forceUnicode
279
- }))
280
-
281
- if (tput.error) {
282
- nextTick(function () {
283
- self.emit('warning', tput.error.message)
284
- })
285
- }
286
-
287
- if (tput.padding) {
288
- nextTick(function () {
289
- self.emit('warning', 'Terminfo padding has been enabled.')
290
- })
291
- }
292
-
293
- this.put = function () {
294
- const args = slice.call(arguments),
295
- cap = args.shift()
296
-
297
- if (tput[cap]) {
298
- return this._write(tput[cap].apply(tput, args))
299
- }
300
- }
301
-
302
- Object.keys(tput).forEach(function (key) {
303
- if (self[key] == null) {
304
- self[key] = tput[key]
305
- }
306
-
307
- if (typeof tput[key] !== 'function') {
308
- self.put[key] = tput[key]
309
- return
310
- }
311
-
312
- if (tput.padding) {
313
- self.put[key] = function () {
314
- return tput._print(tput[key].apply(tput, arguments), write)
315
- }
316
- } else {
317
- self.put[key] = function () {
318
- return self._write(tput[key].apply(tput, arguments))
319
- }
320
- }
321
- })
322
- }
323
-
324
- Program.prototype.__defineGetter__('terminal', function () {
325
- return this._terminal
326
- })
327
-
328
- Program.prototype.__defineSetter__('terminal', function (terminal) {
329
- this.setTerminal(terminal)
330
- return this.terminal
331
- })
332
-
333
- Program.prototype.setTerminal = function (terminal) {
334
- this._terminal = terminal.toLowerCase()
335
- delete this._tputSetup
336
- this.setupTput()
337
- }
338
-
339
- Program.prototype.has = function (name) {
340
- return this.tput ? this.tput.has(name) : false
341
- }
342
-
343
- Program.prototype.term = function (is) {
344
- return this.terminal.indexOf(is) === 0
345
- }
346
-
347
- Program.prototype.listen = function () {
348
- const self = this
349
-
350
- // Potentially reset window title on exit:
351
- // if (!this.isRxvt) {
352
- // if (!this.isVTE) this.setTitleModeFeature(3);
353
- // this.manipulateWindow(21, function(err, data) {
354
- // if (err) return;
355
- // self._originalTitle = data.text;
356
- // });
357
- // }
358
-
359
- // Listen for keys/mouse on input
360
- if (!this.input._blessedInput) {
361
- this.input._blessedInput = 1
362
- this._listenInput()
363
- } else {
364
- this.input._blessedInput++
365
- }
366
-
367
- this.on(
368
- 'newListener',
369
- (this._newHandler = function fn(type) {
370
- if (type === 'keypress' || type === 'mouse') {
371
- self.removeListener('newListener', fn)
372
- if (self.input.setRawMode && !self.input.isRaw) {
373
- self.input.setRawMode(true)
374
- self.input.resume()
375
- }
376
- }
377
- })
378
- )
379
-
380
- this.on('newListener', function fn(type) {
381
- if (type === 'mouse') {
382
- self.removeListener('newListener', fn)
383
- self.bindMouse()
384
- }
385
- })
386
-
387
- // Listen for resize on output
388
- if (!this.output._blessedOutput) {
389
- this.output._blessedOutput = 1
390
- this._listenOutput()
391
- } else {
392
- this.output._blessedOutput++
393
- }
394
- }
395
-
396
- Program.prototype._listenInput = function () {
397
- const keys = require('./keys'),
398
- self = this
399
-
400
- // Input
401
- this.input.on(
402
- 'keypress',
403
- (this.input._keypressHandler = function (ch, key) {
404
- key = key || { ch: ch }
405
-
406
- if (
407
- key.name === 'undefined' &&
408
- (key.code === '[M' || key.code === '[I' || key.code === '[O')
409
- ) {
410
- // A mouse sequence. The `keys` module doesn't understand these.
411
- return
412
- }
413
-
414
- if (key.name === 'undefined') {
415
- // Not sure what this is, but we should probably ignore it.
416
- return
417
- }
418
-
419
- if (key.name === 'enter' && key.sequence === '\n') {
420
- key.name = 'linefeed'
421
- }
422
-
423
- if (key.name === 'return' && key.sequence === '\r') {
424
- self.input.emit('keypress', ch, merge({}, key, { name: 'enter' }))
425
- }
426
-
427
- const name =
428
- (key.ctrl ? 'C-' : '') +
429
- (key.meta ? 'M-' : '') +
430
- (key.shift && key.name ? 'S-' : '') +
431
- (key.name || ch)
432
-
433
- key.full = name
434
-
435
- Program.instances.forEach(function (program) {
436
- if (program.input !== self.input) {
437
- return
438
- }
439
- program.emit('keypress', ch, key)
440
- program.emit('key ' + name, ch, key)
441
- })
442
- })
443
- )
444
-
445
- this.input.on(
446
- 'data',
447
- (this.input._dataHandler = function (data) {
448
- Program.instances.forEach(function (program) {
449
- if (program.input !== self.input) {
450
- return
451
- }
452
- program.emit('data', data)
453
- })
454
- })
455
- )
456
-
457
- keys.emitKeypressEvents(this.input)
458
- }
459
-
460
- Program.prototype._listenOutput = function () {
461
- const self = this
462
-
463
- if (!this.output.isTTY) {
464
- nextTick(function () {
465
- self.emit('warning', 'Output is not a TTY')
466
- })
467
- }
468
-
469
- // Output
470
- function resize() {
471
- Program.instances.forEach(function (program) {
472
- if (program.output !== self.output) {
473
- return
474
- }
475
- program.cols = program.output.columns
476
- program.rows = program.output.rows
477
- program.emit('resize')
478
- })
479
- }
480
-
481
- this.output.on(
482
- 'resize',
483
- (this.output._resizeHandler = function () {
484
- Program.instances.forEach(function (program) {
485
- if (program.output !== self.output) {
486
- return
487
- }
488
- if (!program.options.resizeTimeout) {
489
- return resize()
490
- }
491
- if (program._resizeTimer) {
492
- clearTimeout(program._resizeTimer)
493
- delete program._resizeTimer
494
- }
495
- const time =
496
- typeof program.options.resizeTimeout === 'number'
497
- ? program.options.resizeTimeout
498
- : 300
499
- program._resizeTimer = setTimeout(resize, time)
500
- })
501
- })
502
- )
503
- }
504
-
505
- Program.prototype.destroy = function () {
506
- const index = Program.instances.indexOf(this)
507
-
508
- if (~index) {
509
- Program.instances.splice(index, 1)
510
- Program.total--
511
-
512
- this.flush()
513
- this._exiting = true
514
-
515
- Program.global = Program.instances[0]
516
-
517
- if (Program.total === 0) {
518
- Program.global = null
519
-
520
- process.removeListener('exit', Program._exitHandler)
521
- delete Program._exitHandler
522
-
523
- delete Program._bound
524
- }
525
-
526
- this.input._blessedInput--
527
- this.output._blessedOutput--
528
-
529
- if (this.input._blessedInput === 0) {
530
- this.input.removeListener('keypress', this.input._keypressHandler)
531
- this.input.removeListener('data', this.input._dataHandler)
532
- delete this.input._keypressHandler
533
- delete this.input._dataHandler
534
-
535
- if (this.input.setRawMode) {
536
- if (this.input.isRaw) {
537
- this.input.setRawMode(false)
538
- }
539
- if (!this.input.destroyed) {
540
- this.input.pause()
541
- }
542
- }
543
- }
544
-
545
- if (this.output._blessedOutput === 0) {
546
- this.output.removeListener('resize', this.output._resizeHandler)
547
- delete this.output._resizeHandler
548
- }
549
-
550
- this.removeListener('newListener', this._newHandler)
551
- delete this._newHandler
552
-
553
- this.destroyed = true
554
- this.emit('destroy')
555
- }
556
- }
557
-
558
- Program.prototype.key = function (key, listener) {
559
- if (typeof key === 'string') {
560
- key = key.split(/\s*,\s*/)
561
- }
562
- key.forEach(function (key) {
563
- return this.on('key ' + key, listener)
564
- }, this)
565
- }
566
-
567
- Program.prototype.onceKey = function (key, listener) {
568
- if (typeof key === 'string') {
569
- key = key.split(/\s*,\s*/)
570
- }
571
- key.forEach(function (key) {
572
- return this.once('key ' + key, listener)
573
- }, this)
574
- }
575
-
576
- Program.prototype.unkey = Program.prototype.removeKey = function (
577
- key,
578
- listener
579
- ) {
580
- if (typeof key === 'string') {
581
- key = key.split(/\s*,\s*/)
582
- }
583
- key.forEach(function (key) {
584
- return this.removeListener('key ' + key, listener)
585
- }, this)
586
- }
587
-
588
- // XTerm mouse events
589
- // http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking
590
- // To better understand these
591
- // the xterm code is very helpful:
592
- // Relevant files:
593
- // button.c, charproc.c, misc.c
594
- // Relevant functions in xterm/button.c:
595
- // BtnCode, EmitButtonCode, EditorButton, SendMousePosition
596
- // send a mouse event:
597
- // regular/utf8: ^[[M Cb Cx Cy
598
- // urxvt: ^[[ Cb ; Cx ; Cy M
599
- // sgr: ^[[ Cb ; Cx ; Cy M/m
600
- // vt300: ^[[ 24(1/3/5)~ [ Cx , Cy ] \r
601
- // locator: CSI P e ; P b ; P r ; P c ; P p & w
602
- // motion example of a left click:
603
- // ^[[M 3<^[[M@4<^[[M@5<^[[M@6<^[[M@7<^[[M#7<
604
- // mouseup, mousedown, mousewheel
605
- // left click: ^[[M 3<^[[M#3<
606
- // mousewheel up: ^[[M`3>
607
- Program.prototype.bindMouse = function () {
608
- if (this._boundMouse) {
609
- return
610
- }
611
- this._boundMouse = true
612
-
613
- const decoder = new StringDecoder('utf8'),
614
- self = this
615
-
616
- this.on('data', function (data) {
617
- const text = decoder.write(data)
618
- if (!text) {
619
- return
620
- }
621
- self._bindMouse(text, data)
622
- })
623
- }
624
-
625
- Program.prototype._bindMouse = function (s, buf) {
626
- let self = this,
627
- key,
628
- parts,
629
- b,
630
- x,
631
- y,
632
- mod,
633
- params,
634
- down,
635
- page,
636
- button
637
-
638
- key = {
639
- name: undefined,
640
- ctrl: false,
641
- meta: false,
642
- shift: false
643
- }
644
-
645
- if (Buffer.isBuffer(s)) {
646
- if (s[0] > 127 && s[1] === undefined) {
647
- s[0] -= 128
648
- s = '\x1b' + s.toString('utf-8')
649
- } else {
650
- s = s.toString('utf-8')
651
- }
652
- }
653
-
654
- // if (this.8bit) {
655
- // s = s.replace(/\233/g, '\x1b[');
656
- // buf = new Buffer(s, 'utf8');
657
- // }
658
-
659
- // XTerm / X10 for buggy VTE
660
- // VTE can only send unsigned chars and no unicode for coords. This limits
661
- // them to 0xff. However, normally the x10 protocol does not allow a byte
662
- // under 0x20, but since VTE can have the bytes overflow, we can consider
663
- // bytes below 0x20 to be up to 0xff + 0x20. This gives a limit of 287. Since
664
- // characters ranging from 223 to 248 confuse javascript's utf parser, we
665
- // need to parse the raw binary. We can detect whether the terminal is using
666
- // a bugged VTE version by examining the coordinates and seeing whether they
667
- // are a value they would never otherwise be with a properly implemented x10
668
- // protocol. This method of detecting VTE is only 99% reliable because we
669
- // can't check if the coords are 0x00 (255) since that is a valid x10 coord
670
- // technically.
671
- const bx = s.charCodeAt(4)
672
- const by = s.charCodeAt(5)
673
- if (
674
- buf[0] === 0x1b &&
675
- buf[1] === 0x5b &&
676
- buf[2] === 0x4d &&
677
- (this.isVTE ||
678
- bx >= 65533 ||
679
- by >= 65533 ||
680
- (bx > 0x00 && bx < 0x20) ||
681
- (by > 0x00 && by < 0x20) ||
682
- (buf[4] > 223 && buf[4] < 248 && buf.length === 6) ||
683
- (buf[5] > 223 && buf[5] < 248 && buf.length === 6))
684
- ) {
685
- b = buf[3]
686
- x = buf[4]
687
- y = buf[5]
688
-
689
- // unsigned char overflow.
690
- if (x < 0x20) {
691
- x += 0xff
692
- }
693
- if (y < 0x20) {
694
- y += 0xff
695
- }
696
-
697
- // Convert the coordinates into a
698
- // properly formatted x10 utf8 sequence.
699
- s =
700
- '\x1b[M' +
701
- String.fromCharCode(b) +
702
- String.fromCharCode(x) +
703
- String.fromCharCode(y)
704
- }
705
-
706
- // XTerm / X10
707
- if ((parts = /^\x1b\[M([\x00\u0020-\uffff]{3})/.exec(s))) {
708
- b = parts[1].charCodeAt(0)
709
- x = parts[1].charCodeAt(1)
710
- y = parts[1].charCodeAt(2)
711
-
712
- key.name = 'mouse'
713
- key.type = 'X10'
714
-
715
- key.raw = [b, x, y, parts[0]]
716
- key.buf = buf
717
- key.x = x - 32
718
- key.y = y - 32
719
-
720
- if (this.zero) {
721
- key.x--, key.y--
722
- }
723
-
724
- if (x === 0) {
725
- key.x = 255
726
- }
727
- if (y === 0) {
728
- key.y = 255
729
- }
730
-
731
- mod = b >> 2
732
- key.shift = !!(mod & 1)
733
- key.meta = !!((mod >> 1) & 1)
734
- key.ctrl = !!((mod >> 2) & 1)
735
-
736
- b -= 32
737
-
738
- if ((b >> 6) & 1) {
739
- key.action = b & 1 ? 'wheeldown' : 'wheelup'
740
- key.button = 'middle'
741
- } else if (b === 3) {
742
- // NOTE: x10 and urxvt have no way
743
- // of telling which button mouseup used.
744
- key.action = 'mouseup'
745
- key.button = this._lastButton || 'unknown'
746
- delete this._lastButton
747
- } else {
748
- key.action = 'mousedown'
749
- button = b & 3
750
- key.button =
751
- button === 0
752
- ? 'left'
753
- : button === 1
754
- ? 'middle'
755
- : button === 2
756
- ? 'right'
757
- : 'unknown'
758
- this._lastButton = key.button
759
- }
760
-
761
- // Probably a movement.
762
- // The *newer* VTE gets mouse movements comepletely wrong.
763
- // This presents a problem: older versions of VTE that get it right might
764
- // be confused by the second conditional in the if statement.
765
- // NOTE: Possibly just switch back to the if statement below.
766
- // none, shift, ctrl, alt
767
- // gnome: 32, 36, 48, 40
768
- // xterm: 35, _, 51, _
769
- // urxvt: 35, _, _, _
770
- // if (key.action === 'mousedown' && key.button === 'unknown') {
771
- if (
772
- b === 35 ||
773
- b === 39 ||
774
- b === 51 ||
775
- b === 43 ||
776
- (this.isVTE && (b === 32 || b === 36 || b === 48 || b === 40))
777
- ) {
778
- delete key.button
779
- key.action = 'mousemove'
780
- }
781
-
782
- self.emit('mouse', key)
783
-
784
- return
785
- }
786
-
787
- // URxvt
788
- if ((parts = /^\x1b\[(\d+;\d+;\d+)M/.exec(s))) {
789
- params = parts[1].split(';')
790
- b = +params[0]
791
- x = +params[1]
792
- y = +params[2]
793
-
794
- key.name = 'mouse'
795
- key.type = 'urxvt'
796
-
797
- key.raw = [b, x, y, parts[0]]
798
- key.buf = buf
799
- key.x = x
800
- key.y = y
801
-
802
- if (this.zero) {
803
- key.x--, key.y--
804
- }
805
-
806
- mod = b >> 2
807
- key.shift = !!(mod & 1)
808
- key.meta = !!((mod >> 1) & 1)
809
- key.ctrl = !!((mod >> 2) & 1)
810
-
811
- // XXX Bug in urxvt after wheelup/down on mousemove
812
- // NOTE: This may be different than 128/129 depending
813
- // on mod keys.
814
- if (b === 128 || b === 129) {
815
- b = 67
816
- }
817
-
818
- b -= 32
819
-
820
- if ((b >> 6) & 1) {
821
- key.action = b & 1 ? 'wheeldown' : 'wheelup'
822
- key.button = 'middle'
823
- } else if (b === 3) {
824
- // NOTE: x10 and urxvt have no way
825
- // of telling which button mouseup used.
826
- key.action = 'mouseup'
827
- key.button = this._lastButton || 'unknown'
828
- delete this._lastButton
829
- } else {
830
- key.action = 'mousedown'
831
- button = b & 3
832
- key.button =
833
- button === 0
834
- ? 'left'
835
- : button === 1
836
- ? 'middle'
837
- : button === 2
838
- ? 'right'
839
- : 'unknown'
840
- // NOTE: 0/32 = mousemove, 32/64 = mousemove with left down
841
- // if ((b >> 1) === 32)
842
- this._lastButton = key.button
843
- }
844
-
845
- // Probably a movement.
846
- // The *newer* VTE gets mouse movements comepletely wrong.
847
- // This presents a problem: older versions of VTE that get it right might
848
- // be confused by the second conditional in the if statement.
849
- // NOTE: Possibly just switch back to the if statement below.
850
- // none, shift, ctrl, alt
851
- // urxvt: 35, _, _, _
852
- // gnome: 32, 36, 48, 40
853
- // if (key.action === 'mousedown' && key.button === 'unknown') {
854
- if (
855
- b === 35 ||
856
- b === 39 ||
857
- b === 51 ||
858
- b === 43 ||
859
- (this.isVTE && (b === 32 || b === 36 || b === 48 || b === 40))
860
- ) {
861
- delete key.button
862
- key.action = 'mousemove'
863
- }
864
-
865
- self.emit('mouse', key)
866
-
867
- return
868
- }
869
-
870
- // SGR
871
- if ((parts = /^\x1b\[<(\d+;\d+;\d+)([mM])/.exec(s))) {
872
- down = parts[2] === 'M'
873
- params = parts[1].split(';')
874
- b = +params[0]
875
- x = +params[1]
876
- y = +params[2]
877
-
878
- key.name = 'mouse'
879
- key.type = 'sgr'
880
-
881
- key.raw = [b, x, y, parts[0]]
882
- key.buf = buf
883
- key.x = x
884
- key.y = y
885
-
886
- if (this.zero) {
887
- key.x--, key.y--
888
- }
889
-
890
- mod = b >> 2
891
- key.shift = !!(mod & 1)
892
- key.meta = !!((mod >> 1) & 1)
893
- key.ctrl = !!((mod >> 2) & 1)
894
-
895
- if ((b >> 6) & 1) {
896
- key.action = b & 1 ? 'wheeldown' : 'wheelup'
897
- key.button = 'middle'
898
- } else {
899
- key.action = down ? 'mousedown' : 'mouseup'
900
- button = b & 3
901
- key.button =
902
- button === 0
903
- ? 'left'
904
- : button === 1
905
- ? 'middle'
906
- : button === 2
907
- ? 'right'
908
- : 'unknown'
909
- }
910
-
911
- // Probably a movement.
912
- // The *newer* VTE gets mouse movements comepletely wrong.
913
- // This presents a problem: older versions of VTE that get it right might
914
- // be confused by the second conditional in the if statement.
915
- // NOTE: Possibly just switch back to the if statement below.
916
- // none, shift, ctrl, alt
917
- // xterm: 35, _, 51, _
918
- // gnome: 32, 36, 48, 40
919
- // if (key.action === 'mousedown' && key.button === 'unknown') {
920
- if (
921
- b === 35 ||
922
- b === 39 ||
923
- b === 51 ||
924
- b === 43 ||
925
- (this.isVTE && (b === 32 || b === 36 || b === 48 || b === 40))
926
- ) {
927
- delete key.button
928
- key.action = 'mousemove'
929
- }
930
-
931
- self.emit('mouse', key)
932
-
933
- return
934
- }
935
-
936
- // DEC
937
- // The xterm mouse documentation says there is a
938
- // `<` prefix, the DECRQLP says there is no prefix.
939
- if ((parts = /^\x1b\[<(\d+;\d+;\d+;\d+)&w/.exec(s))) {
940
- params = parts[1].split(';')
941
- b = +params[0]
942
- x = +params[1]
943
- y = +params[2]
944
- page = +params[3]
945
-
946
- key.name = 'mouse'
947
- key.type = 'dec'
948
-
949
- key.raw = [b, x, y, parts[0]]
950
- key.buf = buf
951
- key.x = x
952
- key.y = y
953
- key.page = page
954
-
955
- if (this.zero) {
956
- key.x--, key.y--
957
- }
958
-
959
- key.action = b === 3 ? 'mouseup' : 'mousedown'
960
-
961
- key.button =
962
- b === 2 ? 'left' : b === 4 ? 'middle' : b === 6 ? 'right' : 'unknown'
963
-
964
- self.emit('mouse', key)
965
-
966
- return
967
- }
968
-
969
- // vt300
970
- if ((parts = /^\x1b\[24([0135])~\[(\d+),(\d+)\]\r/.exec(s))) {
971
- b = +parts[1]
972
- x = +parts[2]
973
- y = +parts[3]
974
-
975
- key.name = 'mouse'
976
- key.type = 'vt300'
977
-
978
- key.raw = [b, x, y, parts[0]]
979
- key.buf = buf
980
- key.x = x
981
- key.y = y
982
-
983
- if (this.zero) {
984
- key.x--, key.y--
985
- }
986
-
987
- key.action = 'mousedown'
988
- key.button =
989
- b === 1 ? 'left' : b === 2 ? 'middle' : b === 5 ? 'right' : 'unknown'
990
-
991
- self.emit('mouse', key)
992
-
993
- return
994
- }
995
-
996
- if ((parts = /^\x1b\[(O|I)/.exec(s))) {
997
- key.action = parts[1] === 'I' ? 'focus' : 'blur'
998
-
999
- self.emit('mouse', key)
1000
- self.emit(key.action)
1001
-
1002
- return
1003
- }
1004
- }
1005
-
1006
- // gpm support for linux vc
1007
- Program.prototype.enableGpm = function () {
1008
- const self = this
1009
- const gpmclient = require('./gpmclient')
1010
-
1011
- if (this.gpm) {
1012
- return
1013
- }
1014
-
1015
- this.gpm = gpmclient()
1016
-
1017
- this.gpm.on('btndown', function (btn, modifier, x, y) {
1018
- x--, y--
1019
-
1020
- const key = {
1021
- name: 'mouse',
1022
- type: 'GPM',
1023
- action: 'mousedown',
1024
- button: self.gpm.ButtonName(btn),
1025
- raw: [btn, modifier, x, y],
1026
- x: x,
1027
- y: y,
1028
- shift: self.gpm.hasShiftKey(modifier),
1029
- meta: self.gpm.hasMetaKey(modifier),
1030
- ctrl: self.gpm.hasCtrlKey(modifier)
1031
- }
1032
-
1033
- self.emit('mouse', key)
1034
- })
1035
-
1036
- this.gpm.on('btnup', function (btn, modifier, x, y) {
1037
- x--, y--
1038
-
1039
- const key = {
1040
- name: 'mouse',
1041
- type: 'GPM',
1042
- action: 'mouseup',
1043
- button: self.gpm.ButtonName(btn),
1044
- raw: [btn, modifier, x, y],
1045
- x: x,
1046
- y: y,
1047
- shift: self.gpm.hasShiftKey(modifier),
1048
- meta: self.gpm.hasMetaKey(modifier),
1049
- ctrl: self.gpm.hasCtrlKey(modifier)
1050
- }
1051
-
1052
- self.emit('mouse', key)
1053
- })
1054
-
1055
- this.gpm.on('move', function (btn, modifier, x, y) {
1056
- x--, y--
1057
-
1058
- const key = {
1059
- name: 'mouse',
1060
- type: 'GPM',
1061
- action: 'mousemove',
1062
- button: self.gpm.ButtonName(btn),
1063
- raw: [btn, modifier, x, y],
1064
- x: x,
1065
- y: y,
1066
- shift: self.gpm.hasShiftKey(modifier),
1067
- meta: self.gpm.hasMetaKey(modifier),
1068
- ctrl: self.gpm.hasCtrlKey(modifier)
1069
- }
1070
-
1071
- self.emit('mouse', key)
1072
- })
1073
-
1074
- this.gpm.on('drag', function (btn, modifier, x, y) {
1075
- x--, y--
1076
-
1077
- const key = {
1078
- name: 'mouse',
1079
- type: 'GPM',
1080
- action: 'mousemove',
1081
- button: self.gpm.ButtonName(btn),
1082
- raw: [btn, modifier, x, y],
1083
- x: x,
1084
- y: y,
1085
- shift: self.gpm.hasShiftKey(modifier),
1086
- meta: self.gpm.hasMetaKey(modifier),
1087
- ctrl: self.gpm.hasCtrlKey(modifier)
1088
- }
1089
-
1090
- self.emit('mouse', key)
1091
- })
1092
-
1093
- this.gpm.on('mousewheel', function (btn, modifier, x, y, dx, dy) {
1094
- const key = {
1095
- name: 'mouse',
1096
- type: 'GPM',
1097
- action: dy > 0 ? 'wheelup' : 'wheeldown',
1098
- button: self.gpm.ButtonName(btn),
1099
- raw: [btn, modifier, x, y, dx, dy],
1100
- x: x,
1101
- y: y,
1102
- shift: self.gpm.hasShiftKey(modifier),
1103
- meta: self.gpm.hasMetaKey(modifier),
1104
- ctrl: self.gpm.hasCtrlKey(modifier)
1105
- }
1106
-
1107
- self.emit('mouse', key)
1108
- })
1109
- }
1110
-
1111
- Program.prototype.disableGpm = function () {
1112
- if (this.gpm) {
1113
- this.gpm.stop()
1114
- delete this.gpm
1115
- }
1116
- }
1117
-
1118
- // All possible responses from the terminal
1119
- Program.prototype.bindResponse = function () {
1120
- if (this._boundResponse) {
1121
- return
1122
- }
1123
- this._boundResponse = true
1124
-
1125
- const decoder = new StringDecoder('utf8'),
1126
- self = this
1127
-
1128
- this.on('data', function (data) {
1129
- data = decoder.write(data)
1130
- if (!data) {
1131
- return
1132
- }
1133
- self._bindResponse(data)
1134
- })
1135
- }
1136
-
1137
- Program.prototype._bindResponse = function (s) {
1138
- let out = {},
1139
- parts
1140
-
1141
- if (Buffer.isBuffer(s)) {
1142
- if (s[0] > 127 && s[1] === undefined) {
1143
- s[0] -= 128
1144
- s = '\x1b' + s.toString('utf-8')
1145
- } else {
1146
- s = s.toString('utf-8')
1147
- }
1148
- }
1149
-
1150
- // CSI P s c
1151
- // Send Device Attributes (Primary DA).
1152
- // CSI > P s c
1153
- // Send Device Attributes (Secondary DA).
1154
- if ((parts = /^\x1b\[(\?|>)(\d*(?:;\d*)*)c/.exec(s))) {
1155
- parts = parts[2].split(';').map(function (ch) {
1156
- return +ch || 0
1157
- })
1158
-
1159
- out.event = 'device-attributes'
1160
- out.code = 'DA'
1161
-
1162
- if (parts[1] === '?') {
1163
- out.type = 'primary-attribute'
1164
- // VT100-style params:
1165
- if (parts[0] === 1 && parts[2] === 2) {
1166
- out.term = 'vt100'
1167
- out.advancedVideo = true
1168
- } else if (parts[0] === 1 && parts[2] === 0) {
1169
- out.term = 'vt101'
1170
- } else if (parts[0] === 6) {
1171
- out.term = 'vt102'
1172
- } else if (
1173
- parts[0] === 60 &&
1174
- parts[1] === 1 &&
1175
- parts[2] === 2 &&
1176
- parts[3] === 6 &&
1177
- parts[4] === 8 &&
1178
- parts[5] === 9 &&
1179
- parts[6] === 15
1180
- ) {
1181
- out.term = 'vt220'
1182
- } else {
1183
- // VT200-style params:
1184
- parts.forEach(function (attr) {
1185
- switch (attr) {
1186
- case 1:
1187
- out.cols132 = true
1188
- break
1189
- case 2:
1190
- out.printer = true
1191
- break
1192
- case 6:
1193
- out.selectiveErase = true
1194
- break
1195
- case 8:
1196
- out.userDefinedKeys = true
1197
- break
1198
- case 9:
1199
- out.nationalReplacementCharsets = true
1200
- break
1201
- case 15:
1202
- out.technicalCharacters = true
1203
- break
1204
- case 18:
1205
- out.userWindows = true
1206
- break
1207
- case 21:
1208
- out.horizontalScrolling = true
1209
- break
1210
- case 22:
1211
- out.ansiColor = true
1212
- break
1213
- case 29:
1214
- out.ansiTextLocator = true
1215
- break
1216
- }
1217
- })
1218
- }
1219
- } else {
1220
- out.type = 'secondary-attribute'
1221
- switch (parts[0]) {
1222
- case 0:
1223
- out.term = 'vt100'
1224
- break
1225
- case 1:
1226
- out.term = 'vt220'
1227
- break
1228
- case 2:
1229
- out.term = 'vt240'
1230
- break
1231
- case 18:
1232
- out.term = 'vt330'
1233
- break
1234
- case 19:
1235
- out.term = 'vt340'
1236
- break
1237
- case 24:
1238
- out.term = 'vt320'
1239
- break
1240
- case 41:
1241
- out.term = 'vt420'
1242
- break
1243
- case 61:
1244
- out.term = 'vt510'
1245
- break
1246
- case 64:
1247
- out.term = 'vt520'
1248
- break
1249
- case 65:
1250
- out.term = 'vt525'
1251
- break
1252
- }
1253
- out.firmwareVersion = parts[1]
1254
- out.romCartridgeRegistrationNumber = parts[2]
1255
- }
1256
-
1257
- // LEGACY
1258
- out.deviceAttributes = out
1259
-
1260
- this.emit('response', out)
1261
- this.emit('response ' + out.event, out)
1262
-
1263
- return
1264
- }
1265
-
1266
- // CSI Ps n Device Status Report (DSR).
1267
- // Ps = 5 -> Status Report. Result (``OK'') is
1268
- // CSI 0 n
1269
- // CSI ? Ps n
1270
- // Device Status Report (DSR, DEC-specific).
1271
- // Ps = 1 5 -> Report Printer status as CSI ? 1 0 n (ready).
1272
- // or CSI ? 1 1 n (not ready).
1273
- // Ps = 2 5 -> Report UDK status as CSI ? 2 0 n (unlocked)
1274
- // or CSI ? 2 1 n (locked).
1275
- // Ps = 2 6 -> Report Keyboard status as
1276
- // CSI ? 2 7 ; 1 ; 0 ; 0 n (North American).
1277
- // The last two parameters apply to VT400 & up, and denote key-
1278
- // board ready and LK01 respectively.
1279
- // Ps = 5 3 -> Report Locator status as
1280
- // CSI ? 5 3 n Locator available, if compiled-in, or
1281
- // CSI ? 5 0 n No Locator, if not.
1282
- if ((parts = /^\x1b\[(\?)?(\d+)(?:;(\d+);(\d+);(\d+))?n/.exec(s))) {
1283
- out.event = 'device-status'
1284
- out.code = 'DSR'
1285
-
1286
- if (!parts[1] && parts[2] === '0' && !parts[3]) {
1287
- out.type = 'device-status'
1288
- out.status = 'OK'
1289
-
1290
- // LEGACY
1291
- out.deviceStatus = out.status
1292
-
1293
- this.emit('response', out)
1294
- this.emit('response ' + out.event, out)
1295
-
1296
- return
1297
- }
1298
-
1299
- if (parts[1] && (parts[2] === '10' || parts[2] === '11') && !parts[3]) {
1300
- out.type = 'printer-status'
1301
- out.status = parts[2] === '10' ? 'ready' : 'not ready'
1302
-
1303
- // LEGACY
1304
- out.printerStatus = out.status
1305
-
1306
- this.emit('response', out)
1307
- this.emit('response ' + out.event, out)
1308
-
1309
- return
1310
- }
1311
-
1312
- if (parts[1] && (parts[2] === '20' || parts[2] === '21') && !parts[3]) {
1313
- out.type = 'udk-status'
1314
- out.status = parts[2] === '20' ? 'unlocked' : 'locked'
1315
-
1316
- // LEGACY
1317
- out.UDKStatus = out.status
1318
-
1319
- this.emit('response', out)
1320
- this.emit('response ' + out.event, out)
1321
-
1322
- return
1323
- }
1324
-
1325
- if (
1326
- parts[1] &&
1327
- parts[2] === '27' &&
1328
- parts[3] === '1' &&
1329
- parts[4] === '0' &&
1330
- parts[5] === '0'
1331
- ) {
1332
- out.type = 'keyboard-status'
1333
- out.status = 'OK'
1334
-
1335
- // LEGACY
1336
- out.keyboardStatus = out.status
1337
-
1338
- this.emit('response', out)
1339
- this.emit('response ' + out.event, out)
1340
-
1341
- return
1342
- }
1343
-
1344
- if (parts[1] && (parts[2] === '53' || parts[2] === '50') && !parts[3]) {
1345
- out.type = 'locator-status'
1346
- out.status = parts[2] === '53' ? 'available' : 'unavailable'
1347
-
1348
- // LEGACY
1349
- out.locator = out.status
1350
-
1351
- this.emit('response', out)
1352
- this.emit('response ' + out.event, out)
1353
-
1354
- return
1355
- }
1356
-
1357
- out.type = 'error'
1358
- out.text = 'Unhandled: ' + JSON.stringify(parts)
1359
-
1360
- // LEGACY
1361
- out.error = out.text
1362
-
1363
- this.emit('response', out)
1364
- this.emit('response ' + out.event, out)
1365
-
1366
- return
1367
- }
1368
-
1369
- // CSI Ps n Device Status Report (DSR).
1370
- // Ps = 6 -> Report Cursor Position (CPR) [row;column].
1371
- // Result is
1372
- // CSI r ; c R
1373
- // CSI ? Ps n
1374
- // Device Status Report (DSR, DEC-specific).
1375
- // Ps = 6 -> Report Cursor Position (CPR) [row;column] as CSI
1376
- // ? r ; c R (assumes page is zero).
1377
- if ((parts = /^\x1b\[(\?)?(\d+);(\d+)R/.exec(s))) {
1378
- out.event = 'device-status'
1379
- out.code = 'DSR'
1380
- out.type = 'cursor-status'
1381
-
1382
- out.status = {
1383
- x: +parts[3],
1384
- y: +parts[2],
1385
- page: !parts[1] ? undefined : 0
1386
- }
1387
-
1388
- out.x = out.status.x
1389
- out.y = out.status.y
1390
- out.page = out.status.page
1391
-
1392
- // LEGACY
1393
- out.cursor = out.status
1394
-
1395
- this.emit('response', out)
1396
- this.emit('response ' + out.event, out)
1397
-
1398
- return
1399
- }
1400
-
1401
- // CSI Ps ; Ps ; Ps t
1402
- // Window manipulation (from dtterm, as well as extensions).
1403
- // These controls may be disabled using the allowWindowOps
1404
- // resource. Valid values for the first (and any additional
1405
- // parameters) are:
1406
- // Ps = 1 1 -> Report xterm window state. If the xterm window
1407
- // is open (non-iconified), it returns CSI 1 t . If the xterm
1408
- // window is iconified, it returns CSI 2 t .
1409
- // Ps = 1 3 -> Report xterm window position. Result is CSI 3
1410
- // ; x ; y t
1411
- // Ps = 1 4 -> Report xterm window in pixels. Result is CSI
1412
- // 4 ; height ; width t
1413
- // Ps = 1 8 -> Report the size of the text area in characters.
1414
- // Result is CSI 8 ; height ; width t
1415
- // Ps = 1 9 -> Report the size of the screen in characters.
1416
- // Result is CSI 9 ; height ; width t
1417
- if ((parts = /^\x1b\[(\d+)(?:;(\d+);(\d+))?t/.exec(s))) {
1418
- out.event = 'window-manipulation'
1419
- out.code = ''
1420
-
1421
- if ((parts[1] === '1' || parts[1] === '2') && !parts[2]) {
1422
- out.type = 'window-state'
1423
- out.state = parts[1] === '1' ? 'non-iconified' : 'iconified'
1424
-
1425
- // LEGACY
1426
- out.windowState = out.state
1427
-
1428
- this.emit('response', out)
1429
- this.emit('response ' + out.event, out)
1430
-
1431
- return
1432
- }
1433
-
1434
- if (parts[1] === '3' && parts[2]) {
1435
- out.type = 'window-position'
1436
-
1437
- out.position = {
1438
- x: +parts[2],
1439
- y: +parts[3]
1440
- }
1441
- out.x = out.position.x
1442
- out.y = out.position.y
1443
-
1444
- // LEGACY
1445
- out.windowPosition = out.position
1446
-
1447
- this.emit('response', out)
1448
- this.emit('response ' + out.event, out)
1449
-
1450
- return
1451
- }
1452
-
1453
- if (parts[1] === '4' && parts[2]) {
1454
- out.type = 'window-size-pixels'
1455
- out.size = {
1456
- height: +parts[2],
1457
- width: +parts[3]
1458
- }
1459
- out.height = out.size.height
1460
- out.width = out.size.width
1461
-
1462
- // LEGACY
1463
- out.windowSizePixels = out.size
1464
-
1465
- this.emit('response', out)
1466
- this.emit('response ' + out.event, out)
1467
-
1468
- return
1469
- }
1470
-
1471
- if (parts[1] === '8' && parts[2]) {
1472
- out.type = 'textarea-size'
1473
- out.size = {
1474
- height: +parts[2],
1475
- width: +parts[3]
1476
- }
1477
- out.height = out.size.height
1478
- out.width = out.size.width
1479
-
1480
- // LEGACY
1481
- out.textAreaSizeCharacters = out.size
1482
-
1483
- this.emit('response', out)
1484
- this.emit('response ' + out.event, out)
1485
-
1486
- return
1487
- }
1488
-
1489
- if (parts[1] === '9' && parts[2]) {
1490
- out.type = 'screen-size'
1491
- out.size = {
1492
- height: +parts[2],
1493
- width: +parts[3]
1494
- }
1495
- out.height = out.size.height
1496
- out.width = out.size.width
1497
-
1498
- // LEGACY
1499
- out.screenSizeCharacters = out.size
1500
-
1501
- this.emit('response', out)
1502
- this.emit('response ' + out.event, out)
1503
-
1504
- return
1505
- }
1506
-
1507
- out.type = 'error'
1508
- out.text = 'Unhandled: ' + JSON.stringify(parts)
1509
-
1510
- // LEGACY
1511
- out.error = out.text
1512
-
1513
- this.emit('response', out)
1514
- this.emit('response ' + out.event, out)
1515
-
1516
- return
1517
- }
1518
-
1519
- // rxvt-unicode does not support window manipulation
1520
- // Result Normal: OSC l/L 0xEF 0xBF 0xBD
1521
- // Result ASCII: OSC l/L 0x1c (file separator)
1522
- // Result UTF8->ASCII: OSC l/L 0xFD
1523
- // Test with:
1524
- // echo -ne '\ePtmux;\e\e[>3t\e\\'
1525
- // sleep 2 && echo -ne '\ePtmux;\e\e[21t\e\\' & cat -v
1526
- // -
1527
- // echo -ne '\e[>3t'
1528
- // sleep 2 && echo -ne '\e[21t' & cat -v
1529
- if ((parts = /^\x1b\](l|L)([^\x07\x1b]*)$/.exec(s))) {
1530
- parts[2] = 'rxvt'
1531
- s = '\x1b]' + parts[1] + parts[2] + '\x1b\\'
1532
- }
1533
-
1534
- // CSI Ps ; Ps ; Ps t
1535
- // Window manipulation (from dtterm, as well as extensions).
1536
- // These controls may be disabled using the allowWindowOps
1537
- // resource. Valid values for the first (and any additional
1538
- // parameters) are:
1539
- // Ps = 2 0 -> Report xterm window's icon label. Result is
1540
- // OSC L label ST
1541
- // Ps = 2 1 -> Report xterm window's title. Result is OSC l
1542
- // label ST
1543
- if ((parts = /^\x1b\](l|L)([^\x07\x1b]*)(?:\x07|\x1b\\)/.exec(s))) {
1544
- out.event = 'window-manipulation'
1545
- out.code = ''
1546
-
1547
- if (parts[1] === 'L') {
1548
- out.type = 'window-icon-label'
1549
- out.text = parts[2]
1550
-
1551
- // LEGACY
1552
- out.windowIconLabel = out.text
1553
-
1554
- this.emit('response', out)
1555
- this.emit('response ' + out.event, out)
1556
-
1557
- return
1558
- }
1559
-
1560
- if (parts[1] === 'l') {
1561
- out.type = 'window-title'
1562
- out.text = parts[2]
1563
-
1564
- // LEGACY
1565
- out.windowTitle = out.text
1566
-
1567
- this.emit('response', out)
1568
- this.emit('response ' + out.event, out)
1569
-
1570
- return
1571
- }
1572
-
1573
- out.type = 'error'
1574
- out.text = 'Unhandled: ' + JSON.stringify(parts)
1575
-
1576
- // LEGACY
1577
- out.error = out.text
1578
-
1579
- this.emit('response', out)
1580
- this.emit('response ' + out.event, out)
1581
-
1582
- return
1583
- }
1584
-
1585
- // CSI Ps ' |
1586
- // Request Locator Position (DECRQLP).
1587
- // -> CSI Pe ; Pb ; Pr ; Pc ; Pp & w
1588
- // Parameters are [event;button;row;column;page].
1589
- // Valid values for the event:
1590
- // Pe = 0 -> locator unavailable - no other parameters sent.
1591
- // Pe = 1 -> request - xterm received a DECRQLP.
1592
- // Pe = 2 -> left button down.
1593
- // Pe = 3 -> left button up.
1594
- // Pe = 4 -> middle button down.
1595
- // Pe = 5 -> middle button up.
1596
- // Pe = 6 -> right button down.
1597
- // Pe = 7 -> right button up.
1598
- // Pe = 8 -> M4 button down.
1599
- // Pe = 9 -> M4 button up.
1600
- // Pe = 1 0 -> locator outside filter rectangle.
1601
- // ``button'' parameter is a bitmask indicating which buttons are
1602
- // pressed:
1603
- // Pb = 0 <- no buttons down.
1604
- // Pb & 1 <- right button down.
1605
- // Pb & 2 <- middle button down.
1606
- // Pb & 4 <- left button down.
1607
- // Pb & 8 <- M4 button down.
1608
- // ``row'' and ``column'' parameters are the coordinates of the
1609
- // locator position in the xterm window, encoded as ASCII deci-
1610
- // mal.
1611
- // The ``page'' parameter is not used by xterm, and will be omit-
1612
- // ted.
1613
- // NOTE:
1614
- // This is already implemented in the _bindMouse
1615
- // method, but it might make more sense here.
1616
- // The xterm mouse documentation says there is a
1617
- // `<` prefix, the DECRQLP says there is no prefix.
1618
- if ((parts = /^\x1b\[(\d+(?:;\d+){4})&w/.exec(s))) {
1619
- parts = parts[1].split(';').map(function (ch) {
1620
- return +ch
1621
- })
1622
-
1623
- out.event = 'locator-position'
1624
- out.code = 'DECRQLP'
1625
-
1626
- switch (parts[0]) {
1627
- case 0:
1628
- out.status = 'locator-unavailable'
1629
- break
1630
- case 1:
1631
- out.status = 'request'
1632
- break
1633
- case 2:
1634
- out.status = 'left-button-down'
1635
- break
1636
- case 3:
1637
- out.status = 'left-button-up'
1638
- break
1639
- case 4:
1640
- out.status = 'middle-button-down'
1641
- break
1642
- case 5:
1643
- out.status = 'middle-button-up'
1644
- break
1645
- case 6:
1646
- out.status = 'right-button-down'
1647
- break
1648
- case 7:
1649
- out.status = 'right-button-up'
1650
- break
1651
- case 8:
1652
- out.status = 'm4-button-down'
1653
- break
1654
- case 9:
1655
- out.status = 'm4-button-up'
1656
- break
1657
- case 10:
1658
- out.status = 'locator-outside'
1659
- break
1660
- }
1661
-
1662
- out.mask = parts[1]
1663
- out.row = parts[2]
1664
- out.col = parts[3]
1665
- out.page = parts[4]
1666
-
1667
- // LEGACY
1668
- out.locatorPosition = out
1669
-
1670
- this.emit('response', out)
1671
- this.emit('response ' + out.event, out)
1672
-
1673
- return
1674
- }
1675
-
1676
- // OSC Ps ; Pt BEL
1677
- // OSC Ps ; Pt ST
1678
- // Set Text Parameters
1679
- if ((parts = /^\x1b\](\d+);([^\x07\x1b]+)(?:\x07|\x1b\\)/.exec(s))) {
1680
- out.event = 'text-params'
1681
- out.code = 'Set Text Parameters'
1682
- out.ps = +s[1]
1683
- out.pt = s[2]
1684
- this.emit('response', out)
1685
- this.emit('response ' + out.event, out)
1686
- }
1687
- }
1688
-
1689
- Program.prototype.response = function (name, text, callback, noBypass) {
1690
- const self = this
1691
-
1692
- if (arguments.length === 2) {
1693
- callback = text
1694
- text = name
1695
- name = null
1696
- }
1697
-
1698
- if (!callback) {
1699
- callback = function () {}
1700
- }
1701
-
1702
- this.bindResponse()
1703
-
1704
- name = name ? 'response ' + name : 'response'
1705
-
1706
- let onresponse
1707
-
1708
- this.once(
1709
- name,
1710
- (onresponse = function (event) {
1711
- if (timeout) {
1712
- clearTimeout(timeout)
1713
- }
1714
- if (event.type === 'error') {
1715
- return callback(new Error(event.event + ': ' + event.text))
1716
- }
1717
- return callback(null, event)
1718
- })
1719
- )
1720
-
1721
- const timeout = setTimeout(function () {
1722
- self.removeListener(name, onresponse)
1723
- return callback(new Error('Timeout.'))
1724
- }, 2000)
1725
-
1726
- return noBypass ? this._write(text) : this._twrite(text)
1727
- }
1728
-
1729
- Program.prototype._owrite = Program.prototype.write = function (text) {
1730
- if (!this.output.writable) {
1731
- return
1732
- }
1733
- return this.output.write(text)
1734
- }
1735
-
1736
- Program.prototype._buffer = function (text) {
1737
- if (this._exiting) {
1738
- this.flush()
1739
- this._owrite(text)
1740
- return
1741
- }
1742
-
1743
- if (this._buf) {
1744
- this._buf += text
1745
- return
1746
- }
1747
-
1748
- this._buf = text
1749
-
1750
- nextTick(this._flush)
1751
-
1752
- return true
1753
- }
1754
-
1755
- Program.prototype.flush = function () {
1756
- if (!this._buf) {
1757
- return
1758
- }
1759
- this._owrite(this._buf)
1760
- this._buf = ''
1761
- }
1762
-
1763
- Program.prototype._write = function (text) {
1764
- if (this.ret) {
1765
- return text
1766
- }
1767
- if (this.useBuffer) {
1768
- return this._buffer(text)
1769
- }
1770
- return this._owrite(text)
1771
- }
1772
-
1773
- // Example: `DCS tmux; ESC Pt ST`
1774
- // Real: `DCS tmux; ESC Pt ESC \`
1775
- Program.prototype._twrite = function (data) {
1776
- let self = this,
1777
- iterations = 0,
1778
- timer
1779
-
1780
- if (this.tmux) {
1781
- // Replace all STs with BELs so they can be nested within the DCS code.
1782
- data = data.replace(/\x1b\\/g, '\x07')
1783
-
1784
- // Wrap in tmux forward DCS:
1785
- data = '\x1bPtmux;\x1b' + data + '\x1b\\'
1786
-
1787
- // If we've never even flushed yet, it means we're still in
1788
- // the normal buffer. Wait for alt screen buffer.
1789
- if (this.output.bytesWritten === 0) {
1790
- timer = setInterval(function () {
1791
- if (self.output.bytesWritten > 0 || ++iterations === 50) {
1792
- clearInterval(timer)
1793
- self.flush()
1794
- self._owrite(data)
1795
- }
1796
- }, 100)
1797
- return true
1798
- }
1799
-
1800
- // NOTE: Flushing the buffer is required in some cases.
1801
- // The DCS code must be at the start of the output.
1802
- this.flush()
1803
-
1804
- // Write out raw now that the buffer is flushed.
1805
- return this._owrite(data)
1806
- }
1807
-
1808
- return this._write(data)
1809
- }
1810
-
1811
- Program.prototype.echo = Program.prototype.print = function (text, attr) {
1812
- return attr ? this._write(this.text(text, attr)) : this._write(text)
1813
- }
1814
-
1815
- Program.prototype._ncoords = function () {
1816
- if (this.x < 0) {
1817
- this.x = 0
1818
- } else if (this.x >= this.cols) {
1819
- this.x = this.cols - 1
1820
- }
1821
- if (this.y < 0) {
1822
- this.y = 0
1823
- } else if (this.y >= this.rows) {
1824
- this.y = this.rows - 1
1825
- }
1826
- }
1827
-
1828
- Program.prototype.setx = function (x) {
1829
- return this.cursorCharAbsolute(x)
1830
- // return this.charPosAbsolute(x);
1831
- }
1832
-
1833
- Program.prototype.sety = function (y) {
1834
- return this.linePosAbsolute(y)
1835
- }
1836
-
1837
- Program.prototype.move = function (x, y) {
1838
- return this.cursorPos(y, x)
1839
- }
1840
-
1841
- // TODO: Fix cud and cuu calls.
1842
- Program.prototype.omove = function (x, y) {
1843
- if (!this.zero) {
1844
- x = (x || 1) - 1
1845
- y = (y || 1) - 1
1846
- } else {
1847
- x = x || 0
1848
- y = y || 0
1849
- }
1850
- if (y === this.y && x === this.x) {
1851
- return
1852
- }
1853
- if (y === this.y) {
1854
- if (x > this.x) {
1855
- this.cuf(x - this.x)
1856
- } else if (x < this.x) {
1857
- this.cub(this.x - x)
1858
- }
1859
- } else if (x === this.x) {
1860
- if (y > this.y) {
1861
- this.cud(y - this.y)
1862
- } else if (y < this.y) {
1863
- this.cuu(this.y - y)
1864
- }
1865
- } else {
1866
- if (!this.zero) {
1867
- x++, y++
1868
- }
1869
- this.cup(y, x)
1870
- }
1871
- }
1872
-
1873
- Program.prototype.rsetx = function (x) {
1874
- // return this.HPositionRelative(x);
1875
- if (!x) {
1876
- return
1877
- }
1878
- return x > 0 ? this.forward(x) : this.back(-x)
1879
- }
1880
-
1881
- Program.prototype.rsety = function (y) {
1882
- // return this.VPositionRelative(y);
1883
- if (!y) {
1884
- return
1885
- }
1886
- return y > 0 ? this.up(y) : this.down(-y)
1887
- }
1888
-
1889
- Program.prototype.rmove = function (x, y) {
1890
- this.rsetx(x)
1891
- this.rsety(y)
1892
- }
1893
-
1894
- Program.prototype.simpleInsert = function (ch, i, attr) {
1895
- return this._write(this.repeat(ch, i), attr)
1896
- }
1897
-
1898
- Program.prototype.repeat = function (ch, i) {
1899
- if (!i || i < 0) {
1900
- i = 0
1901
- }
1902
- return Array(i + 1).join(ch)
1903
- }
1904
-
1905
- Program.prototype.__defineGetter__('title', function () {
1906
- return this._title
1907
- })
1908
-
1909
- Program.prototype.__defineSetter__('title', function (title) {
1910
- this.setTitle(title)
1911
- return this._title
1912
- })
1913
-
1914
- // Specific to iTerm2, but I think it's really cool.
1915
- // Example:
1916
- // if (!screen.copyToClipboard(text)) {
1917
- // execClipboardProgram(text);
1918
- // }
1919
- Program.prototype.copyToClipboard = function (text) {
1920
- if (this.isiTerm2) {
1921
- this._twrite('\x1b]50;CopyToCliboard=' + text + '\x07')
1922
- return true
1923
- }
1924
- return false
1925
- }
1926
-
1927
- // Only XTerm and iTerm2. If you know of any others, post them.
1928
- Program.prototype.cursorShape = function (shape, blink) {
1929
- if (this.isiTerm2) {
1930
- switch (shape) {
1931
- case 'block':
1932
- if (!blink) {
1933
- this._twrite('\x1b]50;CursorShape=0;BlinkingCursorEnabled=0\x07')
1934
- } else {
1935
- this._twrite('\x1b]50;CursorShape=0;BlinkingCursorEnabled=1\x07')
1936
- }
1937
- break
1938
- case 'underline':
1939
- if (!blink) {
1940
- // this._twrite('\x1b]50;CursorShape=n;BlinkingCursorEnabled=0\x07');
1941
- } else {
1942
- // this._twrite('\x1b]50;CursorShape=n;BlinkingCursorEnabled=1\x07');
1943
- }
1944
- break
1945
- case 'line':
1946
- if (!blink) {
1947
- this._twrite('\x1b]50;CursorShape=1;BlinkingCursorEnabled=0\x07')
1948
- } else {
1949
- this._twrite('\x1b]50;CursorShape=1;BlinkingCursorEnabled=1\x07')
1950
- }
1951
- break
1952
- }
1953
- return true
1954
- } else if (this.term('xterm') || this.term('screen')) {
1955
- switch (shape) {
1956
- case 'block':
1957
- if (!blink) {
1958
- this._twrite('\x1b[0 q')
1959
- } else {
1960
- this._twrite('\x1b[1 q')
1961
- }
1962
- break
1963
- case 'underline':
1964
- if (!blink) {
1965
- this._twrite('\x1b[2 q')
1966
- } else {
1967
- this._twrite('\x1b[3 q')
1968
- }
1969
- break
1970
- case 'line':
1971
- if (!blink) {
1972
- this._twrite('\x1b[4 q')
1973
- } else {
1974
- this._twrite('\x1b[5 q')
1975
- }
1976
- break
1977
- }
1978
- return true
1979
- }
1980
- return false
1981
- }
1982
-
1983
- Program.prototype.cursorColor = function (color) {
1984
- if (this.term('xterm') || this.term('rxvt') || this.term('screen')) {
1985
- this._twrite('\x1b]12;' + color + '\x07')
1986
- return true
1987
- }
1988
- return false
1989
- }
1990
-
1991
- Program.prototype.cursorReset = Program.prototype.resetCursor = function () {
1992
- if (this.term('xterm') || this.term('rxvt') || this.term('screen')) {
1993
- // XXX
1994
- // return this.resetColors();
1995
- this._twrite('\x1b[0 q')
1996
- this._twrite('\x1b]112\x07')
1997
- // urxvt doesnt support OSC 112
1998
- this._twrite('\x1b]12;white\x07')
1999
- return true
2000
- }
2001
- return false
2002
- }
2003
-
2004
- Program.prototype.getTextParams = function (param, callback) {
2005
- return this.response(
2006
- 'text-params',
2007
- '\x1b]' + param + ';?\x07',
2008
- function (err, data) {
2009
- if (err) {
2010
- return callback(err)
2011
- }
2012
- return callback(null, data.pt)
2013
- }
2014
- )
2015
- }
2016
-
2017
- Program.prototype.getCursorColor = function (callback) {
2018
- return this.getTextParams(12, callback)
2019
- }
2020
-
2021
- /**
2022
- * Normal
2023
- */
2024
-
2025
- //Program.prototype.pad =
2026
- Program.prototype.nul = function () {
2027
- //if (this.has('pad')) return this.put.pad();
2028
- return this._write('\x80')
2029
- }
2030
-
2031
- Program.prototype.bel = Program.prototype.bell = function () {
2032
- if (this.has('bel')) {
2033
- return this.put.bel()
2034
- }
2035
- return this._write('\x07')
2036
- }
2037
-
2038
- Program.prototype.vtab = function () {
2039
- this.y++
2040
- this._ncoords()
2041
- return this._write('\x0b')
2042
- }
2043
-
2044
- Program.prototype.ff = Program.prototype.form = function () {
2045
- if (this.has('ff')) {
2046
- return this.put.ff()
2047
- }
2048
- return this._write('\x0c')
2049
- }
2050
-
2051
- Program.prototype.kbs = Program.prototype.backspace = function () {
2052
- this.x--
2053
- this._ncoords()
2054
- if (this.has('kbs')) {
2055
- return this.put.kbs()
2056
- }
2057
- return this._write('\x08')
2058
- }
2059
-
2060
- Program.prototype.ht = Program.prototype.tab = function () {
2061
- this.x += 8
2062
- this._ncoords()
2063
- if (this.has('ht')) {
2064
- return this.put.ht()
2065
- }
2066
- return this._write('\t')
2067
- }
2068
-
2069
- Program.prototype.shiftOut = function () {
2070
- // if (this.has('S2')) return this.put.S2();
2071
- return this._write('\x0e')
2072
- }
2073
-
2074
- Program.prototype.shiftIn = function () {
2075
- // if (this.has('S3')) return this.put.S3();
2076
- return this._write('\x0f')
2077
- }
2078
-
2079
- Program.prototype.cr = Program.prototype.return = function () {
2080
- this.x = 0
2081
- if (this.has('cr')) {
2082
- return this.put.cr()
2083
- }
2084
- return this._write('\r')
2085
- }
2086
-
2087
- Program.prototype.nel =
2088
- Program.prototype.newline =
2089
- Program.prototype.feed =
2090
- function () {
2091
- if (
2092
- this.tput &&
2093
- this.tput.bools.eat_newline_glitch &&
2094
- this.x >= this.cols
2095
- ) {
2096
- return
2097
- }
2098
- this.x = 0
2099
- this.y++
2100
- this._ncoords()
2101
- if (this.has('nel')) {
2102
- return this.put.nel()
2103
- }
2104
- return this._write('\n')
2105
- }
2106
-
2107
- /**
2108
- * Esc
2109
- */
2110
-
2111
- // ESC D Index (IND is 0x84).
2112
- Program.prototype.ind = Program.prototype.index = function () {
2113
- this.y++
2114
- this._ncoords()
2115
- if (this.tput) {
2116
- return this.put.ind()
2117
- }
2118
- return this._write('\x1bD')
2119
- }
2120
-
2121
- // ESC M Reverse Index (RI is 0x8d).
2122
- Program.prototype.ri =
2123
- Program.prototype.reverse =
2124
- Program.prototype.reverseIndex =
2125
- function () {
2126
- this.y--
2127
- this._ncoords()
2128
- if (this.tput) {
2129
- return this.put.ri()
2130
- }
2131
- return this._write('\x1bM')
2132
- }
2133
-
2134
- // ESC E Next Line (NEL is 0x85).
2135
- Program.prototype.nextLine = function () {
2136
- this.y++
2137
- this.x = 0
2138
- this._ncoords()
2139
- if (this.has('nel')) {
2140
- return this.put.nel()
2141
- }
2142
- return this._write('\x1bE')
2143
- }
2144
-
2145
- // ESC c Full Reset (RIS).
2146
- Program.prototype.reset = function () {
2147
- this.x = this.y = 0
2148
- if (this.has('rs1') || this.has('ris')) {
2149
- return this.has('rs1') ? this.put.rs1() : this.put.ris()
2150
- }
2151
- return this._write('\x1bc')
2152
- }
2153
-
2154
- // ESC H Tab Set (HTS is 0x88).
2155
- Program.prototype.tabSet = function () {
2156
- if (this.tput) {
2157
- return this.put.hts()
2158
- }
2159
- return this._write('\x1bH')
2160
- }
2161
-
2162
- // ESC 7 Save Cursor (DECSC).
2163
- Program.prototype.sc = Program.prototype.saveCursor = function (key) {
2164
- if (key) {
2165
- return this.lsaveCursor(key)
2166
- }
2167
- this.savedX = this.x || 0
2168
- this.savedY = this.y || 0
2169
- if (this.tput) {
2170
- return this.put.sc()
2171
- }
2172
- return this._write('\x1b7')
2173
- }
2174
-
2175
- // ESC 8 Restore Cursor (DECRC).
2176
- Program.prototype.rc = Program.prototype.restoreCursor = function (key, hide) {
2177
- if (key) {
2178
- return this.lrestoreCursor(key, hide)
2179
- }
2180
- this.x = this.savedX || 0
2181
- this.y = this.savedY || 0
2182
- if (this.tput) {
2183
- return this.put.rc()
2184
- }
2185
- return this._write('\x1b8')
2186
- }
2187
-
2188
- // Save Cursor Locally
2189
- Program.prototype.lsaveCursor = function (key) {
2190
- key = key || 'local'
2191
- this._saved = this._saved || {}
2192
- this._saved[key] = this._saved[key] || {}
2193
- this._saved[key].x = this.x
2194
- this._saved[key].y = this.y
2195
- this._saved[key].hidden = this.cursorHidden
2196
- }
2197
-
2198
- // Restore Cursor Locally
2199
- Program.prototype.lrestoreCursor = function (key, hide) {
2200
- let pos
2201
- key = key || 'local'
2202
- if (!this._saved || !this._saved[key]) {
2203
- return
2204
- }
2205
- pos = this._saved[key]
2206
- //delete this._saved[key];
2207
- this.cup(pos.y, pos.x)
2208
- if (hide && pos.hidden !== this.cursorHidden) {
2209
- if (pos.hidden) {
2210
- this.hideCursor()
2211
- } else {
2212
- this.showCursor()
2213
- }
2214
- }
2215
- }
2216
-
2217
- // ESC # 3 DEC line height/width
2218
- Program.prototype.lineHeight = function () {
2219
- return this._write('\x1b#')
2220
- }
2221
-
2222
- // ESC (,),*,+,-,. Designate G0-G2 Character Set.
2223
- Program.prototype.charset = function (val, level) {
2224
- level = level || 0
2225
-
2226
- // See also:
2227
- // acs_chars / acsc / ac
2228
- // enter_alt_charset_mode / smacs / as
2229
- // exit_alt_charset_mode / rmacs / ae
2230
- // enter_pc_charset_mode / smpch / S2
2231
- // exit_pc_charset_mode / rmpch / S3
2232
-
2233
- switch (level) {
2234
- case 0:
2235
- level = '('
2236
- break
2237
- case 1:
2238
- level = ')'
2239
- break
2240
- case 2:
2241
- level = '*'
2242
- break
2243
- case 3:
2244
- level = '+'
2245
- break
2246
- }
2247
-
2248
- const name = typeof val === 'string' ? val.toLowerCase() : val
2249
-
2250
- switch (name) {
2251
- case 'acs':
2252
- case 'scld': // DEC Special Character and Line Drawing Set.
2253
- if (this.tput) {
2254
- return this.put.smacs()
2255
- }
2256
- val = '0'
2257
- break
2258
- case 'uk': // UK
2259
- val = 'A'
2260
- break
2261
- case 'us': // United States (USASCII).
2262
- case 'usascii':
2263
- case 'ascii':
2264
- if (this.tput) {
2265
- return this.put.rmacs()
2266
- }
2267
- val = 'B'
2268
- break
2269
- case 'dutch': // Dutch
2270
- val = '4'
2271
- break
2272
- case 'finnish': // Finnish
2273
- val = 'C'
2274
- val = '5'
2275
- break
2276
- case 'french': // French
2277
- val = 'R'
2278
- break
2279
- case 'frenchcanadian': // FrenchCanadian
2280
- val = 'Q'
2281
- break
2282
- case 'german': // German
2283
- val = 'K'
2284
- break
2285
- case 'italian': // Italian
2286
- val = 'Y'
2287
- break
2288
- case 'norwegiandanish': // NorwegianDanish
2289
- val = 'E'
2290
- val = '6'
2291
- break
2292
- case 'spanish': // Spanish
2293
- val = 'Z'
2294
- break
2295
- case 'swedish': // Swedish
2296
- val = 'H'
2297
- val = '7'
2298
- break
2299
- case 'swiss': // Swiss
2300
- val = '='
2301
- break
2302
- case 'isolatin': // ISOLatin (actually /A)
2303
- val = '/A'
2304
- break
2305
- default: // Default
2306
- if (this.tput) {
2307
- return this.put.rmacs()
2308
- }
2309
- val = 'B'
2310
- break
2311
- }
2312
-
2313
- return this._write('\x1b(' + val)
2314
- }
2315
-
2316
- Program.prototype.enter_alt_charset_mode =
2317
- Program.prototype.as =
2318
- Program.prototype.smacs =
2319
- function () {
2320
- return this.charset('acs')
2321
- }
2322
-
2323
- Program.prototype.exit_alt_charset_mode =
2324
- Program.prototype.ae =
2325
- Program.prototype.rmacs =
2326
- function () {
2327
- return this.charset('ascii')
2328
- }
2329
-
2330
- // ESC N
2331
- // Single Shift Select of G2 Character Set
2332
- // ( SS2 is 0x8e). This affects next character only.
2333
- // ESC O
2334
- // Single Shift Select of G3 Character Set
2335
- // ( SS3 is 0x8f). This affects next character only.
2336
- // ESC n
2337
- // Invoke the G2 Character Set as GL (LS2).
2338
- // ESC o
2339
- // Invoke the G3 Character Set as GL (LS3).
2340
- // ESC |
2341
- // Invoke the G3 Character Set as GR (LS3R).
2342
- // ESC }
2343
- // Invoke the G2 Character Set as GR (LS2R).
2344
- // ESC ~
2345
- // Invoke the G1 Character Set as GR (LS1R).
2346
- Program.prototype.setG = function (val) {
2347
- // if (this.tput) return this.put.S2();
2348
- // if (this.tput) return this.put.S3();
2349
- switch (val) {
2350
- case 1:
2351
- val = '~' // GR
2352
- break
2353
- case 2:
2354
- val = 'n' // GL
2355
- val = '}' // GR
2356
- val = 'N' // Next Char Only
2357
- break
2358
- case 3:
2359
- val = 'o' // GL
2360
- val = '|' // GR
2361
- val = 'O' // Next Char Only
2362
- break
2363
- }
2364
- return this._write('\x1b' + val)
2365
- }
2366
-
2367
- /**
2368
- * OSC
2369
- */
2370
-
2371
- // OSC Ps ; Pt ST
2372
- // OSC Ps ; Pt BEL
2373
- // Set Text Parameters.
2374
- Program.prototype.setTitle = function (title) {
2375
- this._title = title
2376
-
2377
- // if (this.term('screen')) {
2378
- // // Tmux pane
2379
- // // if (this.tmux) {
2380
- // // return this._write('\x1b]2;' + title + '\x1b\\');
2381
- // // }
2382
- // return this._write('\x1bk' + title + '\x1b\\');
2383
- // }
2384
-
2385
- return this._twrite('\x1b]0;' + title + '\x07')
2386
- }
2387
-
2388
- // OSC Ps ; Pt ST
2389
- // OSC Ps ; Pt BEL
2390
- // Reset colors
2391
- Program.prototype.resetColors = function (param) {
2392
- if (this.has('Cr')) {
2393
- return this.put.Cr(param)
2394
- }
2395
- return this._twrite('\x1b]112\x07')
2396
- //return this._twrite('\x1b]112;' + param + '\x07');
2397
- }
2398
-
2399
- // OSC Ps ; Pt ST
2400
- // OSC Ps ; Pt BEL
2401
- // Change dynamic colors
2402
- Program.prototype.dynamicColors = function (param) {
2403
- if (this.has('Cs')) {
2404
- return this.put.Cs(param)
2405
- }
2406
- return this._twrite('\x1b]12;' + param + '\x07')
2407
- }
2408
-
2409
- // OSC Ps ; Pt ST
2410
- // OSC Ps ; Pt BEL
2411
- // Sel data
2412
- Program.prototype.selData = function (a, b) {
2413
- if (this.has('Ms')) {
2414
- return this.put.Ms(a, b)
2415
- }
2416
- return this._twrite('\x1b]52;' + a + ';' + b + '\x07')
2417
- }
2418
-
2419
- /**
2420
- * CSI
2421
- */
2422
-
2423
- // CSI Ps A
2424
- // Cursor Up Ps Times (default = 1) (CUU).
2425
- Program.prototype.cuu =
2426
- Program.prototype.up =
2427
- Program.prototype.cursorUp =
2428
- function (param) {
2429
- this.y -= param || 1
2430
- this._ncoords()
2431
- if (this.tput) {
2432
- if (!this.tput.strings.parm_up_cursor) {
2433
- return this._write(this.repeat(this.tput.cuu1(), param))
2434
- }
2435
- return this.put.cuu(param)
2436
- }
2437
- return this._write('\x1b[' + (param || '') + 'A')
2438
- }
2439
-
2440
- // CSI Ps B
2441
- // Cursor Down Ps Times (default = 1) (CUD).
2442
- Program.prototype.cud =
2443
- Program.prototype.down =
2444
- Program.prototype.cursorDown =
2445
- function (param) {
2446
- this.y += param || 1
2447
- this._ncoords()
2448
- if (this.tput) {
2449
- if (!this.tput.strings.parm_down_cursor) {
2450
- return this._write(this.repeat(this.tput.cud1(), param))
2451
- }
2452
- return this.put.cud(param)
2453
- }
2454
- return this._write('\x1b[' + (param || '') + 'B')
2455
- }
2456
-
2457
- // CSI Ps C
2458
- // Cursor Forward Ps Times (default = 1) (CUF).
2459
- Program.prototype.cuf =
2460
- Program.prototype.right =
2461
- Program.prototype.forward =
2462
- Program.prototype.cursorForward =
2463
- function (param) {
2464
- this.x += param || 1
2465
- this._ncoords()
2466
- if (this.tput) {
2467
- if (!this.tput.strings.parm_right_cursor) {
2468
- return this._write(this.repeat(this.tput.cuf1(), param))
2469
- }
2470
- return this.put.cuf(param)
2471
- }
2472
- return this._write('\x1b[' + (param || '') + 'C')
2473
- }
2474
-
2475
- // CSI Ps D
2476
- // Cursor Backward Ps Times (default = 1) (CUB).
2477
- Program.prototype.cub =
2478
- Program.prototype.left =
2479
- Program.prototype.back =
2480
- Program.prototype.cursorBackward =
2481
- function (param) {
2482
- this.x -= param || 1
2483
- this._ncoords()
2484
- if (this.tput) {
2485
- if (!this.tput.strings.parm_left_cursor) {
2486
- return this._write(this.repeat(this.tput.cub1(), param))
2487
- }
2488
- return this.put.cub(param)
2489
- }
2490
- return this._write('\x1b[' + (param || '') + 'D')
2491
- }
2492
-
2493
- // CSI Ps ; Ps H
2494
- // Cursor Position [row;column] (default = [1,1]) (CUP).
2495
- Program.prototype.cup =
2496
- Program.prototype.pos =
2497
- Program.prototype.cursorPos =
2498
- function (row, col) {
2499
- if (!this.zero) {
2500
- row = (row || 1) - 1
2501
- col = (col || 1) - 1
2502
- } else {
2503
- row = row || 0
2504
- col = col || 0
2505
- }
2506
- this.x = col
2507
- this.y = row
2508
- this._ncoords()
2509
- if (this.tput) {
2510
- return this.put.cup(row, col)
2511
- }
2512
- return this._write('\x1b[' + (row + 1) + ';' + (col + 1) + 'H')
2513
- }
2514
-
2515
- // CSI Ps J Erase in Display (ED).
2516
- // Ps = 0 -> Erase Below (default).
2517
- // Ps = 1 -> Erase Above.
2518
- // Ps = 2 -> Erase All.
2519
- // Ps = 3 -> Erase Saved Lines (xterm).
2520
- // CSI ? Ps J
2521
- // Erase in Display (DECSED).
2522
- // Ps = 0 -> Selective Erase Below (default).
2523
- // Ps = 1 -> Selective Erase Above.
2524
- // Ps = 2 -> Selective Erase All.
2525
- Program.prototype.ed = Program.prototype.eraseInDisplay = function (param) {
2526
- if (this.tput) {
2527
- switch (param) {
2528
- case 'above':
2529
- param = 1
2530
- break
2531
- case 'all':
2532
- param = 2
2533
- break
2534
- case 'saved':
2535
- param = 3
2536
- break
2537
- case 'below':
2538
- default:
2539
- param = 0
2540
- break
2541
- }
2542
- // extended tput.E3 = ^[[3;J
2543
- return this.put.ed(param)
2544
- }
2545
- switch (param) {
2546
- case 'above':
2547
- return this._write('X1b[1J')
2548
- case 'all':
2549
- return this._write('\x1b[2J')
2550
- case 'saved':
2551
- return this._write('\x1b[3J')
2552
- case 'below':
2553
- default:
2554
- return this._write('\x1b[J')
2555
- }
2556
- }
2557
-
2558
- Program.prototype.clear = function () {
2559
- this.x = 0
2560
- this.y = 0
2561
- if (this.tput) {
2562
- return this.put.clear()
2563
- }
2564
- return this._write('\x1b[H\x1b[J')
2565
- }
2566
-
2567
- // CSI Ps K Erase in Line (EL).
2568
- // Ps = 0 -> Erase to Right (default).
2569
- // Ps = 1 -> Erase to Left.
2570
- // Ps = 2 -> Erase All.
2571
- // CSI ? Ps K
2572
- // Erase in Line (DECSEL).
2573
- // Ps = 0 -> Selective Erase to Right (default).
2574
- // Ps = 1 -> Selective Erase to Left.
2575
- // Ps = 2 -> Selective Erase All.
2576
- Program.prototype.el = Program.prototype.eraseInLine = function (param) {
2577
- if (this.tput) {
2578
- //if (this.tput.back_color_erase) ...
2579
- switch (param) {
2580
- case 'left':
2581
- param = 1
2582
- break
2583
- case 'all':
2584
- param = 2
2585
- break
2586
- case 'right':
2587
- default:
2588
- param = 0
2589
- break
2590
- }
2591
- return this.put.el(param)
2592
- }
2593
- switch (param) {
2594
- case 'left':
2595
- return this._write('\x1b[1K')
2596
- case 'all':
2597
- return this._write('\x1b[2K')
2598
- case 'right':
2599
- default:
2600
- return this._write('\x1b[K')
2601
- }
2602
- }
2603
-
2604
- // CSI Pm m Character Attributes (SGR).
2605
- // Ps = 0 -> Normal (default).
2606
- // Ps = 1 -> Bold.
2607
- // Ps = 4 -> Underlined.
2608
- // Ps = 5 -> Blink (appears as Bold).
2609
- // Ps = 7 -> Inverse.
2610
- // Ps = 8 -> Invisible, i.e., hidden (VT300).
2611
- // Ps = 2 2 -> Normal (neither bold nor faint).
2612
- // Ps = 2 4 -> Not underlined.
2613
- // Ps = 2 5 -> Steady (not blinking).
2614
- // Ps = 2 7 -> Positive (not inverse).
2615
- // Ps = 2 8 -> Visible, i.e., not hidden (VT300).
2616
- // Ps = 3 0 -> Set foreground color to Black.
2617
- // Ps = 3 1 -> Set foreground color to Red.
2618
- // Ps = 3 2 -> Set foreground color to Green.
2619
- // Ps = 3 3 -> Set foreground color to Yellow.
2620
- // Ps = 3 4 -> Set foreground color to Blue.
2621
- // Ps = 3 5 -> Set foreground color to Magenta.
2622
- // Ps = 3 6 -> Set foreground color to Cyan.
2623
- // Ps = 3 7 -> Set foreground color to White.
2624
- // Ps = 3 9 -> Set foreground color to default (original).
2625
- // Ps = 4 0 -> Set background color to Black.
2626
- // Ps = 4 1 -> Set background color to Red.
2627
- // Ps = 4 2 -> Set background color to Green.
2628
- // Ps = 4 3 -> Set background color to Yellow.
2629
- // Ps = 4 4 -> Set background color to Blue.
2630
- // Ps = 4 5 -> Set background color to Magenta.
2631
- // Ps = 4 6 -> Set background color to Cyan.
2632
- // Ps = 4 7 -> Set background color to White.
2633
- // Ps = 4 9 -> Set background color to default (original).
2634
-
2635
- // If 16-color support is compiled, the following apply. Assume
2636
- // that xterm's resources are set so that the ISO color codes are
2637
- // the first 8 of a set of 16. Then the aixterm colors are the
2638
- // bright versions of the ISO colors:
2639
- // Ps = 9 0 -> Set foreground color to Black.
2640
- // Ps = 9 1 -> Set foreground color to Red.
2641
- // Ps = 9 2 -> Set foreground color to Green.
2642
- // Ps = 9 3 -> Set foreground color to Yellow.
2643
- // Ps = 9 4 -> Set foreground color to Blue.
2644
- // Ps = 9 5 -> Set foreground color to Magenta.
2645
- // Ps = 9 6 -> Set foreground color to Cyan.
2646
- // Ps = 9 7 -> Set foreground color to White.
2647
- // Ps = 1 0 0 -> Set background color to Black.
2648
- // Ps = 1 0 1 -> Set background color to Red.
2649
- // Ps = 1 0 2 -> Set background color to Green.
2650
- // Ps = 1 0 3 -> Set background color to Yellow.
2651
- // Ps = 1 0 4 -> Set background color to Blue.
2652
- // Ps = 1 0 5 -> Set background color to Magenta.
2653
- // Ps = 1 0 6 -> Set background color to Cyan.
2654
- // Ps = 1 0 7 -> Set background color to White.
2655
-
2656
- // If xterm is compiled with the 16-color support disabled, it
2657
- // supports the following, from rxvt:
2658
- // Ps = 1 0 0 -> Set foreground and background color to
2659
- // default.
2660
-
2661
- // If 88- or 256-color support is compiled, the following apply.
2662
- // Ps = 3 8 ; 5 ; Ps -> Set foreground color to the second
2663
- // Ps.
2664
- // Ps = 4 8 ; 5 ; Ps -> Set background color to the second
2665
- // Ps.
2666
- Program.prototype.sgr =
2667
- Program.prototype.attr =
2668
- Program.prototype.charAttributes =
2669
- function (param, val) {
2670
- return this._write(this._attr(param, val))
2671
- }
2672
-
2673
- Program.prototype.text = function (text, attr) {
2674
- return this._attr(attr, true) + text + this._attr(attr, false)
2675
- }
2676
-
2677
- // NOTE: sun-color may not allow multiple params for SGR.
2678
- Program.prototype._attr = function (param, val) {
2679
- let self = this,
2680
- parts,
2681
- color,
2682
- m
2683
-
2684
- if (Array.isArray(param)) {
2685
- parts = param
2686
- param = parts[0] || 'normal'
2687
- } else {
2688
- param = param || 'normal'
2689
- parts = param.split(/\s*[,;]\s*/)
2690
- }
2691
-
2692
- if (parts.length > 1) {
2693
- const used = {},
2694
- out = []
2695
-
2696
- parts.forEach(function (part) {
2697
- part = self._attr(part, val).slice(2, -1)
2698
- if (part === '') {
2699
- return
2700
- }
2701
- if (used[part]) {
2702
- return
2703
- }
2704
- used[part] = true
2705
- out.push(part)
2706
- })
2707
-
2708
- return '\x1b[' + out.join(';') + 'm'
2709
- }
2710
-
2711
- if (param.indexOf('no ') === 0) {
2712
- param = param.substring(3)
2713
- val = false
2714
- } else if (param.indexOf('!') === 0) {
2715
- param = param.substring(1)
2716
- val = false
2717
- }
2718
-
2719
- switch (param) {
2720
- // attributes
2721
- case 'normal':
2722
- case 'default':
2723
- if (val === false) {
2724
- return ''
2725
- }
2726
- return '\x1b[m'
2727
- case 'bold':
2728
- return val === false ? '\x1b[22m' : '\x1b[1m'
2729
- case 'ul':
2730
- case 'underline':
2731
- case 'underlined':
2732
- return val === false ? '\x1b[24m' : '\x1b[4m'
2733
- case 'blink':
2734
- return val === false ? '\x1b[25m' : '\x1b[5m'
2735
- case 'inverse':
2736
- return val === false ? '\x1b[27m' : '\x1b[7m'
2737
- case 'invisible':
2738
- return val === false ? '\x1b[28m' : '\x1b[8m'
2739
-
2740
- // 8-color foreground
2741
- case 'black fg':
2742
- return val === false ? '\x1b[39m' : '\x1b[30m'
2743
- case 'red fg':
2744
- return val === false ? '\x1b[39m' : '\x1b[31m'
2745
- case 'green fg':
2746
- return val === false ? '\x1b[39m' : '\x1b[32m'
2747
- case 'yellow fg':
2748
- return val === false ? '\x1b[39m' : '\x1b[33m'
2749
- case 'blue fg':
2750
- return val === false ? '\x1b[39m' : '\x1b[34m'
2751
- case 'magenta fg':
2752
- return val === false ? '\x1b[39m' : '\x1b[35m'
2753
- case 'cyan fg':
2754
- return val === false ? '\x1b[39m' : '\x1b[36m'
2755
- case 'white fg':
2756
- case 'light grey fg':
2757
- case 'light gray fg':
2758
- case 'bright grey fg':
2759
- case 'bright gray fg':
2760
- return val === false ? '\x1b[39m' : '\x1b[37m'
2761
- case 'default fg':
2762
- if (val === false) {
2763
- return ''
2764
- }
2765
- return '\x1b[39m'
2766
-
2767
- // 8-color background
2768
- case 'black bg':
2769
- return val === false ? '\x1b[49m' : '\x1b[40m'
2770
- case 'red bg':
2771
- return val === false ? '\x1b[49m' : '\x1b[41m'
2772
- case 'green bg':
2773
- return val === false ? '\x1b[49m' : '\x1b[42m'
2774
- case 'yellow bg':
2775
- return val === false ? '\x1b[49m' : '\x1b[43m'
2776
- case 'blue bg':
2777
- return val === false ? '\x1b[49m' : '\x1b[44m'
2778
- case 'magenta bg':
2779
- return val === false ? '\x1b[49m' : '\x1b[45m'
2780
- case 'cyan bg':
2781
- return val === false ? '\x1b[49m' : '\x1b[46m'
2782
- case 'white bg':
2783
- case 'light grey bg':
2784
- case 'light gray bg':
2785
- case 'bright grey bg':
2786
- case 'bright gray bg':
2787
- return val === false ? '\x1b[49m' : '\x1b[47m'
2788
- case 'default bg':
2789
- if (val === false) {
2790
- return ''
2791
- }
2792
- return '\x1b[49m'
2793
-
2794
- // 16-color foreground
2795
- case 'light black fg':
2796
- case 'bright black fg':
2797
- case 'grey fg':
2798
- case 'gray fg':
2799
- return val === false ? '\x1b[39m' : '\x1b[90m'
2800
- case 'light red fg':
2801
- case 'bright red fg':
2802
- return val === false ? '\x1b[39m' : '\x1b[91m'
2803
- case 'light green fg':
2804
- case 'bright green fg':
2805
- return val === false ? '\x1b[39m' : '\x1b[92m'
2806
- case 'light yellow fg':
2807
- case 'bright yellow fg':
2808
- return val === false ? '\x1b[39m' : '\x1b[93m'
2809
- case 'light blue fg':
2810
- case 'bright blue fg':
2811
- return val === false ? '\x1b[39m' : '\x1b[94m'
2812
- case 'light magenta fg':
2813
- case 'bright magenta fg':
2814
- return val === false ? '\x1b[39m' : '\x1b[95m'
2815
- case 'light cyan fg':
2816
- case 'bright cyan fg':
2817
- return val === false ? '\x1b[39m' : '\x1b[96m'
2818
- case 'light white fg':
2819
- case 'bright white fg':
2820
- return val === false ? '\x1b[39m' : '\x1b[97m'
2821
-
2822
- // 16-color background
2823
- case 'light black bg':
2824
- case 'bright black bg':
2825
- case 'grey bg':
2826
- case 'gray bg':
2827
- return val === false ? '\x1b[49m' : '\x1b[100m'
2828
- case 'light red bg':
2829
- case 'bright red bg':
2830
- return val === false ? '\x1b[49m' : '\x1b[101m'
2831
- case 'light green bg':
2832
- case 'bright green bg':
2833
- return val === false ? '\x1b[49m' : '\x1b[102m'
2834
- case 'light yellow bg':
2835
- case 'bright yellow bg':
2836
- return val === false ? '\x1b[49m' : '\x1b[103m'
2837
- case 'light blue bg':
2838
- case 'bright blue bg':
2839
- return val === false ? '\x1b[49m' : '\x1b[104m'
2840
- case 'light magenta bg':
2841
- case 'bright magenta bg':
2842
- return val === false ? '\x1b[49m' : '\x1b[105m'
2843
- case 'light cyan bg':
2844
- case 'bright cyan bg':
2845
- return val === false ? '\x1b[49m' : '\x1b[106m'
2846
- case 'light white bg':
2847
- case 'bright white bg':
2848
- return val === false ? '\x1b[49m' : '\x1b[107m'
2849
-
2850
- // non-16-color rxvt default fg and bg
2851
- case 'default fg bg':
2852
- if (val === false) {
2853
- return ''
2854
- }
2855
- return this.term('rxvt') ? '\x1b[100m' : '\x1b[39;49m'
2856
-
2857
- default:
2858
- // 256-color fg and bg
2859
- if (param[0] === '#') {
2860
- param = param.replace(/#(?:[0-9a-f]{3}){1,2}/i, colors.match)
2861
- }
2862
-
2863
- m = /^(-?\d+) (fg|bg)$/.exec(param)
2864
- if (m) {
2865
- color = +m[1]
2866
-
2867
- if (val === false || color === -1) {
2868
- return this._attr('default ' + m[2])
2869
- }
2870
-
2871
- color = colors.reduce(color, this.tput.colors)
2872
-
2873
- if (color < 16 || (this.tput && this.tput.colors <= 16)) {
2874
- if (m[2] === 'fg') {
2875
- if (color < 8) {
2876
- color += 30
2877
- } else if (color < 16) {
2878
- color -= 8
2879
- color += 90
2880
- }
2881
- } else if (m[2] === 'bg') {
2882
- if (color < 8) {
2883
- color += 40
2884
- } else if (color < 16) {
2885
- color -= 8
2886
- color += 100
2887
- }
2888
- }
2889
- return '\x1b[' + color + 'm'
2890
- }
2891
-
2892
- if (m[2] === 'fg') {
2893
- return '\x1b[38;5;' + color + 'm'
2894
- }
2895
-
2896
- if (m[2] === 'bg') {
2897
- return '\x1b[48;5;' + color + 'm'
2898
- }
2899
- }
2900
-
2901
- if (/^[\d;]*$/.test(param)) {
2902
- return '\x1b[' + param + 'm'
2903
- }
2904
-
2905
- return null
2906
- }
2907
- }
2908
-
2909
- Program.prototype.fg = Program.prototype.setForeground = function (color, val) {
2910
- color = color.split(/\s*[,;]\s*/).join(' fg, ') + ' fg'
2911
- return this.attr(color, val)
2912
- }
2913
-
2914
- Program.prototype.bg = Program.prototype.setBackground = function (color, val) {
2915
- color = color.split(/\s*[,;]\s*/).join(' bg, ') + ' bg'
2916
- return this.attr(color, val)
2917
- }
2918
-
2919
- // CSI Ps n Device Status Report (DSR).
2920
- // Ps = 5 -> Status Report. Result (``OK'') is
2921
- // CSI 0 n
2922
- // Ps = 6 -> Report Cursor Position (CPR) [row;column].
2923
- // Result is
2924
- // CSI r ; c R
2925
- // CSI ? Ps n
2926
- // Device Status Report (DSR, DEC-specific).
2927
- // Ps = 6 -> Report Cursor Position (CPR) [row;column] as CSI
2928
- // ? r ; c R (assumes page is zero).
2929
- // Ps = 1 5 -> Report Printer status as CSI ? 1 0 n (ready).
2930
- // or CSI ? 1 1 n (not ready).
2931
- // Ps = 2 5 -> Report UDK status as CSI ? 2 0 n (unlocked)
2932
- // or CSI ? 2 1 n (locked).
2933
- // Ps = 2 6 -> Report Keyboard status as
2934
- // CSI ? 2 7 ; 1 ; 0 ; 0 n (North American).
2935
- // The last two parameters apply to VT400 & up, and denote key-
2936
- // board ready and LK01 respectively.
2937
- // Ps = 5 3 -> Report Locator status as
2938
- // CSI ? 5 3 n Locator available, if compiled-in, or
2939
- // CSI ? 5 0 n No Locator, if not.
2940
- Program.prototype.dsr = Program.prototype.deviceStatus = function (
2941
- param,
2942
- callback,
2943
- dec,
2944
- noBypass
2945
- ) {
2946
- if (dec) {
2947
- return this.response(
2948
- 'device-status',
2949
- '\x1b[?' + (param || '0') + 'n',
2950
- callback,
2951
- noBypass
2952
- )
2953
- }
2954
- return this.response(
2955
- 'device-status',
2956
- '\x1b[' + (param || '0') + 'n',
2957
- callback,
2958
- noBypass
2959
- )
2960
- }
2961
-
2962
- Program.prototype.getCursor = function (callback) {
2963
- return this.deviceStatus(6, callback, false, true)
2964
- }
2965
-
2966
- Program.prototype.saveReportedCursor = function (callback) {
2967
- const self = this
2968
- if (this.tput.strings.user7 === '\x1b[6n' || this.term('screen')) {
2969
- return this.getCursor(function (err, data) {
2970
- if (data) {
2971
- self._rx = data.status.x
2972
- self._ry = data.status.y
2973
- }
2974
- if (!callback) {
2975
- return
2976
- }
2977
- return callback(err)
2978
- })
2979
- }
2980
- if (!callback) {
2981
- return
2982
- }
2983
- return callback()
2984
- }
2985
-
2986
- Program.prototype.restoreReportedCursor = function () {
2987
- if (this._rx == null) {
2988
- return
2989
- }
2990
- return this.cup(this._ry, this._rx)
2991
- // return this.nel();
2992
- }
2993
-
2994
- /**
2995
- * Additions
2996
- */
2997
-
2998
- // CSI Ps @
2999
- // Insert Ps (Blank) Character(s) (default = 1) (ICH).
3000
- Program.prototype.ich = Program.prototype.insertChars = function (param) {
3001
- this.x += param || 1
3002
- this._ncoords()
3003
- if (this.tput) {
3004
- return this.put.ich(param)
3005
- }
3006
- return this._write('\x1b[' + (param || 1) + '@')
3007
- }
3008
-
3009
- // CSI Ps E
3010
- // Cursor Next Line Ps Times (default = 1) (CNL).
3011
- // same as CSI Ps B ?
3012
- Program.prototype.cnl = Program.prototype.cursorNextLine = function (param) {
3013
- this.y += param || 1
3014
- this._ncoords()
3015
- return this._write('\x1b[' + (param || '') + 'E')
3016
- }
3017
-
3018
- // CSI Ps F
3019
- // Cursor Preceding Line Ps Times (default = 1) (CNL).
3020
- // reuse CSI Ps A ?
3021
- Program.prototype.cpl = Program.prototype.cursorPrecedingLine = function (
3022
- param
3023
- ) {
3024
- this.y -= param || 1
3025
- this._ncoords()
3026
- return this._write('\x1b[' + (param || '') + 'F')
3027
- }
3028
-
3029
- // CSI Ps G
3030
- // Cursor Character Absolute [column] (default = [row,1]) (CHA).
3031
- Program.prototype.cha = Program.prototype.cursorCharAbsolute = function (
3032
- param
3033
- ) {
3034
- if (!this.zero) {
3035
- param = (param || 1) - 1
3036
- } else {
3037
- param = param || 0
3038
- }
3039
- this.x = param
3040
- this.y = 0
3041
- this._ncoords()
3042
- if (this.tput) {
3043
- return this.put.hpa(param)
3044
- }
3045
- return this._write('\x1b[' + (param + 1) + 'G')
3046
- }
3047
-
3048
- // CSI Ps L
3049
- // Insert Ps Line(s) (default = 1) (IL).
3050
- Program.prototype.il = Program.prototype.insertLines = function (param) {
3051
- if (this.tput) {
3052
- return this.put.il(param)
3053
- }
3054
- return this._write('\x1b[' + (param || '') + 'L')
3055
- }
3056
-
3057
- // CSI Ps M
3058
- // Delete Ps Line(s) (default = 1) (DL).
3059
- Program.prototype.dl = Program.prototype.deleteLines = function (param) {
3060
- if (this.tput) {
3061
- return this.put.dl(param)
3062
- }
3063
- return this._write('\x1b[' + (param || '') + 'M')
3064
- }
3065
-
3066
- // CSI Ps P
3067
- // Delete Ps Character(s) (default = 1) (DCH).
3068
- Program.prototype.dch = Program.prototype.deleteChars = function (param) {
3069
- if (this.tput) {
3070
- return this.put.dch(param)
3071
- }
3072
- return this._write('\x1b[' + (param || '') + 'P')
3073
- }
3074
-
3075
- // CSI Ps X
3076
- // Erase Ps Character(s) (default = 1) (ECH).
3077
- Program.prototype.ech = Program.prototype.eraseChars = function (param) {
3078
- if (this.tput) {
3079
- return this.put.ech(param)
3080
- }
3081
- return this._write('\x1b[' + (param || '') + 'X')
3082
- }
3083
-
3084
- // CSI Pm ` Character Position Absolute
3085
- // [column] (default = [row,1]) (HPA).
3086
- Program.prototype.hpa = Program.prototype.charPosAbsolute = function (param) {
3087
- this.x = param || 0
3088
- this._ncoords()
3089
- if (this.tput) {
3090
- return this.put.hpa.apply(this.put, arguments)
3091
- }
3092
- param = slice.call(arguments).join(';')
3093
- return this._write('\x1b[' + (param || '') + '`')
3094
- }
3095
-
3096
- // 141 61 a * HPR -
3097
- // Horizontal Position Relative
3098
- // reuse CSI Ps C ?
3099
- Program.prototype.hpr = Program.prototype.HPositionRelative = function (param) {
3100
- if (this.tput) {
3101
- return this.cuf(param)
3102
- }
3103
- this.x += param || 1
3104
- this._ncoords()
3105
- // Does not exist:
3106
- // if (this.tput) return this.put.hpr(param);
3107
- return this._write('\x1b[' + (param || '') + 'a')
3108
- }
3109
-
3110
- // CSI Ps c Send Device Attributes (Primary DA).
3111
- // Ps = 0 or omitted -> request attributes from terminal. The
3112
- // response depends on the decTerminalID resource setting.
3113
- // -> CSI ? 1 ; 2 c (``VT100 with Advanced Video Option'')
3114
- // -> CSI ? 1 ; 0 c (``VT101 with No Options'')
3115
- // -> CSI ? 6 c (``VT102'')
3116
- // -> CSI ? 6 0 ; 1 ; 2 ; 6 ; 8 ; 9 ; 1 5 ; c (``VT220'')
3117
- // The VT100-style response parameters do not mean anything by
3118
- // themselves. VT220 parameters do, telling the host what fea-
3119
- // tures the terminal supports:
3120
- // Ps = 1 -> 132-columns.
3121
- // Ps = 2 -> Printer.
3122
- // Ps = 6 -> Selective erase.
3123
- // Ps = 8 -> User-defined keys.
3124
- // Ps = 9 -> National replacement character sets.
3125
- // Ps = 1 5 -> Technical characters.
3126
- // Ps = 2 2 -> ANSI color, e.g., VT525.
3127
- // Ps = 2 9 -> ANSI text locator (i.e., DEC Locator mode).
3128
- // CSI > Ps c
3129
- // Send Device Attributes (Secondary DA).
3130
- // Ps = 0 or omitted -> request the terminal's identification
3131
- // code. The response depends on the decTerminalID resource set-
3132
- // ting. It should apply only to VT220 and up, but xterm extends
3133
- // this to VT100.
3134
- // -> CSI > Pp ; Pv ; Pc c
3135
- // where Pp denotes the terminal type
3136
- // Pp = 0 -> ``VT100''.
3137
- // Pp = 1 -> ``VT220''.
3138
- // and Pv is the firmware version (for xterm, this was originally
3139
- // the XFree86 patch number, starting with 95). In a DEC termi-
3140
- // nal, Pc indicates the ROM cartridge registration number and is
3141
- // always zero.
3142
- // More information:
3143
- // xterm/charproc.c - line 2012, for more information.
3144
- // vim responds with ^[[?0c or ^[[?1c after the terminal's response (?)
3145
- Program.prototype.da = Program.prototype.sendDeviceAttributes = function (
3146
- param,
3147
- callback
3148
- ) {
3149
- return this.response(
3150
- 'device-attributes',
3151
- '\x1b[' + (param || '') + 'c',
3152
- callback
3153
- )
3154
- }
3155
-
3156
- // CSI Pm d
3157
- // Line Position Absolute [row] (default = [1,column]) (VPA).
3158
- // NOTE: Can't find in terminfo, no idea why it has multiple params.
3159
- Program.prototype.vpa = Program.prototype.linePosAbsolute = function (param) {
3160
- this.y = param || 1
3161
- this._ncoords()
3162
- if (this.tput) {
3163
- return this.put.vpa.apply(this.put, arguments)
3164
- }
3165
- param = slice.call(arguments).join(';')
3166
- return this._write('\x1b[' + (param || '') + 'd')
3167
- }
3168
-
3169
- // 145 65 e * VPR - Vertical Position Relative
3170
- // reuse CSI Ps B ?
3171
- Program.prototype.vpr = Program.prototype.VPositionRelative = function (param) {
3172
- if (this.tput) {
3173
- return this.cud(param)
3174
- }
3175
- this.y += param || 1
3176
- this._ncoords()
3177
- // Does not exist:
3178
- // if (this.tput) return this.put.vpr(param);
3179
- return this._write('\x1b[' + (param || '') + 'e')
3180
- }
3181
-
3182
- // CSI Ps ; Ps f
3183
- // Horizontal and Vertical Position [row;column] (default =
3184
- // [1,1]) (HVP).
3185
- Program.prototype.hvp = Program.prototype.HVPosition = function (row, col) {
3186
- if (!this.zero) {
3187
- row = (row || 1) - 1
3188
- col = (col || 1) - 1
3189
- } else {
3190
- row = row || 0
3191
- col = col || 0
3192
- }
3193
- this.y = row
3194
- this.x = col
3195
- this._ncoords()
3196
- // Does not exist (?):
3197
- // if (this.tput) return this.put.hvp(row, col);
3198
- if (this.tput) {
3199
- return this.put.cup(row, col)
3200
- }
3201
- return this._write('\x1b[' + (row + 1) + ';' + (col + 1) + 'f')
3202
- }
3203
-
3204
- // CSI Pm h Set Mode (SM).
3205
- // Ps = 2 -> Keyboard Action Mode (AM).
3206
- // Ps = 4 -> Insert Mode (IRM).
3207
- // Ps = 1 2 -> Send/receive (SRM).
3208
- // Ps = 2 0 -> Automatic Newline (LNM).
3209
- // CSI ? Pm h
3210
- // DEC Private Mode Set (DECSET).
3211
- // Ps = 1 -> Application Cursor Keys (DECCKM).
3212
- // Ps = 2 -> Designate USASCII for character sets G0-G3
3213
- // (DECANM), and set VT100 mode.
3214
- // Ps = 3 -> 132 Column Mode (DECCOLM).
3215
- // Ps = 4 -> Smooth (Slow) Scroll (DECSCLM).
3216
- // Ps = 5 -> Reverse Video (DECSCNM).
3217
- // Ps = 6 -> Origin Mode (DECOM).
3218
- // Ps = 7 -> Wraparound Mode (DECAWM).
3219
- // Ps = 8 -> Auto-repeat Keys (DECARM).
3220
- // Ps = 9 -> Send Mouse X & Y on button press. See the sec-
3221
- // tion Mouse Tracking.
3222
- // Ps = 1 0 -> Show toolbar (rxvt).
3223
- // Ps = 1 2 -> Start Blinking Cursor (att610).
3224
- // Ps = 1 8 -> Print form feed (DECPFF).
3225
- // Ps = 1 9 -> Set print extent to full screen (DECPEX).
3226
- // Ps = 2 5 -> Show Cursor (DECTCEM).
3227
- // Ps = 3 0 -> Show scrollbar (rxvt).
3228
- // Ps = 3 5 -> Enable font-shifting functions (rxvt).
3229
- // Ps = 3 8 -> Enter Tektronix Mode (DECTEK).
3230
- // Ps = 4 0 -> Allow 80 -> 132 Mode.
3231
- // Ps = 4 1 -> more(1) fix (see curses resource).
3232
- // Ps = 4 2 -> Enable Nation Replacement Character sets (DECN-
3233
- // RCM).
3234
- // Ps = 4 4 -> Turn On Margin Bell.
3235
- // Ps = 4 5 -> Reverse-wraparound Mode.
3236
- // Ps = 4 6 -> Start Logging. This is normally disabled by a
3237
- // compile-time option.
3238
- // Ps = 4 7 -> Use Alternate Screen Buffer. (This may be dis-
3239
- // abled by the titeInhibit resource).
3240
- // Ps = 6 6 -> Application keypad (DECNKM).
3241
- // Ps = 6 7 -> Backarrow key sends backspace (DECBKM).
3242
- // Ps = 1 0 0 0 -> Send Mouse X & Y on button press and
3243
- // release. See the section Mouse Tracking.
3244
- // Ps = 1 0 0 1 -> Use Hilite Mouse Tracking.
3245
- // Ps = 1 0 0 2 -> Use Cell Motion Mouse Tracking.
3246
- // Ps = 1 0 0 3 -> Use All Motion Mouse Tracking.
3247
- // Ps = 1 0 0 4 -> Send FocusIn/FocusOut events.
3248
- // Ps = 1 0 0 5 -> Enable Extended Mouse Mode.
3249
- // Ps = 1 0 1 0 -> Scroll to bottom on tty output (rxvt).
3250
- // Ps = 1 0 1 1 -> Scroll to bottom on key press (rxvt).
3251
- // Ps = 1 0 3 4 -> Interpret "meta" key, sets eighth bit.
3252
- // (enables the eightBitInput resource).
3253
- // Ps = 1 0 3 5 -> Enable special modifiers for Alt and Num-
3254
- // Lock keys. (This enables the numLock resource).
3255
- // Ps = 1 0 3 6 -> Send ESC when Meta modifies a key. (This
3256
- // enables the metaSendsEscape resource).
3257
- // Ps = 1 0 3 7 -> Send DEL from the editing-keypad Delete
3258
- // key.
3259
- // Ps = 1 0 3 9 -> Send ESC when Alt modifies a key. (This
3260
- // enables the altSendsEscape resource).
3261
- // Ps = 1 0 4 0 -> Keep selection even if not highlighted.
3262
- // (This enables the keepSelection resource).
3263
- // Ps = 1 0 4 1 -> Use the CLIPBOARD selection. (This enables
3264
- // the selectToClipboard resource).
3265
- // Ps = 1 0 4 2 -> Enable Urgency window manager hint when
3266
- // Control-G is received. (This enables the bellIsUrgent
3267
- // resource).
3268
- // Ps = 1 0 4 3 -> Enable raising of the window when Control-G
3269
- // is received. (enables the popOnBell resource).
3270
- // Ps = 1 0 4 7 -> Use Alternate Screen Buffer. (This may be
3271
- // disabled by the titeInhibit resource).
3272
- // Ps = 1 0 4 8 -> Save cursor as in DECSC. (This may be dis-
3273
- // abled by the titeInhibit resource).
3274
- // Ps = 1 0 4 9 -> Save cursor as in DECSC and use Alternate
3275
- // Screen Buffer, clearing it first. (This may be disabled by
3276
- // the titeInhibit resource). This combines the effects of the 1
3277
- // 0 4 7 and 1 0 4 8 modes. Use this with terminfo-based
3278
- // applications rather than the 4 7 mode.
3279
- // Ps = 1 0 5 0 -> Set terminfo/termcap function-key mode.
3280
- // Ps = 1 0 5 1 -> Set Sun function-key mode.
3281
- // Ps = 1 0 5 2 -> Set HP function-key mode.
3282
- // Ps = 1 0 5 3 -> Set SCO function-key mode.
3283
- // Ps = 1 0 6 0 -> Set legacy keyboard emulation (X11R6).
3284
- // Ps = 1 0 6 1 -> Set VT220 keyboard emulation.
3285
- // Ps = 2 0 0 4 -> Set bracketed paste mode.
3286
- // Modes:
3287
- // http://vt100.net/docs/vt220-rm/chapter4.html
3288
- Program.prototype.sm = Program.prototype.setMode = function () {
3289
- const param = slice.call(arguments).join(';')
3290
- return this._write('\x1b[' + (param || '') + 'h')
3291
- }
3292
-
3293
- Program.prototype.decset = function () {
3294
- const param = slice.call(arguments).join(';')
3295
- return this.setMode('?' + param)
3296
- }
3297
-
3298
- Program.prototype.dectcem =
3299
- Program.prototype.cnorm =
3300
- Program.prototype.cvvis =
3301
- Program.prototype.showCursor =
3302
- function () {
3303
- this.cursorHidden = false
3304
- // NOTE: In xterm terminfo:
3305
- // cnorm stops blinking cursor
3306
- // cvvis starts blinking cursor
3307
- if (this.tput) {
3308
- return this.put.cnorm()
3309
- }
3310
- //if (this.tput) return this.put.cvvis();
3311
- // return this._write('\x1b[?12l\x1b[?25h'); // cursor_normal
3312
- // return this._write('\x1b[?12;25h'); // cursor_visible
3313
- return this.setMode('?25')
3314
- }
3315
-
3316
- Program.prototype.alternate =
3317
- Program.prototype.smcup =
3318
- Program.prototype.alternateBuffer =
3319
- function () {
3320
- this.isAlt = true
3321
- if (this.tput) {
3322
- return this.put.smcup()
3323
- }
3324
- if (this.term('vt') || this.term('linux')) {
3325
- return
3326
- }
3327
- this.setMode('?47')
3328
- return this.setMode('?1049')
3329
- }
3330
-
3331
- // CSI Pm l Reset Mode (RM).
3332
- // Ps = 2 -> Keyboard Action Mode (AM).
3333
- // Ps = 4 -> Replace Mode (IRM).
3334
- // Ps = 1 2 -> Send/receive (SRM).
3335
- // Ps = 2 0 -> Normal Linefeed (LNM).
3336
- // CSI ? Pm l
3337
- // DEC Private Mode Reset (DECRST).
3338
- // Ps = 1 -> Normal Cursor Keys (DECCKM).
3339
- // Ps = 2 -> Designate VT52 mode (DECANM).
3340
- // Ps = 3 -> 80 Column Mode (DECCOLM).
3341
- // Ps = 4 -> Jump (Fast) Scroll (DECSCLM).
3342
- // Ps = 5 -> Normal Video (DECSCNM).
3343
- // Ps = 6 -> Normal Cursor Mode (DECOM).
3344
- // Ps = 7 -> No Wraparound Mode (DECAWM).
3345
- // Ps = 8 -> No Auto-repeat Keys (DECARM).
3346
- // Ps = 9 -> Don't send Mouse X & Y on button press.
3347
- // Ps = 1 0 -> Hide toolbar (rxvt).
3348
- // Ps = 1 2 -> Stop Blinking Cursor (att610).
3349
- // Ps = 1 8 -> Don't print form feed (DECPFF).
3350
- // Ps = 1 9 -> Limit print to scrolling region (DECPEX).
3351
- // Ps = 2 5 -> Hide Cursor (DECTCEM).
3352
- // Ps = 3 0 -> Don't show scrollbar (rxvt).
3353
- // Ps = 3 5 -> Disable font-shifting functions (rxvt).
3354
- // Ps = 4 0 -> Disallow 80 -> 132 Mode.
3355
- // Ps = 4 1 -> No more(1) fix (see curses resource).
3356
- // Ps = 4 2 -> Disable Nation Replacement Character sets (DEC-
3357
- // NRCM).
3358
- // Ps = 4 4 -> Turn Off Margin Bell.
3359
- // Ps = 4 5 -> No Reverse-wraparound Mode.
3360
- // Ps = 4 6 -> Stop Logging. (This is normally disabled by a
3361
- // compile-time option).
3362
- // Ps = 4 7 -> Use Normal Screen Buffer.
3363
- // Ps = 6 6 -> Numeric keypad (DECNKM).
3364
- // Ps = 6 7 -> Backarrow key sends delete (DECBKM).
3365
- // Ps = 1 0 0 0 -> Don't send Mouse X & Y on button press and
3366
- // release. See the section Mouse Tracking.
3367
- // Ps = 1 0 0 1 -> Don't use Hilite Mouse Tracking.
3368
- // Ps = 1 0 0 2 -> Don't use Cell Motion Mouse Tracking.
3369
- // Ps = 1 0 0 3 -> Don't use All Motion Mouse Tracking.
3370
- // Ps = 1 0 0 4 -> Don't send FocusIn/FocusOut events.
3371
- // Ps = 1 0 0 5 -> Disable Extended Mouse Mode.
3372
- // Ps = 1 0 1 0 -> Don't scroll to bottom on tty output
3373
- // (rxvt).
3374
- // Ps = 1 0 1 1 -> Don't scroll to bottom on key press (rxvt).
3375
- // Ps = 1 0 3 4 -> Don't interpret "meta" key. (This disables
3376
- // the eightBitInput resource).
3377
- // Ps = 1 0 3 5 -> Disable special modifiers for Alt and Num-
3378
- // Lock keys. (This disables the numLock resource).
3379
- // Ps = 1 0 3 6 -> Don't send ESC when Meta modifies a key.
3380
- // (This disables the metaSendsEscape resource).
3381
- // Ps = 1 0 3 7 -> Send VT220 Remove from the editing-keypad
3382
- // Delete key.
3383
- // Ps = 1 0 3 9 -> Don't send ESC when Alt modifies a key.
3384
- // (This disables the altSendsEscape resource).
3385
- // Ps = 1 0 4 0 -> Do not keep selection when not highlighted.
3386
- // (This disables the keepSelection resource).
3387
- // Ps = 1 0 4 1 -> Use the PRIMARY selection. (This disables
3388
- // the selectToClipboard resource).
3389
- // Ps = 1 0 4 2 -> Disable Urgency window manager hint when
3390
- // Control-G is received. (This disables the bellIsUrgent
3391
- // resource).
3392
- // Ps = 1 0 4 3 -> Disable raising of the window when Control-
3393
- // G is received. (This disables the popOnBell resource).
3394
- // Ps = 1 0 4 7 -> Use Normal Screen Buffer, clearing screen
3395
- // first if in the Alternate Screen. (This may be disabled by
3396
- // the titeInhibit resource).
3397
- // Ps = 1 0 4 8 -> Restore cursor as in DECRC. (This may be
3398
- // disabled by the titeInhibit resource).
3399
- // Ps = 1 0 4 9 -> Use Normal Screen Buffer and restore cursor
3400
- // as in DECRC. (This may be disabled by the titeInhibit
3401
- // resource). This combines the effects of the 1 0 4 7 and 1 0
3402
- // 4 8 modes. Use this with terminfo-based applications rather
3403
- // than the 4 7 mode.
3404
- // Ps = 1 0 5 0 -> Reset terminfo/termcap function-key mode.
3405
- // Ps = 1 0 5 1 -> Reset Sun function-key mode.
3406
- // Ps = 1 0 5 2 -> Reset HP function-key mode.
3407
- // Ps = 1 0 5 3 -> Reset SCO function-key mode.
3408
- // Ps = 1 0 6 0 -> Reset legacy keyboard emulation (X11R6).
3409
- // Ps = 1 0 6 1 -> Reset keyboard emulation to Sun/PC style.
3410
- // Ps = 2 0 0 4 -> Reset bracketed paste mode.
3411
- Program.prototype.rm = Program.prototype.resetMode = function () {
3412
- const param = slice.call(arguments).join(';')
3413
- return this._write('\x1b[' + (param || '') + 'l')
3414
- }
3415
-
3416
- Program.prototype.decrst = function () {
3417
- const param = slice.call(arguments).join(';')
3418
- return this.resetMode('?' + param)
3419
- }
3420
-
3421
- Program.prototype.dectcemh =
3422
- Program.prototype.cursor_invisible =
3423
- Program.prototype.vi =
3424
- Program.prototype.civis =
3425
- Program.prototype.hideCursor =
3426
- function () {
3427
- this.cursorHidden = true
3428
- if (this.tput) {
3429
- return this.put.civis()
3430
- }
3431
- return this.resetMode('?25')
3432
- }
3433
-
3434
- Program.prototype.rmcup = Program.prototype.normalBuffer = function () {
3435
- this.isAlt = false
3436
- if (this.tput) {
3437
- return this.put.rmcup()
3438
- }
3439
- this.resetMode('?47')
3440
- return this.resetMode('?1049')
3441
- }
3442
-
3443
- Program.prototype.enableMouse = function () {
3444
- if (process.env.BLESSED_FORCE_MODES) {
3445
- const modes = process.env.BLESSED_FORCE_MODES.split(',')
3446
- const options = {}
3447
- for (let n = 0; n < modes.length; ++n) {
3448
- const pair = modes[n].split('=')
3449
- const v = pair[1] !== '0'
3450
- switch (pair[0].toUpperCase()) {
3451
- case 'SGRMOUSE':
3452
- options.sgrMouse = v
3453
- break
3454
- case 'UTFMOUSE':
3455
- options.utfMouse = v
3456
- break
3457
- case 'VT200MOUSE':
3458
- options.vt200Mouse = v
3459
- break
3460
- case 'URXVTMOUSE':
3461
- options.urxvtMouse = v
3462
- break
3463
- case 'X10MOUSE':
3464
- options.x10Mouse = v
3465
- break
3466
- case 'DECMOUSE':
3467
- options.decMouse = v
3468
- break
3469
- case 'PTERMMOUSE':
3470
- options.ptermMouse = v
3471
- break
3472
- case 'JSBTERMMOUSE':
3473
- options.jsbtermMouse = v
3474
- break
3475
- case 'VT200HILITE':
3476
- options.vt200Hilite = v
3477
- break
3478
- case 'GPMMOUSE':
3479
- options.gpmMouse = v
3480
- break
3481
- case 'CELLMOTION':
3482
- options.cellMotion = v
3483
- break
3484
- case 'ALLMOTION':
3485
- options.allMotion = v
3486
- break
3487
- case 'SENDFOCUS':
3488
- options.sendFocus = v
3489
- break
3490
- }
3491
- }
3492
- return this.setMouse(options, true)
3493
- }
3494
-
3495
- // NOTE:
3496
- // Cell Motion isn't normally need for anything below here, but we'll
3497
- // activate it for tmux (whether using it or not) in case our all-motion
3498
- // passthrough does not work. It can't hurt.
3499
-
3500
- if (this.term('rxvt-unicode')) {
3501
- return this.setMouse(
3502
- {
3503
- urxvtMouse: true,
3504
- cellMotion: true,
3505
- allMotion: true
3506
- },
3507
- true
3508
- )
3509
- }
3510
-
3511
- // rxvt does not support the X10 UTF extensions
3512
- if (this.term('rxvt')) {
3513
- return this.setMouse(
3514
- {
3515
- vt200Mouse: true,
3516
- x10Mouse: true,
3517
- cellMotion: true,
3518
- allMotion: true
3519
- },
3520
- true
3521
- )
3522
- }
3523
-
3524
- // libvte is broken. Older versions do not support the
3525
- // X10 UTF extension. However, later versions do support
3526
- // SGR/URXVT.
3527
- if (this.isVTE) {
3528
- return this.setMouse(
3529
- {
3530
- // NOTE: Could also use urxvtMouse here.
3531
- sgrMouse: true,
3532
- cellMotion: true,
3533
- allMotion: true
3534
- },
3535
- true
3536
- )
3537
- }
3538
-
3539
- if (this.term('linux')) {
3540
- return this.setMouse(
3541
- {
3542
- vt200Mouse: true,
3543
- gpmMouse: true
3544
- },
3545
- true
3546
- )
3547
- }
3548
-
3549
- if (
3550
- this.term('xterm') ||
3551
- this.term('screen') ||
3552
- (this.tput && this.tput.strings.key_mouse)
3553
- ) {
3554
- return this.setMouse(
3555
- {
3556
- vt200Mouse: true,
3557
- utfMouse: true,
3558
- cellMotion: true,
3559
- allMotion: true
3560
- },
3561
- true
3562
- )
3563
- }
3564
- }
3565
-
3566
- Program.prototype.disableMouse = function () {
3567
- if (!this._currentMouse) {
3568
- return
3569
- }
3570
-
3571
- const obj = {}
3572
-
3573
- Object.keys(this._currentMouse).forEach(function (key) {
3574
- obj[key] = false
3575
- })
3576
-
3577
- return this.setMouse(obj, false)
3578
- }
3579
-
3580
- // Set Mouse
3581
- Program.prototype.setMouse = function (opt, enable) {
3582
- if (opt.normalMouse != null) {
3583
- opt.vt200Mouse = opt.normalMouse
3584
- opt.allMotion = opt.normalMouse
3585
- }
3586
-
3587
- if (opt.hiliteTracking != null) {
3588
- opt.vt200Hilite = opt.hiliteTracking
3589
- }
3590
-
3591
- if (enable === true) {
3592
- if (this._currentMouse) {
3593
- this.setMouse(opt)
3594
- Object.keys(opt).forEach(function (key) {
3595
- this._currentMouse[key] = opt[key]
3596
- }, this)
3597
- return
3598
- }
3599
- this._currentMouse = opt
3600
- this.mouseEnabled = true
3601
- } else if (enable === false) {
3602
- delete this._currentMouse
3603
- this.mouseEnabled = false
3604
- }
3605
-
3606
- // Ps = 9 -> Send Mouse X & Y on button press. See the sec-
3607
- // tion Mouse Tracking.
3608
- // Ps = 9 -> Don't send Mouse X & Y on button press.
3609
- // x10 mouse
3610
- if (opt.x10Mouse != null) {
3611
- if (opt.x10Mouse) {
3612
- this.setMode('?9')
3613
- } else {
3614
- this.resetMode('?9')
3615
- }
3616
- }
3617
-
3618
- // Ps = 1 0 0 0 -> Send Mouse X & Y on button press and
3619
- // release. See the section Mouse Tracking.
3620
- // Ps = 1 0 0 0 -> Don't send Mouse X & Y on button press and
3621
- // release. See the section Mouse Tracking.
3622
- // vt200 mouse
3623
- if (opt.vt200Mouse != null) {
3624
- if (opt.vt200Mouse) {
3625
- this.setMode('?1000')
3626
- } else {
3627
- this.resetMode('?1000')
3628
- }
3629
- }
3630
-
3631
- // Ps = 1 0 0 1 -> Use Hilite Mouse Tracking.
3632
- // Ps = 1 0 0 1 -> Don't use Hilite Mouse Tracking.
3633
- if (opt.vt200Hilite != null) {
3634
- if (opt.vt200Hilite) {
3635
- this.setMode('?1001')
3636
- } else {
3637
- this.resetMode('?1001')
3638
- }
3639
- }
3640
-
3641
- // Ps = 1 0 0 2 -> Use Cell Motion Mouse Tracking.
3642
- // Ps = 1 0 0 2 -> Don't use Cell Motion Mouse Tracking.
3643
- // button event mouse
3644
- if (opt.cellMotion != null) {
3645
- if (opt.cellMotion) {
3646
- this.setMode('?1002')
3647
- } else {
3648
- this.resetMode('?1002')
3649
- }
3650
- }
3651
-
3652
- // Ps = 1 0 0 3 -> Use All Motion Mouse Tracking.
3653
- // Ps = 1 0 0 3 -> Don't use All Motion Mouse Tracking.
3654
- // any event mouse
3655
- if (opt.allMotion != null) {
3656
- // NOTE: Latest versions of tmux seem to only support cellMotion (not
3657
- // allMotion). We pass all motion through to the terminal.
3658
- if (this.tmux && this.tmuxVersion >= 2) {
3659
- if (opt.allMotion) {
3660
- this._twrite('\x1b[?1003h')
3661
- } else {
3662
- this._twrite('\x1b[?1003l')
3663
- }
3664
- } else {
3665
- if (opt.allMotion) {
3666
- this.setMode('?1003')
3667
- } else {
3668
- this.resetMode('?1003')
3669
- }
3670
- }
3671
- }
3672
-
3673
- // Ps = 1 0 0 4 -> Send FocusIn/FocusOut events.
3674
- // Ps = 1 0 0 4 -> Don't send FocusIn/FocusOut events.
3675
- if (opt.sendFocus != null) {
3676
- if (opt.sendFocus) {
3677
- this.setMode('?1004')
3678
- } else {
3679
- this.resetMode('?1004')
3680
- }
3681
- }
3682
-
3683
- // Ps = 1 0 0 5 -> Enable Extended Mouse Mode.
3684
- // Ps = 1 0 0 5 -> Disable Extended Mouse Mode.
3685
- if (opt.utfMouse != null) {
3686
- if (opt.utfMouse) {
3687
- this.setMode('?1005')
3688
- } else {
3689
- this.resetMode('?1005')
3690
- }
3691
- }
3692
-
3693
- // sgr mouse
3694
- if (opt.sgrMouse != null) {
3695
- if (opt.sgrMouse) {
3696
- this.setMode('?1006')
3697
- } else {
3698
- this.resetMode('?1006')
3699
- }
3700
- }
3701
-
3702
- // urxvt mouse
3703
- if (opt.urxvtMouse != null) {
3704
- if (opt.urxvtMouse) {
3705
- this.setMode('?1015')
3706
- } else {
3707
- this.resetMode('?1015')
3708
- }
3709
- }
3710
-
3711
- // dec mouse
3712
- if (opt.decMouse != null) {
3713
- if (opt.decMouse) {
3714
- this._write("\x1b[1;2'z\x1b[1;3'{")
3715
- } else {
3716
- this._write("\x1b['z")
3717
- }
3718
- }
3719
-
3720
- // pterm mouse
3721
- if (opt.ptermMouse != null) {
3722
- if (opt.ptermMouse) {
3723
- this._write('\x1b[>1h\x1b[>6h\x1b[>7h\x1b[>1h\x1b[>9l')
3724
- } else {
3725
- this._write('\x1b[>1l\x1b[>6l\x1b[>7l\x1b[>1l\x1b[>9h')
3726
- }
3727
- }
3728
-
3729
- // jsbterm mouse
3730
- if (opt.jsbtermMouse != null) {
3731
- // + = advanced mode
3732
- if (opt.jsbtermMouse) {
3733
- this._write('\x1b[0~ZwLMRK+1Q\x1b\\')
3734
- } else {
3735
- this._write('\x1b[0~ZwQ\x1b\\')
3736
- }
3737
- }
3738
-
3739
- // gpm mouse
3740
- if (opt.gpmMouse != null) {
3741
- if (opt.gpmMouse) {
3742
- this.enableGpm()
3743
- } else {
3744
- this.disableGpm()
3745
- }
3746
- }
3747
- }
3748
-
3749
- // CSI Ps ; Ps r
3750
- // Set Scrolling Region [top;bottom] (default = full size of win-
3751
- // dow) (DECSTBM).
3752
- // CSI ? Pm r
3753
- Program.prototype.decstbm =
3754
- Program.prototype.csr =
3755
- Program.prototype.setScrollRegion =
3756
- function (top, bottom) {
3757
- if (!this.zero) {
3758
- top = (top || 1) - 1
3759
- bottom = (bottom || this.rows) - 1
3760
- } else {
3761
- top = top || 0
3762
- bottom = bottom || this.rows - 1
3763
- }
3764
- this.scrollTop = top
3765
- this.scrollBottom = bottom
3766
- this.x = 0
3767
- this.y = 0
3768
- this._ncoords()
3769
- if (this.tput) {
3770
- return this.put.csr(top, bottom)
3771
- }
3772
- return this._write('\x1b[' + (top + 1) + ';' + (bottom + 1) + 'r')
3773
- }
3774
-
3775
- // CSI s
3776
- // Save cursor (ANSI.SYS).
3777
- Program.prototype.scA = Program.prototype.saveCursorA = function () {
3778
- this.savedX = this.x
3779
- this.savedY = this.y
3780
- if (this.tput) {
3781
- return this.put.sc()
3782
- }
3783
- return this._write('\x1b[s')
3784
- }
3785
-
3786
- // CSI u
3787
- // Restore cursor (ANSI.SYS).
3788
- Program.prototype.rcA = Program.prototype.restoreCursorA = function () {
3789
- this.x = this.savedX || 0
3790
- this.y = this.savedY || 0
3791
- if (this.tput) {
3792
- return this.put.rc()
3793
- }
3794
- return this._write('\x1b[u')
3795
- }
3796
-
3797
- /**
3798
- * Lesser Used
3799
- */
3800
-
3801
- // CSI Ps I
3802
- // Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
3803
- Program.prototype.cht = Program.prototype.cursorForwardTab = function (param) {
3804
- this.x += 8
3805
- this._ncoords()
3806
- if (this.tput) {
3807
- return this.put.tab(param)
3808
- }
3809
- return this._write('\x1b[' + (param || 1) + 'I')
3810
- }
3811
-
3812
- // CSI Ps S Scroll up Ps lines (default = 1) (SU).
3813
- Program.prototype.su = Program.prototype.scrollUp = function (param) {
3814
- this.y -= param || 1
3815
- this._ncoords()
3816
- if (this.tput) {
3817
- return this.put.parm_index(param)
3818
- }
3819
- return this._write('\x1b[' + (param || 1) + 'S')
3820
- }
3821
-
3822
- // CSI Ps T Scroll down Ps lines (default = 1) (SD).
3823
- Program.prototype.sd = Program.prototype.scrollDown = function (param) {
3824
- this.y += param || 1
3825
- this._ncoords()
3826
- if (this.tput) {
3827
- return this.put.parm_rindex(param)
3828
- }
3829
- return this._write('\x1b[' + (param || 1) + 'T')
3830
- }
3831
-
3832
- // CSI Ps ; Ps ; Ps ; Ps ; Ps T
3833
- // Initiate highlight mouse tracking. Parameters are
3834
- // [func;startx;starty;firstrow;lastrow]. See the section Mouse
3835
- // Tracking.
3836
- Program.prototype.initMouseTracking = function () {
3837
- return this._write('\x1b[' + slice.call(arguments).join(';') + 'T')
3838
- }
3839
-
3840
- // CSI > Ps; Ps T
3841
- // Reset one or more features of the title modes to the default
3842
- // value. Normally, "reset" disables the feature. It is possi-
3843
- // ble to disable the ability to reset features by compiling a
3844
- // different default for the title modes into xterm.
3845
- // Ps = 0 -> Do not set window/icon labels using hexadecimal.
3846
- // Ps = 1 -> Do not query window/icon labels using hexadeci-
3847
- // mal.
3848
- // Ps = 2 -> Do not set window/icon labels using UTF-8.
3849
- // Ps = 3 -> Do not query window/icon labels using UTF-8.
3850
- // (See discussion of "Title Modes").
3851
- Program.prototype.resetTitleModes = function () {
3852
- return this._write('\x1b[>' + slice.call(arguments).join(';') + 'T')
3853
- }
3854
-
3855
- // CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
3856
- Program.prototype.cbt = Program.prototype.cursorBackwardTab = function (param) {
3857
- this.x -= 8
3858
- this._ncoords()
3859
- if (this.tput) {
3860
- return this.put.cbt(param)
3861
- }
3862
- return this._write('\x1b[' + (param || 1) + 'Z')
3863
- }
3864
-
3865
- // CSI Ps b Repeat the preceding graphic character Ps times (REP).
3866
- Program.prototype.rep = Program.prototype.repeatPrecedingCharacter = function (
3867
- param
3868
- ) {
3869
- this.x += param || 1
3870
- this._ncoords()
3871
- if (this.tput) {
3872
- return this.put.rep(param)
3873
- }
3874
- return this._write('\x1b[' + (param || 1) + 'b')
3875
- }
3876
-
3877
- // CSI Ps g Tab Clear (TBC).
3878
- // Ps = 0 -> Clear Current Column (default).
3879
- // Ps = 3 -> Clear All.
3880
- // Potentially:
3881
- // Ps = 2 -> Clear Stops on Line.
3882
- // http://vt100.net/annarbor/aaa-ug/section6.html
3883
- Program.prototype.tbc = Program.prototype.tabClear = function (param) {
3884
- if (this.tput) {
3885
- return this.put.tbc(param)
3886
- }
3887
- return this._write('\x1b[' + (param || 0) + 'g')
3888
- }
3889
-
3890
- // CSI Pm i Media Copy (MC).
3891
- // Ps = 0 -> Print screen (default).
3892
- // Ps = 4 -> Turn off printer controller mode.
3893
- // Ps = 5 -> Turn on printer controller mode.
3894
- // CSI ? Pm i
3895
- // Media Copy (MC, DEC-specific).
3896
- // Ps = 1 -> Print line containing cursor.
3897
- // Ps = 4 -> Turn off autoprint mode.
3898
- // Ps = 5 -> Turn on autoprint mode.
3899
- // Ps = 1 0 -> Print composed display, ignores DECPEX.
3900
- // Ps = 1 1 -> Print all pages.
3901
- Program.prototype.mc = Program.prototype.mediaCopy = function () {
3902
- return this._write('\x1b[' + slice.call(arguments).join(';') + 'i')
3903
- }
3904
-
3905
- Program.prototype.print_screen =
3906
- Program.prototype.ps =
3907
- Program.prototype.mc0 =
3908
- function () {
3909
- if (this.tput) {
3910
- return this.put.mc0()
3911
- }
3912
- return this.mc('0')
3913
- }
3914
-
3915
- Program.prototype.prtr_on =
3916
- Program.prototype.po =
3917
- Program.prototype.mc5 =
3918
- function () {
3919
- if (this.tput) {
3920
- return this.put.mc5()
3921
- }
3922
- return this.mc('5')
3923
- }
3924
-
3925
- Program.prototype.prtr_off =
3926
- Program.prototype.pf =
3927
- Program.prototype.mc4 =
3928
- function () {
3929
- if (this.tput) {
3930
- return this.put.mc4()
3931
- }
3932
- return this.mc('4')
3933
- }
3934
-
3935
- Program.prototype.prtr_non =
3936
- Program.prototype.pO =
3937
- Program.prototype.mc5p =
3938
- function () {
3939
- if (this.tput) {
3940
- return this.put.mc5p()
3941
- }
3942
- return this.mc('?5')
3943
- }
3944
-
3945
- // CSI > Ps; Ps m
3946
- // Set or reset resource-values used by xterm to decide whether
3947
- // to construct escape sequences holding information about the
3948
- // modifiers pressed with a given key. The first parameter iden-
3949
- // tifies the resource to set/reset. The second parameter is the
3950
- // value to assign to the resource. If the second parameter is
3951
- // omitted, the resource is reset to its initial value.
3952
- // Ps = 1 -> modifyCursorKeys.
3953
- // Ps = 2 -> modifyFunctionKeys.
3954
- // Ps = 4 -> modifyOtherKeys.
3955
- // If no parameters are given, all resources are reset to their
3956
- // initial values.
3957
- Program.prototype.setResources = function () {
3958
- return this._write('\x1b[>' + slice.call(arguments).join(';') + 'm')
3959
- }
3960
-
3961
- // CSI > Ps n
3962
- // Disable modifiers which may be enabled via the CSI > Ps; Ps m
3963
- // sequence. This corresponds to a resource value of "-1", which
3964
- // cannot be set with the other sequence. The parameter identi-
3965
- // fies the resource to be disabled:
3966
- // Ps = 1 -> modifyCursorKeys.
3967
- // Ps = 2 -> modifyFunctionKeys.
3968
- // Ps = 4 -> modifyOtherKeys.
3969
- // If the parameter is omitted, modifyFunctionKeys is disabled.
3970
- // When modifyFunctionKeys is disabled, xterm uses the modifier
3971
- // keys to make an extended sequence of functions rather than
3972
- // adding a parameter to each function key to denote the modi-
3973
- // fiers.
3974
- Program.prototype.disableModifiers = function (param) {
3975
- return this._write('\x1b[>' + (param || '') + 'n')
3976
- }
3977
-
3978
- // CSI > Ps p
3979
- // Set resource value pointerMode. This is used by xterm to
3980
- // decide whether to hide the pointer cursor as the user types.
3981
- // Valid values for the parameter:
3982
- // Ps = 0 -> never hide the pointer.
3983
- // Ps = 1 -> hide if the mouse tracking mode is not enabled.
3984
- // Ps = 2 -> always hide the pointer. If no parameter is
3985
- // given, xterm uses the default, which is 1 .
3986
- Program.prototype.setPointerMode = function (param) {
3987
- return this._write('\x1b[>' + (param || '') + 'p')
3988
- }
3989
-
3990
- // CSI ! p Soft terminal reset (DECSTR).
3991
- // http://vt100.net/docs/vt220-rm/table4-10.html
3992
- Program.prototype.decstr =
3993
- Program.prototype.rs2 =
3994
- Program.prototype.softReset =
3995
- function () {
3996
- //if (this.tput) return this.put.init_2string();
3997
- //if (this.tput) return this.put.reset_2string();
3998
- if (this.tput) {
3999
- return this.put.rs2()
4000
- }
4001
- //return this._write('\x1b[!p');
4002
- //return this._write('\x1b[!p\x1b[?3;4l\x1b[4l\x1b>'); // init
4003
- return this._write('\x1b[!p\x1b[?3;4l\x1b[4l\x1b>') // reset
4004
- }
4005
-
4006
- // CSI Ps$ p
4007
- // Request ANSI mode (DECRQM). For VT300 and up, reply is
4008
- // CSI Ps; Pm$ y
4009
- // where Ps is the mode number as in RM, and Pm is the mode
4010
- // value:
4011
- // 0 - not recognized
4012
- // 1 - set
4013
- // 2 - reset
4014
- // 3 - permanently set
4015
- // 4 - permanently reset
4016
- Program.prototype.decrqm = Program.prototype.requestAnsiMode = function (
4017
- param
4018
- ) {
4019
- return this._write('\x1b[' + (param || '') + '$p')
4020
- }
4021
-
4022
- // CSI ? Ps$ p
4023
- // Request DEC private mode (DECRQM). For VT300 and up, reply is
4024
- // CSI ? Ps; Pm$ p
4025
- // where Ps is the mode number as in DECSET, Pm is the mode value
4026
- // as in the ANSI DECRQM.
4027
- Program.prototype.decrqmp = Program.prototype.requestPrivateMode = function (
4028
- param
4029
- ) {
4030
- return this._write('\x1b[?' + (param || '') + '$p')
4031
- }
4032
-
4033
- // CSI Ps ; Ps " p
4034
- // Set conformance level (DECSCL). Valid values for the first
4035
- // parameter:
4036
- // Ps = 6 1 -> VT100.
4037
- // Ps = 6 2 -> VT200.
4038
- // Ps = 6 3 -> VT300.
4039
- // Valid values for the second parameter:
4040
- // Ps = 0 -> 8-bit controls.
4041
- // Ps = 1 -> 7-bit controls (always set for VT100).
4042
- // Ps = 2 -> 8-bit controls.
4043
- Program.prototype.decscl = Program.prototype.setConformanceLevel = function () {
4044
- return this._write('\x1b[' + slice.call(arguments).join(';') + '"p')
4045
- }
4046
-
4047
- // CSI Ps q Load LEDs (DECLL).
4048
- // Ps = 0 -> Clear all LEDS (default).
4049
- // Ps = 1 -> Light Num Lock.
4050
- // Ps = 2 -> Light Caps Lock.
4051
- // Ps = 3 -> Light Scroll Lock.
4052
- // Ps = 2 1 -> Extinguish Num Lock.
4053
- // Ps = 2 2 -> Extinguish Caps Lock.
4054
- // Ps = 2 3 -> Extinguish Scroll Lock.
4055
- Program.prototype.decll = Program.prototype.loadLEDs = function (param) {
4056
- return this._write('\x1b[' + (param || '') + 'q')
4057
- }
4058
-
4059
- // CSI Ps SP q
4060
- // Set cursor style (DECSCUSR, VT520).
4061
- // Ps = 0 -> blinking block.
4062
- // Ps = 1 -> blinking block (default).
4063
- // Ps = 2 -> steady block.
4064
- // Ps = 3 -> blinking underline.
4065
- // Ps = 4 -> steady underline.
4066
- Program.prototype.decscusr = Program.prototype.setCursorStyle = function (
4067
- param
4068
- ) {
4069
- switch (param) {
4070
- case 'blinking block':
4071
- param = 1
4072
- break
4073
- case 'block':
4074
- case 'steady block':
4075
- param = 2
4076
- break
4077
- case 'blinking underline':
4078
- param = 3
4079
- break
4080
- case 'underline':
4081
- case 'steady underline':
4082
- param = 4
4083
- break
4084
- case 'blinking bar':
4085
- param = 5
4086
- break
4087
- case 'bar':
4088
- case 'steady bar':
4089
- param = 6
4090
- break
4091
- }
4092
- if (param === 2 && this.has('Se')) {
4093
- return this.put.Se()
4094
- }
4095
- if (this.has('Ss')) {
4096
- return this.put.Ss(param)
4097
- }
4098
- return this._write('\x1b[' + (param || 1) + ' q')
4099
- }
4100
-
4101
- // CSI Ps " q
4102
- // Select character protection attribute (DECSCA). Valid values
4103
- // for the parameter:
4104
- // Ps = 0 -> DECSED and DECSEL can erase (default).
4105
- // Ps = 1 -> DECSED and DECSEL cannot erase.
4106
- // Ps = 2 -> DECSED and DECSEL can erase.
4107
- Program.prototype.decsca = Program.prototype.setCharProtectionAttr = function (
4108
- param
4109
- ) {
4110
- return this._write('\x1b[' + (param || 0) + '"q')
4111
- }
4112
-
4113
- // CSI ? Pm r
4114
- // Restore DEC Private Mode Values. The value of Ps previously
4115
- // saved is restored. Ps values are the same as for DECSET.
4116
- Program.prototype.restorePrivateValues = function () {
4117
- return this._write('\x1b[?' + slice.call(arguments).join(';') + 'r')
4118
- }
4119
-
4120
- // CSI Pt; Pl; Pb; Pr; Ps$ r
4121
- // Change Attributes in Rectangular Area (DECCARA), VT400 and up.
4122
- // Pt; Pl; Pb; Pr denotes the rectangle.
4123
- // Ps denotes the SGR attributes to change: 0, 1, 4, 5, 7.
4124
- // NOTE: xterm doesn't enable this code by default.
4125
- Program.prototype.deccara = Program.prototype.setAttrInRectangle = function () {
4126
- return this._write('\x1b[' + slice.call(arguments).join(';') + '$r')
4127
- }
4128
-
4129
- // CSI ? Pm s
4130
- // Save DEC Private Mode Values. Ps values are the same as for
4131
- // DECSET.
4132
- Program.prototype.savePrivateValues = function () {
4133
- return this._write('\x1b[?' + slice.call(arguments).join(';') + 's')
4134
- }
4135
-
4136
- // CSI Ps ; Ps ; Ps t
4137
- // Window manipulation (from dtterm, as well as extensions).
4138
- // These controls may be disabled using the allowWindowOps
4139
- // resource. Valid values for the first (and any additional
4140
- // parameters) are:
4141
- // Ps = 1 -> De-iconify window.
4142
- // Ps = 2 -> Iconify window.
4143
- // Ps = 3 ; x ; y -> Move window to [x, y].
4144
- // Ps = 4 ; height ; width -> Resize the xterm window to
4145
- // height and width in pixels.
4146
- // Ps = 5 -> Raise the xterm window to the front of the stack-
4147
- // ing order.
4148
- // Ps = 6 -> Lower the xterm window to the bottom of the
4149
- // stacking order.
4150
- // Ps = 7 -> Refresh the xterm window.
4151
- // Ps = 8 ; height ; width -> Resize the text area to
4152
- // [height;width] in characters.
4153
- // Ps = 9 ; 0 -> Restore maximized window.
4154
- // Ps = 9 ; 1 -> Maximize window (i.e., resize to screen
4155
- // size).
4156
- // Ps = 1 0 ; 0 -> Undo full-screen mode.
4157
- // Ps = 1 0 ; 1 -> Change to full-screen.
4158
- // Ps = 1 1 -> Report xterm window state. If the xterm window
4159
- // is open (non-iconified), it returns CSI 1 t . If the xterm
4160
- // window is iconified, it returns CSI 2 t .
4161
- // Ps = 1 3 -> Report xterm window position. Result is CSI 3
4162
- // ; x ; y t
4163
- // Ps = 1 4 -> Report xterm window in pixels. Result is CSI
4164
- // 4 ; height ; width t
4165
- // Ps = 1 8 -> Report the size of the text area in characters.
4166
- // Result is CSI 8 ; height ; width t
4167
- // Ps = 1 9 -> Report the size of the screen in characters.
4168
- // Result is CSI 9 ; height ; width t
4169
- // Ps = 2 0 -> Report xterm window's icon label. Result is
4170
- // OSC L label ST
4171
- // Ps = 2 1 -> Report xterm window's title. Result is OSC l
4172
- // label ST
4173
- // Ps = 2 2 ; 0 -> Save xterm icon and window title on
4174
- // stack.
4175
- // Ps = 2 2 ; 1 -> Save xterm icon title on stack.
4176
- // Ps = 2 2 ; 2 -> Save xterm window title on stack.
4177
- // Ps = 2 3 ; 0 -> Restore xterm icon and window title from
4178
- // stack.
4179
- // Ps = 2 3 ; 1 -> Restore xterm icon title from stack.
4180
- // Ps = 2 3 ; 2 -> Restore xterm window title from stack.
4181
- // Ps >= 2 4 -> Resize to Ps lines (DECSLPP).
4182
- Program.prototype.manipulateWindow = function () {
4183
- const args = slice.call(arguments)
4184
-
4185
- const callback =
4186
- typeof args[args.length - 1] === 'function' ? args.pop() : function () {}
4187
-
4188
- return this.response(
4189
- 'window-manipulation',
4190
- '\x1b[' + args.join(';') + 't',
4191
- callback
4192
- )
4193
- }
4194
-
4195
- Program.prototype.getWindowSize = function (callback) {
4196
- return this.manipulateWindow(18, callback)
4197
- }
4198
-
4199
- // CSI Pt; Pl; Pb; Pr; Ps$ t
4200
- // Reverse Attributes in Rectangular Area (DECRARA), VT400 and
4201
- // up.
4202
- // Pt; Pl; Pb; Pr denotes the rectangle.
4203
- // Ps denotes the attributes to reverse, i.e., 1, 4, 5, 7.
4204
- // NOTE: xterm doesn't enable this code by default.
4205
- Program.prototype.decrara = Program.prototype.reverseAttrInRectangle =
4206
- function () {
4207
- return this._write('\x1b[' + slice.call(arguments).join(';') + '$t')
4208
- }
4209
-
4210
- // CSI > Ps; Ps t
4211
- // Set one or more features of the title modes. Each parameter
4212
- // enables a single feature.
4213
- // Ps = 0 -> Set window/icon labels using hexadecimal.
4214
- // Ps = 1 -> Query window/icon labels using hexadecimal.
4215
- // Ps = 2 -> Set window/icon labels using UTF-8.
4216
- // Ps = 3 -> Query window/icon labels using UTF-8. (See dis-
4217
- // cussion of "Title Modes")
4218
- // XXX VTE bizarelly echos this:
4219
- Program.prototype.setTitleModeFeature = function () {
4220
- return this._twrite('\x1b[>' + slice.call(arguments).join(';') + 't')
4221
- }
4222
-
4223
- // CSI Ps SP t
4224
- // Set warning-bell volume (DECSWBV, VT520).
4225
- // Ps = 0 or 1 -> off.
4226
- // Ps = 2 , 3 or 4 -> low.
4227
- // Ps = 5 , 6 , 7 , or 8 -> high.
4228
- Program.prototype.decswbv = Program.prototype.setWarningBellVolume = function (
4229
- param
4230
- ) {
4231
- return this._write('\x1b[' + (param || '') + ' t')
4232
- }
4233
-
4234
- // CSI Ps SP u
4235
- // Set margin-bell volume (DECSMBV, VT520).
4236
- // Ps = 1 -> off.
4237
- // Ps = 2 , 3 or 4 -> low.
4238
- // Ps = 0 , 5 , 6 , 7 , or 8 -> high.
4239
- Program.prototype.decsmbv = Program.prototype.setMarginBellVolume = function (
4240
- param
4241
- ) {
4242
- return this._write('\x1b[' + (param || '') + ' u')
4243
- }
4244
-
4245
- // CSI Pt; Pl; Pb; Pr; Pp; Pt; Pl; Pp$ v
4246
- // Copy Rectangular Area (DECCRA, VT400 and up).
4247
- // Pt; Pl; Pb; Pr denotes the rectangle.
4248
- // Pp denotes the source page.
4249
- // Pt; Pl denotes the target location.
4250
- // Pp denotes the target page.
4251
- // NOTE: xterm doesn't enable this code by default.
4252
- Program.prototype.deccra = Program.prototype.copyRectangle = function () {
4253
- return this._write('\x1b[' + slice.call(arguments).join(';') + '$v')
4254
- }
4255
-
4256
- // CSI Pt ; Pl ; Pb ; Pr ' w
4257
- // Enable Filter Rectangle (DECEFR), VT420 and up.
4258
- // Parameters are [top;left;bottom;right].
4259
- // Defines the coordinates of a filter rectangle and activates
4260
- // it. Anytime the locator is detected outside of the filter
4261
- // rectangle, an outside rectangle event is generated and the
4262
- // rectangle is disabled. Filter rectangles are always treated
4263
- // as "one-shot" events. Any parameters that are omitted default
4264
- // to the current locator position. If all parameters are omit-
4265
- // ted, any locator motion will be reported. DECELR always can-
4266
- // cels any prevous rectangle definition.
4267
- Program.prototype.decefr = Program.prototype.enableFilterRectangle =
4268
- function () {
4269
- return this._write('\x1b[' + slice.call(arguments).join(';') + "'w")
4270
- }
4271
-
4272
- // CSI Ps x Request Terminal Parameters (DECREQTPARM).
4273
- // if Ps is a "0" (default) or "1", and xterm is emulating VT100,
4274
- // the control sequence elicits a response of the same form whose
4275
- // parameters describe the terminal:
4276
- // Ps -> the given Ps incremented by 2.
4277
- // Pn = 1 <- no parity.
4278
- // Pn = 1 <- eight bits.
4279
- // Pn = 1 <- 2 8 transmit 38.4k baud.
4280
- // Pn = 1 <- 2 8 receive 38.4k baud.
4281
- // Pn = 1 <- clock multiplier.
4282
- // Pn = 0 <- STP flags.
4283
- Program.prototype.decreqtparm = Program.prototype.requestParameters = function (
4284
- param
4285
- ) {
4286
- return this._write('\x1b[' + (param || 0) + 'x')
4287
- }
4288
-
4289
- // CSI Ps x Select Attribute Change Extent (DECSACE).
4290
- // Ps = 0 -> from start to end position, wrapped.
4291
- // Ps = 1 -> from start to end position, wrapped.
4292
- // Ps = 2 -> rectangle (exact).
4293
- Program.prototype.decsace = Program.prototype.selectChangeExtent = function (
4294
- param
4295
- ) {
4296
- return this._write('\x1b[' + (param || 0) + 'x')
4297
- }
4298
-
4299
- // CSI Pc; Pt; Pl; Pb; Pr$ x
4300
- // Fill Rectangular Area (DECFRA), VT420 and up.
4301
- // Pc is the character to use.
4302
- // Pt; Pl; Pb; Pr denotes the rectangle.
4303
- // NOTE: xterm doesn't enable this code by default.
4304
- Program.prototype.decfra = Program.prototype.fillRectangle = function () {
4305
- return this._write('\x1b[' + slice.call(arguments).join(';') + '$x')
4306
- }
4307
-
4308
- // CSI Ps ; Pu ' z
4309
- // Enable Locator Reporting (DECELR).
4310
- // Valid values for the first parameter:
4311
- // Ps = 0 -> Locator disabled (default).
4312
- // Ps = 1 -> Locator enabled.
4313
- // Ps = 2 -> Locator enabled for one report, then disabled.
4314
- // The second parameter specifies the coordinate unit for locator
4315
- // reports.
4316
- // Valid values for the second parameter:
4317
- // Pu = 0 <- or omitted -> default to character cells.
4318
- // Pu = 1 <- device physical pixels.
4319
- // Pu = 2 <- character cells.
4320
- Program.prototype.decelr = Program.prototype.enableLocatorReporting =
4321
- function () {
4322
- return this._write('\x1b[' + slice.call(arguments).join(';') + "'z")
4323
- }
4324
-
4325
- // CSI Pt; Pl; Pb; Pr$ z
4326
- // Erase Rectangular Area (DECERA), VT400 and up.
4327
- // Pt; Pl; Pb; Pr denotes the rectangle.
4328
- // NOTE: xterm doesn't enable this code by default.
4329
- Program.prototype.decera = Program.prototype.eraseRectangle = function () {
4330
- return this._write('\x1b[' + slice.call(arguments).join(';') + '$z')
4331
- }
4332
-
4333
- // CSI Pm ' {
4334
- // Select Locator Events (DECSLE).
4335
- // Valid values for the first (and any additional parameters)
4336
- // are:
4337
- // Ps = 0 -> only respond to explicit host requests (DECRQLP).
4338
- // (This is default). It also cancels any filter
4339
- // rectangle.
4340
- // Ps = 1 -> report button down transitions.
4341
- // Ps = 2 -> do not report button down transitions.
4342
- // Ps = 3 -> report button up transitions.
4343
- // Ps = 4 -> do not report button up transitions.
4344
- Program.prototype.decsle = Program.prototype.setLocatorEvents = function () {
4345
- return this._write('\x1b[' + slice.call(arguments).join(';') + "'{")
4346
- }
4347
-
4348
- // CSI Pt; Pl; Pb; Pr$ {
4349
- // Selective Erase Rectangular Area (DECSERA), VT400 and up.
4350
- // Pt; Pl; Pb; Pr denotes the rectangle.
4351
- Program.prototype.decsera = Program.prototype.selectiveEraseRectangle =
4352
- function () {
4353
- return this._write('\x1b[' + slice.call(arguments).join(';') + '${')
4354
- }
4355
-
4356
- // CSI Ps ' |
4357
- // Request Locator Position (DECRQLP).
4358
- // Valid values for the parameter are:
4359
- // Ps = 0 , 1 or omitted -> transmit a single DECLRP locator
4360
- // report.
4361
-
4362
- // If Locator Reporting has been enabled by a DECELR, xterm will
4363
- // respond with a DECLRP Locator Report. This report is also
4364
- // generated on button up and down events if they have been
4365
- // enabled with a DECSLE, or when the locator is detected outside
4366
- // of a filter rectangle, if filter rectangles have been enabled
4367
- // with a DECEFR.
4368
-
4369
- // -> CSI Pe ; Pb ; Pr ; Pc ; Pp & w
4370
-
4371
- // Parameters are [event;button;row;column;page].
4372
- // Valid values for the event:
4373
- // Pe = 0 -> locator unavailable - no other parameters sent.
4374
- // Pe = 1 -> request - xterm received a DECRQLP.
4375
- // Pe = 2 -> left button down.
4376
- // Pe = 3 -> left button up.
4377
- // Pe = 4 -> middle button down.
4378
- // Pe = 5 -> middle button up.
4379
- // Pe = 6 -> right button down.
4380
- // Pe = 7 -> right button up.
4381
- // Pe = 8 -> M4 button down.
4382
- // Pe = 9 -> M4 button up.
4383
- // Pe = 1 0 -> locator outside filter rectangle.
4384
- // ``button'' parameter is a bitmask indicating which buttons are
4385
- // pressed:
4386
- // Pb = 0 <- no buttons down.
4387
- // Pb & 1 <- right button down.
4388
- // Pb & 2 <- middle button down.
4389
- // Pb & 4 <- left button down.
4390
- // Pb & 8 <- M4 button down.
4391
- // ``row'' and ``column'' parameters are the coordinates of the
4392
- // locator position in the xterm window, encoded as ASCII deci-
4393
- // mal.
4394
- // The ``page'' parameter is not used by xterm, and will be omit-
4395
- // ted.
4396
- Program.prototype.decrqlp =
4397
- Program.prototype.req_mouse_pos =
4398
- Program.prototype.reqmp =
4399
- Program.prototype.requestLocatorPosition =
4400
- function (param, callback) {
4401
- // See also:
4402
- // get_mouse / getm / Gm
4403
- // mouse_info / minfo / Mi
4404
- // Correct for tput?
4405
- if (this.has('req_mouse_pos')) {
4406
- const code = this.tput.req_mouse_pos(param)
4407
- return this.response('locator-position', code, callback)
4408
- }
4409
- return this.response(
4410
- 'locator-position',
4411
- '\x1b[' + (param || '') + "'|",
4412
- callback
4413
- )
4414
- }
4415
-
4416
- // CSI P m SP }
4417
- // Insert P s Column(s) (default = 1) (DECIC), VT420 and up.
4418
- // NOTE: xterm doesn't enable this code by default.
4419
- Program.prototype.decic = Program.prototype.insertColumns = function () {
4420
- return this._write('\x1b[' + slice.call(arguments).join(';') + ' }')
4421
- }
4422
-
4423
- // CSI P m SP ~
4424
- // Delete P s Column(s) (default = 1) (DECDC), VT420 and up
4425
- // NOTE: xterm doesn't enable this code by default.
4426
- Program.prototype.decdc = Program.prototype.deleteColumns = function () {
4427
- return this._write('\x1b[' + slice.call(arguments).join(';') + ' ~')
4428
- }
4429
-
4430
- Program.prototype.out = function (name) {
4431
- const args = Array.prototype.slice.call(arguments, 1)
4432
- this.ret = true
4433
- const out = this[name].apply(this, args)
4434
- this.ret = false
4435
- return out
4436
- }
4437
-
4438
- Program.prototype.sigtstp = function (callback) {
4439
- const resume = this.pause()
4440
-
4441
- process.once('SIGCONT', function () {
4442
- resume()
4443
- if (callback) {
4444
- callback()
4445
- }
4446
- })
4447
-
4448
- process.kill(process.pid, 'SIGTSTP')
4449
- }
4450
-
4451
- Program.prototype.pause = function (callback) {
4452
- const self = this,
4453
- isAlt = this.isAlt,
4454
- mouseEnabled = this.mouseEnabled
4455
-
4456
- this.lsaveCursor('pause')
4457
- //this.csr(0, screen.height - 1);
4458
- if (isAlt) {
4459
- this.normalBuffer()
4460
- }
4461
- this.showCursor()
4462
- if (mouseEnabled) {
4463
- this.disableMouse()
4464
- }
4465
-
4466
- const write = this.output.write
4467
- this.output.write = function () {}
4468
- if (this.input.setRawMode) {
4469
- this.input.setRawMode(false)
4470
- }
4471
- this.input.pause()
4472
-
4473
- return (this._resume = function () {
4474
- delete self._resume
4475
-
4476
- if (self.input.setRawMode) {
4477
- self.input.setRawMode(true)
4478
- }
4479
- self.input.resume()
4480
- self.output.write = write
4481
-
4482
- if (isAlt) {
4483
- self.alternateBuffer()
4484
- }
4485
- //self.csr(0, screen.height - 1);
4486
- if (mouseEnabled) {
4487
- self.enableMouse()
4488
- }
4489
- self.lrestoreCursor('pause', true)
4490
-
4491
- if (callback) {
4492
- callback()
4493
- }
4494
- })
4495
- }
4496
-
4497
- Program.prototype.resume = function () {
4498
- if (this._resume) {
4499
- return this._resume()
4500
- }
4501
- }
4502
-
4503
- /**
4504
- * Helpers
4505
- */
4506
-
4507
- // We could do this easier by just manipulating the _events object, or for
4508
- // older versions of node, manipulating the array returned by listeners(), but
4509
- // neither of these methods are guaranteed to work in future versions of node.
4510
- function unshiftEvent(obj, event, listener) {
4511
- const listeners = obj.listeners(event)
4512
- obj.removeAllListeners(event)
4513
- obj.on(event, listener)
4514
- listeners.forEach(function (listener) {
4515
- obj.on(event, listener)
4516
- })
4517
- }
4518
-
4519
- function merge(out) {
4520
- slice.call(arguments, 1).forEach(function (obj) {
4521
- Object.keys(obj).forEach(function (key) {
4522
- out[key] = obj[key]
4523
- })
4524
- })
4525
- return out
4526
- }
4527
-
4528
- /**
4529
- * Expose
4530
- */
4531
-
4532
- module.exports = Program