@socketsecurity/cli-with-sentry 0.14.137 → 0.14.138

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