pssh 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,29 @@
1
+ body {
2
+ padding: 0;
3
+ overflow: hidden;
4
+ }
5
+
6
+ #term {
7
+ overflow: hidden;
8
+ }
9
+
10
+ .monospace {
11
+ font-family: "DejaVu Sans Mono", "Liberation Mono", monospace;
12
+ font-size: 11px;
13
+ padding: 0;
14
+ }
15
+ .terminal {
16
+ font-family: "DejaVu Sans Mono", "Liberation Mono", monospace;
17
+ font-size: 11px;
18
+ line-height: 13px;
19
+ color: #f0f0f0;
20
+ background: #000;
21
+ width: 100%;
22
+ box-shadow: rgba(0, 0, 0, 0.8) 2px 2px 20px;
23
+ }
24
+
25
+ .reverse-video {
26
+ color: #000;
27
+ background: #f0f0f0;
28
+ }
29
+
@@ -0,0 +1,4245 @@
1
+ /**
2
+ * tty.js - an xterm emulator
3
+ *
4
+ * Copyright (c) 2012-2013, Christopher Jeffrey (https://github.com/chjj/tty.js)
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ *
24
+ * Originally forked from (with the author's permission):
25
+ * Fabrice Bellard's javascript vt100 for jslinux:
26
+ * http://bellard.org/jslinux/
27
+ * Copyright (c) 2011 Fabrice Bellard
28
+ * The original design remains. The terminal itself
29
+ * has been extended to include xterm CSI codes, among
30
+ * other features.
31
+ */
32
+
33
+ ;(function() {
34
+
35
+ /**
36
+ * Terminal Emulation References:
37
+ * http://vt100.net/
38
+ * http://invisible-island.net/xterm/ctlseqs/ctlseqs.txt
39
+ * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
40
+ * http://invisible-island.net/vttest/
41
+ * http://www.inwap.com/pdp10/ansicode.txt
42
+ * http://linux.die.net/man/4/console_codes
43
+ * http://linux.die.net/man/7/urxvt
44
+ */
45
+
46
+ 'use strict';
47
+
48
+ /**
49
+ * Shared
50
+ */
51
+
52
+ var window = this
53
+ , document = this.document;
54
+
55
+ /**
56
+ * EventEmitter
57
+ */
58
+
59
+ function EventEmitter() {
60
+ this._events = this._events || {};
61
+ }
62
+
63
+ EventEmitter.prototype.addListener = function(type, listener) {
64
+ this._events[type] = this._events[type] || [];
65
+ this._events[type].push(listener);
66
+ };
67
+
68
+ EventEmitter.prototype.on = EventEmitter.prototype.addListener;
69
+
70
+ EventEmitter.prototype.removeListener = function(type, listener) {
71
+ if (!this._events[type]) return;
72
+
73
+ var obj = this._events[type]
74
+ , i = obj.length;
75
+
76
+ while (i--) {
77
+ if (obj[i] === listener || obj[i].listener === listener) {
78
+ obj.splice(i, 1);
79
+ return;
80
+ }
81
+ }
82
+ };
83
+
84
+ EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
85
+
86
+ EventEmitter.prototype.removeAllListeners = function(type) {
87
+ if (this._events[type]) delete this._events[type];
88
+ };
89
+
90
+ EventEmitter.prototype.once = function(type, listener) {
91
+ function on() {
92
+ var args = Array.prototype.slice.call(arguments);
93
+ this.removeListener(type, on);
94
+ return listener.apply(this, args);
95
+ }
96
+ on.listener = listener;
97
+ return this.on(type, on);
98
+ };
99
+
100
+ EventEmitter.prototype.emit = function(type) {
101
+ if (!this._events[type]) return;
102
+
103
+ var args = Array.prototype.slice.call(arguments, 1)
104
+ , obj = this._events[type]
105
+ , l = obj.length
106
+ , i = 0;
107
+
108
+ for (; i < l; i++) {
109
+ obj[i].apply(this, args);
110
+ // if (obj[i].apply(this, args) === false) return false;
111
+ }
112
+ };
113
+
114
+ EventEmitter.prototype.listeners = function(type) {
115
+ return this._events[type] = this._events[type] || [];
116
+ };
117
+
118
+ /**
119
+ * States
120
+ */
121
+
122
+ var normal = 0
123
+ , escaped = 1
124
+ , csi = 2
125
+ , osc = 3
126
+ , charset = 4
127
+ , dcs = 5
128
+ , ignore = 6;
129
+
130
+ /**
131
+ * Terminal
132
+ */
133
+
134
+ function Terminal(cols, rows, handler) {
135
+ EventEmitter.call(this);
136
+
137
+ var options;
138
+ if (typeof cols === 'object') {
139
+ options = cols;
140
+ cols = options.cols;
141
+ rows = options.rows;
142
+ handler = options.handler;
143
+ }
144
+ this._options = options || {};
145
+
146
+ this.cols = cols || Terminal.geometry[0];
147
+ this.rows = rows || Terminal.geometry[1];
148
+
149
+ if (handler) {
150
+ this.on('data', handler);
151
+ }
152
+
153
+ this.ybase = 0;
154
+ this.ydisp = 0;
155
+ this.x = 0;
156
+ this.y = 0;
157
+ this.cursorState = 0;
158
+ this.cursorHidden = false;
159
+ this.convertEol = false;
160
+ this.state = 0;
161
+ this.queue = '';
162
+ this.scrollTop = 0;
163
+ this.scrollBottom = this.rows - 1;
164
+
165
+ // modes
166
+ this.applicationKeypad = false;
167
+ this.applicationCursor = false;
168
+ this.originMode = false;
169
+ this.insertMode = false;
170
+ this.wraparoundMode = false;
171
+ this.normal = null;
172
+
173
+ // charset
174
+ this.charset = null;
175
+ this.gcharset = null;
176
+ this.glevel = 0;
177
+ this.charsets = [null];
178
+
179
+ // mouse properties
180
+ this.decLocator;
181
+ this.x10Mouse;
182
+ this.vt200Mouse;
183
+ this.vt300Mouse;
184
+ this.normalMouse;
185
+ this.mouseEvents;
186
+ this.sendFocus;
187
+ this.utfMouse;
188
+ this.sgrMouse;
189
+ this.urxvtMouse;
190
+
191
+ // misc
192
+ this.element;
193
+ this.children;
194
+ this.refreshStart;
195
+ this.refreshEnd;
196
+ this.savedX;
197
+ this.savedY;
198
+ this.savedCols;
199
+
200
+ // stream
201
+ this.readable = true;
202
+ this.writable = true;
203
+
204
+ this.defAttr = (257 << 9) | 256;
205
+ this.curAttr = this.defAttr;
206
+
207
+ this.params = [];
208
+ this.currentParam = 0;
209
+ this.prefix = '';
210
+ this.postfix = '';
211
+
212
+ this.lines = [];
213
+ var i = this.rows;
214
+ while (i--) {
215
+ this.lines.push(this.blankLine());
216
+ }
217
+
218
+ this.tabs;
219
+ this.setupStops();
220
+ }
221
+
222
+ inherits(Terminal, EventEmitter);
223
+
224
+ /**
225
+ * Colors
226
+ */
227
+
228
+ // Colors 0-15
229
+ Terminal.colors = [
230
+ // dark:
231
+ '#2e3436',
232
+ '#cc0000',
233
+ '#4e9a06',
234
+ '#c4a000',
235
+ '#3465a4',
236
+ '#75507b',
237
+ '#06989a',
238
+ '#d3d7cf',
239
+ // bright:
240
+ '#555753',
241
+ '#ef2929',
242
+ '#8ae234',
243
+ '#fce94f',
244
+ '#729fcf',
245
+ '#ad7fa8',
246
+ '#34e2e2',
247
+ '#eeeeec'
248
+ ];
249
+ // Solarized Light:
250
+ Terminal.colors = [
251
+ '#eee8d5', // S_base02
252
+ '#dc322f',
253
+ '#859900',
254
+ '#b58900',
255
+ '#268bd2',
256
+ '#d33682',
257
+ '#2aa198',
258
+ '#eee8d5', // S_base02
259
+ '#cb4b16',
260
+ '#dc322f', // S_base03
261
+ '#93a1a1', // S_base01
262
+ '#839496', // S_base00
263
+ '#657b83', // S_base0
264
+ '#6c71c4',
265
+ '#586e75', // S_base1
266
+ '#fdf6e3' // S_base3
267
+ ];
268
+ // Colors 16-255
269
+ // Much thanks to TooTallNate for writing this.
270
+ Terminal.colors = (function() {
271
+ var colors = Terminal.colors
272
+ , r = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff]
273
+ , i;
274
+
275
+ // 16-231
276
+ i = 0;
277
+ for (; i < 216; i++) {
278
+ out(r[(i / 36) % 6 | 0], r[(i / 6) % 6 | 0], r[i % 6]);
279
+ }
280
+
281
+ // 232-255 (grey)
282
+ i = 0;
283
+ for (; i < 24; i++) {
284
+ r = 8 + i * 10;
285
+ out(r, r, r);
286
+ }
287
+
288
+ function out(r, g, b) {
289
+ colors.push('#' + hex(r) + hex(g) + hex(b));
290
+ }
291
+
292
+ function hex(c) {
293
+ c = c.toString(16);
294
+ return c.length < 2 ? '0' + c : c;
295
+ }
296
+
297
+ return colors;
298
+ })();
299
+
300
+ // Default BG/FG
301
+ Terminal.defaultColors = {
302
+ bg: '#000000',
303
+ fg: '#f0f0f0'
304
+ };
305
+
306
+ Terminal.defaultColors = {
307
+ bg: '#fdf6e3', // base03
308
+ fg: '#657b83' // base0
309
+ };
310
+ Terminal.colors[256] = Terminal.defaultColors.bg;
311
+ Terminal.colors[257] = Terminal.defaultColors.fg;
312
+
313
+ /**
314
+ * Options
315
+ */
316
+
317
+ Terminal.termName = 'xterm-256color';
318
+ Terminal.geometry = [80, 24];
319
+ Terminal.cursorBlink = true;
320
+ Terminal.visualBell = false;
321
+ Terminal.popOnBell = false;
322
+ Terminal.scrollback = 1000;
323
+ Terminal.screenKeys = false;
324
+ Terminal.programFeatures = false;
325
+ Terminal.escapeKey = null;
326
+ Terminal.debug = false;
327
+
328
+ /**
329
+ * Focused Terminal
330
+ */
331
+
332
+ Terminal.focus = null;
333
+
334
+ Terminal.prototype.focus = function() {
335
+ if (Terminal.focus === this) return;
336
+ if (Terminal.focus) {
337
+ Terminal.focus.cursorState = 0;
338
+ Terminal.focus.refresh(Terminal.focus.y, Terminal.focus.y);
339
+ if (Terminal.focus.sendFocus) Terminal.focus.send('\x1b[O');
340
+ }
341
+ Terminal.focus = this;
342
+ if (this.sendFocus) this.send('\x1b[I');
343
+ this.showCursor();
344
+ };
345
+
346
+ /**
347
+ * Global Events for key handling
348
+ */
349
+
350
+ Terminal.bindKeys = function() {
351
+ if (Terminal.focus) return;
352
+
353
+ // We could put an "if (Terminal.focus)" check
354
+ // here, but it shouldn't be necessary.
355
+ on(document, 'keydown', function(ev) {
356
+ return Terminal.focus.keyDown(ev);
357
+ }, true);
358
+
359
+ on(document, 'keypress', function(ev) {
360
+ return Terminal.focus.keyPress(ev);
361
+ }, true);
362
+ };
363
+
364
+ /**
365
+ * Open Terminal
366
+ */
367
+
368
+ Terminal.prototype.open = function() {
369
+ var self = this
370
+ , i = 0
371
+ , div;
372
+
373
+ this.element = document.createElement('div');
374
+ this.element.className = 'terminal';
375
+ this.children = [];
376
+
377
+ for (; i < this.rows; i++) {
378
+ div = document.createElement('div');
379
+ this.element.appendChild(div);
380
+ this.children.push(div);
381
+ }
382
+
383
+ document.body.appendChild(this.element);
384
+
385
+ this.refresh(0, this.rows - 1);
386
+
387
+ Terminal.bindKeys();
388
+ this.focus();
389
+
390
+ this.startBlink();
391
+
392
+ on(this.element, 'mousedown', function() {
393
+ self.focus();
394
+ });
395
+
396
+ // This probably shouldn't work,
397
+ // ... but it does. Firefox's paste
398
+ // event seems to only work for textareas?
399
+ on(this.element, 'mousedown', function(ev) {
400
+ var button = ev.button != null
401
+ ? +ev.button
402
+ : ev.which != null
403
+ ? ev.which - 1
404
+ : null;
405
+
406
+ // Does IE9 do this?
407
+ if (~navigator.userAgent.indexOf('MSIE')) {
408
+ button = button === 1 ? 0 : button === 4 ? 1 : button;
409
+ }
410
+
411
+ if (button !== 2) return;
412
+
413
+ self.element.contentEditable = 'true';
414
+ setTimeout(function() {
415
+ self.element.contentEditable = 'inherit'; // 'false';
416
+ }, 1);
417
+ }, true);
418
+
419
+ on(this.element, 'paste', function(ev) {
420
+ if (ev.clipboardData) {
421
+ self.send(ev.clipboardData.getData('text/plain'));
422
+ } else if (window.clipboardData) {
423
+ self.send(window.clipboardData.getData('Text'));
424
+ }
425
+ // Not necessary. Do it anyway for good measure.
426
+ self.element.contentEditable = 'inherit';
427
+ return cancel(ev);
428
+ });
429
+
430
+ this.bindMouse();
431
+
432
+ // XXX - hack, move this somewhere else.
433
+ if (Terminal.brokenBold == null) {
434
+ Terminal.brokenBold = isBoldBroken();
435
+ }
436
+
437
+ // sync default bg/fg colors
438
+ this.element.style.backgroundColor = Terminal.defaultColors.bg;
439
+ this.element.style.color = Terminal.defaultColors.fg;
440
+
441
+ //this.emit('open');
442
+ };
443
+
444
+ // XTerm mouse events
445
+ // http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking
446
+ // To better understand these
447
+ // the xterm code is very helpful:
448
+ // Relevant files:
449
+ // button.c, charproc.c, misc.c
450
+ // Relevant functions in xterm/button.c:
451
+ // BtnCode, EmitButtonCode, EditorButton, SendMousePosition
452
+ Terminal.prototype.bindMouse = function() {
453
+ var el = this.element
454
+ , self = this
455
+ , pressed = 32;
456
+
457
+ var wheelEvent = 'onmousewheel' in window
458
+ ? 'mousewheel'
459
+ : 'DOMMouseScroll';
460
+
461
+ // mouseup, mousedown, mousewheel
462
+ // left click: ^[[M 3<^[[M#3<
463
+ // mousewheel up: ^[[M`3>
464
+ function sendButton(ev) {
465
+ var button
466
+ , pos;
467
+
468
+ // get the xterm-style button
469
+ button = getButton(ev);
470
+
471
+ // get mouse coordinates
472
+ pos = getCoords(ev);
473
+ if (!pos) return;
474
+
475
+ sendEvent(button, pos);
476
+
477
+ switch (ev.type) {
478
+ case 'mousedown':
479
+ pressed = button;
480
+ break;
481
+ case 'mouseup':
482
+ // keep it at the left
483
+ // button, just in case.
484
+ pressed = 32;
485
+ break;
486
+ case wheelEvent:
487
+ // nothing. don't
488
+ // interfere with
489
+ // `pressed`.
490
+ break;
491
+ }
492
+ }
493
+
494
+ // motion example of a left click:
495
+ // ^[[M 3<^[[M@4<^[[M@5<^[[M@6<^[[M@7<^[[M#7<
496
+ function sendMove(ev) {
497
+ var button = pressed
498
+ , pos;
499
+
500
+ pos = getCoords(ev);
501
+ if (!pos) return;
502
+
503
+ // buttons marked as motions
504
+ // are incremented by 32
505
+ button += 32;
506
+
507
+ sendEvent(button, pos);
508
+ }
509
+
510
+ // encode button and
511
+ // position to characters
512
+ function encode(data, ch) {
513
+ if (!self.utfMouse) {
514
+ if (ch === 255) return data.push(0);
515
+ if (ch > 127) ch = 127;
516
+ data.push(ch);
517
+ } else {
518
+ if (ch === 2047) return data.push(0);
519
+ if (ch < 127) {
520
+ data.push(ch);
521
+ } else {
522
+ if (ch > 2047) ch = 2047;
523
+ data.push(0xC0 | (ch >> 6));
524
+ data.push(0x80 | (ch & 0x3F));
525
+ }
526
+ }
527
+ }
528
+
529
+ // send a mouse event:
530
+ // regular/utf8: ^[[M Cb Cx Cy
531
+ // urxvt: ^[[ Cb ; Cx ; Cy M
532
+ // sgr: ^[[ Cb ; Cx ; Cy M/m
533
+ // vt300: ^[[ 24(1/3/5)~ [ Cx , Cy ] \r
534
+ // locator: CSI P e ; P b ; P r ; P c ; P p & w
535
+ function sendEvent(button, pos) {
536
+ // self.emit('mouse', {
537
+ // x: pos.x - 32,
538
+ // y: pos.x - 32,
539
+ // button: button
540
+ // });
541
+
542
+ if (self.vt300Mouse) {
543
+ // NOTE: Unstable.
544
+ // http://www.vt100.net/docs/vt3xx-gp/chapter15.html
545
+ button &= 3;
546
+ pos.x -= 32;
547
+ pos.y -= 32;
548
+ var data = '\x1b[24';
549
+ if (button === 0) data += '1';
550
+ else if (button === 1) data += '3';
551
+ else if (button === 2) data += '5';
552
+ else if (button === 3) return;
553
+ else data += '0';
554
+ data += '~[' + pos.x + ',' + pos.y + ']\r';
555
+ self.send(data);
556
+ return;
557
+ }
558
+
559
+ if (self.decLocator) {
560
+ // NOTE: Unstable.
561
+ button &= 3;
562
+ pos.x -= 32;
563
+ pos.y -= 32;
564
+ if (button === 0) button = 2;
565
+ else if (button === 1) button = 4;
566
+ else if (button === 2) button = 6;
567
+ else if (button === 3) button = 3;
568
+ self.send('\x1b['
569
+ + button
570
+ + ';'
571
+ + (button === 3 ? 4 : 0)
572
+ + ';'
573
+ + pos.y
574
+ + ';'
575
+ + pos.x
576
+ + ';'
577
+ + (pos.page || 0)
578
+ + '&w');
579
+ return;
580
+ }
581
+
582
+ if (self.urxvtMouse) {
583
+ pos.x -= 32;
584
+ pos.y -= 32;
585
+ pos.x++;
586
+ pos.y++;
587
+ self.send('\x1b[' + button + ';' + pos.x + ';' + pos.y + 'M');
588
+ return;
589
+ }
590
+
591
+ if (self.sgrMouse) {
592
+ pos.x -= 32;
593
+ pos.y -= 32;
594
+ self.send('\x1b[<'
595
+ + ((button & 3) === 3 ? button & ~3 : button)
596
+ + ';'
597
+ + pos.x
598
+ + ';'
599
+ + pos.y
600
+ + ((button & 3) === 3 ? 'm' : 'M'));
601
+ return;
602
+ }
603
+
604
+ var data = [];
605
+
606
+ encode(data, button);
607
+ encode(data, pos.x);
608
+ encode(data, pos.y);
609
+
610
+ self.send('\x1b[M' + String.fromCharCode.apply(String, data));
611
+ }
612
+
613
+ function getButton(ev) {
614
+ var button
615
+ , shift
616
+ , meta
617
+ , ctrl
618
+ , mod;
619
+
620
+ // two low bits:
621
+ // 0 = left
622
+ // 1 = middle
623
+ // 2 = right
624
+ // 3 = release
625
+ // wheel up/down:
626
+ // 1, and 2 - with 64 added
627
+ switch (ev.type) {
628
+ case 'mousedown':
629
+ button = ev.button != null
630
+ ? +ev.button
631
+ : ev.which != null
632
+ ? ev.which - 1
633
+ : null;
634
+
635
+ if (~navigator.userAgent.indexOf('MSIE')) {
636
+ button = button === 1 ? 0 : button === 4 ? 1 : button;
637
+ }
638
+ break;
639
+ case 'mouseup':
640
+ button = 3;
641
+ break;
642
+ case 'DOMMouseScroll':
643
+ button = ev.detail < 0
644
+ ? 64
645
+ : 65;
646
+ break;
647
+ case 'mousewheel':
648
+ button = ev.wheelDeltaY > 0
649
+ ? 64
650
+ : 65;
651
+ break;
652
+ }
653
+
654
+ // next three bits are the modifiers:
655
+ // 4 = shift, 8 = meta, 16 = control
656
+ shift = ev.shiftKey ? 4 : 0;
657
+ meta = ev.metaKey ? 8 : 0;
658
+ ctrl = ev.ctrlKey ? 16 : 0;
659
+ mod = shift | meta | ctrl;
660
+
661
+ // no mods
662
+ if (self.vt200Mouse) {
663
+ // ctrl only
664
+ mod &= ctrl;
665
+ } else if (!self.normalMouse) {
666
+ mod = 0;
667
+ }
668
+
669
+ // increment to SP
670
+ button = (32 + (mod << 2)) + button;
671
+
672
+ return button;
673
+ }
674
+
675
+ // mouse coordinates measured in cols/rows
676
+ function getCoords(ev) {
677
+ var x, y, w, h, el;
678
+
679
+ // ignore browsers without pageX for now
680
+ if (ev.pageX == null) return;
681
+
682
+ x = ev.pageX;
683
+ y = ev.pageY;
684
+ el = self.element;
685
+
686
+ // should probably check offsetParent
687
+ // but this is more portable
688
+ while (el !== document.documentElement) {
689
+ x -= el.offsetLeft;
690
+ y -= el.offsetTop;
691
+ el = el.parentNode;
692
+ }
693
+
694
+ // convert to cols/rows
695
+ w = self.element.clientWidth;
696
+ h = self.element.clientHeight;
697
+ x = ((x / w) * self.cols) | 0;
698
+ y = ((y / h) * self.rows) | 0;
699
+
700
+ // be sure to avoid sending
701
+ // bad positions to the program
702
+ if (x < 0) x = 0;
703
+ if (x > self.cols) x = self.cols;
704
+ if (y < 0) y = 0;
705
+ if (y > self.rows) y = self.rows;
706
+
707
+ // xterm sends raw bytes and
708
+ // starts at 32 (SP) for each.
709
+ x += 32;
710
+ y += 32;
711
+
712
+ return {
713
+ x: x,
714
+ y: y,
715
+ down: ev.type === 'mousedown',
716
+ up: ev.type === 'mouseup',
717
+ wheel: ev.type === wheelEvent,
718
+ move: ev.type === 'mousemove'
719
+ };
720
+ }
721
+
722
+ on(el, 'mousedown', function(ev) {
723
+ if (!self.mouseEvents) return;
724
+
725
+ // send the button
726
+ sendButton(ev);
727
+
728
+ // ensure focus
729
+ self.focus();
730
+
731
+ // fix for odd bug
732
+ if (self.vt200Mouse) {
733
+ sendButton({ __proto__: ev, type: 'mouseup' });
734
+ return cancel(ev);
735
+ }
736
+
737
+ // bind events
738
+ if (self.normalMouse) on(document, 'mousemove', sendMove);
739
+
740
+ // x10 compatibility mode can't send button releases
741
+ if (!self.x10Mouse) {
742
+ on(document, 'mouseup', function up(ev) {
743
+ sendButton(ev);
744
+ if (self.normalMouse) off(document, 'mousemove', sendMove);
745
+ off(document, 'mouseup', up);
746
+ return cancel(ev);
747
+ });
748
+ }
749
+
750
+ return cancel(ev);
751
+ });
752
+
753
+ on(el, wheelEvent, function(ev) {
754
+ if (!self.mouseEvents) return;
755
+ if (self.x10Mouse
756
+ || self.vt300Mouse
757
+ || self.decLocator) return;
758
+ sendButton(ev);
759
+ return cancel(ev);
760
+ });
761
+
762
+ // allow mousewheel scrolling in
763
+ // the shell for example
764
+ on(el, wheelEvent, function(ev) {
765
+ if (self.mouseEvents) return;
766
+ if (self.applicationKeypad) return;
767
+ if (ev.type === 'DOMMouseScroll') {
768
+ self.scrollDisp(ev.detail < 0 ? -5 : 5);
769
+ } else {
770
+ self.scrollDisp(ev.wheelDeltaY > 0 ? -5 : 5);
771
+ }
772
+ return cancel(ev);
773
+ });
774
+ };
775
+
776
+ /**
777
+ * Destroy Terminal
778
+ */
779
+
780
+ Terminal.prototype.destroy = function() {
781
+ this.readable = false;
782
+ this.writable = false;
783
+ this._events = {};
784
+ this.handler = function() {};
785
+ this.write = function() {};
786
+ //this.emit('close');
787
+ };
788
+
789
+ /**
790
+ * Rendering Engine
791
+ */
792
+
793
+ // In the screen buffer, each character
794
+ // is stored as a an array with a character
795
+ // and a 32-bit integer.
796
+ // First value: a utf-16 character.
797
+ // Second value:
798
+ // Next 9 bits: background color (0-511).
799
+ // Next 9 bits: foreground color (0-511).
800
+ // Next 14 bits: a mask for misc. flags:
801
+ // 1=bold, 2=underline, 4=inverse
802
+
803
+ Terminal.prototype.refresh = function(start, end) {
804
+ var x
805
+ , y
806
+ , i
807
+ , line
808
+ , out
809
+ , ch
810
+ , width
811
+ , data
812
+ , attr
813
+ , fgColor
814
+ , bgColor
815
+ , flags
816
+ , row
817
+ , parent;
818
+
819
+ if (end - start >= this.rows / 2) {
820
+ parent = this.element.parentNode;
821
+ if (parent) parent.removeChild(this.element);
822
+ }
823
+
824
+ width = this.cols;
825
+ y = start;
826
+
827
+ // if (end > this.lines.length) {
828
+ // end = this.lines.length;
829
+ // }
830
+
831
+ for (; y <= end; y++) {
832
+ row = y + this.ydisp;
833
+
834
+ line = this.lines[row];
835
+ if (typeof line === 'undefined') {
836
+ continue;
837
+ }
838
+ out = '';
839
+
840
+ if (y === this.y
841
+ && this.cursorState
842
+ && this.ydisp === this.ybase
843
+ && !this.cursorHidden) {
844
+ x = this.x;
845
+ } else {
846
+ x = -1;
847
+ }
848
+
849
+ attr = this.defAttr;
850
+ i = 0;
851
+
852
+ for (; i < width; i++) {
853
+ data = line[i][0];
854
+ ch = line[i][1];
855
+
856
+ if (i === x) data = -1;
857
+
858
+ if (data !== attr) {
859
+ if (attr !== this.defAttr) {
860
+ out += '</span>';
861
+ }
862
+ if (data !== this.defAttr) {
863
+ if (data === -1) {
864
+ out += '<span class="reverse-video">';
865
+ } else {
866
+ out += '<span style="';
867
+
868
+ bgColor = data & 0x1ff;
869
+ fgColor = (data >> 9) & 0x1ff;
870
+ flags = data >> 18;
871
+
872
+ if (flags & 1) {
873
+ if (!Terminal.brokenBold) {
874
+ out += 'font-weight:bold;';
875
+ }
876
+ // see: XTerm*boldColors
877
+ if (fgColor < 8) fgColor += 8;
878
+ }
879
+
880
+ if (flags & 2) {
881
+ out += 'text-decoration:underline;';
882
+ }
883
+
884
+ if (bgColor !== 256) {
885
+ out += 'background-color:'
886
+ + Terminal.colors[bgColor]
887
+ + ';';
888
+ }
889
+
890
+ if (fgColor !== 257) {
891
+ out += 'color:'
892
+ + Terminal.colors[fgColor]
893
+ + ';';
894
+ }
895
+
896
+ out += '">';
897
+ }
898
+ }
899
+ }
900
+
901
+ switch (ch) {
902
+ case '&':
903
+ out += '&amp;';
904
+ break;
905
+ case '<':
906
+ out += '&lt;';
907
+ break;
908
+ case '>':
909
+ out += '&gt;';
910
+ break;
911
+ default:
912
+ if (ch <= ' ') {
913
+ out += '&nbsp;';
914
+ } else {
915
+ out += ch;
916
+ }
917
+ break;
918
+ }
919
+
920
+ attr = data;
921
+ }
922
+
923
+ if (attr !== this.defAttr) {
924
+ out += '</span>';
925
+ }
926
+
927
+ this.children[y].innerHTML = out;
928
+ }
929
+
930
+ if (parent) parent.appendChild(this.element);
931
+ };
932
+
933
+ Terminal.prototype.cursorBlink = function() {
934
+ if (Terminal.focus !== this) return;
935
+ this.cursorState ^= 1;
936
+ this.refresh(this.y, this.y);
937
+ };
938
+
939
+ Terminal.prototype.showCursor = function() {
940
+ if (!this.cursorState) {
941
+ this.cursorState = 1;
942
+ this.refresh(this.y, this.y);
943
+ } else {
944
+ // Temporarily disabled:
945
+ // this.refreshBlink();
946
+ }
947
+ };
948
+
949
+ Terminal.prototype.startBlink = function() {
950
+ if (!Terminal.cursorBlink) return;
951
+ var self = this;
952
+ this._blinker = function() {
953
+ self.cursorBlink();
954
+ };
955
+ this._blink = setInterval(this._blinker, 500);
956
+ };
957
+
958
+ Terminal.prototype.refreshBlink = function() {
959
+ if (!Terminal.cursorBlink) return;
960
+ clearInterval(this._blink);
961
+ this._blink = setInterval(this._blinker, 500);
962
+ };
963
+
964
+ Terminal.prototype.scroll = function() {
965
+ var row;
966
+
967
+ if (++this.ybase === Terminal.scrollback) {
968
+ this.ybase = this.ybase / 2 | 0;
969
+ this.lines = this.lines.slice(-(this.ybase + this.rows) + 1);
970
+ }
971
+
972
+ this.ydisp = this.ybase;
973
+
974
+ // last line
975
+ row = this.ybase + this.rows - 1;
976
+
977
+ // subtract the bottom scroll region
978
+ row -= this.rows - 1 - this.scrollBottom;
979
+
980
+ if (row === this.lines.length) {
981
+ // potential optimization:
982
+ // pushing is faster than splicing
983
+ // when they amount to the same
984
+ // behavior.
985
+ this.lines.push(this.blankLine());
986
+ } else {
987
+ // add our new line
988
+ this.lines.splice(row, 0, this.blankLine());
989
+ }
990
+
991
+ if (this.scrollTop !== 0) {
992
+ if (this.ybase !== 0) {
993
+ this.ybase--;
994
+ this.ydisp = this.ybase;
995
+ }
996
+ this.lines.splice(this.ybase + this.scrollTop, 1);
997
+ }
998
+
999
+ // this.maxRange();
1000
+ this.updateRange(this.scrollTop);
1001
+ this.updateRange(this.scrollBottom);
1002
+ };
1003
+
1004
+ Terminal.prototype.scrollDisp = function(disp) {
1005
+ this.ydisp += disp;
1006
+
1007
+ if (this.ydisp > this.ybase) {
1008
+ this.ydisp = this.ybase;
1009
+ } else if (this.ydisp < 0) {
1010
+ this.ydisp = 0;
1011
+ }
1012
+
1013
+ this.refresh(0, this.rows - 1);
1014
+ };
1015
+
1016
+ Terminal.prototype.write = function(data) {
1017
+ var l = data.length
1018
+ , i = 0
1019
+ , cs
1020
+ , ch;
1021
+
1022
+ this.refreshStart = this.y;
1023
+ this.refreshEnd = this.y;
1024
+
1025
+ if (this.ybase !== this.ydisp) {
1026
+ this.ydisp = this.ybase;
1027
+ this.maxRange();
1028
+ }
1029
+
1030
+ // this.log(JSON.stringify(data.replace(/\x1b/g, '^[')));
1031
+
1032
+ for (; i < l; i++) {
1033
+ ch = data[i];
1034
+ switch (this.state) {
1035
+ case normal:
1036
+ switch (ch) {
1037
+ // '\0'
1038
+ // case '\0':
1039
+ // case '\200':
1040
+ // break;
1041
+
1042
+ // '\a'
1043
+ case '\x07':
1044
+ this.bell();
1045
+ break;
1046
+
1047
+ // '\n', '\v', '\f'
1048
+ case '\n':
1049
+ case '\x0b':
1050
+ case '\x0c':
1051
+ if (this.convertEol) {
1052
+ this.x = 0;
1053
+ }
1054
+ this.y++;
1055
+ if (this.y > this.scrollBottom) {
1056
+ this.y--;
1057
+ this.scroll();
1058
+ }
1059
+ break;
1060
+
1061
+ // '\r'
1062
+ case '\r':
1063
+ this.x = 0;
1064
+ break;
1065
+
1066
+ // '\b'
1067
+ case '\x08':
1068
+ if (this.x > 0) {
1069
+ this.x--;
1070
+ }
1071
+ break;
1072
+
1073
+ // '\t'
1074
+ case '\t':
1075
+ this.x = this.nextStop();
1076
+ break;
1077
+
1078
+ // shift out
1079
+ case '\x0e':
1080
+ this.setgLevel(1);
1081
+ break;
1082
+
1083
+ // shift in
1084
+ case '\x0f':
1085
+ this.setgLevel(0);
1086
+ break;
1087
+
1088
+ // '\e'
1089
+ case '\x1b':
1090
+ this.state = escaped;
1091
+ break;
1092
+
1093
+ default:
1094
+ // ' '
1095
+ if (ch >= ' ') {
1096
+ if (this.charset && this.charset[ch]) {
1097
+ ch = this.charset[ch];
1098
+ }
1099
+ if (this.x >= this.cols) {
1100
+ this.x = 0;
1101
+ this.y++;
1102
+ if (this.y > this.scrollBottom) {
1103
+ this.y--;
1104
+ this.scroll();
1105
+ }
1106
+ }
1107
+ if (typeof this.lines[this.y + this.ybase] !== 'undefined') {
1108
+ this.lines[this.y + this.ybase][this.x] = [this.curAttr, ch];
1109
+ }
1110
+ this.x++;
1111
+ this.updateRange(this.y);
1112
+ }
1113
+ break;
1114
+ }
1115
+ break;
1116
+ case escaped:
1117
+ switch (ch) {
1118
+ // ESC [ Control Sequence Introducer ( CSI is 0x9b).
1119
+ case '[':
1120
+ this.params = [];
1121
+ this.currentParam = 0;
1122
+ this.state = csi;
1123
+ break;
1124
+
1125
+ // ESC ] Operating System Command ( OSC is 0x9d).
1126
+ case ']':
1127
+ this.params = [];
1128
+ this.currentParam = 0;
1129
+ this.state = osc;
1130
+ break;
1131
+
1132
+ // ESC P Device Control String ( DCS is 0x90).
1133
+ case 'P':
1134
+ this.params = [];
1135
+ this.currentParam = 0;
1136
+ this.state = dcs;
1137
+ break;
1138
+
1139
+ // ESC _ Application Program Command ( APC is 0x9f).
1140
+ case '_':
1141
+ this.state = ignore;
1142
+ break;
1143
+
1144
+ // ESC ^ Privacy Message ( PM is 0x9e).
1145
+ case '^':
1146
+ this.state = ignore;
1147
+ break;
1148
+
1149
+ // ESC c Full Reset (RIS).
1150
+ case 'c':
1151
+ this.reset();
1152
+ break;
1153
+
1154
+ // ESC E Next Line ( NEL is 0x85).
1155
+ // ESC D Index ( IND is 0x84).
1156
+ case 'E':
1157
+ this.x = 0;
1158
+ ;
1159
+ case 'D':
1160
+ this.index();
1161
+ break;
1162
+
1163
+ // ESC M Reverse Index ( RI is 0x8d).
1164
+ case 'M':
1165
+ this.reverseIndex();
1166
+ break;
1167
+
1168
+ // ESC % Select default/utf-8 character set.
1169
+ // @ = default, G = utf-8
1170
+ case '%':
1171
+ //this.charset = null;
1172
+ this.setgLevel(0);
1173
+ this.setgCharset(0, Terminal.charsets.US);
1174
+ this.state = normal;
1175
+ i++;
1176
+ break;
1177
+
1178
+ // ESC (,),*,+,-,. Designate G0-G2 Character Set.
1179
+ case '(': // <-- this seems to get all the attention
1180
+ case ')':
1181
+ case '*':
1182
+ case '+':
1183
+ case '-':
1184
+ case '.':
1185
+ switch (ch) {
1186
+ case '(':
1187
+ this.gcharset = 0;
1188
+ break;
1189
+ case ')':
1190
+ this.gcharset = 1;
1191
+ break;
1192
+ case '*':
1193
+ this.gcharset = 2;
1194
+ break;
1195
+ case '+':
1196
+ this.gcharset = 3;
1197
+ break;
1198
+ case '-':
1199
+ this.gcharset = 1;
1200
+ break;
1201
+ case '.':
1202
+ this.gcharset = 2;
1203
+ break;
1204
+ }
1205
+ this.state = charset;
1206
+ break;
1207
+
1208
+ // Designate G3 Character Set (VT300).
1209
+ // A = ISO Latin-1 Supplemental.
1210
+ // Not implemented.
1211
+ case '/':
1212
+ this.gcharset = 3;
1213
+ this.state = charset;
1214
+ i--;
1215
+ break;
1216
+
1217
+ // ESC N
1218
+ // Single Shift Select of G2 Character Set
1219
+ // ( SS2 is 0x8e). This affects next character only.
1220
+ case 'N':
1221
+ break;
1222
+ // ESC O
1223
+ // Single Shift Select of G3 Character Set
1224
+ // ( SS3 is 0x8f). This affects next character only.
1225
+ case 'O':
1226
+ break;
1227
+ // ESC n
1228
+ // Invoke the G2 Character Set as GL (LS2).
1229
+ case 'n':
1230
+ this.setgLevel(2);
1231
+ break;
1232
+ // ESC o
1233
+ // Invoke the G3 Character Set as GL (LS3).
1234
+ case 'o':
1235
+ this.setgLevel(3);
1236
+ break;
1237
+ // ESC |
1238
+ // Invoke the G3 Character Set as GR (LS3R).
1239
+ case '|':
1240
+ this.setgLevel(3);
1241
+ break;
1242
+ // ESC }
1243
+ // Invoke the G2 Character Set as GR (LS2R).
1244
+ case '}':
1245
+ this.setgLevel(2);
1246
+ break;
1247
+ // ESC ~
1248
+ // Invoke the G1 Character Set as GR (LS1R).
1249
+ case '~':
1250
+ this.setgLevel(1);
1251
+ break;
1252
+
1253
+ // ESC 7 Save Cursor (DECSC).
1254
+ case '7':
1255
+ this.saveCursor();
1256
+ this.state = normal;
1257
+ break;
1258
+
1259
+ // ESC 8 Restore Cursor (DECRC).
1260
+ case '8':
1261
+ this.restoreCursor();
1262
+ this.state = normal;
1263
+ break;
1264
+
1265
+ // ESC # 3 DEC line height/width
1266
+ case '#':
1267
+ this.state = normal;
1268
+ i++;
1269
+ break;
1270
+
1271
+ // ESC H Tab Set (HTS is 0x88).
1272
+ case 'H':
1273
+ this.tabSet();
1274
+ break;
1275
+
1276
+ // ESC = Application Keypad (DECPAM).
1277
+ case '=':
1278
+ this.log('Serial port requested application keypad.');
1279
+ this.applicationKeypad = true;
1280
+ this.state = normal;
1281
+ break;
1282
+
1283
+ // ESC > Normal Keypad (DECPNM).
1284
+ case '>':
1285
+ this.log('Switching back to normal keypad.');
1286
+ this.applicationKeypad = false;
1287
+ this.state = normal;
1288
+ break;
1289
+
1290
+ default:
1291
+ this.state = normal;
1292
+ this.error('Unknown ESC control: %s.', ch);
1293
+ break;
1294
+ }
1295
+ break;
1296
+
1297
+ case charset:
1298
+ switch (ch) {
1299
+ case '0': // DEC Special Character and Line Drawing Set.
1300
+ cs = Terminal.charsets.SCLD;
1301
+ break;
1302
+ case 'A': // UK
1303
+ cs = Terminal.charsets.UK;
1304
+ break;
1305
+ case 'B': // United States (USASCII).
1306
+ cs = Terminal.charsets.US;
1307
+ break;
1308
+ case '4': // Dutch
1309
+ cs = Terminal.charsets.Dutch;
1310
+ break;
1311
+ case 'C': // Finnish
1312
+ case '5':
1313
+ cs = Terminal.charsets.Finnish;
1314
+ break;
1315
+ case 'R': // French
1316
+ cs = Terminal.charsets.French;
1317
+ break;
1318
+ case 'Q': // FrenchCanadian
1319
+ cs = Terminal.charsets.FrenchCanadian;
1320
+ break;
1321
+ case 'K': // German
1322
+ cs = Terminal.charsets.German;
1323
+ break;
1324
+ case 'Y': // Italian
1325
+ cs = Terminal.charsets.Italian;
1326
+ break;
1327
+ case 'E': // NorwegianDanish
1328
+ case '6':
1329
+ cs = Terminal.charsets.NorwegianDanish;
1330
+ break;
1331
+ case 'Z': // Spanish
1332
+ cs = Terminal.charsets.Spanish;
1333
+ break;
1334
+ case 'H': // Swedish
1335
+ case '7':
1336
+ cs = Terminal.charsets.Swedish;
1337
+ break;
1338
+ case '=': // Swiss
1339
+ cs = Terminal.charsets.Swiss;
1340
+ break;
1341
+ case '/': // ISOLatin (actually /A)
1342
+ cs = Terminal.charsets.ISOLatin;
1343
+ i++;
1344
+ break;
1345
+ default: // Default
1346
+ cs = Terminal.charsets.US;
1347
+ break;
1348
+ }
1349
+ this.setgCharset(this.gcharset, cs);
1350
+ this.gcharset = null;
1351
+ this.state = normal;
1352
+ break;
1353
+
1354
+ case osc:
1355
+ // OSC Ps ; Pt ST
1356
+ // OSC Ps ; Pt BEL
1357
+ // Set Text Parameters.
1358
+ if (ch === '\x1b' || ch === '\x07') {
1359
+ if (ch === '\x1b') i++;
1360
+
1361
+ this.params.push(this.currentParam);
1362
+
1363
+ switch (this.params[0]) {
1364
+ case 0:
1365
+ case 1:
1366
+ case 2:
1367
+ if (this.params[1]) {
1368
+ this.title = this.params[1];
1369
+ this.handleTitle(this.title);
1370
+ }
1371
+ break;
1372
+ case 3:
1373
+ // set X property
1374
+ break;
1375
+ case 4:
1376
+ case 5:
1377
+ // change dynamic colors
1378
+ break;
1379
+ case 10:
1380
+ case 11:
1381
+ case 12:
1382
+ case 13:
1383
+ case 14:
1384
+ case 15:
1385
+ case 16:
1386
+ case 17:
1387
+ case 18:
1388
+ case 19:
1389
+ // change dynamic ui colors
1390
+ break;
1391
+ case 46:
1392
+ // change log file
1393
+ break;
1394
+ case 50:
1395
+ // dynamic font
1396
+ break;
1397
+ case 51:
1398
+ // emacs shell
1399
+ break;
1400
+ case 52:
1401
+ // manipulate selection data
1402
+ break;
1403
+ case 104:
1404
+ case 105:
1405
+ case 110:
1406
+ case 111:
1407
+ case 112:
1408
+ case 113:
1409
+ case 114:
1410
+ case 115:
1411
+ case 116:
1412
+ case 117:
1413
+ case 118:
1414
+ // reset colors
1415
+ break;
1416
+ }
1417
+
1418
+ this.params = [];
1419
+ this.currentParam = 0;
1420
+ this.state = normal;
1421
+ } else {
1422
+ if (!this.params.length) {
1423
+ if (ch >= '0' && ch <= '9') {
1424
+ this.currentParam =
1425
+ this.currentParam * 10 + ch.charCodeAt(0) - 48;
1426
+ } else if (ch === ';') {
1427
+ this.params.push(this.currentParam);
1428
+ this.currentParam = '';
1429
+ }
1430
+ } else {
1431
+ this.currentParam += ch;
1432
+ }
1433
+ }
1434
+ break;
1435
+
1436
+ case csi:
1437
+ // '?', '>', '!'
1438
+ if (ch === '?' || ch === '>' || ch === '!') {
1439
+ this.prefix = ch;
1440
+ break;
1441
+ }
1442
+
1443
+ // 0 - 9
1444
+ if (ch >= '0' && ch <= '9') {
1445
+ this.currentParam = this.currentParam * 10 + ch.charCodeAt(0) - 48;
1446
+ break;
1447
+ }
1448
+
1449
+ // '$', '"', ' ', '\''
1450
+ if (ch === '$' || ch === '"' || ch === ' ' || ch === '\'') {
1451
+ this.postfix = ch;
1452
+ break;
1453
+ }
1454
+
1455
+ this.params.push(this.currentParam);
1456
+ this.currentParam = 0;
1457
+
1458
+ // ';'
1459
+ if (ch === ';') break;
1460
+
1461
+ this.state = normal;
1462
+
1463
+ switch (ch) {
1464
+ // CSI Ps A
1465
+ // Cursor Up Ps Times (default = 1) (CUU).
1466
+ case 'A':
1467
+ this.cursorUp(this.params);
1468
+ break;
1469
+
1470
+ // CSI Ps B
1471
+ // Cursor Down Ps Times (default = 1) (CUD).
1472
+ case 'B':
1473
+ this.cursorDown(this.params);
1474
+ break;
1475
+
1476
+ // CSI Ps C
1477
+ // Cursor Forward Ps Times (default = 1) (CUF).
1478
+ case 'C':
1479
+ this.cursorForward(this.params);
1480
+ break;
1481
+
1482
+ // CSI Ps D
1483
+ // Cursor Backward Ps Times (default = 1) (CUB).
1484
+ case 'D':
1485
+ this.cursorBackward(this.params);
1486
+ break;
1487
+
1488
+ // CSI Ps ; Ps H
1489
+ // Cursor Position [row;column] (default = [1,1]) (CUP).
1490
+ case 'H':
1491
+ this.cursorPos(this.params);
1492
+ break;
1493
+
1494
+ // CSI Ps J Erase in Display (ED).
1495
+ case 'J':
1496
+ this.eraseInDisplay(this.params);
1497
+ break;
1498
+
1499
+ // CSI Ps K Erase in Line (EL).
1500
+ case 'K':
1501
+ this.eraseInLine(this.params);
1502
+ break;
1503
+
1504
+ // CSI Pm m Character Attributes (SGR).
1505
+ case 'm':
1506
+ this.charAttributes(this.params);
1507
+ break;
1508
+
1509
+ // CSI Ps n Device Status Report (DSR).
1510
+ case 'n':
1511
+ this.deviceStatus(this.params);
1512
+ break;
1513
+
1514
+ /**
1515
+ * Additions
1516
+ */
1517
+
1518
+ // CSI Ps @
1519
+ // Insert Ps (Blank) Character(s) (default = 1) (ICH).
1520
+ case '@':
1521
+ this.insertChars(this.params);
1522
+ break;
1523
+
1524
+ // CSI Ps E
1525
+ // Cursor Next Line Ps Times (default = 1) (CNL).
1526
+ case 'E':
1527
+ this.cursorNextLine(this.params);
1528
+ break;
1529
+
1530
+ // CSI Ps F
1531
+ // Cursor Preceding Line Ps Times (default = 1) (CNL).
1532
+ case 'F':
1533
+ this.cursorPrecedingLine(this.params);
1534
+ break;
1535
+
1536
+ // CSI Ps G
1537
+ // Cursor Character Absolute [column] (default = [row,1]) (CHA).
1538
+ case 'G':
1539
+ this.cursorCharAbsolute(this.params);
1540
+ break;
1541
+
1542
+ // CSI Ps L
1543
+ // Insert Ps Line(s) (default = 1) (IL).
1544
+ case 'L':
1545
+ this.insertLines(this.params);
1546
+ break;
1547
+
1548
+ // CSI Ps M
1549
+ // Delete Ps Line(s) (default = 1) (DL).
1550
+ case 'M':
1551
+ this.deleteLines(this.params);
1552
+ break;
1553
+
1554
+ // CSI Ps P
1555
+ // Delete Ps Character(s) (default = 1) (DCH).
1556
+ case 'P':
1557
+ this.deleteChars(this.params);
1558
+ break;
1559
+
1560
+ // CSI Ps X
1561
+ // Erase Ps Character(s) (default = 1) (ECH).
1562
+ case 'X':
1563
+ this.eraseChars(this.params);
1564
+ break;
1565
+
1566
+ // CSI Pm ` Character Position Absolute
1567
+ // [column] (default = [row,1]) (HPA).
1568
+ case '`':
1569
+ this.charPosAbsolute(this.params);
1570
+ break;
1571
+
1572
+ // 141 61 a * HPR -
1573
+ // Horizontal Position Relative
1574
+ case 'a':
1575
+ this.HPositionRelative(this.params);
1576
+ break;
1577
+
1578
+ // CSI P s c
1579
+ // Send Device Attributes (Primary DA).
1580
+ // CSI > P s c
1581
+ // Send Device Attributes (Secondary DA)
1582
+ case 'c':
1583
+ this.sendDeviceAttributes(this.params);
1584
+ break;
1585
+
1586
+ // CSI Pm d
1587
+ // Line Position Absolute [row] (default = [1,column]) (VPA).
1588
+ case 'd':
1589
+ this.linePosAbsolute(this.params);
1590
+ break;
1591
+
1592
+ // 145 65 e * VPR - Vertical Position Relative
1593
+ case 'e':
1594
+ this.VPositionRelative(this.params);
1595
+ break;
1596
+
1597
+ // CSI Ps ; Ps f
1598
+ // Horizontal and Vertical Position [row;column] (default =
1599
+ // [1,1]) (HVP).
1600
+ case 'f':
1601
+ this.HVPosition(this.params);
1602
+ break;
1603
+
1604
+ // CSI Pm h Set Mode (SM).
1605
+ // CSI ? Pm h - mouse escape codes, cursor escape codes
1606
+ case 'h':
1607
+ this.setMode(this.params);
1608
+ break;
1609
+
1610
+ // CSI Pm l Reset Mode (RM).
1611
+ // CSI ? Pm l
1612
+ case 'l':
1613
+ this.resetMode(this.params);
1614
+ break;
1615
+
1616
+ // CSI Ps ; Ps r
1617
+ // Set Scrolling Region [top;bottom] (default = full size of win-
1618
+ // dow) (DECSTBM).
1619
+ // CSI ? Pm r
1620
+ case 'r':
1621
+ this.setScrollRegion(this.params);
1622
+ break;
1623
+
1624
+ // CSI s
1625
+ // Save cursor (ANSI.SYS).
1626
+ case 's':
1627
+ this.saveCursor(this.params);
1628
+ break;
1629
+
1630
+ // CSI u
1631
+ // Restore cursor (ANSI.SYS).
1632
+ case 'u':
1633
+ this.restoreCursor(this.params);
1634
+ break;
1635
+
1636
+ /**
1637
+ * Lesser Used
1638
+ */
1639
+
1640
+ // CSI Ps I
1641
+ // Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
1642
+ case 'I':
1643
+ this.cursorForwardTab(this.params);
1644
+ break;
1645
+
1646
+ // CSI Ps S Scroll up Ps lines (default = 1) (SU).
1647
+ case 'S':
1648
+ this.scrollUp(this.params);
1649
+ break;
1650
+
1651
+ // CSI Ps T Scroll down Ps lines (default = 1) (SD).
1652
+ // CSI Ps ; Ps ; Ps ; Ps ; Ps T
1653
+ // CSI > Ps; Ps T
1654
+ case 'T':
1655
+ // if (this.prefix === '>') {
1656
+ // this.resetTitleModes(this.params);
1657
+ // break;
1658
+ // }
1659
+ // if (this.params.length > 2) {
1660
+ // this.initMouseTracking(this.params);
1661
+ // break;
1662
+ // }
1663
+ if (this.params.length < 2 && !this.prefix) {
1664
+ this.scrollDown(this.params);
1665
+ }
1666
+ break;
1667
+
1668
+ // CSI Ps Z
1669
+ // Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
1670
+ case 'Z':
1671
+ this.cursorBackwardTab(this.params);
1672
+ break;
1673
+
1674
+ // CSI Ps b Repeat the preceding graphic character Ps times (REP).
1675
+ case 'b':
1676
+ this.repeatPrecedingCharacter(this.params);
1677
+ break;
1678
+
1679
+ // CSI Ps g Tab Clear (TBC).
1680
+ case 'g':
1681
+ this.tabClear(this.params);
1682
+ break;
1683
+
1684
+ // CSI Pm i Media Copy (MC).
1685
+ // CSI ? Pm i
1686
+ // case 'i':
1687
+ // this.mediaCopy(this.params);
1688
+ // break;
1689
+
1690
+ // CSI Pm m Character Attributes (SGR).
1691
+ // CSI > Ps; Ps m
1692
+ // case 'm': // duplicate
1693
+ // if (this.prefix === '>') {
1694
+ // this.setResources(this.params);
1695
+ // } else {
1696
+ // this.charAttributes(this.params);
1697
+ // }
1698
+ // break;
1699
+
1700
+ // CSI Ps n Device Status Report (DSR).
1701
+ // CSI > Ps n
1702
+ // case 'n': // duplicate
1703
+ // if (this.prefix === '>') {
1704
+ // this.disableModifiers(this.params);
1705
+ // } else {
1706
+ // this.deviceStatus(this.params);
1707
+ // }
1708
+ // break;
1709
+
1710
+ // CSI > Ps p Set pointer mode.
1711
+ // CSI ! p Soft terminal reset (DECSTR).
1712
+ // CSI Ps$ p
1713
+ // Request ANSI mode (DECRQM).
1714
+ // CSI ? Ps$ p
1715
+ // Request DEC private mode (DECRQM).
1716
+ // CSI Ps ; Ps " p
1717
+ case 'p':
1718
+ switch (this.prefix) {
1719
+ // case '>':
1720
+ // this.setPointerMode(this.params);
1721
+ // break;
1722
+ case '!':
1723
+ this.softReset(this.params);
1724
+ break;
1725
+ // case '?':
1726
+ // if (this.postfix === '$') {
1727
+ // this.requestPrivateMode(this.params);
1728
+ // }
1729
+ // break;
1730
+ // default:
1731
+ // if (this.postfix === '"') {
1732
+ // this.setConformanceLevel(this.params);
1733
+ // } else if (this.postfix === '$') {
1734
+ // this.requestAnsiMode(this.params);
1735
+ // }
1736
+ // break;
1737
+ }
1738
+ break;
1739
+
1740
+ // CSI Ps q Load LEDs (DECLL).
1741
+ // CSI Ps SP q
1742
+ // CSI Ps " q
1743
+ // case 'q':
1744
+ // if (this.postfix === ' ') {
1745
+ // this.setCursorStyle(this.params);
1746
+ // break;
1747
+ // }
1748
+ // if (this.postfix === '"') {
1749
+ // this.setCharProtectionAttr(this.params);
1750
+ // break;
1751
+ // }
1752
+ // this.loadLEDs(this.params);
1753
+ // break;
1754
+
1755
+ // CSI Ps ; Ps r
1756
+ // Set Scrolling Region [top;bottom] (default = full size of win-
1757
+ // dow) (DECSTBM).
1758
+ // CSI ? Pm r
1759
+ // CSI Pt; Pl; Pb; Pr; Ps$ r
1760
+ // case 'r': // duplicate
1761
+ // if (this.prefix === '?') {
1762
+ // this.restorePrivateValues(this.params);
1763
+ // } else if (this.postfix === '$') {
1764
+ // this.setAttrInRectangle(this.params);
1765
+ // } else {
1766
+ // this.setScrollRegion(this.params);
1767
+ // }
1768
+ // break;
1769
+
1770
+ // CSI s Save cursor (ANSI.SYS).
1771
+ // CSI ? Pm s
1772
+ // case 's': // duplicate
1773
+ // if (this.prefix === '?') {
1774
+ // this.savePrivateValues(this.params);
1775
+ // } else {
1776
+ // this.saveCursor(this.params);
1777
+ // }
1778
+ // break;
1779
+
1780
+ // CSI Ps ; Ps ; Ps t
1781
+ // CSI Pt; Pl; Pb; Pr; Ps$ t
1782
+ // CSI > Ps; Ps t
1783
+ // CSI Ps SP t
1784
+ // case 't':
1785
+ // if (this.postfix === '$') {
1786
+ // this.reverseAttrInRectangle(this.params);
1787
+ // } else if (this.postfix === ' ') {
1788
+ // this.setWarningBellVolume(this.params);
1789
+ // } else {
1790
+ // if (this.prefix === '>') {
1791
+ // this.setTitleModeFeature(this.params);
1792
+ // } else {
1793
+ // this.manipulateWindow(this.params);
1794
+ // }
1795
+ // }
1796
+ // break;
1797
+
1798
+ // CSI u Restore cursor (ANSI.SYS).
1799
+ // CSI Ps SP u
1800
+ // case 'u': // duplicate
1801
+ // if (this.postfix === ' ') {
1802
+ // this.setMarginBellVolume(this.params);
1803
+ // } else {
1804
+ // this.restoreCursor(this.params);
1805
+ // }
1806
+ // break;
1807
+
1808
+ // CSI Pt; Pl; Pb; Pr; Pp; Pt; Pl; Pp$ v
1809
+ // case 'v':
1810
+ // if (this.postfix === '$') {
1811
+ // this.copyRectagle(this.params);
1812
+ // }
1813
+ // break;
1814
+
1815
+ // CSI Pt ; Pl ; Pb ; Pr ' w
1816
+ // case 'w':
1817
+ // if (this.postfix === '\'') {
1818
+ // this.enableFilterRectangle(this.params);
1819
+ // }
1820
+ // break;
1821
+
1822
+ // CSI Ps x Request Terminal Parameters (DECREQTPARM).
1823
+ // CSI Ps x Select Attribute Change Extent (DECSACE).
1824
+ // CSI Pc; Pt; Pl; Pb; Pr$ x
1825
+ // case 'x':
1826
+ // if (this.postfix === '$') {
1827
+ // this.fillRectangle(this.params);
1828
+ // } else {
1829
+ // this.requestParameters(this.params);
1830
+ // //this.__(this.params);
1831
+ // }
1832
+ // break;
1833
+
1834
+ // CSI Ps ; Pu ' z
1835
+ // CSI Pt; Pl; Pb; Pr$ z
1836
+ // case 'z':
1837
+ // if (this.postfix === '\'') {
1838
+ // this.enableLocatorReporting(this.params);
1839
+ // } else if (this.postfix === '$') {
1840
+ // this.eraseRectangle(this.params);
1841
+ // }
1842
+ // break;
1843
+
1844
+ // CSI Pm ' {
1845
+ // CSI Pt; Pl; Pb; Pr$ {
1846
+ // case '{':
1847
+ // if (this.postfix === '\'') {
1848
+ // this.setLocatorEvents(this.params);
1849
+ // } else if (this.postfix === '$') {
1850
+ // this.selectiveEraseRectangle(this.params);
1851
+ // }
1852
+ // break;
1853
+
1854
+ // CSI Ps ' |
1855
+ // case '|':
1856
+ // if (this.postfix === '\'') {
1857
+ // this.requestLocatorPosition(this.params);
1858
+ // }
1859
+ // break;
1860
+
1861
+ // CSI P m SP }
1862
+ // Insert P s Column(s) (default = 1) (DECIC), VT420 and up.
1863
+ // case '}':
1864
+ // if (this.postfix === ' ') {
1865
+ // this.insertColumns(this.params);
1866
+ // }
1867
+ // break;
1868
+
1869
+ // CSI P m SP ~
1870
+ // Delete P s Column(s) (default = 1) (DECDC), VT420 and up
1871
+ // case '~':
1872
+ // if (this.postfix === ' ') {
1873
+ // this.deleteColumns(this.params);
1874
+ // }
1875
+ // break;
1876
+
1877
+ default:
1878
+ this.error('Unknown CSI code: %s.', ch);
1879
+ break;
1880
+ }
1881
+
1882
+ this.prefix = '';
1883
+ this.postfix = '';
1884
+ break;
1885
+
1886
+ case dcs:
1887
+ if (ch === '\x1b' || ch === '\x07') {
1888
+ if (ch === '\x1b') i++;
1889
+
1890
+ switch (this.prefix) {
1891
+ // User-Defined Keys (DECUDK).
1892
+ case '':
1893
+ break;
1894
+
1895
+ // Request Status String (DECRQSS).
1896
+ // test: echo -e '\eP$q"p\e\\'
1897
+ case '$q':
1898
+ var pt = this.currentParam
1899
+ , valid = false;
1900
+
1901
+ switch (pt) {
1902
+ // DECSCA
1903
+ case '"q':
1904
+ pt = '0"q';
1905
+ break;
1906
+
1907
+ // DECSCL
1908
+ case '"p':
1909
+ pt = '61"p';
1910
+ break;
1911
+
1912
+ // DECSTBM
1913
+ case 'r':
1914
+ pt = ''
1915
+ + (this.scrollTop + 1)
1916
+ + ';'
1917
+ + (this.scrollBottom + 1)
1918
+ + 'r';
1919
+ break;
1920
+
1921
+ // SGR
1922
+ case 'm':
1923
+ pt = '0m';
1924
+ break;
1925
+
1926
+ default:
1927
+ this.error('Unknown DCS Pt: %s.', pt);
1928
+ pt = '';
1929
+ break;
1930
+ }
1931
+
1932
+ this.send('\x1bP' + +valid + '$r' + pt + '\x1b\\');
1933
+ break;
1934
+
1935
+ // Set Termcap/Terminfo Data (xterm, experimental).
1936
+ case '+p':
1937
+ break;
1938
+
1939
+ // Request Termcap/Terminfo String (xterm, experimental)
1940
+ // Regular xterm does not even respond to this sequence.
1941
+ // This can cause a small glitch in vim.
1942
+ // test: echo -ne '\eP+q6b64\e\\'
1943
+ case '+q':
1944
+ var pt = this.currentParam
1945
+ , valid = false;
1946
+
1947
+ this.send('\x1bP' + +valid + '+r' + pt + '\x1b\\');
1948
+ break;
1949
+
1950
+ default:
1951
+ this.error('Unknown DCS prefix: %s.', this.prefix);
1952
+ break;
1953
+ }
1954
+
1955
+ this.currentParam = 0;
1956
+ this.prefix = '';
1957
+ this.state = normal;
1958
+ } else if (!this.currentParam) {
1959
+ if (!this.prefix && ch !== '$' && ch !== '+') {
1960
+ this.currentParam = ch;
1961
+ } else if (this.prefix.length === 2) {
1962
+ this.currentParam = ch;
1963
+ } else {
1964
+ this.prefix += ch;
1965
+ }
1966
+ } else {
1967
+ this.currentParam += ch;
1968
+ }
1969
+ break;
1970
+
1971
+ case ignore:
1972
+ // For PM and APC.
1973
+ if (ch === '\x1b' || ch === '\x07') {
1974
+ if (ch === '\x1b') i++;
1975
+ this.state = normal;
1976
+ }
1977
+ break;
1978
+ }
1979
+ }
1980
+
1981
+ this.updateRange(this.y);
1982
+ this.refresh(this.refreshStart, this.refreshEnd);
1983
+ };
1984
+
1985
+ Terminal.prototype.writeln = function(data) {
1986
+ this.write(data + '\r\n');
1987
+ };
1988
+
1989
+ // Key Resources:
1990
+ // https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
1991
+ Terminal.prototype.keyDown = function(ev) {
1992
+ var key;
1993
+
1994
+ switch (ev.keyCode) {
1995
+ // backspace
1996
+ case 8:
1997
+ if (ev.shiftKey) {
1998
+ key = '\x08'; // ^H
1999
+ break;
2000
+ }
2001
+ key = '\x7f'; // ^?
2002
+ break;
2003
+ // tab
2004
+ case 9:
2005
+ if (ev.shiftKey) {
2006
+ key = '\x1b[Z';
2007
+ break;
2008
+ }
2009
+ key = '\t';
2010
+ break;
2011
+ // return/enter
2012
+ case 13:
2013
+ key = '\r';
2014
+ break;
2015
+ // escape
2016
+ case 27:
2017
+ key = '\x1b';
2018
+ break;
2019
+ // left-arrow
2020
+ case 37:
2021
+ if (this.applicationCursor) {
2022
+ key = '\x1bOD'; // SS3 as ^[O for 7-bit
2023
+ //key = '\x8fD'; // SS3 as 0x8f for 8-bit
2024
+ break;
2025
+ }
2026
+ key = '\x1b[D';
2027
+ break;
2028
+ // right-arrow
2029
+ case 39:
2030
+ if (this.applicationCursor) {
2031
+ key = '\x1bOC';
2032
+ break;
2033
+ }
2034
+ key = '\x1b[C';
2035
+ break;
2036
+ // up-arrow
2037
+ case 38:
2038
+ if (this.applicationCursor) {
2039
+ key = '\x1bOA';
2040
+ break;
2041
+ }
2042
+ if (ev.ctrlKey) {
2043
+ this.scrollDisp(-1);
2044
+ return cancel(ev);
2045
+ } else {
2046
+ key = '\x1b[A';
2047
+ }
2048
+ break;
2049
+ // down-arrow
2050
+ case 40:
2051
+ if (this.applicationCursor) {
2052
+ key = '\x1bOB';
2053
+ break;
2054
+ }
2055
+ if (ev.ctrlKey) {
2056
+ this.scrollDisp(1);
2057
+ return cancel(ev);
2058
+ } else {
2059
+ key = '\x1b[B';
2060
+ }
2061
+ break;
2062
+ // delete
2063
+ case 46:
2064
+ key = '\x1b[3~';
2065
+ break;
2066
+ // insert
2067
+ case 45:
2068
+ key = '\x1b[2~';
2069
+ break;
2070
+ // home
2071
+ case 36:
2072
+ if (this.applicationKeypad) {
2073
+ key = '\x1bOH';
2074
+ break;
2075
+ }
2076
+ key = '\x1bOH';
2077
+ break;
2078
+ // end
2079
+ case 35:
2080
+ if (this.applicationKeypad) {
2081
+ key = '\x1bOF';
2082
+ break;
2083
+ }
2084
+ key = '\x1bOF';
2085
+ break;
2086
+ // page up
2087
+ case 33:
2088
+ if (ev.shiftKey) {
2089
+ this.scrollDisp(-(this.rows - 1));
2090
+ return cancel(ev);
2091
+ } else {
2092
+ key = '\x1b[5~';
2093
+ }
2094
+ break;
2095
+ // page down
2096
+ case 34:
2097
+ if (ev.shiftKey) {
2098
+ this.scrollDisp(this.rows - 1);
2099
+ return cancel(ev);
2100
+ } else {
2101
+ key = '\x1b[6~';
2102
+ }
2103
+ break;
2104
+ // F1
2105
+ case 112:
2106
+ key = '\x1bOP';
2107
+ break;
2108
+ // F2
2109
+ case 113:
2110
+ key = '\x1bOQ';
2111
+ break;
2112
+ // F3
2113
+ case 114:
2114
+ key = '\x1bOR';
2115
+ break;
2116
+ // F4
2117
+ case 115:
2118
+ key = '\x1bOS';
2119
+ break;
2120
+ // F5
2121
+ case 116:
2122
+ key = '\x1b[15~';
2123
+ break;
2124
+ // F6
2125
+ case 117:
2126
+ key = '\x1b[17~';
2127
+ break;
2128
+ // F7
2129
+ case 118:
2130
+ key = '\x1b[18~';
2131
+ break;
2132
+ // F8
2133
+ case 119:
2134
+ key = '\x1b[19~';
2135
+ break;
2136
+ // F9
2137
+ case 120:
2138
+ key = '\x1b[20~';
2139
+ break;
2140
+ // F10
2141
+ case 121:
2142
+ key = '\x1b[21~';
2143
+ break;
2144
+ // F11
2145
+ case 122:
2146
+ key = '\x1b[23~';
2147
+ break;
2148
+ // F12
2149
+ case 123:
2150
+ key = '\x1b[24~';
2151
+ break;
2152
+ default:
2153
+ // a-z and space
2154
+ if (ev.ctrlKey) {
2155
+ if (ev.keyCode >= 65 && ev.keyCode <= 90) {
2156
+ key = String.fromCharCode(ev.keyCode - 64);
2157
+ } else if (ev.keyCode === 32) {
2158
+ // NUL
2159
+ key = String.fromCharCode(0);
2160
+ } else if (ev.keyCode >= 51 && ev.keyCode <= 55) {
2161
+ // escape, file sep, group sep, record sep, unit sep
2162
+ key = String.fromCharCode(ev.keyCode - 51 + 27);
2163
+ } else if (ev.keyCode === 56) {
2164
+ // delete
2165
+ key = String.fromCharCode(127);
2166
+ } else if (ev.keyCode === 219) {
2167
+ // ^[ - escape
2168
+ key = String.fromCharCode(27);
2169
+ } else if (ev.keyCode === 221) {
2170
+ // ^] - group sep
2171
+ key = String.fromCharCode(29);
2172
+ }
2173
+ } else if ((!isMac && ev.altKey) || (isMac && ev.metaKey)) {
2174
+ if (ev.keyCode >= 65 && ev.keyCode <= 90) {
2175
+ key = '\x1b' + String.fromCharCode(ev.keyCode + 32);
2176
+ } else if (ev.keyCode === 192) {
2177
+ key = '\x1b`';
2178
+ } else if (ev.keyCode >= 48 && ev.keyCode <= 57) {
2179
+ key = '\x1b' + (ev.keyCode - 48);
2180
+ }
2181
+ }
2182
+ break;
2183
+ }
2184
+
2185
+ this.emit('keydown', ev);
2186
+ // if (this.emit('keydown', key, ev) === false) { this.showCursor(); cancel(ev); return; }
2187
+
2188
+ if (key) {
2189
+ this.emit('key', key, ev);
2190
+ // if (this.emit('key', key, ev) === false) { this.showCursor(); cancel(ev); return; }
2191
+
2192
+ this.showCursor();
2193
+ this.handler(key);
2194
+
2195
+ return cancel(ev);
2196
+ }
2197
+
2198
+ return true;
2199
+ };
2200
+
2201
+ Terminal.prototype.setgLevel = function(g) {
2202
+ this.glevel = g;
2203
+ this.charset = this.charsets[g];
2204
+ };
2205
+
2206
+ Terminal.prototype.setgCharset = function(g, charset) {
2207
+ this.charsets[g] = charset;
2208
+ if (this.glevel === g) {
2209
+ this.charset = charset;
2210
+ }
2211
+ };
2212
+
2213
+ Terminal.prototype.keyPress = function(ev) {
2214
+ var key;
2215
+
2216
+ cancel(ev);
2217
+
2218
+ if (ev.charCode) {
2219
+ key = ev.charCode;
2220
+ } else if (ev.which == null) {
2221
+ key = ev.keyCode;
2222
+ } else if (ev.which !== 0 && ev.charCode !== 0) {
2223
+ key = ev.which;
2224
+ } else {
2225
+ return false;
2226
+ }
2227
+
2228
+ if (!key || ev.ctrlKey || ev.altKey || ev.metaKey) return false;
2229
+
2230
+ key = String.fromCharCode(key);
2231
+
2232
+ this.emit('keypress', key, ev);
2233
+ // if (this.emit('keypress', key, ev) === false) { this.showCursor(); return; }
2234
+ this.emit('key', key, ev);
2235
+ // if (this.emit('key', key, ev) === false) { this.showCursor(); return; }
2236
+
2237
+ this.showCursor();
2238
+ this.handler(key);
2239
+
2240
+ return false;
2241
+ };
2242
+
2243
+ Terminal.prototype.send = function(data) {
2244
+ var self = this;
2245
+
2246
+ if (!this.queue) {
2247
+ setTimeout(function() {
2248
+ self.handler(self.queue);
2249
+ self.queue = '';
2250
+ }, 1);
2251
+ }
2252
+
2253
+ this.queue += data;
2254
+ };
2255
+
2256
+ Terminal.prototype.bell = function() {
2257
+ if (!Terminal.visualBell) return;
2258
+ var self = this;
2259
+ this.element.style.borderColor = 'white';
2260
+ setTimeout(function() {
2261
+ self.element.style.borderColor = '';
2262
+ }, 10);
2263
+ if (Terminal.popOnBell) this.focus();
2264
+ };
2265
+
2266
+ Terminal.prototype.log = function() {
2267
+ if (!Terminal.debug) return;
2268
+ if (!window.console || !window.console.log) return;
2269
+ var args = Array.prototype.slice.call(arguments);
2270
+ window.console.log.apply(window.console, args);
2271
+ };
2272
+
2273
+ Terminal.prototype.error = function() {
2274
+ if (!Terminal.debug) return;
2275
+ if (!window.console || !window.console.error) return;
2276
+ var args = Array.prototype.slice.call(arguments);
2277
+ window.console.error.apply(window.console, args);
2278
+ };
2279
+
2280
+ Terminal.prototype.resize = function(x, y) {
2281
+ var line
2282
+ , el
2283
+ , i
2284
+ , j
2285
+ , ch;
2286
+
2287
+ if (x < 1) x = 1;
2288
+ if (y < 1) y = 1;
2289
+
2290
+ // resize cols
2291
+ j = this.cols;
2292
+ if (j < x) {
2293
+ ch = [this.defAttr, ' '];
2294
+ i = this.lines.length;
2295
+ while (i--) {
2296
+ while (this.lines[i].length < x) {
2297
+ this.lines[i].push(ch);
2298
+ }
2299
+ }
2300
+ } else if (j > x) {
2301
+ i = this.lines.length;
2302
+ while (i--) {
2303
+ while (this.lines[i].length > x) {
2304
+ this.lines[i].pop();
2305
+ }
2306
+ }
2307
+ }
2308
+ this.setupStops(j);
2309
+ this.cols = x;
2310
+
2311
+ // resize rows
2312
+ j = this.rows;
2313
+ if (j < y) {
2314
+ el = this.element;
2315
+ while (j++ < y) {
2316
+ if (this.lines.length < y + this.ybase) {
2317
+ this.lines.push(this.blankLine());
2318
+ }
2319
+ if (this.children.length < y) {
2320
+ line = document.createElement('div');
2321
+ el.appendChild(line);
2322
+ this.children.push(line);
2323
+ }
2324
+ }
2325
+ } else if (j > y) {
2326
+ while (j-- > y) {
2327
+ if (this.lines.length > y + this.ybase) {
2328
+ this.lines.pop();
2329
+ }
2330
+ if (this.children.length > y) {
2331
+ el = this.children.pop();
2332
+ if (!el) continue;
2333
+ el.parentNode.removeChild(el);
2334
+ }
2335
+ }
2336
+ }
2337
+ this.rows = y;
2338
+
2339
+ // make sure the cursor stays on screen
2340
+ if (this.y >= y) this.y = y - 1;
2341
+ if (this.x >= x) this.x = x - 1;
2342
+
2343
+ this.scrollTop = 0;
2344
+ this.scrollBottom = y - 1;
2345
+
2346
+ this.refresh(0, this.rows - 1);
2347
+
2348
+ // it's a real nightmare trying
2349
+ // to resize the original
2350
+ // screen buffer. just set it
2351
+ // to null for now.
2352
+ this.normal = null;
2353
+ };
2354
+
2355
+ Terminal.prototype.updateRange = function(y) {
2356
+ if (y < this.refreshStart) this.refreshStart = y;
2357
+ if (y > this.refreshEnd) this.refreshEnd = y;
2358
+ // if (y > this.refreshEnd) {
2359
+ // this.refreshEnd = y;
2360
+ // if (y > this.rows - 1) {
2361
+ // this.refreshEnd = this.rows - 1;
2362
+ // }
2363
+ // }
2364
+ };
2365
+
2366
+ Terminal.prototype.maxRange = function() {
2367
+ this.refreshStart = 0;
2368
+ this.refreshEnd = this.rows - 1;
2369
+ };
2370
+
2371
+ Terminal.prototype.setupStops = function(i) {
2372
+ if (i != null) {
2373
+ if (!this.tabs[i]) {
2374
+ i = this.prevStop(i);
2375
+ }
2376
+ } else {
2377
+ this.tabs = {};
2378
+ i = 0;
2379
+ }
2380
+
2381
+ for (; i < this.cols; i += 8) {
2382
+ this.tabs[i] = true;
2383
+ }
2384
+ };
2385
+
2386
+ Terminal.prototype.prevStop = function(x) {
2387
+ if (x == null) x = this.x;
2388
+ while (!this.tabs[--x] && x > 0);
2389
+ return x >= this.cols
2390
+ ? this.cols - 1
2391
+ : x < 0 ? 0 : x;
2392
+ };
2393
+
2394
+ Terminal.prototype.nextStop = function(x) {
2395
+ if (x == null) x = this.x;
2396
+ while (!this.tabs[++x] && x < this.cols);
2397
+ return x >= this.cols
2398
+ ? this.cols - 1
2399
+ : x < 0 ? 0 : x;
2400
+ };
2401
+
2402
+ Terminal.prototype.eraseRight = function(x, y) {
2403
+ var line = this.lines[this.ybase + y]
2404
+ , ch = [this.curAttr, ' ']; // xterm
2405
+ if (typeof line !== 'undefined') {
2406
+ for (; x < this.cols; x++) {
2407
+ line[x] = ch;
2408
+ }
2409
+ }
2410
+
2411
+ this.updateRange(y);
2412
+ };
2413
+
2414
+ Terminal.prototype.eraseLeft = function(x, y) {
2415
+ var line = this.lines[this.ybase + y]
2416
+ , ch = [this.curAttr, ' ']; // xterm
2417
+
2418
+ x++;
2419
+ while (x--) {
2420
+ if (typeof line[x] !== 'undefined') {
2421
+ line[x] = ch;
2422
+ }
2423
+ }
2424
+
2425
+ this.updateRange(y);
2426
+ };
2427
+
2428
+ Terminal.prototype.eraseLine = function(y) {
2429
+ this.eraseRight(0, y);
2430
+ };
2431
+
2432
+ Terminal.prototype.blankLine = function(cur) {
2433
+ var attr = cur
2434
+ ? this.curAttr
2435
+ : this.defAttr;
2436
+
2437
+ var ch = [attr, ' ']
2438
+ , line = []
2439
+ , i = 0;
2440
+
2441
+ for (; i < this.cols; i++) {
2442
+ line[i] = ch;
2443
+ }
2444
+
2445
+ return line;
2446
+ };
2447
+
2448
+ Terminal.prototype.ch = function(cur) {
2449
+ return cur
2450
+ ? [this.curAttr, ' ']
2451
+ : [this.defAttr, ' '];
2452
+ };
2453
+
2454
+ Terminal.prototype.is = function(term) {
2455
+ var name = this.termName || Terminal.termName;
2456
+ return (name + '').indexOf(term) === 0;
2457
+ };
2458
+
2459
+ Terminal.prototype.handler = function(data) {
2460
+ this.emit('data', data);
2461
+ };
2462
+
2463
+ Terminal.prototype.handleTitle = function(title) {
2464
+ this.emit('title', title);
2465
+ };
2466
+
2467
+ /**
2468
+ * ESC
2469
+ */
2470
+
2471
+ // ESC D Index (IND is 0x84).
2472
+ Terminal.prototype.index = function() {
2473
+ this.y++;
2474
+ if (this.y > this.scrollBottom) {
2475
+ this.y--;
2476
+ this.scroll();
2477
+ }
2478
+ this.state = normal;
2479
+ };
2480
+
2481
+ // ESC M Reverse Index (RI is 0x8d).
2482
+ Terminal.prototype.reverseIndex = function() {
2483
+ var j;
2484
+ this.y--;
2485
+ if (this.y < this.scrollTop) {
2486
+ this.y++;
2487
+ // possibly move the code below to term.reverseScroll();
2488
+ // test: echo -ne '\e[1;1H\e[44m\eM\e[0m'
2489
+ // blankLine(true) is xterm/linux behavior
2490
+ this.lines.splice(this.y + this.ybase, 0, this.blankLine(true));
2491
+ j = this.rows - 1 - this.scrollBottom;
2492
+ this.lines.splice(this.rows - 1 + this.ybase - j + 1, 1);
2493
+ // this.maxRange();
2494
+ this.updateRange(this.scrollTop);
2495
+ this.updateRange(this.scrollBottom);
2496
+ }
2497
+ this.state = normal;
2498
+ };
2499
+
2500
+ // ESC c Full Reset (RIS).
2501
+ Terminal.prototype.reset = function() {
2502
+ Terminal.call(this, this.cols, this.rows);
2503
+ this.refresh(0, this.rows - 1);
2504
+ };
2505
+
2506
+ // ESC H Tab Set (HTS is 0x88).
2507
+ Terminal.prototype.tabSet = function() {
2508
+ this.tabs[this.x] = true;
2509
+ this.state = normal;
2510
+ };
2511
+
2512
+ /**
2513
+ * CSI
2514
+ */
2515
+
2516
+ // CSI Ps A
2517
+ // Cursor Up Ps Times (default = 1) (CUU).
2518
+ Terminal.prototype.cursorUp = function(params) {
2519
+ var param = params[0];
2520
+ if (param < 1) param = 1;
2521
+ this.y -= param;
2522
+ if (this.y < 0) this.y = 0;
2523
+ };
2524
+
2525
+ // CSI Ps B
2526
+ // Cursor Down Ps Times (default = 1) (CUD).
2527
+ Terminal.prototype.cursorDown = function(params) {
2528
+ var param = params[0];
2529
+ if (param < 1) param = 1;
2530
+ this.y += param;
2531
+ if (this.y >= this.rows) {
2532
+ this.y = this.rows - 1;
2533
+ }
2534
+ };
2535
+
2536
+ // CSI Ps C
2537
+ // Cursor Forward Ps Times (default = 1) (CUF).
2538
+ Terminal.prototype.cursorForward = function(params) {
2539
+ var param = params[0];
2540
+ if (param < 1) param = 1;
2541
+ this.x += param;
2542
+ if (this.x >= this.cols) {
2543
+ this.x = this.cols - 1;
2544
+ }
2545
+ };
2546
+
2547
+ // CSI Ps D
2548
+ // Cursor Backward Ps Times (default = 1) (CUB).
2549
+ Terminal.prototype.cursorBackward = function(params) {
2550
+ var param = params[0];
2551
+ if (param < 1) param = 1;
2552
+ this.x -= param;
2553
+ if (this.x < 0) this.x = 0;
2554
+ };
2555
+
2556
+ // CSI Ps ; Ps H
2557
+ // Cursor Position [row;column] (default = [1,1]) (CUP).
2558
+ Terminal.prototype.cursorPos = function(params) {
2559
+ var row, col;
2560
+
2561
+ row = params[0] - 1;
2562
+
2563
+ if (params.length >= 2) {
2564
+ col = params[1] - 1;
2565
+ } else {
2566
+ col = 0;
2567
+ }
2568
+
2569
+ if (row < 0) {
2570
+ row = 0;
2571
+ } else if (row >= this.rows) {
2572
+ row = this.rows - 1;
2573
+ }
2574
+
2575
+ if (col < 0) {
2576
+ col = 0;
2577
+ } else if (col >= this.cols) {
2578
+ col = this.cols - 1;
2579
+ }
2580
+
2581
+ this.x = col;
2582
+ this.y = row;
2583
+ };
2584
+
2585
+ // CSI Ps J Erase in Display (ED).
2586
+ // Ps = 0 -> Erase Below (default).
2587
+ // Ps = 1 -> Erase Above.
2588
+ // Ps = 2 -> Erase All.
2589
+ // Ps = 3 -> Erase Saved Lines (xterm).
2590
+ // CSI ? Ps J
2591
+ // Erase in Display (DECSED).
2592
+ // Ps = 0 -> Selective Erase Below (default).
2593
+ // Ps = 1 -> Selective Erase Above.
2594
+ // Ps = 2 -> Selective Erase All.
2595
+ Terminal.prototype.eraseInDisplay = function(params) {
2596
+ var j;
2597
+ switch (params[0]) {
2598
+ case 0:
2599
+ this.eraseRight(this.x, this.y);
2600
+ j = this.y + 1;
2601
+ for (; j < this.rows; j++) {
2602
+ this.eraseLine(j);
2603
+ }
2604
+ break;
2605
+ case 1:
2606
+ this.eraseLeft(this.x, this.y);
2607
+ j = this.y;
2608
+ while (j--) {
2609
+ this.eraseLine(j);
2610
+ }
2611
+ break;
2612
+ case 2:
2613
+ j = this.rows;
2614
+ while (j--) this.eraseLine(j);
2615
+ break;
2616
+ case 3:
2617
+ ; // no saved lines
2618
+ break;
2619
+ }
2620
+ };
2621
+
2622
+ // CSI Ps K Erase in Line (EL).
2623
+ // Ps = 0 -> Erase to Right (default).
2624
+ // Ps = 1 -> Erase to Left.
2625
+ // Ps = 2 -> Erase All.
2626
+ // CSI ? Ps K
2627
+ // Erase in Line (DECSEL).
2628
+ // Ps = 0 -> Selective Erase to Right (default).
2629
+ // Ps = 1 -> Selective Erase to Left.
2630
+ // Ps = 2 -> Selective Erase All.
2631
+ Terminal.prototype.eraseInLine = function(params) {
2632
+ switch (params[0]) {
2633
+ case 0:
2634
+ this.eraseRight(this.x, this.y);
2635
+ break;
2636
+ case 1:
2637
+ this.eraseLeft(this.x, this.y);
2638
+ break;
2639
+ case 2:
2640
+ this.eraseLine(this.y);
2641
+ break;
2642
+ }
2643
+ };
2644
+
2645
+ // CSI Pm m Character Attributes (SGR).
2646
+ // Ps = 0 -> Normal (default).
2647
+ // Ps = 1 -> Bold.
2648
+ // Ps = 4 -> Underlined.
2649
+ // Ps = 5 -> Blink (appears as Bold).
2650
+ // Ps = 7 -> Inverse.
2651
+ // Ps = 8 -> Invisible, i.e., hidden (VT300).
2652
+ // Ps = 2 2 -> Normal (neither bold nor faint).
2653
+ // Ps = 2 4 -> Not underlined.
2654
+ // Ps = 2 5 -> Steady (not blinking).
2655
+ // Ps = 2 7 -> Positive (not inverse).
2656
+ // Ps = 2 8 -> Visible, i.e., not hidden (VT300).
2657
+ // Ps = 3 0 -> Set foreground color to Black.
2658
+ // Ps = 3 1 -> Set foreground color to Red.
2659
+ // Ps = 3 2 -> Set foreground color to Green.
2660
+ // Ps = 3 3 -> Set foreground color to Yellow.
2661
+ // Ps = 3 4 -> Set foreground color to Blue.
2662
+ // Ps = 3 5 -> Set foreground color to Magenta.
2663
+ // Ps = 3 6 -> Set foreground color to Cyan.
2664
+ // Ps = 3 7 -> Set foreground color to White.
2665
+ // Ps = 3 9 -> Set foreground color to default (original).
2666
+ // Ps = 4 0 -> Set background color to Black.
2667
+ // Ps = 4 1 -> Set background color to Red.
2668
+ // Ps = 4 2 -> Set background color to Green.
2669
+ // Ps = 4 3 -> Set background color to Yellow.
2670
+ // Ps = 4 4 -> Set background color to Blue.
2671
+ // Ps = 4 5 -> Set background color to Magenta.
2672
+ // Ps = 4 6 -> Set background color to Cyan.
2673
+ // Ps = 4 7 -> Set background color to White.
2674
+ // Ps = 4 9 -> Set background color to default (original).
2675
+
2676
+ // If 16-color support is compiled, the following apply. Assume
2677
+ // that xterm's resources are set so that the ISO color codes are
2678
+ // the first 8 of a set of 16. Then the aixterm colors are the
2679
+ // bright versions of the ISO colors:
2680
+ // Ps = 9 0 -> Set foreground color to Black.
2681
+ // Ps = 9 1 -> Set foreground color to Red.
2682
+ // Ps = 9 2 -> Set foreground color to Green.
2683
+ // Ps = 9 3 -> Set foreground color to Yellow.
2684
+ // Ps = 9 4 -> Set foreground color to Blue.
2685
+ // Ps = 9 5 -> Set foreground color to Magenta.
2686
+ // Ps = 9 6 -> Set foreground color to Cyan.
2687
+ // Ps = 9 7 -> Set foreground color to White.
2688
+ // Ps = 1 0 0 -> Set background color to Black.
2689
+ // Ps = 1 0 1 -> Set background color to Red.
2690
+ // Ps = 1 0 2 -> Set background color to Green.
2691
+ // Ps = 1 0 3 -> Set background color to Yellow.
2692
+ // Ps = 1 0 4 -> Set background color to Blue.
2693
+ // Ps = 1 0 5 -> Set background color to Magenta.
2694
+ // Ps = 1 0 6 -> Set background color to Cyan.
2695
+ // Ps = 1 0 7 -> Set background color to White.
2696
+
2697
+ // If xterm is compiled with the 16-color support disabled, it
2698
+ // supports the following, from rxvt:
2699
+ // Ps = 1 0 0 -> Set foreground and background color to
2700
+ // default.
2701
+
2702
+ // If 88- or 256-color support is compiled, the following apply.
2703
+ // Ps = 3 8 ; 5 ; Ps -> Set foreground color to the second
2704
+ // Ps.
2705
+ // Ps = 4 8 ; 5 ; Ps -> Set background color to the second
2706
+ // Ps.
2707
+ Terminal.prototype.charAttributes = function(params) {
2708
+ var l = params.length
2709
+ , i = 0
2710
+ , bg
2711
+ , fg
2712
+ , p;
2713
+
2714
+ for (; i < l; i++) {
2715
+ p = params[i];
2716
+ if (p >= 30 && p <= 37) {
2717
+ // fg color 8
2718
+ this.curAttr = (this.curAttr & ~(0x1ff << 9)) | ((p - 30) << 9);
2719
+ } else if (p >= 40 && p <= 47) {
2720
+ // bg color 8
2721
+ this.curAttr = (this.curAttr & ~0x1ff) | (p - 40);
2722
+ } else if (p >= 90 && p <= 97) {
2723
+ // fg color 16
2724
+ p += 8;
2725
+ this.curAttr = (this.curAttr & ~(0x1ff << 9)) | ((p - 90) << 9);
2726
+ } else if (p >= 100 && p <= 107) {
2727
+ // bg color 16
2728
+ p += 8;
2729
+ this.curAttr = (this.curAttr & ~0x1ff) | (p - 100);
2730
+ } else if (p === 0) {
2731
+ // default
2732
+ this.curAttr = this.defAttr;
2733
+ } else if (p === 1) {
2734
+ // bold text
2735
+ this.curAttr = this.curAttr | (1 << 18);
2736
+ } else if (p === 4) {
2737
+ // underlined text
2738
+ this.curAttr = this.curAttr | (2 << 18);
2739
+ } else if (p === 7 || p === 27) {
2740
+ // inverse and positive
2741
+ // test with: echo -e '\e[31m\e[42mhello\e[7mworld\e[27mhi\e[m'
2742
+ if (p === 7) {
2743
+ if ((this.curAttr >> 18) & 4) continue;
2744
+ this.curAttr = this.curAttr | (4 << 18);
2745
+ } else if (p === 27) {
2746
+ if (~(this.curAttr >> 18) & 4) continue;
2747
+ this.curAttr = this.curAttr & ~(4 << 18);
2748
+ }
2749
+
2750
+ bg = this.curAttr & 0x1ff;
2751
+ fg = (this.curAttr >> 9) & 0x1ff;
2752
+
2753
+ this.curAttr = (this.curAttr & ~0x3ffff) | ((bg << 9) | fg);
2754
+ } else if (p === 22) {
2755
+ // not bold
2756
+ this.curAttr = this.curAttr & ~(1 << 18);
2757
+ } else if (p === 24) {
2758
+ // not underlined
2759
+ this.curAttr = this.curAttr & ~(2 << 18);
2760
+ } else if (p === 39) {
2761
+ // reset fg
2762
+ this.curAttr = this.curAttr & ~(0x1ff << 9);
2763
+ this.curAttr = this.curAttr | (((this.defAttr >> 9) & 0x1ff) << 9);
2764
+ } else if (p === 49) {
2765
+ // reset bg
2766
+ this.curAttr = this.curAttr & ~0x1ff;
2767
+ this.curAttr = this.curAttr | (this.defAttr & 0x1ff);
2768
+ } else if (p === 38) {
2769
+ // fg color 256
2770
+ if (params[i+1] !== 5) continue;
2771
+ i += 2;
2772
+ p = params[i] & 0xff;
2773
+ // convert 88 colors to 256
2774
+ // if (this.is('rxvt-unicode') && p < 88) p = p * 2.9090 | 0;
2775
+ this.curAttr = (this.curAttr & ~(0x1ff << 9)) | (p << 9);
2776
+ } else if (p === 48) {
2777
+ // bg color 256
2778
+ if (params[i+1] !== 5) continue;
2779
+ i += 2;
2780
+ p = params[i] & 0xff;
2781
+ // convert 88 colors to 256
2782
+ // if (this.is('rxvt-unicode') && p < 88) p = p * 2.9090 | 0;
2783
+ this.curAttr = (this.curAttr & ~0x1ff) | p;
2784
+ }
2785
+ }
2786
+ };
2787
+
2788
+ // CSI Ps n Device Status Report (DSR).
2789
+ // Ps = 5 -> Status Report. Result (``OK'') is
2790
+ // CSI 0 n
2791
+ // Ps = 6 -> Report Cursor Position (CPR) [row;column].
2792
+ // Result is
2793
+ // CSI r ; c R
2794
+ // CSI ? Ps n
2795
+ // Device Status Report (DSR, DEC-specific).
2796
+ // Ps = 6 -> Report Cursor Position (CPR) [row;column] as CSI
2797
+ // ? r ; c R (assumes page is zero).
2798
+ // Ps = 1 5 -> Report Printer status as CSI ? 1 0 n (ready).
2799
+ // or CSI ? 1 1 n (not ready).
2800
+ // Ps = 2 5 -> Report UDK status as CSI ? 2 0 n (unlocked)
2801
+ // or CSI ? 2 1 n (locked).
2802
+ // Ps = 2 6 -> Report Keyboard status as
2803
+ // CSI ? 2 7 ; 1 ; 0 ; 0 n (North American).
2804
+ // The last two parameters apply to VT400 & up, and denote key-
2805
+ // board ready and LK01 respectively.
2806
+ // Ps = 5 3 -> Report Locator status as
2807
+ // CSI ? 5 3 n Locator available, if compiled-in, or
2808
+ // CSI ? 5 0 n No Locator, if not.
2809
+ Terminal.prototype.deviceStatus = function(params) {
2810
+ if (!this.prefix) {
2811
+ switch (params[0]) {
2812
+ case 5:
2813
+ // status report
2814
+ this.send('\x1b[0n');
2815
+ break;
2816
+ case 6:
2817
+ // cursor position
2818
+ this.send('\x1b['
2819
+ + (this.y + 1)
2820
+ + ';'
2821
+ + (this.x + 1)
2822
+ + 'R');
2823
+ break;
2824
+ }
2825
+ } else if (this.prefix === '?') {
2826
+ // modern xterm doesnt seem to
2827
+ // respond to any of these except ?6, 6, and 5
2828
+ switch (params[0]) {
2829
+ case 6:
2830
+ // cursor position
2831
+ this.send('\x1b[?'
2832
+ + (this.y + 1)
2833
+ + ';'
2834
+ + (this.x + 1)
2835
+ + 'R');
2836
+ break;
2837
+ case 15:
2838
+ // no printer
2839
+ // this.send('\x1b[?11n');
2840
+ break;
2841
+ case 25:
2842
+ // dont support user defined keys
2843
+ // this.send('\x1b[?21n');
2844
+ break;
2845
+ case 26:
2846
+ // north american keyboard
2847
+ // this.send('\x1b[?27;1;0;0n');
2848
+ break;
2849
+ case 53:
2850
+ // no dec locator/mouse
2851
+ // this.send('\x1b[?50n');
2852
+ break;
2853
+ }
2854
+ }
2855
+ };
2856
+
2857
+ /**
2858
+ * Additions
2859
+ */
2860
+
2861
+ // CSI Ps @
2862
+ // Insert Ps (Blank) Character(s) (default = 1) (ICH).
2863
+ Terminal.prototype.insertChars = function(params) {
2864
+ var param, row, j, ch;
2865
+
2866
+ param = params[0];
2867
+ if (param < 1) param = 1;
2868
+
2869
+ row = this.y + this.ybase;
2870
+ j = this.x;
2871
+ ch = [this.curAttr, ' ']; // xterm
2872
+
2873
+ while (param-- && j < this.cols) {
2874
+ this.lines[row].splice(j++, 0, ch);
2875
+ this.lines[row].pop();
2876
+ }
2877
+ };
2878
+
2879
+ // CSI Ps E
2880
+ // Cursor Next Line Ps Times (default = 1) (CNL).
2881
+ // same as CSI Ps B ?
2882
+ Terminal.prototype.cursorNextLine = function(params) {
2883
+ var param = params[0];
2884
+ if (param < 1) param = 1;
2885
+ this.y += param;
2886
+ if (this.y >= this.rows) {
2887
+ this.y = this.rows - 1;
2888
+ }
2889
+ this.x = 0;
2890
+ };
2891
+
2892
+ // CSI Ps F
2893
+ // Cursor Preceding Line Ps Times (default = 1) (CNL).
2894
+ // reuse CSI Ps A ?
2895
+ Terminal.prototype.cursorPrecedingLine = function(params) {
2896
+ var param = params[0];
2897
+ if (param < 1) param = 1;
2898
+ this.y -= param;
2899
+ if (this.y < 0) this.y = 0;
2900
+ this.x = 0;
2901
+ };
2902
+
2903
+ // CSI Ps G
2904
+ // Cursor Character Absolute [column] (default = [row,1]) (CHA).
2905
+ Terminal.prototype.cursorCharAbsolute = function(params) {
2906
+ var param = params[0];
2907
+ if (param < 1) param = 1;
2908
+ this.x = param - 1;
2909
+ };
2910
+
2911
+ // CSI Ps L
2912
+ // Insert Ps Line(s) (default = 1) (IL).
2913
+ Terminal.prototype.insertLines = function(params) {
2914
+ var param, row, j;
2915
+
2916
+ param = params[0];
2917
+ if (param < 1) param = 1;
2918
+ row = this.y + this.ybase;
2919
+
2920
+ j = this.rows - 1 - this.scrollBottom;
2921
+ j = this.rows - 1 + this.ybase - j + 1;
2922
+
2923
+ while (param--) {
2924
+ // test: echo -e '\e[44m\e[1L\e[0m'
2925
+ // blankLine(true) - xterm/linux behavior
2926
+ this.lines.splice(row, 0, this.blankLine(true));
2927
+ this.lines.splice(j, 1);
2928
+ }
2929
+
2930
+ // this.maxRange();
2931
+ this.updateRange(this.y);
2932
+ this.updateRange(this.scrollBottom);
2933
+ };
2934
+
2935
+ // CSI Ps M
2936
+ // Delete Ps Line(s) (default = 1) (DL).
2937
+ Terminal.prototype.deleteLines = function(params) {
2938
+ var param, row, j;
2939
+
2940
+ param = params[0];
2941
+ if (param < 1) param = 1;
2942
+ row = this.y + this.ybase;
2943
+
2944
+ j = this.rows - 1 - this.scrollBottom;
2945
+ j = this.rows - 1 + this.ybase - j;
2946
+
2947
+ while (param--) {
2948
+ // test: echo -e '\e[44m\e[1M\e[0m'
2949
+ // blankLine(true) - xterm/linux behavior
2950
+ this.lines.splice(j + 1, 0, this.blankLine(true));
2951
+ this.lines.splice(row, 1);
2952
+ }
2953
+
2954
+ // this.maxRange();
2955
+ this.updateRange(this.y);
2956
+ this.updateRange(this.scrollBottom);
2957
+ };
2958
+
2959
+ // CSI Ps P
2960
+ // Delete Ps Character(s) (default = 1) (DCH).
2961
+ Terminal.prototype.deleteChars = function(params) {
2962
+ var param, row, ch;
2963
+
2964
+ param = params[0];
2965
+ if (param < 1) param = 1;
2966
+
2967
+ row = this.y + this.ybase;
2968
+ ch = [this.curAttr, ' ']; // xterm
2969
+
2970
+ while (param--) {
2971
+ this.lines[row].splice(this.x, 1);
2972
+ this.lines[row].push(ch);
2973
+ }
2974
+ };
2975
+
2976
+ // CSI Ps X
2977
+ // Erase Ps Character(s) (default = 1) (ECH).
2978
+ Terminal.prototype.eraseChars = function(params) {
2979
+ var param, row, j, ch;
2980
+
2981
+ param = params[0];
2982
+ if (param < 1) param = 1;
2983
+
2984
+ row = this.y + this.ybase;
2985
+ j = this.x;
2986
+ ch = [this.curAttr, ' ']; // xterm
2987
+
2988
+ while (param-- && j < this.cols) {
2989
+ this.lines[row][j++] = ch;
2990
+ }
2991
+ };
2992
+
2993
+ // CSI Pm ` Character Position Absolute
2994
+ // [column] (default = [row,1]) (HPA).
2995
+ Terminal.prototype.charPosAbsolute = function(params) {
2996
+ var param = params[0];
2997
+ if (param < 1) param = 1;
2998
+ this.x = param - 1;
2999
+ if (this.x >= this.cols) {
3000
+ this.x = this.cols - 1;
3001
+ }
3002
+ };
3003
+
3004
+ // 141 61 a * HPR -
3005
+ // Horizontal Position Relative
3006
+ // reuse CSI Ps C ?
3007
+ Terminal.prototype.HPositionRelative = function(params) {
3008
+ var param = params[0];
3009
+ if (param < 1) param = 1;
3010
+ this.x += param;
3011
+ if (this.x >= this.cols) {
3012
+ this.x = this.cols - 1;
3013
+ }
3014
+ };
3015
+
3016
+ // CSI Ps c Send Device Attributes (Primary DA).
3017
+ // Ps = 0 or omitted -> request attributes from terminal. The
3018
+ // response depends on the decTerminalID resource setting.
3019
+ // -> CSI ? 1 ; 2 c (``VT100 with Advanced Video Option'')
3020
+ // -> CSI ? 1 ; 0 c (``VT101 with No Options'')
3021
+ // -> CSI ? 6 c (``VT102'')
3022
+ // -> CSI ? 6 0 ; 1 ; 2 ; 6 ; 8 ; 9 ; 1 5 ; c (``VT220'')
3023
+ // The VT100-style response parameters do not mean anything by
3024
+ // themselves. VT220 parameters do, telling the host what fea-
3025
+ // tures the terminal supports:
3026
+ // Ps = 1 -> 132-columns.
3027
+ // Ps = 2 -> Printer.
3028
+ // Ps = 6 -> Selective erase.
3029
+ // Ps = 8 -> User-defined keys.
3030
+ // Ps = 9 -> National replacement character sets.
3031
+ // Ps = 1 5 -> Technical characters.
3032
+ // Ps = 2 2 -> ANSI color, e.g., VT525.
3033
+ // Ps = 2 9 -> ANSI text locator (i.e., DEC Locator mode).
3034
+ // CSI > Ps c
3035
+ // Send Device Attributes (Secondary DA).
3036
+ // Ps = 0 or omitted -> request the terminal's identification
3037
+ // code. The response depends on the decTerminalID resource set-
3038
+ // ting. It should apply only to VT220 and up, but xterm extends
3039
+ // this to VT100.
3040
+ // -> CSI > Pp ; Pv ; Pc c
3041
+ // where Pp denotes the terminal type
3042
+ // Pp = 0 -> ``VT100''.
3043
+ // Pp = 1 -> ``VT220''.
3044
+ // and Pv is the firmware version (for xterm, this was originally
3045
+ // the XFree86 patch number, starting with 95). In a DEC termi-
3046
+ // nal, Pc indicates the ROM cartridge registration number and is
3047
+ // always zero.
3048
+ // More information:
3049
+ // xterm/charproc.c - line 2012, for more information.
3050
+ // vim responds with ^[[?0c or ^[[?1c after the terminal's response (?)
3051
+ Terminal.prototype.sendDeviceAttributes = function(params) {
3052
+ if (params[0] > 0) return;
3053
+
3054
+ if (!this.prefix) {
3055
+ if (this.is('xterm')
3056
+ || this.is('rxvt-unicode')
3057
+ || this.is('screen')) {
3058
+ this.send('\x1b[?1;2c');
3059
+ } else if (this.is('linux')) {
3060
+ this.send('\x1b[?6c');
3061
+ }
3062
+ } else if (this.prefix === '>') {
3063
+ // xterm and urxvt
3064
+ // seem to spit this
3065
+ // out around ~370 times (?).
3066
+ if (this.is('xterm')) {
3067
+ this.send('\x1b[>0;276;0c');
3068
+ } else if (this.is('rxvt-unicode')) {
3069
+ this.send('\x1b[>85;95;0c');
3070
+ } else if (this.is('linux')) {
3071
+ // not supported by linux console.
3072
+ // linux console echoes parameters.
3073
+ this.send(params[0] + 'c');
3074
+ } else if (this.is('screen')) {
3075
+ this.send('\x1b[>83;40003;0c');
3076
+ }
3077
+ }
3078
+ };
3079
+
3080
+ // CSI Pm d
3081
+ // Line Position Absolute [row] (default = [1,column]) (VPA).
3082
+ Terminal.prototype.linePosAbsolute = function(params) {
3083
+ var param = params[0];
3084
+ if (param < 1) param = 1;
3085
+ this.y = param - 1;
3086
+ if (this.y >= this.rows) {
3087
+ this.y = this.rows - 1;
3088
+ }
3089
+ };
3090
+
3091
+ // 145 65 e * VPR - Vertical Position Relative
3092
+ // reuse CSI Ps B ?
3093
+ Terminal.prototype.VPositionRelative = function(params) {
3094
+ var param = params[0];
3095
+ if (param < 1) param = 1;
3096
+ this.y += param;
3097
+ if (this.y >= this.rows) {
3098
+ this.y = this.rows - 1;
3099
+ }
3100
+ };
3101
+
3102
+ // CSI Ps ; Ps f
3103
+ // Horizontal and Vertical Position [row;column] (default =
3104
+ // [1,1]) (HVP).
3105
+ Terminal.prototype.HVPosition = function(params) {
3106
+ if (params[0] < 1) params[0] = 1;
3107
+ if (params[1] < 1) params[1] = 1;
3108
+
3109
+ this.y = params[0] - 1;
3110
+ if (this.y >= this.rows) {
3111
+ this.y = this.rows - 1;
3112
+ }
3113
+
3114
+ this.x = params[1] - 1;
3115
+ if (this.x >= this.cols) {
3116
+ this.x = this.cols - 1;
3117
+ }
3118
+ };
3119
+
3120
+ // CSI Pm h Set Mode (SM).
3121
+ // Ps = 2 -> Keyboard Action Mode (AM).
3122
+ // Ps = 4 -> Insert Mode (IRM).
3123
+ // Ps = 1 2 -> Send/receive (SRM).
3124
+ // Ps = 2 0 -> Automatic Newline (LNM).
3125
+ // CSI ? Pm h
3126
+ // DEC Private Mode Set (DECSET).
3127
+ // Ps = 1 -> Application Cursor Keys (DECCKM).
3128
+ // Ps = 2 -> Designate USASCII for character sets G0-G3
3129
+ // (DECANM), and set VT100 mode.
3130
+ // Ps = 3 -> 132 Column Mode (DECCOLM).
3131
+ // Ps = 4 -> Smooth (Slow) Scroll (DECSCLM).
3132
+ // Ps = 5 -> Reverse Video (DECSCNM).
3133
+ // Ps = 6 -> Origin Mode (DECOM).
3134
+ // Ps = 7 -> Wraparound Mode (DECAWM).
3135
+ // Ps = 8 -> Auto-repeat Keys (DECARM).
3136
+ // Ps = 9 -> Send Mouse X & Y on button press. See the sec-
3137
+ // tion Mouse Tracking.
3138
+ // Ps = 1 0 -> Show toolbar (rxvt).
3139
+ // Ps = 1 2 -> Start Blinking Cursor (att610).
3140
+ // Ps = 1 8 -> Print form feed (DECPFF).
3141
+ // Ps = 1 9 -> Set print extent to full screen (DECPEX).
3142
+ // Ps = 2 5 -> Show Cursor (DECTCEM).
3143
+ // Ps = 3 0 -> Show scrollbar (rxvt).
3144
+ // Ps = 3 5 -> Enable font-shifting functions (rxvt).
3145
+ // Ps = 3 8 -> Enter Tektronix Mode (DECTEK).
3146
+ // Ps = 4 0 -> Allow 80 -> 132 Mode.
3147
+ // Ps = 4 1 -> more(1) fix (see curses resource).
3148
+ // Ps = 4 2 -> Enable Nation Replacement Character sets (DECN-
3149
+ // RCM).
3150
+ // Ps = 4 4 -> Turn On Margin Bell.
3151
+ // Ps = 4 5 -> Reverse-wraparound Mode.
3152
+ // Ps = 4 6 -> Start Logging. This is normally disabled by a
3153
+ // compile-time option.
3154
+ // Ps = 4 7 -> Use Alternate Screen Buffer. (This may be dis-
3155
+ // abled by the titeInhibit resource).
3156
+ // Ps = 6 6 -> Application keypad (DECNKM).
3157
+ // Ps = 6 7 -> Backarrow key sends backspace (DECBKM).
3158
+ // Ps = 1 0 0 0 -> Send Mouse X & Y on button press and
3159
+ // release. See the section Mouse Tracking.
3160
+ // Ps = 1 0 0 1 -> Use Hilite Mouse Tracking.
3161
+ // Ps = 1 0 0 2 -> Use Cell Motion Mouse Tracking.
3162
+ // Ps = 1 0 0 3 -> Use All Motion Mouse Tracking.
3163
+ // Ps = 1 0 0 4 -> Send FocusIn/FocusOut events.
3164
+ // Ps = 1 0 0 5 -> Enable Extended Mouse Mode.
3165
+ // Ps = 1 0 1 0 -> Scroll to bottom on tty output (rxvt).
3166
+ // Ps = 1 0 1 1 -> Scroll to bottom on key press (rxvt).
3167
+ // Ps = 1 0 3 4 -> Interpret "meta" key, sets eighth bit.
3168
+ // (enables the eightBitInput resource).
3169
+ // Ps = 1 0 3 5 -> Enable special modifiers for Alt and Num-
3170
+ // Lock keys. (This enables the numLock resource).
3171
+ // Ps = 1 0 3 6 -> Send ESC when Meta modifies a key. (This
3172
+ // enables the metaSendsEscape resource).
3173
+ // Ps = 1 0 3 7 -> Send DEL from the editing-keypad Delete
3174
+ // key.
3175
+ // Ps = 1 0 3 9 -> Send ESC when Alt modifies a key. (This
3176
+ // enables the altSendsEscape resource).
3177
+ // Ps = 1 0 4 0 -> Keep selection even if not highlighted.
3178
+ // (This enables the keepSelection resource).
3179
+ // Ps = 1 0 4 1 -> Use the CLIPBOARD selection. (This enables
3180
+ // the selectToClipboard resource).
3181
+ // Ps = 1 0 4 2 -> Enable Urgency window manager hint when
3182
+ // Control-G is received. (This enables the bellIsUrgent
3183
+ // resource).
3184
+ // Ps = 1 0 4 3 -> Enable raising of the window when Control-G
3185
+ // is received. (enables the popOnBell resource).
3186
+ // Ps = 1 0 4 7 -> Use Alternate Screen Buffer. (This may be
3187
+ // disabled by the titeInhibit resource).
3188
+ // Ps = 1 0 4 8 -> Save cursor as in DECSC. (This may be dis-
3189
+ // abled by the titeInhibit resource).
3190
+ // Ps = 1 0 4 9 -> Save cursor as in DECSC and use Alternate
3191
+ // Screen Buffer, clearing it first. (This may be disabled by
3192
+ // the titeInhibit resource). This combines the effects of the 1
3193
+ // 0 4 7 and 1 0 4 8 modes. Use this with terminfo-based
3194
+ // applications rather than the 4 7 mode.
3195
+ // Ps = 1 0 5 0 -> Set terminfo/termcap function-key mode.
3196
+ // Ps = 1 0 5 1 -> Set Sun function-key mode.
3197
+ // Ps = 1 0 5 2 -> Set HP function-key mode.
3198
+ // Ps = 1 0 5 3 -> Set SCO function-key mode.
3199
+ // Ps = 1 0 6 0 -> Set legacy keyboard emulation (X11R6).
3200
+ // Ps = 1 0 6 1 -> Set VT220 keyboard emulation.
3201
+ // Ps = 2 0 0 4 -> Set bracketed paste mode.
3202
+ // Modes:
3203
+ // http://vt100.net/docs/vt220-rm/chapter4.html
3204
+ Terminal.prototype.setMode = function(params) {
3205
+ if (typeof params === 'object') {
3206
+ var l = params.length
3207
+ , i = 0;
3208
+
3209
+ for (; i < l; i++) {
3210
+ this.setMode(params[i]);
3211
+ }
3212
+
3213
+ return;
3214
+ }
3215
+
3216
+ if (!this.prefix) {
3217
+ switch (params) {
3218
+ case 4:
3219
+ this.insertMode = true;
3220
+ break;
3221
+ case 20:
3222
+ //this.convertEol = true;
3223
+ break;
3224
+ }
3225
+ } else if (this.prefix === '?') {
3226
+ switch (params) {
3227
+ case 1:
3228
+ this.applicationCursor = true;
3229
+ break;
3230
+ case 2:
3231
+ this.setgCharset(0, Terminal.charsets.US);
3232
+ this.setgCharset(1, Terminal.charsets.US);
3233
+ this.setgCharset(2, Terminal.charsets.US);
3234
+ this.setgCharset(3, Terminal.charsets.US);
3235
+ // set VT100 mode here
3236
+ break;
3237
+ case 3: // 132 col mode
3238
+ this.savedCols = this.cols;
3239
+ this.resize(132, this.rows);
3240
+ break;
3241
+ case 6:
3242
+ this.originMode = true;
3243
+ break;
3244
+ case 7:
3245
+ this.wraparoundMode = true;
3246
+ break;
3247
+ case 12:
3248
+ // this.cursorBlink = true;
3249
+ break;
3250
+ case 9: // X10 Mouse
3251
+ // no release, no motion, no wheel, no modifiers.
3252
+ case 1000: // vt200 mouse
3253
+ // no motion.
3254
+ // no modifiers, except control on the wheel.
3255
+ case 1002: // button event mouse
3256
+ case 1003: // any event mouse
3257
+ // any event - sends motion events,
3258
+ // even if there is no button held down.
3259
+ this.x10Mouse = params === 9;
3260
+ this.vt200Mouse = params === 1000;
3261
+ this.normalMouse = params > 1000;
3262
+ this.mouseEvents = true;
3263
+ this.element.style.cursor = 'default';
3264
+ this.log('Binding to mouse events.');
3265
+ break;
3266
+ case 1004: // send focusin/focusout events
3267
+ // focusin: ^[[I
3268
+ // focusout: ^[[O
3269
+ this.sendFocus = true;
3270
+ break;
3271
+ case 1005: // utf8 ext mode mouse
3272
+ this.utfMouse = true;
3273
+ // for wide terminals
3274
+ // simply encodes large values as utf8 characters
3275
+ break;
3276
+ case 1006: // sgr ext mode mouse
3277
+ this.sgrMouse = true;
3278
+ // for wide terminals
3279
+ // does not add 32 to fields
3280
+ // press: ^[[<b;x;yM
3281
+ // release: ^[[<b;x;ym
3282
+ break;
3283
+ case 1015: // urxvt ext mode mouse
3284
+ this.urxvtMouse = true;
3285
+ // for wide terminals
3286
+ // numbers for fields
3287
+ // press: ^[[b;x;yM
3288
+ // motion: ^[[b;x;yT
3289
+ break;
3290
+ case 25: // show cursor
3291
+ this.cursorHidden = false;
3292
+ break;
3293
+ case 1049: // alt screen buffer cursor
3294
+ //this.saveCursor();
3295
+ ; // FALL-THROUGH
3296
+ case 47: // alt screen buffer
3297
+ case 1047: // alt screen buffer
3298
+ if (!this.normal) {
3299
+ var normal = {
3300
+ lines: this.lines,
3301
+ ybase: this.ybase,
3302
+ ydisp: this.ydisp,
3303
+ x: this.x,
3304
+ y: this.y,
3305
+ scrollTop: this.scrollTop,
3306
+ scrollBottom: this.scrollBottom,
3307
+ tabs: this.tabs
3308
+ // XXX save charset(s) here?
3309
+ // charset: this.charset,
3310
+ // glevel: this.glevel,
3311
+ // charsets: this.charsets
3312
+ };
3313
+ this.reset();
3314
+ this.normal = normal;
3315
+ this.showCursor();
3316
+ }
3317
+ break;
3318
+ }
3319
+ }
3320
+ };
3321
+
3322
+ // CSI Pm l Reset Mode (RM).
3323
+ // Ps = 2 -> Keyboard Action Mode (AM).
3324
+ // Ps = 4 -> Replace Mode (IRM).
3325
+ // Ps = 1 2 -> Send/receive (SRM).
3326
+ // Ps = 2 0 -> Normal Linefeed (LNM).
3327
+ // CSI ? Pm l
3328
+ // DEC Private Mode Reset (DECRST).
3329
+ // Ps = 1 -> Normal Cursor Keys (DECCKM).
3330
+ // Ps = 2 -> Designate VT52 mode (DECANM).
3331
+ // Ps = 3 -> 80 Column Mode (DECCOLM).
3332
+ // Ps = 4 -> Jump (Fast) Scroll (DECSCLM).
3333
+ // Ps = 5 -> Normal Video (DECSCNM).
3334
+ // Ps = 6 -> Normal Cursor Mode (DECOM).
3335
+ // Ps = 7 -> No Wraparound Mode (DECAWM).
3336
+ // Ps = 8 -> No Auto-repeat Keys (DECARM).
3337
+ // Ps = 9 -> Don't send Mouse X & Y on button press.
3338
+ // Ps = 1 0 -> Hide toolbar (rxvt).
3339
+ // Ps = 1 2 -> Stop Blinking Cursor (att610).
3340
+ // Ps = 1 8 -> Don't print form feed (DECPFF).
3341
+ // Ps = 1 9 -> Limit print to scrolling region (DECPEX).
3342
+ // Ps = 2 5 -> Hide Cursor (DECTCEM).
3343
+ // Ps = 3 0 -> Don't show scrollbar (rxvt).
3344
+ // Ps = 3 5 -> Disable font-shifting functions (rxvt).
3345
+ // Ps = 4 0 -> Disallow 80 -> 132 Mode.
3346
+ // Ps = 4 1 -> No more(1) fix (see curses resource).
3347
+ // Ps = 4 2 -> Disable Nation Replacement Character sets (DEC-
3348
+ // NRCM).
3349
+ // Ps = 4 4 -> Turn Off Margin Bell.
3350
+ // Ps = 4 5 -> No Reverse-wraparound Mode.
3351
+ // Ps = 4 6 -> Stop Logging. (This is normally disabled by a
3352
+ // compile-time option).
3353
+ // Ps = 4 7 -> Use Normal Screen Buffer.
3354
+ // Ps = 6 6 -> Numeric keypad (DECNKM).
3355
+ // Ps = 6 7 -> Backarrow key sends delete (DECBKM).
3356
+ // Ps = 1 0 0 0 -> Don't send Mouse X & Y on button press and
3357
+ // release. See the section Mouse Tracking.
3358
+ // Ps = 1 0 0 1 -> Don't use Hilite Mouse Tracking.
3359
+ // Ps = 1 0 0 2 -> Don't use Cell Motion Mouse Tracking.
3360
+ // Ps = 1 0 0 3 -> Don't use All Motion Mouse Tracking.
3361
+ // Ps = 1 0 0 4 -> Don't send FocusIn/FocusOut events.
3362
+ // Ps = 1 0 0 5 -> Disable Extended Mouse Mode.
3363
+ // Ps = 1 0 1 0 -> Don't scroll to bottom on tty output
3364
+ // (rxvt).
3365
+ // Ps = 1 0 1 1 -> Don't scroll to bottom on key press (rxvt).
3366
+ // Ps = 1 0 3 4 -> Don't interpret "meta" key. (This disables
3367
+ // the eightBitInput resource).
3368
+ // Ps = 1 0 3 5 -> Disable special modifiers for Alt and Num-
3369
+ // Lock keys. (This disables the numLock resource).
3370
+ // Ps = 1 0 3 6 -> Don't send ESC when Meta modifies a key.
3371
+ // (This disables the metaSendsEscape resource).
3372
+ // Ps = 1 0 3 7 -> Send VT220 Remove from the editing-keypad
3373
+ // Delete key.
3374
+ // Ps = 1 0 3 9 -> Don't send ESC when Alt modifies a key.
3375
+ // (This disables the altSendsEscape resource).
3376
+ // Ps = 1 0 4 0 -> Do not keep selection when not highlighted.
3377
+ // (This disables the keepSelection resource).
3378
+ // Ps = 1 0 4 1 -> Use the PRIMARY selection. (This disables
3379
+ // the selectToClipboard resource).
3380
+ // Ps = 1 0 4 2 -> Disable Urgency window manager hint when
3381
+ // Control-G is received. (This disables the bellIsUrgent
3382
+ // resource).
3383
+ // Ps = 1 0 4 3 -> Disable raising of the window when Control-
3384
+ // G is received. (This disables the popOnBell resource).
3385
+ // Ps = 1 0 4 7 -> Use Normal Screen Buffer, clearing screen
3386
+ // first if in the Alternate Screen. (This may be disabled by
3387
+ // the titeInhibit resource).
3388
+ // Ps = 1 0 4 8 -> Restore cursor as in DECRC. (This may be
3389
+ // disabled by the titeInhibit resource).
3390
+ // Ps = 1 0 4 9 -> Use Normal Screen Buffer and restore cursor
3391
+ // as in DECRC. (This may be disabled by the titeInhibit
3392
+ // resource). This combines the effects of the 1 0 4 7 and 1 0
3393
+ // 4 8 modes. Use this with terminfo-based applications rather
3394
+ // than the 4 7 mode.
3395
+ // Ps = 1 0 5 0 -> Reset terminfo/termcap function-key mode.
3396
+ // Ps = 1 0 5 1 -> Reset Sun function-key mode.
3397
+ // Ps = 1 0 5 2 -> Reset HP function-key mode.
3398
+ // Ps = 1 0 5 3 -> Reset SCO function-key mode.
3399
+ // Ps = 1 0 6 0 -> Reset legacy keyboard emulation (X11R6).
3400
+ // Ps = 1 0 6 1 -> Reset keyboard emulation to Sun/PC style.
3401
+ // Ps = 2 0 0 4 -> Reset bracketed paste mode.
3402
+ Terminal.prototype.resetMode = function(params) {
3403
+ if (typeof params === 'object') {
3404
+ var l = params.length
3405
+ , i = 0;
3406
+
3407
+ for (; i < l; i++) {
3408
+ this.resetMode(params[i]);
3409
+ }
3410
+
3411
+ return;
3412
+ }
3413
+
3414
+ if (!this.prefix) {
3415
+ switch (params) {
3416
+ case 4:
3417
+ this.insertMode = false;
3418
+ break;
3419
+ case 20:
3420
+ //this.convertEol = false;
3421
+ break;
3422
+ }
3423
+ } else if (this.prefix === '?') {
3424
+ switch (params) {
3425
+ case 1:
3426
+ this.applicationCursor = false;
3427
+ break;
3428
+ case 3:
3429
+ if (this.cols === 132 && this.savedCols) {
3430
+ this.resize(this.savedCols, this.rows);
3431
+ }
3432
+ delete this.savedCols;
3433
+ break;
3434
+ case 6:
3435
+ this.originMode = false;
3436
+ break;
3437
+ case 7:
3438
+ this.wraparoundMode = false;
3439
+ break;
3440
+ case 12:
3441
+ // this.cursorBlink = false;
3442
+ break;
3443
+ case 9: // X10 Mouse
3444
+ case 1000: // vt200 mouse
3445
+ case 1002: // button event mouse
3446
+ case 1003: // any event mouse
3447
+ this.x10Mouse = false;
3448
+ this.vt200Mouse = false;
3449
+ this.normalMouse = false;
3450
+ this.mouseEvents = false;
3451
+ this.element.style.cursor = '';
3452
+ break;
3453
+ case 1004: // send focusin/focusout events
3454
+ this.sendFocus = false;
3455
+ break;
3456
+ case 1005: // utf8 ext mode mouse
3457
+ this.utfMouse = false;
3458
+ break;
3459
+ case 1006: // sgr ext mode mouse
3460
+ this.sgrMouse = false;
3461
+ break;
3462
+ case 1015: // urxvt ext mode mouse
3463
+ this.urxvtMouse = false;
3464
+ break;
3465
+ case 25: // hide cursor
3466
+ this.cursorHidden = true;
3467
+ break;
3468
+ case 1049: // alt screen buffer cursor
3469
+ ; // FALL-THROUGH
3470
+ case 47: // normal screen buffer
3471
+ case 1047: // normal screen buffer - clearing it first
3472
+ if (this.normal) {
3473
+ this.lines = this.normal.lines;
3474
+ this.ybase = this.normal.ybase;
3475
+ this.ydisp = this.normal.ydisp;
3476
+ this.x = this.normal.x;
3477
+ this.y = this.normal.y;
3478
+ this.scrollTop = this.normal.scrollTop;
3479
+ this.scrollBottom = this.normal.scrollBottom;
3480
+ this.tabs = this.normal.tabs;
3481
+ this.normal = null;
3482
+ // if (params === 1049) {
3483
+ // this.x = this.savedX;
3484
+ // this.y = this.savedY;
3485
+ // }
3486
+ this.refresh(0, this.rows - 1);
3487
+ this.showCursor();
3488
+ }
3489
+ break;
3490
+ }
3491
+ }
3492
+ };
3493
+
3494
+ // CSI Ps ; Ps r
3495
+ // Set Scrolling Region [top;bottom] (default = full size of win-
3496
+ // dow) (DECSTBM).
3497
+ // CSI ? Pm r
3498
+ Terminal.prototype.setScrollRegion = function(params) {
3499
+ if (this.prefix) return;
3500
+ this.scrollTop = (params[0] || 1) - 1;
3501
+ this.scrollBottom = (params[1] || this.rows) - 1;
3502
+ this.x = 0;
3503
+ this.y = 0;
3504
+ };
3505
+
3506
+ // CSI s
3507
+ // Save cursor (ANSI.SYS).
3508
+ Terminal.prototype.saveCursor = function(params) {
3509
+ this.savedX = this.x;
3510
+ this.savedY = this.y;
3511
+ };
3512
+
3513
+ // CSI u
3514
+ // Restore cursor (ANSI.SYS).
3515
+ Terminal.prototype.restoreCursor = function(params) {
3516
+ this.x = this.savedX || 0;
3517
+ this.y = this.savedY || 0;
3518
+ };
3519
+
3520
+ /**
3521
+ * Lesser Used
3522
+ */
3523
+
3524
+ // CSI Ps I
3525
+ // Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
3526
+ Terminal.prototype.cursorForwardTab = function(params) {
3527
+ var param = params[0] || 1;
3528
+ while (param--) {
3529
+ this.x = this.nextStop();
3530
+ }
3531
+ };
3532
+
3533
+ // CSI Ps S Scroll up Ps lines (default = 1) (SU).
3534
+ Terminal.prototype.scrollUp = function(params) {
3535
+ var param = params[0] || 1;
3536
+ while (param--) {
3537
+ this.lines.splice(this.ybase + this.scrollTop, 1);
3538
+ this.lines.splice(this.ybase + this.scrollBottom, 0, this.blankLine());
3539
+ }
3540
+ // this.maxRange();
3541
+ this.updateRange(this.scrollTop);
3542
+ this.updateRange(this.scrollBottom);
3543
+ };
3544
+
3545
+ // CSI Ps T Scroll down Ps lines (default = 1) (SD).
3546
+ Terminal.prototype.scrollDown = function(params) {
3547
+ var param = params[0] || 1;
3548
+ while (param--) {
3549
+ this.lines.splice(this.ybase + this.scrollBottom, 1);
3550
+ this.lines.splice(this.ybase + this.scrollTop, 0, this.blankLine());
3551
+ }
3552
+ // this.maxRange();
3553
+ this.updateRange(this.scrollTop);
3554
+ this.updateRange(this.scrollBottom);
3555
+ };
3556
+
3557
+ // CSI Ps ; Ps ; Ps ; Ps ; Ps T
3558
+ // Initiate highlight mouse tracking. Parameters are
3559
+ // [func;startx;starty;firstrow;lastrow]. See the section Mouse
3560
+ // Tracking.
3561
+ Terminal.prototype.initMouseTracking = function(params) {
3562
+ // Relevant: DECSET 1001
3563
+ };
3564
+
3565
+ // CSI > Ps; Ps T
3566
+ // Reset one or more features of the title modes to the default
3567
+ // value. Normally, "reset" disables the feature. It is possi-
3568
+ // ble to disable the ability to reset features by compiling a
3569
+ // different default for the title modes into xterm.
3570
+ // Ps = 0 -> Do not set window/icon labels using hexadecimal.
3571
+ // Ps = 1 -> Do not query window/icon labels using hexadeci-
3572
+ // mal.
3573
+ // Ps = 2 -> Do not set window/icon labels using UTF-8.
3574
+ // Ps = 3 -> Do not query window/icon labels using UTF-8.
3575
+ // (See discussion of "Title Modes").
3576
+ Terminal.prototype.resetTitleModes = function(params) {
3577
+ ;
3578
+ };
3579
+
3580
+ // CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
3581
+ Terminal.prototype.cursorBackwardTab = function(params) {
3582
+ var param = params[0] || 1;
3583
+ while (param--) {
3584
+ this.x = this.prevStop();
3585
+ }
3586
+ };
3587
+
3588
+ // CSI Ps b Repeat the preceding graphic character Ps times (REP).
3589
+ Terminal.prototype.repeatPrecedingCharacter = function(params) {
3590
+ var param = params[0] || 1
3591
+ , line = this.lines[this.ybase + this.y]
3592
+ , ch = line[this.x - 1] || [this.defAttr, ' '];
3593
+
3594
+ while (param--) line[this.x++] = ch;
3595
+ };
3596
+
3597
+ // CSI Ps g Tab Clear (TBC).
3598
+ // Ps = 0 -> Clear Current Column (default).
3599
+ // Ps = 3 -> Clear All.
3600
+ // Potentially:
3601
+ // Ps = 2 -> Clear Stops on Line.
3602
+ // http://vt100.net/annarbor/aaa-ug/section6.html
3603
+ Terminal.prototype.tabClear = function(params) {
3604
+ var param = params[0];
3605
+ if (param <= 0) {
3606
+ delete this.tabs[this.x];
3607
+ } else if (param === 3) {
3608
+ this.tabs = {};
3609
+ }
3610
+ };
3611
+
3612
+ // CSI Pm i Media Copy (MC).
3613
+ // Ps = 0 -> Print screen (default).
3614
+ // Ps = 4 -> Turn off printer controller mode.
3615
+ // Ps = 5 -> Turn on printer controller mode.
3616
+ // CSI ? Pm i
3617
+ // Media Copy (MC, DEC-specific).
3618
+ // Ps = 1 -> Print line containing cursor.
3619
+ // Ps = 4 -> Turn off autoprint mode.
3620
+ // Ps = 5 -> Turn on autoprint mode.
3621
+ // Ps = 1 0 -> Print composed display, ignores DECPEX.
3622
+ // Ps = 1 1 -> Print all pages.
3623
+ Terminal.prototype.mediaCopy = function(params) {
3624
+ ;
3625
+ };
3626
+
3627
+ // CSI > Ps; Ps m
3628
+ // Set or reset resource-values used by xterm to decide whether
3629
+ // to construct escape sequences holding information about the
3630
+ // modifiers pressed with a given key. The first parameter iden-
3631
+ // tifies the resource to set/reset. The second parameter is the
3632
+ // value to assign to the resource. If the second parameter is
3633
+ // omitted, the resource is reset to its initial value.
3634
+ // Ps = 1 -> modifyCursorKeys.
3635
+ // Ps = 2 -> modifyFunctionKeys.
3636
+ // Ps = 4 -> modifyOtherKeys.
3637
+ // If no parameters are given, all resources are reset to their
3638
+ // initial values.
3639
+ Terminal.prototype.setResources = function(params) {
3640
+ ;
3641
+ };
3642
+
3643
+ // CSI > Ps n
3644
+ // Disable modifiers which may be enabled via the CSI > Ps; Ps m
3645
+ // sequence. This corresponds to a resource value of "-1", which
3646
+ // cannot be set with the other sequence. The parameter identi-
3647
+ // fies the resource to be disabled:
3648
+ // Ps = 1 -> modifyCursorKeys.
3649
+ // Ps = 2 -> modifyFunctionKeys.
3650
+ // Ps = 4 -> modifyOtherKeys.
3651
+ // If the parameter is omitted, modifyFunctionKeys is disabled.
3652
+ // When modifyFunctionKeys is disabled, xterm uses the modifier
3653
+ // keys to make an extended sequence of functions rather than
3654
+ // adding a parameter to each function key to denote the modi-
3655
+ // fiers.
3656
+ Terminal.prototype.disableModifiers = function(params) {
3657
+ ;
3658
+ };
3659
+
3660
+ // CSI > Ps p
3661
+ // Set resource value pointerMode. This is used by xterm to
3662
+ // decide whether to hide the pointer cursor as the user types.
3663
+ // Valid values for the parameter:
3664
+ // Ps = 0 -> never hide the pointer.
3665
+ // Ps = 1 -> hide if the mouse tracking mode is not enabled.
3666
+ // Ps = 2 -> always hide the pointer. If no parameter is
3667
+ // given, xterm uses the default, which is 1 .
3668
+ Terminal.prototype.setPointerMode = function(params) {
3669
+ ;
3670
+ };
3671
+
3672
+ // CSI ! p Soft terminal reset (DECSTR).
3673
+ // http://vt100.net/docs/vt220-rm/table4-10.html
3674
+ Terminal.prototype.softReset = function(params) {
3675
+ this.cursorHidden = false;
3676
+ this.insertMode = false;
3677
+ this.originMode = false;
3678
+ this.wraparoundMode = false; // autowrap
3679
+ this.applicationKeypad = false; // ?
3680
+ this.applicationCursor = false;
3681
+ this.scrollTop = 0;
3682
+ this.scrollBottom = this.rows - 1;
3683
+ this.curAttr = this.defAttr;
3684
+ this.x = this.y = 0; // ?
3685
+ this.charset = null;
3686
+ this.glevel = 0; // ??
3687
+ this.charsets = [null]; // ??
3688
+ };
3689
+
3690
+ // CSI Ps$ p
3691
+ // Request ANSI mode (DECRQM). For VT300 and up, reply is
3692
+ // CSI Ps; Pm$ y
3693
+ // where Ps is the mode number as in RM, and Pm is the mode
3694
+ // value:
3695
+ // 0 - not recognized
3696
+ // 1 - set
3697
+ // 2 - reset
3698
+ // 3 - permanently set
3699
+ // 4 - permanently reset
3700
+ Terminal.prototype.requestAnsiMode = function(params) {
3701
+ ;
3702
+ };
3703
+
3704
+ // CSI ? Ps$ p
3705
+ // Request DEC private mode (DECRQM). For VT300 and up, reply is
3706
+ // CSI ? Ps; Pm$ p
3707
+ // where Ps is the mode number as in DECSET, Pm is the mode value
3708
+ // as in the ANSI DECRQM.
3709
+ Terminal.prototype.requestPrivateMode = function(params) {
3710
+ ;
3711
+ };
3712
+
3713
+ // CSI Ps ; Ps " p
3714
+ // Set conformance level (DECSCL). Valid values for the first
3715
+ // parameter:
3716
+ // Ps = 6 1 -> VT100.
3717
+ // Ps = 6 2 -> VT200.
3718
+ // Ps = 6 3 -> VT300.
3719
+ // Valid values for the second parameter:
3720
+ // Ps = 0 -> 8-bit controls.
3721
+ // Ps = 1 -> 7-bit controls (always set for VT100).
3722
+ // Ps = 2 -> 8-bit controls.
3723
+ Terminal.prototype.setConformanceLevel = function(params) {
3724
+ ;
3725
+ };
3726
+
3727
+ // CSI Ps q Load LEDs (DECLL).
3728
+ // Ps = 0 -> Clear all LEDS (default).
3729
+ // Ps = 1 -> Light Num Lock.
3730
+ // Ps = 2 -> Light Caps Lock.
3731
+ // Ps = 3 -> Light Scroll Lock.
3732
+ // Ps = 2 1 -> Extinguish Num Lock.
3733
+ // Ps = 2 2 -> Extinguish Caps Lock.
3734
+ // Ps = 2 3 -> Extinguish Scroll Lock.
3735
+ Terminal.prototype.loadLEDs = function(params) {
3736
+ ;
3737
+ };
3738
+
3739
+ // CSI Ps SP q
3740
+ // Set cursor style (DECSCUSR, VT520).
3741
+ // Ps = 0 -> blinking block.
3742
+ // Ps = 1 -> blinking block (default).
3743
+ // Ps = 2 -> steady block.
3744
+ // Ps = 3 -> blinking underline.
3745
+ // Ps = 4 -> steady underline.
3746
+ Terminal.prototype.setCursorStyle = function(params) {
3747
+ ;
3748
+ };
3749
+
3750
+ // CSI Ps " q
3751
+ // Select character protection attribute (DECSCA). Valid values
3752
+ // for the parameter:
3753
+ // Ps = 0 -> DECSED and DECSEL can erase (default).
3754
+ // Ps = 1 -> DECSED and DECSEL cannot erase.
3755
+ // Ps = 2 -> DECSED and DECSEL can erase.
3756
+ Terminal.prototype.setCharProtectionAttr = function(params) {
3757
+ ;
3758
+ };
3759
+
3760
+ // CSI ? Pm r
3761
+ // Restore DEC Private Mode Values. The value of Ps previously
3762
+ // saved is restored. Ps values are the same as for DECSET.
3763
+ Terminal.prototype.restorePrivateValues = function(params) {
3764
+ ;
3765
+ };
3766
+
3767
+ // CSI Pt; Pl; Pb; Pr; Ps$ r
3768
+ // Change Attributes in Rectangular Area (DECCARA), VT400 and up.
3769
+ // Pt; Pl; Pb; Pr denotes the rectangle.
3770
+ // Ps denotes the SGR attributes to change: 0, 1, 4, 5, 7.
3771
+ // NOTE: xterm doesn't enable this code by default.
3772
+ Terminal.prototype.setAttrInRectangle = function(params) {
3773
+ var t = params[0]
3774
+ , l = params[1]
3775
+ , b = params[2]
3776
+ , r = params[3]
3777
+ , attr = params[4];
3778
+
3779
+ var line
3780
+ , i;
3781
+
3782
+ for (; t < b + 1; t++) {
3783
+ line = this.lines[this.ybase + t];
3784
+ for (i = l; i < r; i++) {
3785
+ line[i] = [attr, line[i][1]];
3786
+ }
3787
+ }
3788
+
3789
+ // this.maxRange();
3790
+ this.updateRange(params[0]);
3791
+ this.updateRange(params[2]);
3792
+ };
3793
+
3794
+ // CSI ? Pm s
3795
+ // Save DEC Private Mode Values. Ps values are the same as for
3796
+ // DECSET.
3797
+ Terminal.prototype.savePrivateValues = function(params) {
3798
+ ;
3799
+ };
3800
+
3801
+ // CSI Ps ; Ps ; Ps t
3802
+ // Window manipulation (from dtterm, as well as extensions).
3803
+ // These controls may be disabled using the allowWindowOps
3804
+ // resource. Valid values for the first (and any additional
3805
+ // parameters) are:
3806
+ // Ps = 1 -> De-iconify window.
3807
+ // Ps = 2 -> Iconify window.
3808
+ // Ps = 3 ; x ; y -> Move window to [x, y].
3809
+ // Ps = 4 ; height ; width -> Resize the xterm window to
3810
+ // height and width in pixels.
3811
+ // Ps = 5 -> Raise the xterm window to the front of the stack-
3812
+ // ing order.
3813
+ // Ps = 6 -> Lower the xterm window to the bottom of the
3814
+ // stacking order.
3815
+ // Ps = 7 -> Refresh the xterm window.
3816
+ // Ps = 8 ; height ; width -> Resize the text area to
3817
+ // [height;width] in characters.
3818
+ // Ps = 9 ; 0 -> Restore maximized window.
3819
+ // Ps = 9 ; 1 -> Maximize window (i.e., resize to screen
3820
+ // size).
3821
+ // Ps = 1 0 ; 0 -> Undo full-screen mode.
3822
+ // Ps = 1 0 ; 1 -> Change to full-screen.
3823
+ // Ps = 1 1 -> Report xterm window state. If the xterm window
3824
+ // is open (non-iconified), it returns CSI 1 t . If the xterm
3825
+ // window is iconified, it returns CSI 2 t .
3826
+ // Ps = 1 3 -> Report xterm window position. Result is CSI 3
3827
+ // ; x ; y t
3828
+ // Ps = 1 4 -> Report xterm window in pixels. Result is CSI
3829
+ // 4 ; height ; width t
3830
+ // Ps = 1 8 -> Report the size of the text area in characters.
3831
+ // Result is CSI 8 ; height ; width t
3832
+ // Ps = 1 9 -> Report the size of the screen in characters.
3833
+ // Result is CSI 9 ; height ; width t
3834
+ // Ps = 2 0 -> Report xterm window's icon label. Result is
3835
+ // OSC L label ST
3836
+ // Ps = 2 1 -> Report xterm window's title. Result is OSC l
3837
+ // label ST
3838
+ // Ps = 2 2 ; 0 -> Save xterm icon and window title on
3839
+ // stack.
3840
+ // Ps = 2 2 ; 1 -> Save xterm icon title on stack.
3841
+ // Ps = 2 2 ; 2 -> Save xterm window title on stack.
3842
+ // Ps = 2 3 ; 0 -> Restore xterm icon and window title from
3843
+ // stack.
3844
+ // Ps = 2 3 ; 1 -> Restore xterm icon title from stack.
3845
+ // Ps = 2 3 ; 2 -> Restore xterm window title from stack.
3846
+ // Ps >= 2 4 -> Resize to Ps lines (DECSLPP).
3847
+ Terminal.prototype.manipulateWindow = function(params) {
3848
+ ;
3849
+ };
3850
+
3851
+ // CSI Pt; Pl; Pb; Pr; Ps$ t
3852
+ // Reverse Attributes in Rectangular Area (DECRARA), VT400 and
3853
+ // up.
3854
+ // Pt; Pl; Pb; Pr denotes the rectangle.
3855
+ // Ps denotes the attributes to reverse, i.e., 1, 4, 5, 7.
3856
+ // NOTE: xterm doesn't enable this code by default.
3857
+ Terminal.prototype.reverseAttrInRectangle = function(params) {
3858
+ ;
3859
+ };
3860
+
3861
+ // CSI > Ps; Ps t
3862
+ // Set one or more features of the title modes. Each parameter
3863
+ // enables a single feature.
3864
+ // Ps = 0 -> Set window/icon labels using hexadecimal.
3865
+ // Ps = 1 -> Query window/icon labels using hexadecimal.
3866
+ // Ps = 2 -> Set window/icon labels using UTF-8.
3867
+ // Ps = 3 -> Query window/icon labels using UTF-8. (See dis-
3868
+ // cussion of "Title Modes")
3869
+ Terminal.prototype.setTitleModeFeature = function(params) {
3870
+ ;
3871
+ };
3872
+
3873
+ // CSI Ps SP t
3874
+ // Set warning-bell volume (DECSWBV, VT520).
3875
+ // Ps = 0 or 1 -> off.
3876
+ // Ps = 2 , 3 or 4 -> low.
3877
+ // Ps = 5 , 6 , 7 , or 8 -> high.
3878
+ Terminal.prototype.setWarningBellVolume = function(params) {
3879
+ ;
3880
+ };
3881
+
3882
+ // CSI Ps SP u
3883
+ // Set margin-bell volume (DECSMBV, VT520).
3884
+ // Ps = 1 -> off.
3885
+ // Ps = 2 , 3 or 4 -> low.
3886
+ // Ps = 0 , 5 , 6 , 7 , or 8 -> high.
3887
+ Terminal.prototype.setMarginBellVolume = function(params) {
3888
+ ;
3889
+ };
3890
+
3891
+ // CSI Pt; Pl; Pb; Pr; Pp; Pt; Pl; Pp$ v
3892
+ // Copy Rectangular Area (DECCRA, VT400 and up).
3893
+ // Pt; Pl; Pb; Pr denotes the rectangle.
3894
+ // Pp denotes the source page.
3895
+ // Pt; Pl denotes the target location.
3896
+ // Pp denotes the target page.
3897
+ // NOTE: xterm doesn't enable this code by default.
3898
+ Terminal.prototype.copyRectangle = function(params) {
3899
+ ;
3900
+ };
3901
+
3902
+ // CSI Pt ; Pl ; Pb ; Pr ' w
3903
+ // Enable Filter Rectangle (DECEFR), VT420 and up.
3904
+ // Parameters are [top;left;bottom;right].
3905
+ // Defines the coordinates of a filter rectangle and activates
3906
+ // it. Anytime the locator is detected outside of the filter
3907
+ // rectangle, an outside rectangle event is generated and the
3908
+ // rectangle is disabled. Filter rectangles are always treated
3909
+ // as "one-shot" events. Any parameters that are omitted default
3910
+ // to the current locator position. If all parameters are omit-
3911
+ // ted, any locator motion will be reported. DECELR always can-
3912
+ // cels any prevous rectangle definition.
3913
+ Terminal.prototype.enableFilterRectangle = function(params) {
3914
+ ;
3915
+ };
3916
+
3917
+ // CSI Ps x Request Terminal Parameters (DECREQTPARM).
3918
+ // if Ps is a "0" (default) or "1", and xterm is emulating VT100,
3919
+ // the control sequence elicits a response of the same form whose
3920
+ // parameters describe the terminal:
3921
+ // Ps -> the given Ps incremented by 2.
3922
+ // Pn = 1 <- no parity.
3923
+ // Pn = 1 <- eight bits.
3924
+ // Pn = 1 <- 2 8 transmit 38.4k baud.
3925
+ // Pn = 1 <- 2 8 receive 38.4k baud.
3926
+ // Pn = 1 <- clock multiplier.
3927
+ // Pn = 0 <- STP flags.
3928
+ Terminal.prototype.requestParameters = function(params) {
3929
+ ;
3930
+ };
3931
+
3932
+ // CSI Ps x Select Attribute Change Extent (DECSACE).
3933
+ // Ps = 0 -> from start to end position, wrapped.
3934
+ // Ps = 1 -> from start to end position, wrapped.
3935
+ // Ps = 2 -> rectangle (exact).
3936
+ Terminal.prototype.selectChangeExtent = function(params) {
3937
+ ;
3938
+ };
3939
+
3940
+ // CSI Pc; Pt; Pl; Pb; Pr$ x
3941
+ // Fill Rectangular Area (DECFRA), VT420 and up.
3942
+ // Pc is the character to use.
3943
+ // Pt; Pl; Pb; Pr denotes the rectangle.
3944
+ // NOTE: xterm doesn't enable this code by default.
3945
+ Terminal.prototype.fillRectangle = function(params) {
3946
+ var ch = params[0]
3947
+ , t = params[1]
3948
+ , l = params[2]
3949
+ , b = params[3]
3950
+ , r = params[4];
3951
+
3952
+ var line
3953
+ , i;
3954
+
3955
+ for (; t < b + 1; t++) {
3956
+ line = this.lines[this.ybase + t];
3957
+ for (i = l; i < r; i++) {
3958
+ line[i] = [line[i][0], String.fromCharCode(ch)];
3959
+ }
3960
+ }
3961
+
3962
+ // this.maxRange();
3963
+ this.updateRange(params[1]);
3964
+ this.updateRange(params[3]);
3965
+ };
3966
+
3967
+ // CSI Ps ; Pu ' z
3968
+ // Enable Locator Reporting (DECELR).
3969
+ // Valid values for the first parameter:
3970
+ // Ps = 0 -> Locator disabled (default).
3971
+ // Ps = 1 -> Locator enabled.
3972
+ // Ps = 2 -> Locator enabled for one report, then disabled.
3973
+ // The second parameter specifies the coordinate unit for locator
3974
+ // reports.
3975
+ // Valid values for the second parameter:
3976
+ // Pu = 0 <- or omitted -> default to character cells.
3977
+ // Pu = 1 <- device physical pixels.
3978
+ // Pu = 2 <- character cells.
3979
+ Terminal.prototype.enableLocatorReporting = function(params) {
3980
+ var val = params[0] > 0;
3981
+ //this.mouseEvents = val;
3982
+ //this.decLocator = val;
3983
+ };
3984
+
3985
+ // CSI Pt; Pl; Pb; Pr$ z
3986
+ // Erase Rectangular Area (DECERA), VT400 and up.
3987
+ // Pt; Pl; Pb; Pr denotes the rectangle.
3988
+ // NOTE: xterm doesn't enable this code by default.
3989
+ Terminal.prototype.eraseRectangle = function(params) {
3990
+ var t = params[0]
3991
+ , l = params[1]
3992
+ , b = params[2]
3993
+ , r = params[3];
3994
+
3995
+ var line
3996
+ , i
3997
+ , ch;
3998
+
3999
+ ch = [this.curAttr, ' ']; // xterm?
4000
+
4001
+ for (; t < b + 1; t++) {
4002
+ line = this.lines[this.ybase + t];
4003
+ for (i = l; i < r; i++) {
4004
+ line[i] = ch;
4005
+ }
4006
+ }
4007
+
4008
+ // this.maxRange();
4009
+ this.updateRange(params[0]);
4010
+ this.updateRange(params[2]);
4011
+ };
4012
+
4013
+ // CSI Pm ' {
4014
+ // Select Locator Events (DECSLE).
4015
+ // Valid values for the first (and any additional parameters)
4016
+ // are:
4017
+ // Ps = 0 -> only respond to explicit host requests (DECRQLP).
4018
+ // (This is default). It also cancels any filter
4019
+ // rectangle.
4020
+ // Ps = 1 -> report button down transitions.
4021
+ // Ps = 2 -> do not report button down transitions.
4022
+ // Ps = 3 -> report button up transitions.
4023
+ // Ps = 4 -> do not report button up transitions.
4024
+ Terminal.prototype.setLocatorEvents = function(params) {
4025
+ ;
4026
+ };
4027
+
4028
+ // CSI Pt; Pl; Pb; Pr$ {
4029
+ // Selective Erase Rectangular Area (DECSERA), VT400 and up.
4030
+ // Pt; Pl; Pb; Pr denotes the rectangle.
4031
+ Terminal.prototype.selectiveEraseRectangle = function(params) {
4032
+ ;
4033
+ };
4034
+
4035
+ // CSI Ps ' |
4036
+ // Request Locator Position (DECRQLP).
4037
+ // Valid values for the parameter are:
4038
+ // Ps = 0 , 1 or omitted -> transmit a single DECLRP locator
4039
+ // report.
4040
+
4041
+ // If Locator Reporting has been enabled by a DECELR, xterm will
4042
+ // respond with a DECLRP Locator Report. This report is also
4043
+ // generated on button up and down events if they have been
4044
+ // enabled with a DECSLE, or when the locator is detected outside
4045
+ // of a filter rectangle, if filter rectangles have been enabled
4046
+ // with a DECEFR.
4047
+
4048
+ // -> CSI Pe ; Pb ; Pr ; Pc ; Pp & w
4049
+
4050
+ // Parameters are [event;button;row;column;page].
4051
+ // Valid values for the event:
4052
+ // Pe = 0 -> locator unavailable - no other parameters sent.
4053
+ // Pe = 1 -> request - xterm received a DECRQLP.
4054
+ // Pe = 2 -> left button down.
4055
+ // Pe = 3 -> left button up.
4056
+ // Pe = 4 -> middle button down.
4057
+ // Pe = 5 -> middle button up.
4058
+ // Pe = 6 -> right button down.
4059
+ // Pe = 7 -> right button up.
4060
+ // Pe = 8 -> M4 button down.
4061
+ // Pe = 9 -> M4 button up.
4062
+ // Pe = 1 0 -> locator outside filter rectangle.
4063
+ // ``button'' parameter is a bitmask indicating which buttons are
4064
+ // pressed:
4065
+ // Pb = 0 <- no buttons down.
4066
+ // Pb & 1 <- right button down.
4067
+ // Pb & 2 <- middle button down.
4068
+ // Pb & 4 <- left button down.
4069
+ // Pb & 8 <- M4 button down.
4070
+ // ``row'' and ``column'' parameters are the coordinates of the
4071
+ // locator position in the xterm window, encoded as ASCII deci-
4072
+ // mal.
4073
+ // The ``page'' parameter is not used by xterm, and will be omit-
4074
+ // ted.
4075
+ Terminal.prototype.requestLocatorPosition = function(params) {
4076
+ ;
4077
+ };
4078
+
4079
+ // CSI P m SP }
4080
+ // Insert P s Column(s) (default = 1) (DECIC), VT420 and up.
4081
+ // NOTE: xterm doesn't enable this code by default.
4082
+ Terminal.prototype.insertColumns = function() {
4083
+ var param = params[0]
4084
+ , l = this.ybase + this.rows
4085
+ , ch = [this.curAttr, ' '] // xterm?
4086
+ , i;
4087
+
4088
+ while (param--) {
4089
+ for (i = this.ybase; i < l; i++) {
4090
+ this.lines[i].splice(this.x + 1, 0, ch);
4091
+ this.lines[i].pop();
4092
+ }
4093
+ }
4094
+
4095
+ this.maxRange();
4096
+ };
4097
+
4098
+ // CSI P m SP ~
4099
+ // Delete P s Column(s) (default = 1) (DECDC), VT420 and up
4100
+ // NOTE: xterm doesn't enable this code by default.
4101
+ Terminal.prototype.deleteColumns = function() {
4102
+ var param = params[0]
4103
+ , l = this.ybase + this.rows
4104
+ , ch = [this.curAttr, ' '] // xterm?
4105
+ , i;
4106
+
4107
+ while (param--) {
4108
+ for (i = this.ybase; i < l; i++) {
4109
+ this.lines[i].splice(this.x, 1);
4110
+ this.lines[i].push(ch);
4111
+ }
4112
+ }
4113
+
4114
+ this.maxRange();
4115
+ };
4116
+
4117
+ /**
4118
+ * Character Sets
4119
+ */
4120
+
4121
+ Terminal.charsets = {};
4122
+
4123
+ // DEC Special Character and Line Drawing Set.
4124
+ // http://vt100.net/docs/vt102-ug/table5-13.html
4125
+ // A lot of curses apps use this if they see TERM=xterm.
4126
+ // testing: echo -e '\e(0a\e(B'
4127
+ // The xterm output sometimes seems to conflict with the
4128
+ // reference above. xterm seems in line with the reference
4129
+ // when running vttest however.
4130
+ // The table below now uses xterm's output from vttest.
4131
+ Terminal.charsets.SCLD = { // (0
4132
+ '`': '\u25c6', // '◆'
4133
+ 'a': '\u2592', // '▒'
4134
+ 'b': '\u0009', // '\t'
4135
+ 'c': '\u000c', // '\f'
4136
+ 'd': '\u000d', // '\r'
4137
+ 'e': '\u000a', // '\n'
4138
+ 'f': '\u00b0', // '°'
4139
+ 'g': '\u00b1', // '±'
4140
+ 'h': '\u2424', // '\u2424' (NL)
4141
+ 'i': '\u000b', // '\v'
4142
+ 'j': '\u2518', // '┘'
4143
+ 'k': '\u2510', // '┐'
4144
+ 'l': '\u250c', // '┌'
4145
+ 'm': '\u2514', // '└'
4146
+ 'n': '\u253c', // '┼'
4147
+ 'o': '\u23ba', // '⎺'
4148
+ 'p': '\u23bb', // '⎻'
4149
+ 'q': '\u2500', // '─'
4150
+ 'r': '\u23bc', // '⎼'
4151
+ 's': '\u23bd', // '⎽'
4152
+ 't': '\u251c', // '├'
4153
+ 'u': '\u2524', // '┤'
4154
+ 'v': '\u2534', // '┴'
4155
+ 'w': '\u252c', // '┬'
4156
+ 'x': '\u2502', // '│'
4157
+ 'y': '\u2264', // '≤'
4158
+ 'z': '\u2265', // '≥'
4159
+ '{': '\u03c0', // 'π'
4160
+ '|': '\u2260', // '≠'
4161
+ '}': '\u00a3', // '£'
4162
+ '~': '\u00b7' // '·'
4163
+ };
4164
+
4165
+ Terminal.charsets.UK = null; // (A
4166
+ Terminal.charsets.US = null; // (B (USASCII)
4167
+ Terminal.charsets.Dutch = null; // (4
4168
+ Terminal.charsets.Finnish = null; // (C or (5
4169
+ Terminal.charsets.French = null; // (R
4170
+ Terminal.charsets.FrenchCanadian = null; // (Q
4171
+ Terminal.charsets.German = null; // (K
4172
+ Terminal.charsets.Italian = null; // (Y
4173
+ Terminal.charsets.NorwegianDanish = null; // (E or (6
4174
+ Terminal.charsets.Spanish = null; // (Z
4175
+ Terminal.charsets.Swedish = null; // (H or (7
4176
+ Terminal.charsets.Swiss = null; // (=
4177
+ Terminal.charsets.ISOLatin = null; // /A
4178
+
4179
+ /**
4180
+ * Helpers
4181
+ */
4182
+
4183
+ function on(el, type, handler, capture) {
4184
+ el.addEventListener(type, handler, capture || false);
4185
+ }
4186
+
4187
+ function off(el, type, handler, capture) {
4188
+ el.removeEventListener(type, handler, capture || false);
4189
+ }
4190
+
4191
+ function cancel(ev) {
4192
+ if (ev.preventDefault) ev.preventDefault();
4193
+ ev.returnValue = false;
4194
+ if (ev.stopPropagation) ev.stopPropagation();
4195
+ ev.cancelBubble = true;
4196
+ return false;
4197
+ }
4198
+
4199
+ function inherits(child, parent) {
4200
+ function f() {
4201
+ this.constructor = child;
4202
+ }
4203
+ f.prototype = parent.prototype;
4204
+ child.prototype = new f;
4205
+ }
4206
+
4207
+ var isMac = ~navigator.userAgent.indexOf('Mac');
4208
+
4209
+ // if bold is broken, we can't
4210
+ // use it in the terminal.
4211
+ function isBoldBroken() {
4212
+ var el = document.createElement('span');
4213
+ el.innerHTML = 'hello world';
4214
+ document.body.appendChild(el);
4215
+ var w1 = el.scrollWidth;
4216
+ el.style.fontWeight = 'bold';
4217
+ var w2 = el.scrollWidth;
4218
+ document.body.removeChild(el);
4219
+ return w1 !== w2;
4220
+ }
4221
+
4222
+ var String = this.String;
4223
+ var setTimeout = this.setTimeout;
4224
+ var setInterval = this.setInterval;
4225
+
4226
+ /**
4227
+ * Expose
4228
+ */
4229
+
4230
+ Terminal.EventEmitter = EventEmitter;
4231
+ Terminal.isMac = isMac;
4232
+ Terminal.inherits = inherits;
4233
+ Terminal.on = on;
4234
+ Terminal.off = off;
4235
+ Terminal.cancel = cancel;
4236
+
4237
+ if (typeof module !== 'undefined') {
4238
+ module.exports = Terminal;
4239
+ } else {
4240
+ this.Terminal = Terminal;
4241
+ }
4242
+
4243
+ }).call(function() {
4244
+ return this || (typeof window !== 'undefined' ? window : global);
4245
+ }());