@socketsecurity/cli-with-sentry 0.14.94 → 0.14.96

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 +178 -159
  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 +160 -140
  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,3113 +0,0 @@
1
- 'use strict'
2
-
3
- /**
4
- * tput.js - parse and compile terminfo caps to javascript.
5
- * Copyright (c) 2013-2015, Christopher Jeffrey and contributors (MIT License).
6
- * https://github.com/chjj/blessed
7
- */
8
-
9
- // Resources:
10
- // $ man term
11
- // $ man terminfo
12
- // http://invisible-island.net/ncurses/man/term.5.html
13
- // https://en.wikipedia.org/wiki/Terminfo
14
-
15
- // Todo:
16
- // - xterm's XT (set-title capability?) value should
17
- // be true (at least tmux thinks it should).
18
- // It's not parsed as true. Investigate.
19
- // - Possibly switch to other method of finding the
20
- // extended data string table: i += h.symOffsetCount * 2;
21
-
22
- /**
23
- * Modules
24
- */
25
-
26
- const assert = require('node:assert'),
27
- path = require('node:path'),
28
- fs = require('node:fs'),
29
- cp = require('node:child_process')
30
-
31
- /**
32
- * Tput
33
- */
34
-
35
- function Tput(options) {
36
- if (!(this instanceof Tput)) {
37
- return new Tput(options)
38
- }
39
-
40
- options = options || {}
41
- if (typeof options === 'string') {
42
- options = { terminal: options }
43
- }
44
-
45
- this.options = options
46
- this.terminal =
47
- options.terminal ||
48
- options.term ||
49
- process.env.TERM ||
50
- (process.platform === 'win32' ? 'windows-ansi' : 'xterm')
51
-
52
- this.terminal = this.terminal.toLowerCase()
53
-
54
- this.debug = options.debug
55
- this.padding = options.padding
56
- this.extended = options.extended
57
- this.printf = options.printf
58
- this.termcap = options.termcap
59
- this.error = null
60
-
61
- this.terminfoPrefix = options.terminfoPrefix
62
- this.terminfoFile = options.terminfoFile
63
- this.termcapFile = options.termcapFile
64
-
65
- if (options.terminal || options.term) {
66
- this.setup()
67
- }
68
- }
69
-
70
- Tput.prototype.setup = function () {
71
- this.error = null
72
- try {
73
- if (this.termcap) {
74
- try {
75
- this.injectTermcap()
76
- } catch (e) {
77
- if (this.debug) {
78
- throw e
79
- }
80
- this.error = new Error('Termcap parse error.')
81
- this._useInternalCap(this.terminal)
82
- }
83
- } else {
84
- try {
85
- this.injectTerminfo()
86
- } catch (e) {
87
- if (this.debug) {
88
- throw e
89
- }
90
- this.error = new Error('Terminfo parse error.')
91
- this._useInternalInfo(this.terminal)
92
- }
93
- }
94
- } catch (e) {
95
- // If there was an error, fallback
96
- // to an internally stored terminfo/cap.
97
- if (this.debug) {
98
- throw e
99
- }
100
- this.error = new Error('Terminfo not found.')
101
- this._useXtermInfo()
102
- }
103
- }
104
-
105
- Tput.prototype.term = function (is) {
106
- return this.terminal.indexOf(is) === 0
107
- }
108
-
109
- Tput.prototype._debug = function () {
110
- if (!this.debug) {
111
- return
112
- }
113
- return console.log.apply(console, arguments)
114
- }
115
-
116
- /**
117
- * Fallback
118
- */
119
-
120
- Tput.prototype._useVt102Cap = function () {
121
- return this.injectTermcap('vt102')
122
- }
123
-
124
- Tput.prototype._useXtermCap = function () {
125
- return this.injectTermcap(__dirname + '/../usr/xterm.termcap')
126
- }
127
-
128
- Tput.prototype._useXtermInfo = function () {
129
- return this.injectTerminfo(__dirname + '/../usr/xterm')
130
- }
131
-
132
- Tput.prototype._useInternalInfo = function (name) {
133
- name = path.basename(name)
134
- return this.injectTerminfo(__dirname + '/../usr/' + name)
135
- }
136
-
137
- Tput.prototype._useInternalCap = function (name) {
138
- name = path.basename(name)
139
- return this.injectTermcap(__dirname + '/../usr/' + name + '.termcap')
140
- }
141
-
142
- /**
143
- * Terminfo
144
- */
145
-
146
- Tput.ipaths = [
147
- process.env.TERMINFO || '',
148
- (process.env.TERMINFO_DIRS || '').split(':'),
149
- (process.env.HOME || '') + '/.terminfo',
150
- '/usr/share/terminfo',
151
- '/usr/share/lib/terminfo',
152
- '/usr/lib/terminfo',
153
- '/usr/local/share/terminfo',
154
- '/usr/local/share/lib/terminfo',
155
- '/usr/local/lib/terminfo',
156
- '/usr/local/ncurses/lib/terminfo',
157
- '/lib/terminfo'
158
- ]
159
-
160
- Tput.prototype.readTerminfo = function (term) {
161
- let data, file, info
162
-
163
- term = term || this.terminal
164
-
165
- file = path.normalize(this._prefix(term))
166
- data = fs.readFileSync(file)
167
- info = this.parseTerminfo(data, file)
168
-
169
- if (this.debug) {
170
- this._terminfo = info
171
- }
172
-
173
- return info
174
- }
175
-
176
- Tput._prefix = Tput.prototype._prefix = function (term) {
177
- // If we have a terminfoFile, or our
178
- // term looks like a filename, use it.
179
- if (term) {
180
- if (~term.indexOf(path.sep)) {
181
- return term
182
- }
183
- if (this.terminfoFile) {
184
- return this.terminfoFile
185
- }
186
- }
187
-
188
- let paths = Tput.ipaths.slice(),
189
- file
190
-
191
- if (this.terminfoPrefix) {
192
- paths.unshift(this.terminfoPrefix)
193
- }
194
-
195
- // Try exact matches.
196
- file = this._tprefix(paths, term)
197
- if (file) {
198
- return file
199
- }
200
-
201
- // Try similar matches.
202
- file = this._tprefix(paths, term, true)
203
- if (file) {
204
- return file
205
- }
206
-
207
- // Not found.
208
- throw new Error('Terminfo directory not found.')
209
- }
210
-
211
- Tput._tprefix = Tput.prototype._tprefix = function (prefix, term, soft) {
212
- if (!prefix) {
213
- return
214
- }
215
-
216
- let file, dir, i, sdiff, sfile, list
217
-
218
- if (Array.isArray(prefix)) {
219
- for (i = 0; i < prefix.length; i++) {
220
- file = this._tprefix(prefix[i], term, soft)
221
- if (file) {
222
- return file
223
- }
224
- }
225
- return
226
- }
227
-
228
- const find = function (word) {
229
- let file, ch
230
-
231
- file = path.resolve(prefix, word[0])
232
- try {
233
- fs.statSync(file)
234
- return file
235
- } catch (e) {}
236
-
237
- ch = word[0].charCodeAt(0).toString(16)
238
- if (ch.length < 2) {
239
- ch = '0' + ch
240
- }
241
-
242
- file = path.resolve(prefix, ch)
243
- try {
244
- fs.statSync(file)
245
- return file
246
- } catch (e) {}
247
- }
248
-
249
- if (!term) {
250
- // Make sure the directory's sub-directories
251
- // are all one-letter, or hex digits.
252
- // return find('x') ? prefix : null;
253
- try {
254
- dir = fs.readdirSync(prefix).filter(function (file) {
255
- return file.length !== 1 && !/^[0-9a-fA-F]{2}$/.test(file)
256
- })
257
- if (!dir.length) {
258
- return prefix
259
- }
260
- } catch (e) {}
261
- return
262
- }
263
-
264
- term = path.basename(term)
265
- dir = find(term)
266
-
267
- if (!dir) {
268
- return
269
- }
270
-
271
- if (soft) {
272
- try {
273
- list = fs.readdirSync(dir)
274
- } catch (e) {
275
- return
276
- }
277
-
278
- list.forEach(function (file) {
279
- if (file.indexOf(term) === 0) {
280
- const diff = file.length - term.length
281
- if (!sfile || diff < sdiff) {
282
- sdiff = diff
283
- sfile = file
284
- }
285
- }
286
- })
287
-
288
- return sfile && (soft || sdiff === 0) ? path.resolve(dir, sfile) : null
289
- }
290
-
291
- file = path.resolve(dir, term)
292
- try {
293
- fs.statSync(file)
294
- return file
295
- } catch (e) {}
296
- }
297
-
298
- /**
299
- * Terminfo Parser
300
- * All shorts are little-endian
301
- */
302
-
303
- Tput.prototype.parseTerminfo = function (data, file) {
304
- let info = {},
305
- extended,
306
- l = data.length,
307
- i = 0,
308
- v,
309
- o
310
-
311
- const h = (info.header = {
312
- dataSize: data.length,
313
- headerSize: 12,
314
- magicNumber: (data[1] << 8) | data[0],
315
- namesSize: (data[3] << 8) | data[2],
316
- boolCount: (data[5] << 8) | data[4],
317
- numCount: (data[7] << 8) | data[6],
318
- strCount: (data[9] << 8) | data[8],
319
- strTableSize: (data[11] << 8) | data[10]
320
- })
321
-
322
- h.total =
323
- h.headerSize +
324
- h.namesSize +
325
- h.boolCount +
326
- h.numCount * 2 +
327
- h.strCount * 2 +
328
- h.strTableSize
329
-
330
- i += h.headerSize
331
-
332
- // Names Section
333
- const names = data.toString('ascii', i, i + h.namesSize - 1),
334
- parts = names.split('|'),
335
- name = parts[0],
336
- desc = parts.pop()
337
-
338
- info.name = name
339
- info.names = parts
340
- info.desc = desc
341
-
342
- info.dir = path.resolve(file, '..', '..')
343
- info.file = file
344
-
345
- i += h.namesSize - 1
346
-
347
- // Names is nul-terminated.
348
- assert.equal(data[i], 0)
349
- i++
350
-
351
- // Booleans Section
352
- // One byte for each flag
353
- // Same order as <term.h>
354
- info.bools = {}
355
- l = i + h.boolCount
356
- o = 0
357
- for (; i < l; i++) {
358
- v = Tput.bools[o++]
359
- info.bools[v] = data[i] === 1
360
- }
361
-
362
- // Null byte in between to make sure numbers begin on an even byte.
363
- if (i % 2) {
364
- assert.equal(data[i], 0)
365
- i++
366
- }
367
-
368
- // Numbers Section
369
- info.numbers = {}
370
- l = i + h.numCount * 2
371
- o = 0
372
- for (; i < l; i += 2) {
373
- v = Tput.numbers[o++]
374
- if (data[i + 1] === 0xff && data[i] === 0xff) {
375
- info.numbers[v] = -1
376
- } else {
377
- info.numbers[v] = (data[i + 1] << 8) | data[i]
378
- }
379
- }
380
-
381
- // Strings Section
382
- info.strings = {}
383
- l = i + h.strCount * 2
384
- o = 0
385
- for (; i < l; i += 2) {
386
- v = Tput.strings[o++]
387
- if (data[i + 1] === 0xff && data[i] === 0xff) {
388
- info.strings[v] = -1
389
- } else {
390
- info.strings[v] = (data[i + 1] << 8) | data[i]
391
- }
392
- }
393
-
394
- // String Table
395
- Object.keys(info.strings).forEach(function (key) {
396
- if (info.strings[key] === -1) {
397
- delete info.strings[key]
398
- return
399
- }
400
-
401
- // Workaround: fix an odd bug in the screen-256color terminfo where it tries
402
- // to set -1, but it appears to have {0xfe, 0xff} instead of {0xff, 0xff}.
403
- // TODO: Possibly handle errors gracefully below, as well as in the
404
- // extended info. Also possibly do: `if (info.strings[key] >= data.length)`.
405
- if (info.strings[key] === 65534) {
406
- delete info.strings[key]
407
- return
408
- }
409
-
410
- let s = i + info.strings[key],
411
- j = s
412
-
413
- while (data[j]) {
414
- j++
415
- }
416
-
417
- assert(j < data.length)
418
-
419
- info.strings[key] = data.toString('ascii', s, j)
420
- })
421
-
422
- // Extended Header
423
- if (this.extended !== false) {
424
- i--
425
- i += h.strTableSize
426
- if (i % 2) {
427
- assert.equal(data[i], 0)
428
- i++
429
- }
430
- l = data.length
431
- if (i < l - 1) {
432
- try {
433
- extended = this.parseExtended(data.slice(i))
434
- } catch (e) {
435
- if (this.debug) {
436
- throw e
437
- }
438
- return info
439
- }
440
- info.header.extended = extended.header
441
- ;['bools', 'numbers', 'strings'].forEach(function (key) {
442
- merge(info[key], extended[key])
443
- })
444
- }
445
- }
446
-
447
- return info
448
- }
449
-
450
- /**
451
- * Extended Parsing
452
- */
453
-
454
- // Some data to help understand:
455
-
456
- // For xterm, non-extended header:
457
- // { dataSize: 3270,
458
- // headerSize: 12,
459
- // magicNumber: 282,
460
- // namesSize: 48,
461
- // boolCount: 38,
462
- // numCount: 15,
463
- // strCount: 413,
464
- // strTableSize: 1388,
465
- // total: 2342 }
466
-
467
- // For xterm, header:
468
- // Offset: 2342
469
- // { header:
470
- // { dataSize: 928,
471
- // headerSize: 10,
472
- // boolCount: 2,
473
- // numCount: 1,
474
- // strCount: 57,
475
- // strTableSize: 117,
476
- // lastStrTableOffset: 680,
477
- // total: 245 },
478
-
479
- // For xterm, layout:
480
- // { header: '0 - 10', // length: 10
481
- // bools: '10 - 12', // length: 2
482
- // numbers: '12 - 14', // length: 2
483
- // strings: '14 - 128', // length: 114 (57 short)
484
- // symoffsets: '128 - 248', // length: 120 (60 short)
485
- // stringtable: '248 - 612', // length: 364
486
- // sym: '612 - 928' } // length: 316
487
- //
488
- // How lastStrTableOffset works:
489
- // data.length - h.lastStrTableOffset === 248
490
- // (sym-offset end, string-table start)
491
- // 364 + 316 === 680 (lastStrTableOffset)
492
- // How strTableSize works:
493
- // h.strCount + [symOffsetCount] === h.strTableSize
494
- // 57 + 60 === 117 (strTableSize)
495
- // symOffsetCount doesn't actually exist in the header. it's just implied.
496
- // Getting the number of sym offsets:
497
- // h.symOffsetCount = h.strTableSize - h.strCount;
498
- // h.symOffsetSize = (h.strTableSize - h.strCount) * 2;
499
-
500
- Tput.prototype.parseExtended = function (data) {
501
- let info = {},
502
- l = data.length,
503
- i = 0
504
-
505
- const h = (info.header = {
506
- dataSize: data.length,
507
- headerSize: 10,
508
- boolCount: (data[i + 1] << 8) | data[i + 0],
509
- numCount: (data[i + 3] << 8) | data[i + 2],
510
- strCount: (data[i + 5] << 8) | data[i + 4],
511
- strTableSize: (data[i + 7] << 8) | data[i + 6],
512
- lastStrTableOffset: (data[i + 9] << 8) | data[i + 8]
513
- })
514
-
515
- // h.symOffsetCount = h.strTableSize - h.strCount;
516
-
517
- h.total =
518
- h.headerSize +
519
- h.boolCount +
520
- h.numCount * 2 +
521
- h.strCount * 2 +
522
- h.strTableSize
523
-
524
- i += h.headerSize
525
-
526
- // Booleans Section
527
- // One byte for each flag
528
- const _bools = []
529
- l = i + h.boolCount
530
- for (; i < l; i++) {
531
- _bools.push(data[i] === 1)
532
- }
533
-
534
- // Null byte in between to make sure numbers begin on an even byte.
535
- if (i % 2) {
536
- assert.equal(data[i], 0)
537
- i++
538
- }
539
-
540
- // Numbers Section
541
- const _numbers = []
542
- l = i + h.numCount * 2
543
- for (; i < l; i += 2) {
544
- if (data[i + 1] === 0xff && data[i] === 0xff) {
545
- _numbers.push(-1)
546
- } else {
547
- _numbers.push((data[i + 1] << 8) | data[i])
548
- }
549
- }
550
-
551
- // Strings Section
552
- const _strings = []
553
- l = i + h.strCount * 2
554
- for (; i < l; i += 2) {
555
- if (data[i + 1] === 0xff && data[i] === 0xff) {
556
- _strings.push(-1)
557
- } else {
558
- _strings.push((data[i + 1] << 8) | data[i])
559
- }
560
- }
561
-
562
- // Pass over the sym offsets and get to the string table.
563
- i = data.length - h.lastStrTableOffset
564
- // Might be better to do this instead if the file has trailing bytes:
565
- // i += h.symOffsetCount * 2;
566
-
567
- // String Table
568
- let high = 0
569
- _strings.forEach(function (offset, k) {
570
- if (offset === -1) {
571
- _strings[k] = ''
572
- return
573
- }
574
-
575
- let s = i + offset,
576
- j = s
577
-
578
- while (data[j]) {
579
- j++
580
- }
581
-
582
- assert(j < data.length)
583
-
584
- // Find out where the string table ends by
585
- // getting the highest string length.
586
- if (high < j - i) {
587
- high = j - i
588
- }
589
-
590
- _strings[k] = data.toString('ascii', s, j)
591
- })
592
-
593
- // Symbol Table
594
- // Add one to the highest string length because we didn't count \0.
595
- i += high + 1
596
- l = data.length
597
-
598
- let sym = [],
599
- j
600
-
601
- for (; i < l; i++) {
602
- j = i
603
- while (data[j]) {
604
- j++
605
- }
606
- sym.push(data.toString('ascii', i, j))
607
- i = j
608
- }
609
-
610
- // Identify by name
611
- j = 0
612
-
613
- info.bools = {}
614
- _bools.forEach(function (bool) {
615
- info.bools[sym[j++]] = bool
616
- })
617
-
618
- info.numbers = {}
619
- _numbers.forEach(function (number) {
620
- info.numbers[sym[j++]] = number
621
- })
622
-
623
- info.strings = {}
624
- _strings.forEach(function (string) {
625
- info.strings[sym[j++]] = string
626
- })
627
-
628
- // Should be the very last bit of data.
629
- assert.equal(i, data.length)
630
-
631
- return info
632
- }
633
-
634
- Tput.prototype.compileTerminfo = function (term) {
635
- return this.compile(this.readTerminfo(term))
636
- }
637
-
638
- Tput.prototype.injectTerminfo = function (term) {
639
- return this.inject(this.compileTerminfo(term))
640
- }
641
-
642
- /**
643
- * Compiler - terminfo cap->javascript
644
- */
645
-
646
- Tput.prototype.compile = function (info) {
647
- const self = this
648
-
649
- if (!info) {
650
- throw new Error('Terminal not found.')
651
- }
652
-
653
- this.detectFeatures(info)
654
-
655
- this._debug(info)
656
-
657
- info.all = {}
658
- info.methods = {}
659
-
660
- ;['bools', 'numbers', 'strings'].forEach(function (type) {
661
- Object.keys(info[type]).forEach(function (key) {
662
- info.all[key] = info[type][key]
663
- info.methods[key] = self._compile(info, key, info.all[key])
664
- })
665
- })
666
-
667
- Tput.bools.forEach(function (key) {
668
- if (info.methods[key] == null) {
669
- info.methods[key] = false
670
- }
671
- })
672
-
673
- Tput.numbers.forEach(function (key) {
674
- if (info.methods[key] == null) {
675
- info.methods[key] = -1
676
- }
677
- })
678
-
679
- Tput.strings.forEach(function (key) {
680
- if (!info.methods[key]) {
681
- info.methods[key] = noop
682
- }
683
- })
684
-
685
- Object.keys(info.methods).forEach(function (key) {
686
- if (!Tput.alias[key]) {
687
- return
688
- }
689
- Tput.alias[key].forEach(function (alias) {
690
- info.methods[alias] = info.methods[key]
691
- })
692
- // Could just use:
693
- // Object.keys(Tput.aliasMap).forEach(function(key) {
694
- // info.methods[key] = info.methods[Tput.aliasMap[key]];
695
- // });
696
- })
697
-
698
- return info
699
- }
700
-
701
- Tput.prototype.inject = function (info) {
702
- const self = this,
703
- methods = info.methods || info
704
-
705
- Object.keys(methods).forEach(function (key) {
706
- if (typeof methods[key] !== 'function') {
707
- self[key] = methods[key]
708
- return
709
- }
710
- self[key] = function () {
711
- const args = Array.prototype.slice.call(arguments)
712
- return methods[key].call(self, args)
713
- }
714
- })
715
-
716
- this.info = info
717
- this.all = info.all
718
- this.methods = info.methods
719
- this.bools = info.bools
720
- this.numbers = info.numbers
721
- this.strings = info.strings
722
-
723
- if (!~info.names.indexOf(this.terminal)) {
724
- this.terminal = info.name
725
- }
726
-
727
- this.features = info.features
728
- Object.keys(info.features).forEach(function (key) {
729
- if (key === 'padding') {
730
- if (!info.features.padding && self.options.padding !== true) {
731
- self.padding = false
732
- }
733
- return
734
- }
735
- self[key] = info.features[key]
736
- })
737
- }
738
-
739
- // See:
740
- // ~/ncurses/ncurses/tinfo/lib_tparm.c
741
- // ~/ncurses/ncurses/tinfo/comp_scan.c
742
- Tput.prototype._compile = function (info, key, str) {
743
- let v
744
-
745
- this._debug('Compiling %s: %s', key, JSON.stringify(str))
746
-
747
- switch (typeof str) {
748
- case 'boolean':
749
- return str
750
- case 'number':
751
- return str
752
- case 'string':
753
- break
754
- default:
755
- return noop
756
- }
757
-
758
- if (!str) {
759
- return noop
760
- }
761
-
762
- // See:
763
- // ~/ncurses/progs/tput.c - tput() - L149
764
- // ~/ncurses/progs/tset.c - set_init() - L992
765
- if (key === 'init_file' || key === 'reset_file') {
766
- try {
767
- str = fs.readFileSync(str, 'utf8')
768
- if (this.debug) {
769
- v = ('return ' + JSON.stringify(str) + ';')
770
- .replace(/\x1b/g, '\\x1b')
771
- .replace(/\r/g, '\\r')
772
- .replace(/\n/g, '\\n')
773
- process.stdout.write(v + '\n')
774
- }
775
- return function () {
776
- return str
777
- }
778
- } catch (e) {
779
- return noop
780
- }
781
- }
782
-
783
- let tkey = info.name + '.' + key,
784
- header = 'var v, dyn = {}, stat = {}, stack = [], out = [];',
785
- footer = ';return out.join("");',
786
- code = header,
787
- val = str,
788
- buff = '',
789
- cap,
790
- ch,
791
- fi,
792
- then,
793
- els,
794
- end
795
-
796
- function read(regex, no) {
797
- cap = regex.exec(val)
798
- if (!cap) {
799
- return
800
- }
801
- val = val.substring(cap[0].length)
802
- ch = cap[1]
803
- if (!no) {
804
- clear()
805
- }
806
- return cap
807
- }
808
-
809
- function stmt(c) {
810
- if (code[code.length - 1] === ',') {
811
- code = code.slice(0, -1)
812
- }
813
- code += c
814
- }
815
-
816
- function expr(c) {
817
- code += c + ','
818
- }
819
-
820
- function echo(c) {
821
- if (c === '""') {
822
- return
823
- }
824
- expr('out.push(' + c + ')')
825
- }
826
-
827
- function print(c) {
828
- buff += c
829
- }
830
-
831
- function clear() {
832
- if (buff) {
833
- echo(JSON.stringify(buff).replace(/\\u00([0-9a-fA-F]{2})/g, '\\x$1'))
834
- buff = ''
835
- }
836
- }
837
-
838
- while (val) {
839
- // Ignore newlines
840
- if (read(/^\n /, true)) {
841
- continue
842
- }
843
-
844
- // '^A' -> ^A
845
- if (read(/^\^(.)/i, true)) {
846
- if (!(ch >= ' ' && ch <= '~')) {
847
- this._debug('%s: bad caret char.', tkey)
848
- // NOTE: ncurses appears to simply
849
- // continue in this situation, but
850
- // I could be wrong.
851
- print(cap[0])
852
- continue
853
- }
854
- if (ch === '?') {
855
- ch = '\x7f'
856
- } else {
857
- ch = ch.charCodeAt(0) & 31
858
- if (ch === 0) {
859
- ch = 128
860
- }
861
- ch = String.fromCharCode(ch)
862
- }
863
- print(ch)
864
- continue
865
- }
866
-
867
- // 3 octal digits -> character
868
- if (read(/^\\([0-7]{3})/, true)) {
869
- print(String.fromCharCode(parseInt(ch, 8)))
870
- continue
871
- }
872
-
873
- // '\e' -> ^[
874
- // '\n' -> \n
875
- // '\r' -> \r
876
- // '\0' -> \x80 (special case)
877
- if (read(/^\\([eEnlrtbfs^\\,:0]|.)/, true)) {
878
- switch (ch) {
879
- case 'e':
880
- case 'E':
881
- ch = '\x1b'
882
- break
883
- case 'n':
884
- ch = '\n'
885
- break
886
- case 'l':
887
- ch = '\x85'
888
- break
889
- case 'r':
890
- ch = '\r'
891
- break
892
- case 't':
893
- ch = '\t'
894
- break
895
- case 'b':
896
- ch = '\x08'
897
- break
898
- case 'f':
899
- ch = '\x0c'
900
- break
901
- case 's':
902
- ch = ' '
903
- break
904
- case '^':
905
- ch = '^'
906
- break
907
- case '\\':
908
- ch = '\\'
909
- break
910
- case ',':
911
- ch = ','
912
- break
913
- case ':':
914
- ch = ':'
915
- break
916
- case '0':
917
- ch = '\x80'
918
- break
919
- case 'a':
920
- ch = '\x07'
921
- break
922
- default:
923
- this._debug('%s: bad backslash char.', tkey)
924
- ch = cap[0]
925
- break
926
- }
927
- print(ch)
928
- continue
929
- }
930
-
931
- // $<5> -> padding
932
- // e.g. flash_screen: '\u001b[?5h$<100/>\u001b[?5l',
933
- if (read(/^\$<(\d+)([*/]{0,2})>/, true)) {
934
- if (this.padding) {
935
- print(cap[0])
936
- }
937
- continue
938
- }
939
-
940
- // %% outputs `%'
941
- if (read(/^%%/, true)) {
942
- print('%')
943
- continue
944
- }
945
-
946
- // %[[:]flags][width[.precision]][doxXs]
947
- // as in printf, flags are [-+#] and space. Use a `:' to allow the
948
- // next character to be a `-' flag, avoiding interpreting "%-" as an
949
- // operator.
950
- // %c print pop() like %c in printf
951
- // Example from screen terminfo:
952
- // S0: "\u001b(%p1%c"
953
- // %d print pop()
954
- // "Print (e.g., "%d") is a special case."
955
- // %s print pop() like %s in printf
956
- if (read(/^%((?::-|[+# ]){1,4})?(\d+(?:\.\d+)?)?([doxXsc])/)) {
957
- if (this.printf || cap[1] || cap[2] || ~'oxX'.indexOf(cap[3])) {
958
- echo('sprintf("' + cap[0].replace(':-', '-') + '", stack.pop())')
959
- } else if (cap[3] === 'c') {
960
- echo(
961
- '(v = stack.pop(), isFinite(v) ' +
962
- '? String.fromCharCode(v || 0200) : "")'
963
- )
964
- } else {
965
- echo('stack.pop()')
966
- }
967
- continue
968
- }
969
-
970
- // %p[1-9]
971
- // push i'th parameter
972
- if (read(/^%p([1-9])/)) {
973
- expr('(stack.push(v = params[' + (ch - 1) + ']), v)')
974
- continue
975
- }
976
-
977
- // %P[a-z]
978
- // set dynamic variable [a-z] to pop()
979
- if (read(/^%P([a-z])/)) {
980
- expr('dyn.' + ch + ' = stack.pop()')
981
- continue
982
- }
983
-
984
- // %g[a-z]
985
- // get dynamic variable [a-z] and push it
986
- if (read(/^%g([a-z])/)) {
987
- expr('(stack.push(dyn.' + ch + '), dyn.' + ch + ')')
988
- continue
989
- }
990
-
991
- // %P[A-Z]
992
- // set static variable [a-z] to pop()
993
- if (read(/^%P([A-Z])/)) {
994
- expr('stat.' + ch + ' = stack.pop()')
995
- continue
996
- }
997
-
998
- // %g[A-Z]
999
- // get static variable [a-z] and push it
1000
- // The terms "static" and "dynamic" are misleading. Historically,
1001
- // these are simply two different sets of variables, whose values are
1002
- // not reset between calls to tparm. However, that fact is not
1003
- // documented in other implementations. Relying on it will adversely
1004
- // impact portability to other implementations.
1005
- if (read(/^%g([A-Z])/)) {
1006
- expr('(stack.push(v = stat.' + ch + '), v)')
1007
- continue
1008
- }
1009
-
1010
- // %'c' char constant c
1011
- // NOTE: These are stored as c chars, exemplified by:
1012
- // cursor_address: "\u001b=%p1%' '%+%c%p2%' '%+%c"
1013
- if (read(/^%'(.)'/)) {
1014
- expr('(stack.push(v = ' + ch.charCodeAt(0) + '), v)')
1015
- continue
1016
- }
1017
-
1018
- // %{nn}
1019
- // integer constant nn
1020
- if (read(/^%\{(\d+)\}/)) {
1021
- expr('(stack.push(v = ' + ch + '), v)')
1022
- continue
1023
- }
1024
-
1025
- // %l push strlen(pop)
1026
- if (read(/^%l/)) {
1027
- expr('(stack.push(v = (stack.pop() || "").length || 0), v)')
1028
- continue
1029
- }
1030
-
1031
- // %+ %- %* %/ %m
1032
- // arithmetic (%m is mod): push(pop() op pop())
1033
- // %& %| %^
1034
- // bit operations (AND, OR and exclusive-OR): push(pop() op pop())
1035
- // %= %> %<
1036
- // logical operations: push(pop() op pop())
1037
- if (read(/^%([+\-*/m&|^=><])/)) {
1038
- if (ch === '=') {
1039
- ch = '==='
1040
- } else if (ch === 'm') {
1041
- ch = '%'
1042
- }
1043
- expr(
1044
- '(v = stack.pop(),' +
1045
- ' stack.push(v = (stack.pop() ' +
1046
- ch +
1047
- ' v) || 0),' +
1048
- ' v)'
1049
- )
1050
- continue
1051
- }
1052
-
1053
- // %A, %O
1054
- // logical AND and OR operations (for conditionals)
1055
- if (read(/^%([AO])/)) {
1056
- // Are we supposed to store the result on the stack?
1057
- expr(
1058
- '(stack.push(v = (stack.pop() ' +
1059
- (ch === 'A' ? '&&' : '||') +
1060
- ' stack.pop())), v)'
1061
- )
1062
- continue
1063
- }
1064
-
1065
- // %! %~
1066
- // unary operations (logical and bit complement): push(op pop())
1067
- if (read(/^%([!~])/)) {
1068
- expr('(stack.push(v = ' + ch + 'stack.pop()), v)')
1069
- continue
1070
- }
1071
-
1072
- // %i add 1 to first two parameters (for ANSI terminals)
1073
- if (read(/^%i/)) {
1074
- // Are these supposed to go on the stack in certain situations?
1075
- // ncurses doesn't seem to put them on the stack, but xterm.user6
1076
- // seems to assume they're on the stack for some reason. Could
1077
- // just be a bad terminfo string.
1078
- // user6: "\u001b[%i%d;%dR" - possibly a termcap-style string.
1079
- // expr('(params[0] |= 0, params[1] |= 0, params[0]++, params[1]++)');
1080
- expr('(params[0]++, params[1]++)')
1081
- continue
1082
- }
1083
-
1084
- // %? expr %t thenpart %e elsepart %;
1085
- // This forms an if-then-else. The %e elsepart is optional. Usually
1086
- // the %? expr part pushes a value onto the stack, and %t pops it from
1087
- // the stack, testing if it is nonzero (true). If it is zero (false),
1088
- // control passes to the %e (else) part.
1089
- // It is possible to form else-if's a la Algol 68:
1090
- // %? c1 %t b1 %e c2 %t b2 %e c3 %t b3 %e c4 %t b4 %e %;
1091
- // where ci are conditions, bi are bodies.
1092
- if (read(/^%\?/)) {
1093
- end = -1
1094
- stmt(';if (')
1095
- continue
1096
- }
1097
-
1098
- if (read(/^%t/)) {
1099
- end = -1
1100
- // Technically this is supposed to pop everything off the stack that was
1101
- // pushed onto the stack after the if statement, see man terminfo.
1102
- // Right now, we don't pop anything off. This could cause compat issues.
1103
- // Perhaps implement a "pushed" counter from the time the if statement
1104
- // is added, to the time the then statement is added, and pop off
1105
- // the appropriate number of elements.
1106
- // while (pushed--) expr('stack.pop()');
1107
- stmt(') {')
1108
- continue
1109
- }
1110
-
1111
- // Terminfo does elseif's like
1112
- // this: %?[expr]%t...%e[expr]%t...%;
1113
- if (read(/^%e/)) {
1114
- fi = val.indexOf('%?')
1115
- then = val.indexOf('%t')
1116
- els = val.indexOf('%e')
1117
- end = val.indexOf('%;')
1118
- if (end === -1) {
1119
- end = Infinity
1120
- }
1121
- if (
1122
- then !== -1 &&
1123
- then < end &&
1124
- (fi === -1 || then < fi) &&
1125
- (els === -1 || then < els)
1126
- ) {
1127
- stmt('} else if (')
1128
- } else {
1129
- stmt('} else {')
1130
- }
1131
- continue
1132
- }
1133
-
1134
- if (read(/^%;/)) {
1135
- end = null
1136
- stmt('}')
1137
- continue
1138
- }
1139
-
1140
- buff += val[0]
1141
- val = val.substring(1)
1142
- }
1143
-
1144
- // Clear the buffer of any remaining text.
1145
- clear()
1146
-
1147
- // Some terminfos (I'm looking at you, atari-color), don't end an if
1148
- // statement. It's assumed terminfo will automatically end it for
1149
- // them, because they are a bunch of lazy bastards.
1150
- if (end != null) {
1151
- stmt('}')
1152
- }
1153
-
1154
- // Add the footer.
1155
- stmt(footer)
1156
-
1157
- // Optimize and cleanup generated code.
1158
- v = code.slice(header.length, -footer.length)
1159
- if (!v.length) {
1160
- code = 'return "";'
1161
- } else if ((v = /^out\.push\(("(?:[^"]|\\")+")\)$/.exec(v))) {
1162
- code = 'return ' + v[1] + ';'
1163
- } else {
1164
- // Turn `(stack.push(v = params[0]), v),out.push(stack.pop())`
1165
- // into `out.push(params[0])`.
1166
- code = code.replace(
1167
- /\(stack\.push\(v = params\[(\d+)\]\), v\),out\.push\(stack\.pop\(\)\)/g,
1168
- 'out.push(params[$1])'
1169
- )
1170
-
1171
- // Remove unnecessary variable initializations.
1172
- v = code.slice(header.length, -footer.length)
1173
- if (!~v.indexOf('v = ')) {
1174
- code = code.replace('v, ', '')
1175
- }
1176
- if (!~v.indexOf('dyn')) {
1177
- code = code.replace('dyn = {}, ', '')
1178
- }
1179
- if (!~v.indexOf('stat')) {
1180
- code = code.replace('stat = {}, ', '')
1181
- }
1182
- if (!~v.indexOf('stack')) {
1183
- code = code.replace('stack = [], ', '')
1184
- }
1185
-
1186
- // Turn `var out = [];out.push("foo"),` into `var out = ["foo"];`.
1187
- code = code.replace(
1188
- /out = \[\];out\.push\(("(?:[^"]|\\")+")\),/,
1189
- 'out = [$1];'
1190
- )
1191
- }
1192
-
1193
- // Terminfos `wyse350-vb`, and `wy350-w`
1194
- // seem to have a few broken strings.
1195
- if (str === '\u001b%?') {
1196
- code = 'return "\\x1b";'
1197
- }
1198
-
1199
- if (this.debug) {
1200
- v = code
1201
- .replace(/\x1b/g, '\\x1b')
1202
- .replace(/\r/g, '\\r')
1203
- .replace(/\n/g, '\\n')
1204
- process.stdout.write(v + '\n')
1205
- }
1206
-
1207
- try {
1208
- if (this.options.stringify && code.indexOf('return ') === 0) {
1209
- return new Function('', code)()
1210
- }
1211
- return this.printf || ~code.indexOf('sprintf(')
1212
- ? new Function('sprintf, params', code).bind(null, sprintf)
1213
- : new Function('params', code)
1214
- } catch (e) {
1215
- console.error('')
1216
- console.error('Error on %s:', tkey)
1217
- console.error(JSON.stringify(str))
1218
- console.error('')
1219
- console.error(code.replace(/(,|;)/g, '$1\n'))
1220
- e.stack = e.stack.replace(/\x1b/g, '\\x1b')
1221
- throw e
1222
- }
1223
- }
1224
-
1225
- // See: ~/ncurses/ncurses/tinfo/lib_tputs.c
1226
- Tput.prototype._print = function (code, print, done) {
1227
- const xon = !this.bools.needs_xon_xoff || this.bools.xon_xoff
1228
-
1229
- print = print || write
1230
- done = done || noop
1231
-
1232
- if (!this.padding) {
1233
- print(code)
1234
- return done()
1235
- }
1236
-
1237
- let parts = code.split(/(?=\$<[\d.]+[*/]{0,2}>)/),
1238
- i = 0
1239
-
1240
- ;(function next() {
1241
- if (i === parts.length) {
1242
- return done()
1243
- }
1244
-
1245
- let part = parts[i++],
1246
- padding = /^\$<([\d.]+)([*/]{0,2})>/.exec(part),
1247
- amount,
1248
- suffix
1249
- // , affect;
1250
-
1251
- if (!padding) {
1252
- print(part)
1253
- return next()
1254
- }
1255
-
1256
- part = part.substring(padding[0].length)
1257
- amount = +padding[1]
1258
- suffix = padding[2]
1259
-
1260
- // A `/' suffix indicates that the padding is mandatory and forces a
1261
- // delay of the given number of milliseconds even on devices for which xon
1262
- // is present to indicate flow control.
1263
- if (xon && !~suffix.indexOf('/')) {
1264
- print(part)
1265
- return next()
1266
- }
1267
-
1268
- // A `*' indicates that the padding required is proportional to the number
1269
- // of lines affected by the operation, and the amount given is the
1270
- // per-affected-unit padding required. (In the case of insert character,
1271
- // the factor is still the number of lines affected.) Normally, padding is
1272
- // advisory if the device has the xon capability; it is used for cost
1273
- // computation but does not trigger delays.
1274
- if (~suffix.indexOf('*')) {
1275
- // XXX Disable this for now.
1276
- amount = amount
1277
- // if (affect = /\x1b\[(\d+)[LM]/.exec(part)) {
1278
- // amount *= +affect[1];
1279
- // }
1280
- // The above is a huge workaround. In reality, we need to compile
1281
- // `_print` into the string functions and check the cap name and
1282
- // params.
1283
- // if (cap === 'insert_line' || cap === 'delete_line') {
1284
- // amount *= params[0];
1285
- // }
1286
- // if (cap === 'clear_screen') {
1287
- // amount *= process.stdout.rows;
1288
- // }
1289
- }
1290
-
1291
- return setTimeout(function () {
1292
- print(part)
1293
- return next()
1294
- }, amount)
1295
- })()
1296
- }
1297
-
1298
- // A small helper function if we want
1299
- // to easily output text with setTimeouts.
1300
- Tput.print = function () {
1301
- const fake = {
1302
- padding: true,
1303
- bools: { needs_xon_xoff: true, xon_xoff: false }
1304
- }
1305
- return Tput.prototype._print.apply(fake, arguments)
1306
- }
1307
-
1308
- /**
1309
- * Termcap
1310
- */
1311
-
1312
- Tput.cpaths = [
1313
- process.env.TERMCAP || '',
1314
- (process.env.TERMPATH || '').split(/[: ]/),
1315
- (process.env.HOME || '') + '/.termcap',
1316
- '/usr/share/misc/termcap',
1317
- '/etc/termcap'
1318
- ]
1319
-
1320
- Tput.prototype.readTermcap = function (term) {
1321
- let self = this,
1322
- terms,
1323
- term_,
1324
- root,
1325
- paths
1326
-
1327
- term = term || this.terminal
1328
-
1329
- // Termcap has a bunch of terminals usually stored in one file/string,
1330
- // so we need to find the one containing our desired terminal.
1331
- if (~term.indexOf(path.sep) && (terms = this._tryCap(path.resolve(term)))) {
1332
- term_ = path.basename(term).split('.')[0]
1333
- if (terms[process.env.TERM]) {
1334
- term = process.env.TERM
1335
- } else if (terms[term_]) {
1336
- term = term_
1337
- } else {
1338
- term = Object.keys(terms)[0]
1339
- }
1340
- } else {
1341
- paths = Tput.cpaths.slice()
1342
-
1343
- if (this.termcapFile) {
1344
- paths.unshift(this.termcapFile)
1345
- }
1346
-
1347
- paths.push(Tput.termcap)
1348
-
1349
- terms = this._tryCap(paths, term)
1350
- }
1351
-
1352
- if (!terms) {
1353
- throw new Error('Cannot find termcap for: ' + term)
1354
- }
1355
-
1356
- root = terms[term]
1357
-
1358
- if (this.debug) {
1359
- this._termcap = terms
1360
- }
1361
-
1362
- ;(function tc(term) {
1363
- if (term && term.strings.tc) {
1364
- root.inherits = root.inherits || []
1365
- root.inherits.push(term.strings.tc)
1366
-
1367
- const names = terms[term.strings.tc]
1368
- ? terms[term.strings.tc].names
1369
- : [term.strings.tc]
1370
-
1371
- self._debug('%s inherits from %s.', term.names.join('/'), names.join('/'))
1372
-
1373
- const inherit = tc(terms[term.strings.tc])
1374
- if (inherit) {
1375
- ;['bools', 'numbers', 'strings'].forEach(function (type) {
1376
- merge(term[type], inherit[type])
1377
- })
1378
- }
1379
- }
1380
- return term
1381
- })(root)
1382
-
1383
- // Translate termcap names to terminfo-style names.
1384
- root = this.translateTermcap(root)
1385
-
1386
- return root
1387
- }
1388
-
1389
- Tput.prototype._tryCap = function (file, term) {
1390
- if (!file) {
1391
- return
1392
- }
1393
-
1394
- let terms, data, i
1395
-
1396
- if (Array.isArray(file)) {
1397
- for (i = 0; i < file.length; i++) {
1398
- data = this._tryCap(file[i], term)
1399
- if (data) {
1400
- return data
1401
- }
1402
- }
1403
- return
1404
- }
1405
-
1406
- // If the termcap string starts with `/`,
1407
- // ncurses considers it a filename.
1408
- data = file[0] === '/' ? tryRead(file) : file
1409
-
1410
- if (!data) {
1411
- return
1412
- }
1413
-
1414
- terms = this.parseTermcap(data, file)
1415
-
1416
- if (term && !terms[term]) {
1417
- return
1418
- }
1419
-
1420
- return terms
1421
- }
1422
-
1423
- /**
1424
- * Termcap Parser
1425
- * http://en.wikipedia.org/wiki/Termcap
1426
- * http://www.gnu.org/software
1427
- * /termutils/manual/termcap-1.3/html_mono/termcap.html
1428
- * http://www.gnu.org/software
1429
- * /termutils/manual/termcap-1.3/html_mono/termcap.html#SEC17
1430
- * http://tldp.org/HOWTO/Text-Terminal-HOWTO.html#toc16
1431
- * man termcap
1432
- */
1433
-
1434
- // Example:
1435
- // vt102|dec vt102:\
1436
- // :do=^J:co#80:li#24:cl=50\E[;H\E[2J:\
1437
- // :le=^H:bs:cm=5\E[%i%d;%dH:nd=2\E[C:up=2\E[A:\
1438
- // :ce=3\E[K:cd=50\E[J:so=2\E[7m:se=2\E[m:us=2\E[4m:ue=2\E[m:\
1439
- // :md=2\E[1m:mr=2\E[7m:mb=2\E[5m:me=2\E[m:is=\E[1;24r\E[24;1H:\
1440
- // :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:ks=\E[?1h\E=:ke=\E[?1l\E>:\
1441
- // :ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:kb=^H:\
1442
- // :ho=\E[H:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:pt:sr=5\EM:vt#3:\
1443
- // :sc=\E7:rc=\E8:cs=\E[%i%d;%dr:vs=\E[?7l:ve=\E[?7h:\
1444
- // :mi:al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4l:im=\E[4h:
1445
-
1446
- Tput.prototype.parseTermcap = function (data, file) {
1447
- let terms = {},
1448
- parts,
1449
- term,
1450
- entries,
1451
- fields,
1452
- field,
1453
- names,
1454
- i,
1455
- j,
1456
- k
1457
-
1458
- // remove escaped newlines
1459
- data = data.replace(/\\\n[ \t]*/g, '')
1460
-
1461
- // remove comments
1462
- data = data.replace(/^#[^\n]+/gm, '')
1463
-
1464
- // split entries
1465
- entries = data.trim().split(/\n+/)
1466
-
1467
- for (i = 0; i < entries.length; i++) {
1468
- fields = entries[i].split(/:+/)
1469
- for (j = 0; j < fields.length; j++) {
1470
- field = fields[j].trim()
1471
- if (!field) {
1472
- continue
1473
- }
1474
-
1475
- if (j === 0) {
1476
- names = field.split('|')
1477
- term = {
1478
- name: names[0],
1479
- names: names,
1480
- desc: names.pop(),
1481
- file: ~file.indexOf(path.sep) ? path.resolve(file) : file,
1482
- termcap: true
1483
- }
1484
-
1485
- for (k = 0; k < names.length; k++) {
1486
- terms[names[k]] = term
1487
- }
1488
-
1489
- term.bools = {}
1490
- term.numbers = {}
1491
- term.strings = {}
1492
-
1493
- continue
1494
- }
1495
-
1496
- if (~field.indexOf('=')) {
1497
- parts = field.split('=')
1498
- term.strings[parts[0]] = parts.slice(1).join('=')
1499
- } else if (~field.indexOf('#')) {
1500
- parts = field.split('#')
1501
- term.numbers[parts[0]] = +parts.slice(1).join('#')
1502
- } else {
1503
- term.bools[field] = true
1504
- }
1505
- }
1506
- }
1507
-
1508
- return terms
1509
- }
1510
-
1511
- /**
1512
- * Termcap Compiler
1513
- * man termcap
1514
- */
1515
-
1516
- Tput.prototype.translateTermcap = function (info) {
1517
- const self = this,
1518
- out = {}
1519
-
1520
- if (!info) {
1521
- return
1522
- }
1523
-
1524
- this._debug(info)
1525
-
1526
- ;['name', 'names', 'desc', 'file', 'termcap'].forEach(function (key) {
1527
- out[key] = info[key]
1528
- })
1529
-
1530
- // Separate aliases for termcap
1531
- const map = (function () {
1532
- const out = {}
1533
-
1534
- Object.keys(Tput.alias).forEach(function (key) {
1535
- const aliases = Tput.alias[key]
1536
- out[aliases.termcap] = key
1537
- })
1538
-
1539
- return out
1540
- })()
1541
-
1542
- // Translate termcap cap names to terminfo cap names.
1543
- // e.g. `up` -> `cursor_up`
1544
- ;['bools', 'numbers', 'strings'].forEach(function (key) {
1545
- out[key] = {}
1546
- Object.keys(info[key]).forEach(function (cap) {
1547
- if (key === 'strings') {
1548
- info.strings[cap] = self._captoinfo(cap, info.strings[cap], 1)
1549
- }
1550
- if (map[cap]) {
1551
- out[key][map[cap]] = info[key][cap]
1552
- } else {
1553
- // NOTE: Possibly include all termcap names
1554
- // in a separate alias.js file. Some are
1555
- // missing from the terminfo alias.js file
1556
- // which is why we have to do this:
1557
- // See: $ man termcap
1558
- out[key][cap] = info[key][cap]
1559
- }
1560
- })
1561
- })
1562
-
1563
- return out
1564
- }
1565
-
1566
- Tput.prototype.compileTermcap = function (term) {
1567
- return this.compile(this.readTermcap(term))
1568
- }
1569
-
1570
- Tput.prototype.injectTermcap = function (term) {
1571
- return this.inject(this.compileTermcap(term))
1572
- }
1573
-
1574
- /**
1575
- * _nc_captoinfo - ported to javascript directly from ncurses.
1576
- * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.
1577
- * See: ~/ncurses/ncurses/tinfo/captoinfo.c
1578
- *
1579
- * Convert a termcap string to terminfo format.
1580
- * 'cap' is the relevant terminfo capability index.
1581
- * 's' is the string value of the capability.
1582
- * 'parameterized' tells what type of translations to do:
1583
- * % translations if 1
1584
- * pad translations if >=0
1585
- */
1586
-
1587
- Tput.prototype._captoinfo = function (cap, s, parameterized) {
1588
- const self = this
1589
-
1590
- let capstart
1591
-
1592
- if (parameterized == null) {
1593
- parameterized = 0
1594
- }
1595
-
1596
- const MAX_PUSHED = 16,
1597
- stack = []
1598
-
1599
- let stackptr = 0,
1600
- onstack = 0,
1601
- seenm = 0,
1602
- seenn = 0,
1603
- seenr = 0,
1604
- param = 1,
1605
- i = 0,
1606
- out = ''
1607
-
1608
- function warn() {
1609
- const args = Array.prototype.slice.call(arguments)
1610
- args[0] = 'captoinfo: ' + (args[0] || '')
1611
- return self._debug.apply(self, args)
1612
- }
1613
-
1614
- function isdigit(ch) {
1615
- return ch >= '0' && ch <= '9'
1616
- }
1617
-
1618
- function isgraph(ch) {
1619
- return ch > ' ' && ch <= '~'
1620
- }
1621
-
1622
- // convert a character to a terminfo push
1623
- function cvtchar(sp) {
1624
- let c = '\0',
1625
- len
1626
-
1627
- let j = i
1628
-
1629
- switch (sp[j]) {
1630
- case '\\':
1631
- switch (sp[++j]) {
1632
- case "'":
1633
- case '$':
1634
- case '\\':
1635
- case '%':
1636
- c = sp[j]
1637
- len = 2
1638
- break
1639
- case '\0':
1640
- c = '\\'
1641
- len = 1
1642
- break
1643
- case '0':
1644
- case '1':
1645
- case '2':
1646
- case '3':
1647
- len = 1
1648
- while (isdigit(sp[j])) {
1649
- c = String.fromCharCode(
1650
- 8 * c.charCodeAt(0) +
1651
- (sp[j++].charCodeAt(0) - '0'.charCodeAt(0))
1652
- )
1653
- len++
1654
- }
1655
- break
1656
- default:
1657
- c = sp[j]
1658
- len = 2
1659
- break
1660
- }
1661
- break
1662
- case '^':
1663
- c = String.fromCharCode(sp[++j].charCodeAt(0) & 0x1f)
1664
- len = 2
1665
- break
1666
- default:
1667
- c = sp[j]
1668
- len = 1
1669
- }
1670
- if (isgraph(c) && c !== ',' && c !== "'" && c !== '\\' && c !== ':') {
1671
- out += "%'"
1672
- out += c
1673
- out += "'"
1674
- } else {
1675
- out += '%{'
1676
- if (c.charCodeAt(0) > 99) {
1677
- out += String.fromCharCode(
1678
- ((c.charCodeAt(0) / 100) | 0) + '0'.charCodeAt(0)
1679
- )
1680
- }
1681
- if (c.charCodeAt(0) > 9) {
1682
- out += String.fromCharCode(
1683
- (((c.charCodeAt(0) / 10) | 0) % 10) + '0'.charCodeAt(0)
1684
- )
1685
- }
1686
- out += String.fromCharCode((c.charCodeAt(0) % 10) + '0'.charCodeAt(0))
1687
- out += '}'
1688
- }
1689
-
1690
- return len
1691
- }
1692
-
1693
- // push n copies of param on the terminfo stack if not already there
1694
- function getparm(parm, n) {
1695
- if (seenr) {
1696
- if (parm === 1) {
1697
- parm = 2
1698
- } else if (parm === 2) {
1699
- parm = 1
1700
- }
1701
- }
1702
-
1703
- if (onstack === parm) {
1704
- if (n > 1) {
1705
- warn('string may not be optimal')
1706
- out += '%Pa'
1707
- while (n--) {
1708
- out += '%ga'
1709
- }
1710
- }
1711
- return
1712
- }
1713
-
1714
- if (onstack !== 0) {
1715
- push()
1716
- }
1717
-
1718
- onstack = parm
1719
-
1720
- while (n--) {
1721
- out += '%p'
1722
- out += String.fromCharCode('0'.charCodeAt(0) + parm)
1723
- }
1724
-
1725
- if (seenn && parm < 3) {
1726
- out += '%{96}%^'
1727
- }
1728
-
1729
- if (seenm && parm < 3) {
1730
- out += '%{127}%^'
1731
- }
1732
- }
1733
-
1734
- // push onstack on to the stack
1735
- function push() {
1736
- if (stackptr >= MAX_PUSHED) {
1737
- warn('string too complex to convert')
1738
- } else {
1739
- stack[stackptr++] = onstack
1740
- }
1741
- }
1742
-
1743
- // pop the top of the stack into onstack
1744
- function pop() {
1745
- if (stackptr === 0) {
1746
- if (onstack === 0) {
1747
- warn("I'm confused")
1748
- } else {
1749
- onstack = 0
1750
- }
1751
- } else {
1752
- onstack = stack[--stackptr]
1753
- }
1754
- param++
1755
- }
1756
-
1757
- function see03() {
1758
- getparm(param, 1)
1759
- out += '%3d'
1760
- pop()
1761
- }
1762
-
1763
- function invalid() {
1764
- out += '%'
1765
- i--
1766
- warn(
1767
- 'unknown %% code %s (%#x) in %s',
1768
- JSON.stringify(s[i]),
1769
- s[i].charCodeAt(0),
1770
- cap
1771
- )
1772
- }
1773
-
1774
- // skip the initial padding (if we haven't been told not to)
1775
- capstart = null
1776
- if (s == null) {
1777
- s = ''
1778
- }
1779
-
1780
- if (parameterized >= 0 && isdigit(s[i])) {
1781
- for (capstart = i; ; i++) {
1782
- if (!(isdigit(s[i]) || s[i] === '*' || s[i] === '.')) {
1783
- break
1784
- }
1785
- }
1786
- }
1787
-
1788
- while (s[i]) {
1789
- switch (s[i]) {
1790
- case '%':
1791
- i++
1792
- if (parameterized < 1) {
1793
- out += '%'
1794
- break
1795
- }
1796
- switch (s[i++]) {
1797
- case '%':
1798
- out += '%'
1799
- break
1800
- case 'r':
1801
- if (seenr++ === 1) {
1802
- warn('saw %%r twice in %s', cap)
1803
- }
1804
- break
1805
- case 'm':
1806
- if (seenm++ === 1) {
1807
- warn('saw %%m twice in %s', cap)
1808
- }
1809
- break
1810
- case 'n':
1811
- if (seenn++ === 1) {
1812
- warn('saw %%n twice in %s', cap)
1813
- }
1814
- break
1815
- case 'i':
1816
- out += '%i'
1817
- break
1818
- case '6':
1819
- case 'B':
1820
- getparm(param, 1)
1821
- out += '%{10}%/%{16}%*'
1822
- getparm(param, 1)
1823
- out += '%{10}%m%+'
1824
- break
1825
- case '8':
1826
- case 'D':
1827
- getparm(param, 2)
1828
- out += '%{2}%*%-'
1829
- break
1830
- case '>':
1831
- getparm(param, 2)
1832
- // %?%{x}%>%t%{y}%+%;
1833
- out += '%?'
1834
- i += cvtchar(s)
1835
- out += '%>%t'
1836
- i += cvtchar(s)
1837
- out += '%+%;'
1838
- break
1839
- case 'a':
1840
- if (
1841
- (s[i] === '=' ||
1842
- s[i] === '+' ||
1843
- s[i] === '-' ||
1844
- s[i] === '*' ||
1845
- s[i] === '/') &&
1846
- (s[i + 1] === 'p' || s[i + 1] === 'c') &&
1847
- s[i + 2] !== '\0' &&
1848
- s[i + 2]
1849
- ) {
1850
- let l
1851
- l = 2
1852
- if (s[i] !== '=') {
1853
- getparm(param, 1)
1854
- }
1855
- if (s[i + 1] === 'p') {
1856
- getparm(param + s[i + 2].charCodeAt(0) - '@'.charCodeAt(0), 1)
1857
- if (param !== onstack) {
1858
- pop()
1859
- param--
1860
- }
1861
- l++
1862
- } else {
1863
- ;(i += 2), (l += cvtchar(s)), (i -= 2)
1864
- }
1865
- switch (s[i]) {
1866
- case '+':
1867
- out += '%+'
1868
- break
1869
- case '-':
1870
- out += '%-'
1871
- break
1872
- case '*':
1873
- out += '%*'
1874
- break
1875
- case '/':
1876
- out += '%/'
1877
- break
1878
- case '=':
1879
- if (seenr) {
1880
- if (param === 1) {
1881
- onstack = 2
1882
- } else if (param === 2) {
1883
- onstack = 1
1884
- } else {
1885
- onstack = param
1886
- }
1887
- } else {
1888
- onstack = param
1889
- }
1890
- break
1891
- }
1892
- i += l
1893
- break
1894
- }
1895
- getparm(param, 1)
1896
- i += cvtchar(s)
1897
- out += '%+'
1898
- break
1899
- case '+':
1900
- getparm(param, 1)
1901
- i += cvtchar(s)
1902
- out += '%+%c'
1903
- pop()
1904
- break
1905
- case 's':
1906
- // #ifdef WATERLOO
1907
- // i += cvtchar(s);
1908
- // getparm(param, 1);
1909
- // out += '%-';
1910
- // #else
1911
- getparm(param, 1)
1912
- out += '%s'
1913
- pop()
1914
- // #endif /* WATERLOO */
1915
- break
1916
- case '-':
1917
- i += cvtchar(s)
1918
- getparm(param, 1)
1919
- out += '%-%c'
1920
- pop()
1921
- break
1922
- case '.':
1923
- getparm(param, 1)
1924
- out += '%c'
1925
- pop()
1926
- break
1927
- case '0': // not clear any of the historical termcaps did this
1928
- if (s[i] === '3') {
1929
- see03() // goto
1930
- break
1931
- } else if (s[i] !== '2') {
1932
- invalid() // goto
1933
- break
1934
- }
1935
- // FALLTHRU
1936
- case '2':
1937
- getparm(param, 1)
1938
- out += '%2d'
1939
- pop()
1940
- break
1941
- case '3':
1942
- see03()
1943
- break
1944
- case 'd':
1945
- getparm(param, 1)
1946
- out += '%d'
1947
- pop()
1948
- break
1949
- case 'f':
1950
- param++
1951
- break
1952
- case 'b':
1953
- param--
1954
- break
1955
- case '\\':
1956
- out += '%\\'
1957
- break
1958
- default:
1959
- invalid()
1960
- break
1961
- }
1962
- break
1963
- // #ifdef REVISIBILIZE
1964
- // case '\\':
1965
- // out += s[i++];
1966
- // out += s[i++];
1967
- // break;
1968
- // case '\n':
1969
- // out += '\\n';
1970
- // i++;
1971
- // break;
1972
- // case '\t':
1973
- // out += '\\t';
1974
- // i++;
1975
- // break;
1976
- // case '\r':
1977
- // out += '\\r';
1978
- // i++;
1979
- // break;
1980
- // case '\x80':
1981
- // out += '\\0';
1982
- // i++;
1983
- // break;
1984
- // case '\f':
1985
- // out += '\\f';
1986
- // i++;
1987
- // break;
1988
- // case '\b':
1989
- // out += '\\b';
1990
- // i++;
1991
- // break;
1992
- // case ' ':
1993
- // out += '\\s';
1994
- // i++;
1995
- // break;
1996
- // case '^':
1997
- // out += '\\^';
1998
- // i++;
1999
- // break;
2000
- // case ':':
2001
- // out += '\\:';
2002
- // i++;
2003
- // break;
2004
- // case ',':
2005
- // out += '\\,';
2006
- // i++;
2007
- // break;
2008
- // default:
2009
- // if (s[i] === '\033') {
2010
- // out += '\\E';
2011
- // i++;
2012
- // } else if (s[i].charCodeAt(0) > 0 && s[i].charCodeAt(0) < 32) {
2013
- // out += '^';
2014
- // out += String.fromCharCode(s[i].charCodeAt(0) + '@'.charCodeAt(0));
2015
- // i++;
2016
- // } else if (s[i].charCodeAt(0) <= 0 || s[i].charCodeAt(0) >= 127) {
2017
- // out += '\\';
2018
- // out += String.fromCharCode(
2019
- // ((s[i].charCodeAt(0) & 0300) >> 6) + '0'.charCodeAt(0));
2020
- // out += String.fromCharCode(
2021
- // ((s[i].charCodeAt(0) & 0070) >> 3) + '0'.charCodeAt(0));
2022
- // out += String.fromCharCode(
2023
- // (s[i].charCodeAt(0) & 0007) + '0'.charCodeAt(0));
2024
- // i++;
2025
- // } else {
2026
- // out += s[i++];
2027
- // }
2028
- // break;
2029
- // #else
2030
- default:
2031
- out += s[i++]
2032
- break
2033
- // #endif
2034
- }
2035
- }
2036
-
2037
- // Now, if we stripped off some leading padding, add it at the end
2038
- // of the string as mandatory padding.
2039
- if (capstart != null) {
2040
- out += '$<'
2041
- for (i = capstart; ; i++) {
2042
- if (isdigit(s[i]) || s[i] === '*' || s[i] === '.') {
2043
- out += s[i]
2044
- } else {
2045
- break
2046
- }
2047
- }
2048
- out += '/>'
2049
- }
2050
-
2051
- if (s !== out) {
2052
- warn(
2053
- 'Translating %s from %s to %s.',
2054
- cap,
2055
- JSON.stringify(s),
2056
- JSON.stringify(out)
2057
- )
2058
- }
2059
-
2060
- return out
2061
- }
2062
-
2063
- /**
2064
- * Compile All Terminfo
2065
- */
2066
-
2067
- Tput.prototype.getAll = function () {
2068
- const dir = this._prefix(),
2069
- list = asort(fs.readdirSync(dir)),
2070
- infos = []
2071
-
2072
- list.forEach(function (letter) {
2073
- const terms = asort(fs.readdirSync(path.resolve(dir, letter)))
2074
- infos.push.apply(infos, terms)
2075
- })
2076
-
2077
- function asort(obj) {
2078
- return obj.sort(function (a, b) {
2079
- a = a.toLowerCase().charCodeAt(0)
2080
- b = b.toLowerCase().charCodeAt(0)
2081
- return a - b
2082
- })
2083
- }
2084
-
2085
- return infos
2086
- }
2087
-
2088
- Tput.prototype.compileAll = function (start) {
2089
- const self = this,
2090
- all = {}
2091
-
2092
- this.getAll().forEach(function (name) {
2093
- if (start && name !== start) {
2094
- return
2095
- } else {
2096
- start = null
2097
- }
2098
- all[name] = self.compileTerminfo(name)
2099
- })
2100
-
2101
- return all
2102
- }
2103
-
2104
- /**
2105
- * Detect Features / Quirks
2106
- */
2107
-
2108
- Tput.prototype.detectFeatures = function (info) {
2109
- const data = this.parseACS(info)
2110
- info.features = {
2111
- unicode: this.detectUnicode(info),
2112
- brokenACS: this.detectBrokenACS(info),
2113
- PCRomSet: this.detectPCRomSet(info),
2114
- magicCookie: this.detectMagicCookie(info),
2115
- padding: this.detectPadding(info),
2116
- setbuf: this.detectSetbuf(info),
2117
- acsc: data.acsc,
2118
- acscr: data.acscr
2119
- }
2120
- return info.features
2121
- }
2122
-
2123
- Tput.prototype.detectUnicode = function () {
2124
- if (this.options.forceUnicode != null) {
2125
- return this.options.forceUnicode
2126
- }
2127
-
2128
- const LANG =
2129
- process.env.LANG +
2130
- ':' +
2131
- process.env.LANGUAGE +
2132
- ':' +
2133
- process.env.LC_ALL +
2134
- ':' +
2135
- process.env.LC_CTYPE
2136
-
2137
- return /utf-?8/i.test(LANG) || this.GetConsoleCP() === 65001
2138
- }
2139
-
2140
- // For some reason TERM=linux has smacs/rmacs, but it maps to `^[[11m`
2141
- // and it does not switch to the DEC SCLD character set. What the hell?
2142
- // xterm: \x1b(0, screen: \x0e, linux: \x1b[11m (doesn't work)
2143
- // `man console_codes` says:
2144
- // 11 select null mapping, set display control flag, reset tog‐
2145
- // gle meta flag (ECMA-48 says "first alternate font").
2146
- // See ncurses:
2147
- // ~/ncurses/ncurses/base/lib_set_term.c
2148
- // ~/ncurses/ncurses/tinfo/lib_acs.c
2149
- // ~/ncurses/ncurses/tinfo/tinfo_driver.c
2150
- // ~/ncurses/ncurses/tinfo/lib_setup.c
2151
- Tput.prototype.detectBrokenACS = function (info) {
2152
- // ncurses-compatible env variable.
2153
- if (process.env.NCURSES_NO_UTF8_ACS != null) {
2154
- return !!+process.env.NCURSES_NO_UTF8_ACS
2155
- }
2156
-
2157
- // If the terminal supports unicode, we don't need ACS.
2158
- if (info.numbers.U8 >= 0) {
2159
- return !!info.numbers.U8
2160
- }
2161
-
2162
- // The linux console is just broken for some reason.
2163
- // Apparently the Linux console does not support ACS,
2164
- // but it does support the PC ROM character set.
2165
- if (info.name === 'linux') {
2166
- return true
2167
- }
2168
-
2169
- // PC alternate charset
2170
- // if (acsc.indexOf('+\x10,\x11-\x18.\x190') === 0) {
2171
- if (this.detectPCRomSet(info)) {
2172
- return true
2173
- }
2174
-
2175
- // screen termcap is bugged?
2176
- if (
2177
- this.termcap &&
2178
- info.name.indexOf('screen') === 0 &&
2179
- process.env.TERMCAP &&
2180
- ~process.env.TERMCAP.indexOf('screen') &&
2181
- ~process.env.TERMCAP.indexOf('hhII00')
2182
- ) {
2183
- if (
2184
- ~info.strings.enter_alt_charset_mode.indexOf('\x0E') ||
2185
- ~info.strings.enter_alt_charset_mode.indexOf('\x0F') ||
2186
- ~info.strings.set_attributes.indexOf('\x0E') ||
2187
- ~info.strings.set_attributes.indexOf('\x0F')
2188
- ) {
2189
- return true
2190
- }
2191
- }
2192
-
2193
- return false
2194
- }
2195
-
2196
- // If enter_pc_charset is the same as enter_alt_charset,
2197
- // the terminal does not support SCLD as ACS.
2198
- // See: ~/ncurses/ncurses/tinfo/lib_acs.c
2199
- Tput.prototype.detectPCRomSet = function (info) {
2200
- const s = info.strings
2201
- if (
2202
- s.enter_pc_charset_mode &&
2203
- s.enter_alt_charset_mode &&
2204
- s.enter_pc_charset_mode === s.enter_alt_charset_mode &&
2205
- s.exit_pc_charset_mode === s.exit_alt_charset_mode
2206
- ) {
2207
- return true
2208
- }
2209
- return false
2210
- }
2211
-
2212
- Tput.prototype.detectMagicCookie = function () {
2213
- return process.env.NCURSES_NO_MAGIC_COOKIE == null
2214
- }
2215
-
2216
- Tput.prototype.detectPadding = function () {
2217
- return process.env.NCURSES_NO_PADDING == null
2218
- }
2219
-
2220
- Tput.prototype.detectSetbuf = function () {
2221
- return process.env.NCURSES_NO_SETBUF == null
2222
- }
2223
-
2224
- Tput.prototype.parseACS = function (info) {
2225
- const data = {}
2226
-
2227
- data.acsc = {}
2228
- data.acscr = {}
2229
-
2230
- // Possibly just return an empty object, as done here, instead of
2231
- // specifically saying ACS is "broken" above. This would be more
2232
- // accurate to ncurses logic. But it doesn't really matter.
2233
- if (this.detectPCRomSet(info)) {
2234
- return data
2235
- }
2236
-
2237
- // See: ~/ncurses/ncurses/tinfo/lib_acs.c: L208
2238
- Object.keys(Tput.acsc).forEach(function (ch) {
2239
- const acs_chars = info.strings.acs_chars || '',
2240
- i = acs_chars.indexOf(ch),
2241
- next = acs_chars[i + 1]
2242
-
2243
- if (!next || i === -1 || !Tput.acsc[next]) {
2244
- return
2245
- }
2246
-
2247
- data.acsc[ch] = Tput.acsc[next]
2248
- data.acscr[Tput.acsc[next]] = ch
2249
- })
2250
-
2251
- return data
2252
- }
2253
-
2254
- Tput.prototype.GetConsoleCP = function () {
2255
- let ccp
2256
-
2257
- if (process.platform !== 'win32') {
2258
- return -1
2259
- }
2260
-
2261
- // Allow unicode on all windows consoles for now:
2262
- if (+process.env.NCURSES_UNICODE !== 0) {
2263
- return 65001
2264
- }
2265
-
2266
- // cp.execSync('chcp 65001', { stdio: 'ignore', timeout: 1500 });
2267
-
2268
- try {
2269
- // Produces something like: 'Active code page: 437\n\n'
2270
- ccp = cp.execFileSync(process.env.WINDIR + '\\system32\\chcp.com', [], {
2271
- stdio: ['ignore', 'pipe', 'ignore'],
2272
- encoding: 'ascii',
2273
- timeout: 1500
2274
- })
2275
- // ccp = cp.execSync('chcp', {
2276
- // stdio: ['ignore', 'pipe', 'ignore'],
2277
- // encoding: 'ascii',
2278
- // timeout: 1500
2279
- // });
2280
- } catch (e) {}
2281
-
2282
- ccp = /\d+/.exec(ccp)
2283
-
2284
- if (!ccp) {
2285
- return -1
2286
- }
2287
-
2288
- ccp = +ccp[0]
2289
-
2290
- return ccp
2291
- }
2292
-
2293
- /**
2294
- * Helpers
2295
- */
2296
-
2297
- function noop() {
2298
- return ''
2299
- }
2300
-
2301
- noop.unsupported = true
2302
-
2303
- function merge(a, b) {
2304
- Object.keys(b).forEach(function (key) {
2305
- a[key] = b[key]
2306
- })
2307
- return a
2308
- }
2309
-
2310
- function write(data) {
2311
- return process.stdout.write(data)
2312
- }
2313
-
2314
- function tryRead(file) {
2315
- if (Array.isArray(file)) {
2316
- for (let i = 0; i < file.length; i++) {
2317
- const data = tryRead(file[i])
2318
- if (data) {
2319
- return data
2320
- }
2321
- }
2322
- return ''
2323
- }
2324
- if (!file) {
2325
- return ''
2326
- }
2327
- file = path.resolve.apply(path, arguments)
2328
- try {
2329
- return fs.readFileSync(file, 'utf8')
2330
- } catch (e) {
2331
- return ''
2332
- }
2333
- }
2334
-
2335
- /**
2336
- * sprintf
2337
- * http://www.cplusplus.com/reference/cstdio/printf/
2338
- */
2339
-
2340
- function sprintf(src) {
2341
- let params = Array.prototype.slice.call(arguments, 1),
2342
- rule = /%([-+# ]{1,4})?(\d+(?:\.\d+)?)?([doxXsc])/g,
2343
- i = 0
2344
-
2345
- return src.replace(rule, function (_, flag, width, type) {
2346
- let flags = (flag || '').split(''),
2347
- param = params[i] != null ? params[i] : '',
2348
- initial = param,
2349
- // , width = +width
2350
- opt = {},
2351
- pre = ''
2352
-
2353
- i++
2354
-
2355
- switch (type) {
2356
- case 'd': // signed int
2357
- param = (+param).toString(10)
2358
- break
2359
- case 'o': // unsigned octal
2360
- param = (+param).toString(8)
2361
- break
2362
- case 'x': // unsigned hex int
2363
- param = (+param).toString(16)
2364
- break
2365
- case 'X': // unsigned hex int uppercase
2366
- param = (+param).toString(16).toUppercase()
2367
- break
2368
- case 's': // string
2369
- break
2370
- case 'c': // char
2371
- param = isFinite(param) ? String.fromCharCode(param || 0x80) : ''
2372
- break
2373
- }
2374
-
2375
- flags.forEach(function (flag) {
2376
- switch (flag) {
2377
- // left-justify by width
2378
- case '-':
2379
- opt.left = true
2380
- break
2381
- // always precede numbers with their signs
2382
- case '+':
2383
- opt.signs = true
2384
- break
2385
- // used with o, x, X - value is preceded with 0, 0x, or 0X respectively.
2386
- // used with a, A, e, E, f, F, g, G - forces written output to contain
2387
- // a decimal point even if no more digits follow
2388
- case '#':
2389
- opt.hexpoint = true
2390
- break
2391
- // if no sign is going to be written, black space in front of the value
2392
- case ' ':
2393
- opt.space = true
2394
- break
2395
- }
2396
- })
2397
-
2398
- width = +width.split('.')[0]
2399
-
2400
- // Should this be for opt.left too?
2401
- // Example: %2.2X - turns 0 into 00
2402
- if (width && !opt.left) {
2403
- param = param + ''
2404
- while (param.length < width) {
2405
- param = '0' + param
2406
- }
2407
- }
2408
-
2409
- if (opt.signs) {
2410
- if (+initial >= 0) {
2411
- pre += '+'
2412
- }
2413
- }
2414
-
2415
- if (opt.space) {
2416
- if (!opt.signs && +initial >= 0) {
2417
- pre += ' '
2418
- }
2419
- }
2420
-
2421
- if (opt.hexpoint) {
2422
- switch (type) {
2423
- case 'o': // unsigned octal
2424
- pre += '0'
2425
- break
2426
- case 'x': // unsigned hex int
2427
- pre += '0x'
2428
- break
2429
- case 'X': // unsigned hex int uppercase
2430
- pre += '0X'
2431
- break
2432
- }
2433
- }
2434
-
2435
- if (opt.left) {
2436
- if (width > pre.length + param.length) {
2437
- width -= pre.length + param.length
2438
- pre = Array(width + 1).join(' ') + pre
2439
- }
2440
- }
2441
-
2442
- return pre + param
2443
- })
2444
- }
2445
-
2446
- /**
2447
- * Aliases
2448
- */
2449
-
2450
- Tput._alias = require('./alias')
2451
-
2452
- Tput.alias = {}
2453
-
2454
- ;['bools', 'numbers', 'strings'].forEach(function (type) {
2455
- Object.keys(Tput._alias[type]).forEach(function (key) {
2456
- const aliases = Tput._alias[type][key]
2457
- Tput.alias[key] = [aliases[0]]
2458
- Tput.alias[key].terminfo = aliases[0]
2459
- Tput.alias[key].termcap = aliases[1]
2460
- })
2461
- })
2462
-
2463
- // Bools
2464
- Tput.alias.no_esc_ctlc.push('beehive_glitch')
2465
- Tput.alias.dest_tabs_magic_smso.push('teleray_glitch')
2466
-
2467
- // Numbers
2468
- Tput.alias.micro_col_size.push('micro_char_size')
2469
-
2470
- /**
2471
- * Feature Checking
2472
- */
2473
-
2474
- Tput.aliasMap = {}
2475
-
2476
- Object.keys(Tput.alias).forEach(function (key) {
2477
- Tput.aliasMap[key] = key
2478
- Tput.alias[key].forEach(function (k) {
2479
- Tput.aliasMap[k] = key
2480
- })
2481
- })
2482
-
2483
- Tput.prototype.has = function (name) {
2484
- name = Tput.aliasMap[name]
2485
-
2486
- const val = this.all[name]
2487
-
2488
- if (!name) {
2489
- return false
2490
- }
2491
-
2492
- if (typeof val === 'number') {
2493
- return val !== -1
2494
- }
2495
-
2496
- return !!val
2497
- }
2498
-
2499
- /**
2500
- * Fallback Termcap Entry
2501
- */
2502
-
2503
- Tput.termcap =
2504
- '' +
2505
- 'vt102|dec vt102:' +
2506
- ':do=^J:co#80:li#24:cl=50\\E[;H\\E[2J:' +
2507
- ':le=^H:bs:cm=5\\E[%i%d;%dH:nd=2\\E[C:up=2\\E[A:' +
2508
- ':ce=3\\E[K:cd=50\\E[J:so=2\\E[7m:se=2\\E[m:us=2\\E[4m:ue=2\\E[m:' +
2509
- ':md=2\\E[1m:mr=2\\E[7m:mb=2\\E[5m:me=2\\E[m:is=\\E[1;24r\\E[24;1H:' +
2510
- ':rs=\\E>\\E[?3l\\E[?4l\\E[?5l\\E[?7h\\E[?8h:ks=\\E[?1h\\E=:ke=\\E[?1l\\E>:' +
2511
- ':ku=\\EOA:kd=\\EOB:kr=\\EOC:kl=\\EOD:kb=^H:\\\n' +
2512
- ':ho=\\E[H:k1=\\EOP:k2=\\EOQ:k3=\\EOR:k4=\\EOS:pt:sr=5\\EM:vt#3:' +
2513
- ':sc=\\E7:rc=\\E8:cs=\\E[%i%d;%dr:vs=\\E[?7l:ve=\\E[?7h:' +
2514
- ':mi:al=\\E[L:dc=\\E[P:dl=\\E[M:ei=\\E[4l:im=\\E[4h:'
2515
-
2516
- /**
2517
- * Terminfo Data
2518
- */
2519
-
2520
- Tput.bools = [
2521
- 'auto_left_margin',
2522
- 'auto_right_margin',
2523
- 'no_esc_ctlc',
2524
- 'ceol_standout_glitch',
2525
- 'eat_newline_glitch',
2526
- 'erase_overstrike',
2527
- 'generic_type',
2528
- 'hard_copy',
2529
- 'has_meta_key',
2530
- 'has_status_line',
2531
- 'insert_null_glitch',
2532
- 'memory_above',
2533
- 'memory_below',
2534
- 'move_insert_mode',
2535
- 'move_standout_mode',
2536
- 'over_strike',
2537
- 'status_line_esc_ok',
2538
- 'dest_tabs_magic_smso',
2539
- 'tilde_glitch',
2540
- 'transparent_underline',
2541
- 'xon_xoff',
2542
- 'needs_xon_xoff',
2543
- 'prtr_silent',
2544
- 'hard_cursor',
2545
- 'non_rev_rmcup',
2546
- 'no_pad_char',
2547
- 'non_dest_scroll_region',
2548
- 'can_change',
2549
- 'back_color_erase',
2550
- 'hue_lightness_saturation',
2551
- 'col_addr_glitch',
2552
- 'cr_cancels_micro_mode',
2553
- 'has_print_wheel',
2554
- 'row_addr_glitch',
2555
- 'semi_auto_right_margin',
2556
- 'cpi_changes_res',
2557
- 'lpi_changes_res',
2558
-
2559
- // #ifdef __INTERNAL_CAPS_VISIBLE
2560
- 'backspaces_with_bs',
2561
- 'crt_no_scrolling',
2562
- 'no_correctly_working_cr',
2563
- 'gnu_has_meta_key',
2564
- 'linefeed_is_newline',
2565
- 'has_hardware_tabs',
2566
- 'return_does_clr_eol'
2567
- ]
2568
-
2569
- Tput.numbers = [
2570
- 'columns',
2571
- 'init_tabs',
2572
- 'lines',
2573
- 'lines_of_memory',
2574
- 'magic_cookie_glitch',
2575
- 'padding_baud_rate',
2576
- 'virtual_terminal',
2577
- 'width_status_line',
2578
- 'num_labels',
2579
- 'label_height',
2580
- 'label_width',
2581
- 'max_attributes',
2582
- 'maximum_windows',
2583
- 'max_colors',
2584
- 'max_pairs',
2585
- 'no_color_video',
2586
- 'buffer_capacity',
2587
- 'dot_vert_spacing',
2588
- 'dot_horz_spacing',
2589
- 'max_micro_address',
2590
- 'max_micro_jump',
2591
- 'micro_col_size',
2592
- 'micro_line_size',
2593
- 'number_of_pins',
2594
- 'output_res_char',
2595
- 'output_res_line',
2596
- 'output_res_horz_inch',
2597
- 'output_res_vert_inch',
2598
- 'print_rate',
2599
- 'wide_char_size',
2600
- 'buttons',
2601
- 'bit_image_entwining',
2602
- 'bit_image_type',
2603
-
2604
- // #ifdef __INTERNAL_CAPS_VISIBLE
2605
- 'magic_cookie_glitch_ul',
2606
- 'carriage_return_delay',
2607
- 'new_line_delay',
2608
- 'backspace_delay',
2609
- 'horizontal_tab_delay',
2610
- 'number_of_function_keys'
2611
- ]
2612
-
2613
- Tput.strings = [
2614
- 'back_tab',
2615
- 'bell',
2616
- 'carriage_return',
2617
- 'change_scroll_region',
2618
- 'clear_all_tabs',
2619
- 'clear_screen',
2620
- 'clr_eol',
2621
- 'clr_eos',
2622
- 'column_address',
2623
- 'command_character',
2624
- 'cursor_address',
2625
- 'cursor_down',
2626
- 'cursor_home',
2627
- 'cursor_invisible',
2628
- 'cursor_left',
2629
- 'cursor_mem_address',
2630
- 'cursor_normal',
2631
- 'cursor_right',
2632
- 'cursor_to_ll',
2633
- 'cursor_up',
2634
- 'cursor_visible',
2635
- 'delete_character',
2636
- 'delete_line',
2637
- 'dis_status_line',
2638
- 'down_half_line',
2639
- 'enter_alt_charset_mode',
2640
- 'enter_blink_mode',
2641
- 'enter_bold_mode',
2642
- 'enter_ca_mode',
2643
- 'enter_delete_mode',
2644
- 'enter_dim_mode',
2645
- 'enter_insert_mode',
2646
- 'enter_secure_mode',
2647
- 'enter_protected_mode',
2648
- 'enter_reverse_mode',
2649
- 'enter_standout_mode',
2650
- 'enter_underline_mode',
2651
- 'erase_chars',
2652
- 'exit_alt_charset_mode',
2653
- 'exit_attribute_mode',
2654
- 'exit_ca_mode',
2655
- 'exit_delete_mode',
2656
- 'exit_insert_mode',
2657
- 'exit_standout_mode',
2658
- 'exit_underline_mode',
2659
- 'flash_screen',
2660
- 'form_feed',
2661
- 'from_status_line',
2662
- 'init_1string',
2663
- 'init_2string',
2664
- 'init_3string',
2665
- 'init_file',
2666
- 'insert_character',
2667
- 'insert_line',
2668
- 'insert_padding',
2669
- 'key_backspace',
2670
- 'key_catab',
2671
- 'key_clear',
2672
- 'key_ctab',
2673
- 'key_dc',
2674
- 'key_dl',
2675
- 'key_down',
2676
- 'key_eic',
2677
- 'key_eol',
2678
- 'key_eos',
2679
- 'key_f0',
2680
- 'key_f1',
2681
- 'key_f10',
2682
- 'key_f2',
2683
- 'key_f3',
2684
- 'key_f4',
2685
- 'key_f5',
2686
- 'key_f6',
2687
- 'key_f7',
2688
- 'key_f8',
2689
- 'key_f9',
2690
- 'key_home',
2691
- 'key_ic',
2692
- 'key_il',
2693
- 'key_left',
2694
- 'key_ll',
2695
- 'key_npage',
2696
- 'key_ppage',
2697
- 'key_right',
2698
- 'key_sf',
2699
- 'key_sr',
2700
- 'key_stab',
2701
- 'key_up',
2702
- 'keypad_local',
2703
- 'keypad_xmit',
2704
- 'lab_f0',
2705
- 'lab_f1',
2706
- 'lab_f10',
2707
- 'lab_f2',
2708
- 'lab_f3',
2709
- 'lab_f4',
2710
- 'lab_f5',
2711
- 'lab_f6',
2712
- 'lab_f7',
2713
- 'lab_f8',
2714
- 'lab_f9',
2715
- 'meta_off',
2716
- 'meta_on',
2717
- 'newline',
2718
- 'pad_char',
2719
- 'parm_dch',
2720
- 'parm_delete_line',
2721
- 'parm_down_cursor',
2722
- 'parm_ich',
2723
- 'parm_index',
2724
- 'parm_insert_line',
2725
- 'parm_left_cursor',
2726
- 'parm_right_cursor',
2727
- 'parm_rindex',
2728
- 'parm_up_cursor',
2729
- 'pkey_key',
2730
- 'pkey_local',
2731
- 'pkey_xmit',
2732
- 'print_screen',
2733
- 'prtr_off',
2734
- 'prtr_on',
2735
- 'repeat_char',
2736
- 'reset_1string',
2737
- 'reset_2string',
2738
- 'reset_3string',
2739
- 'reset_file',
2740
- 'restore_cursor',
2741
- 'row_address',
2742
- 'save_cursor',
2743
- 'scroll_forward',
2744
- 'scroll_reverse',
2745
- 'set_attributes',
2746
- 'set_tab',
2747
- 'set_window',
2748
- 'tab',
2749
- 'to_status_line',
2750
- 'underline_char',
2751
- 'up_half_line',
2752
- 'init_prog',
2753
- 'key_a1',
2754
- 'key_a3',
2755
- 'key_b2',
2756
- 'key_c1',
2757
- 'key_c3',
2758
- 'prtr_non',
2759
- 'char_padding',
2760
- 'acs_chars',
2761
- 'plab_norm',
2762
- 'key_btab',
2763
- 'enter_xon_mode',
2764
- 'exit_xon_mode',
2765
- 'enter_am_mode',
2766
- 'exit_am_mode',
2767
- 'xon_character',
2768
- 'xoff_character',
2769
- 'ena_acs',
2770
- 'label_on',
2771
- 'label_off',
2772
- 'key_beg',
2773
- 'key_cancel',
2774
- 'key_close',
2775
- 'key_command',
2776
- 'key_copy',
2777
- 'key_create',
2778
- 'key_end',
2779
- 'key_enter',
2780
- 'key_exit',
2781
- 'key_find',
2782
- 'key_help',
2783
- 'key_mark',
2784
- 'key_message',
2785
- 'key_move',
2786
- 'key_next',
2787
- 'key_open',
2788
- 'key_options',
2789
- 'key_previous',
2790
- 'key_print',
2791
- 'key_redo',
2792
- 'key_reference',
2793
- 'key_refresh',
2794
- 'key_replace',
2795
- 'key_restart',
2796
- 'key_resume',
2797
- 'key_save',
2798
- 'key_suspend',
2799
- 'key_undo',
2800
- 'key_sbeg',
2801
- 'key_scancel',
2802
- 'key_scommand',
2803
- 'key_scopy',
2804
- 'key_screate',
2805
- 'key_sdc',
2806
- 'key_sdl',
2807
- 'key_select',
2808
- 'key_send',
2809
- 'key_seol',
2810
- 'key_sexit',
2811
- 'key_sfind',
2812
- 'key_shelp',
2813
- 'key_shome',
2814
- 'key_sic',
2815
- 'key_sleft',
2816
- 'key_smessage',
2817
- 'key_smove',
2818
- 'key_snext',
2819
- 'key_soptions',
2820
- 'key_sprevious',
2821
- 'key_sprint',
2822
- 'key_sredo',
2823
- 'key_sreplace',
2824
- 'key_sright',
2825
- 'key_srsume',
2826
- 'key_ssave',
2827
- 'key_ssuspend',
2828
- 'key_sundo',
2829
- 'req_for_input',
2830
- 'key_f11',
2831
- 'key_f12',
2832
- 'key_f13',
2833
- 'key_f14',
2834
- 'key_f15',
2835
- 'key_f16',
2836
- 'key_f17',
2837
- 'key_f18',
2838
- 'key_f19',
2839
- 'key_f20',
2840
- 'key_f21',
2841
- 'key_f22',
2842
- 'key_f23',
2843
- 'key_f24',
2844
- 'key_f25',
2845
- 'key_f26',
2846
- 'key_f27',
2847
- 'key_f28',
2848
- 'key_f29',
2849
- 'key_f30',
2850
- 'key_f31',
2851
- 'key_f32',
2852
- 'key_f33',
2853
- 'key_f34',
2854
- 'key_f35',
2855
- 'key_f36',
2856
- 'key_f37',
2857
- 'key_f38',
2858
- 'key_f39',
2859
- 'key_f40',
2860
- 'key_f41',
2861
- 'key_f42',
2862
- 'key_f43',
2863
- 'key_f44',
2864
- 'key_f45',
2865
- 'key_f46',
2866
- 'key_f47',
2867
- 'key_f48',
2868
- 'key_f49',
2869
- 'key_f50',
2870
- 'key_f51',
2871
- 'key_f52',
2872
- 'key_f53',
2873
- 'key_f54',
2874
- 'key_f55',
2875
- 'key_f56',
2876
- 'key_f57',
2877
- 'key_f58',
2878
- 'key_f59',
2879
- 'key_f60',
2880
- 'key_f61',
2881
- 'key_f62',
2882
- 'key_f63',
2883
- 'clr_bol',
2884
- 'clear_margins',
2885
- 'set_left_margin',
2886
- 'set_right_margin',
2887
- 'label_format',
2888
- 'set_clock',
2889
- 'display_clock',
2890
- 'remove_clock',
2891
- 'create_window',
2892
- 'goto_window',
2893
- 'hangup',
2894
- 'dial_phone',
2895
- 'quick_dial',
2896
- 'tone',
2897
- 'pulse',
2898
- 'flash_hook',
2899
- 'fixed_pause',
2900
- 'wait_tone',
2901
- 'user0',
2902
- 'user1',
2903
- 'user2',
2904
- 'user3',
2905
- 'user4',
2906
- 'user5',
2907
- 'user6',
2908
- 'user7',
2909
- 'user8',
2910
- 'user9',
2911
- 'orig_pair',
2912
- 'orig_colors',
2913
- 'initialize_color',
2914
- 'initialize_pair',
2915
- 'set_color_pair',
2916
- 'set_foreground',
2917
- 'set_background',
2918
- 'change_char_pitch',
2919
- 'change_line_pitch',
2920
- 'change_res_horz',
2921
- 'change_res_vert',
2922
- 'define_char',
2923
- 'enter_doublewide_mode',
2924
- 'enter_draft_quality',
2925
- 'enter_italics_mode',
2926
- 'enter_leftward_mode',
2927
- 'enter_micro_mode',
2928
- 'enter_near_letter_quality',
2929
- 'enter_normal_quality',
2930
- 'enter_shadow_mode',
2931
- 'enter_subscript_mode',
2932
- 'enter_superscript_mode',
2933
- 'enter_upward_mode',
2934
- 'exit_doublewide_mode',
2935
- 'exit_italics_mode',
2936
- 'exit_leftward_mode',
2937
- 'exit_micro_mode',
2938
- 'exit_shadow_mode',
2939
- 'exit_subscript_mode',
2940
- 'exit_superscript_mode',
2941
- 'exit_upward_mode',
2942
- 'micro_column_address',
2943
- 'micro_down',
2944
- 'micro_left',
2945
- 'micro_right',
2946
- 'micro_row_address',
2947
- 'micro_up',
2948
- 'order_of_pins',
2949
- 'parm_down_micro',
2950
- 'parm_left_micro',
2951
- 'parm_right_micro',
2952
- 'parm_up_micro',
2953
- 'select_char_set',
2954
- 'set_bottom_margin',
2955
- 'set_bottom_margin_parm',
2956
- 'set_left_margin_parm',
2957
- 'set_right_margin_parm',
2958
- 'set_top_margin',
2959
- 'set_top_margin_parm',
2960
- 'start_bit_image',
2961
- 'start_char_set_def',
2962
- 'stop_bit_image',
2963
- 'stop_char_set_def',
2964
- 'subscript_characters',
2965
- 'superscript_characters',
2966
- 'these_cause_cr',
2967
- 'zero_motion',
2968
- 'char_set_names',
2969
- 'key_mouse',
2970
- 'mouse_info',
2971
- 'req_mouse_pos',
2972
- 'get_mouse',
2973
- 'set_a_foreground',
2974
- 'set_a_background',
2975
- 'pkey_plab',
2976
- 'device_type',
2977
- 'code_set_init',
2978
- 'set0_des_seq',
2979
- 'set1_des_seq',
2980
- 'set2_des_seq',
2981
- 'set3_des_seq',
2982
- 'set_lr_margin',
2983
- 'set_tb_margin',
2984
- 'bit_image_repeat',
2985
- 'bit_image_newline',
2986
- 'bit_image_carriage_return',
2987
- 'color_names',
2988
- 'define_bit_image_region',
2989
- 'end_bit_image_region',
2990
- 'set_color_band',
2991
- 'set_page_length',
2992
- 'display_pc_char',
2993
- 'enter_pc_charset_mode',
2994
- 'exit_pc_charset_mode',
2995
- 'enter_scancode_mode',
2996
- 'exit_scancode_mode',
2997
- 'pc_term_options',
2998
- 'scancode_escape',
2999
- 'alt_scancode_esc',
3000
- 'enter_horizontal_hl_mode',
3001
- 'enter_left_hl_mode',
3002
- 'enter_low_hl_mode',
3003
- 'enter_right_hl_mode',
3004
- 'enter_top_hl_mode',
3005
- 'enter_vertical_hl_mode',
3006
- 'set_a_attributes',
3007
- 'set_pglen_inch',
3008
-
3009
- // #ifdef __INTERNAL_CAPS_VISIBLE
3010
- 'termcap_init2',
3011
- 'termcap_reset',
3012
- 'linefeed_if_not_lf',
3013
- 'backspace_if_not_bs',
3014
- 'other_non_function_keys',
3015
- 'arrow_key_map',
3016
- 'acs_ulcorner',
3017
- 'acs_llcorner',
3018
- 'acs_urcorner',
3019
- 'acs_lrcorner',
3020
- 'acs_ltee',
3021
- 'acs_rtee',
3022
- 'acs_btee',
3023
- 'acs_ttee',
3024
- 'acs_hline',
3025
- 'acs_vline',
3026
- 'acs_plus',
3027
- 'memory_lock',
3028
- 'memory_unlock',
3029
- 'box_chars_1'
3030
- ]
3031
-
3032
- // DEC Special Character and Line Drawing Set.
3033
- // Taken from tty.js.
3034
- Tput.acsc = {
3035
- // (0
3036
- '`': '\u25c6', // '◆'
3037
- a: '\u2592', // '▒'
3038
- b: '\u0009', // '\t'
3039
- c: '\u000c', // '\f'
3040
- d: '\u000d', // '\r'
3041
- e: '\u000a', // '\n'
3042
- f: '\u00b0', // '°'
3043
- g: '\u00b1', // '±'
3044
- h: '\u2424', // '\u2424' (NL)
3045
- i: '\u000b', // '\v'
3046
- j: '\u2518', // '┘'
3047
- k: '\u2510', // '┐'
3048
- l: '\u250c', // '┌'
3049
- m: '\u2514', // '└'
3050
- n: '\u253c', // '┼'
3051
- o: '\u23ba', // '⎺'
3052
- p: '\u23bb', // '⎻'
3053
- q: '\u2500', // '─'
3054
- r: '\u23bc', // '⎼'
3055
- s: '\u23bd', // '⎽'
3056
- t: '\u251c', // '├'
3057
- u: '\u2524', // '┤'
3058
- v: '\u2534', // '┴'
3059
- w: '\u252c', // '┬'
3060
- x: '\u2502', // '│'
3061
- y: '\u2264', // '≤'
3062
- z: '\u2265', // '≥'
3063
- '{': '\u03c0', // 'π'
3064
- '|': '\u2260', // '≠'
3065
- '}': '\u00a3', // '£'
3066
- '~': '\u00b7' // '·'
3067
- }
3068
-
3069
- // Convert ACS unicode characters to the
3070
- // most similar-looking ascii characters.
3071
- Tput.utoa = Tput.prototype.utoa = {
3072
- '\u25c6': '*', // '◆'
3073
- '\u2592': ' ', // '▒'
3074
- // '\u0009': '\t', // '\t'
3075
- // '\u000c': '\f', // '\f'
3076
- // '\u000d': '\r', // '\r'
3077
- // '\u000a': '\n', // '\n'
3078
- '\u00b0': '*', // '°'
3079
- '\u00b1': '+', // '±'
3080
- '\u2424': '\n', // '\u2424' (NL)
3081
- // '\u000b': '\v', // '\v'
3082
- '\u2518': '+', // '┘'
3083
- '\u2510': '+', // '┐'
3084
- '\u250c': '+', // '┌'
3085
- '\u2514': '+', // '└'
3086
- '\u253c': '+', // '┼'
3087
- '\u23ba': '-', // '⎺'
3088
- '\u23bb': '-', // '⎻'
3089
- '\u2500': '-', // '─'
3090
- '\u23bc': '-', // '⎼'
3091
- '\u23bd': '_', // '⎽'
3092
- '\u251c': '+', // '├'
3093
- '\u2524': '+', // '┤'
3094
- '\u2534': '+', // '┴'
3095
- '\u252c': '+', // '┬'
3096
- '\u2502': '|', // '│'
3097
- '\u2264': '<', // '≤'
3098
- '\u2265': '>', // '≥'
3099
- '\u03c0': '?', // 'π'
3100
- '\u2260': '=', // '≠'
3101
- '\u00a3': '?', // '£'
3102
- '\u00b7': '*' // '·'
3103
- }
3104
-
3105
- /**
3106
- * Expose
3107
- */
3108
-
3109
- exports = Tput
3110
- exports.sprintf = sprintf
3111
- exports.tryRead = tryRead
3112
-
3113
- module.exports = exports