@teaui/core 1.1.4

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