]>
git.proxmox.com Git - mirror_xterm.js.git/blob - src/xterm.js
2 * xterm.js: xterm, in the browser
3 * Copyright (c) 2014, sourceLair Limited (www.sourcelair.com (MIT License)
4 * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
5 * https://github.com/chjj/term.js
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 * Originally forked from (with the author's permission):
26 * Fabrice Bellard's javascript vt100 for jslinux:
27 * http://bellard.org/jslinux/
28 * Copyright (c) 2011 Fabrice Bellard
29 * The original design remains. The terminal itself
30 * has been extended to include xterm CSI codes, among
35 if (typeof exports
=== 'object' && typeof module
=== 'object') {
37 * CommonJS environment
39 module
.exports
= xterm
.call(this);
40 } else if (typeof define
== 'function') {
42 * Require.js is available
44 define([], xterm
.bind(window
));
47 * Plain browser environment
49 this.Xterm
= xterm
.call(this);
50 this.Terminal
= this.Xterm
; /* Backwards compatibility with term.js */
54 * Terminal Emulation References:
56 * http://invisible-island.net/xterm/ctlseqs/ctlseqs.txt
57 * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
58 * http://invisible-island.net/vttest/
59 * http://www.inwap.com/pdp10/ansicode.txt
60 * http://linux.die.net/man/4/console_codes
61 * http://linux.die.net/man/7/urxvt
70 var window
= this, document
= this.document
;
76 function EventEmitter() {
77 this._events
= this._events
|| {};
80 EventEmitter
.prototype.addListener = function(type
, listener
) {
81 this._events
[type
] = this._events
[type
] || [];
82 this._events
[type
].push(listener
);
85 EventEmitter
.prototype.on
= EventEmitter
.prototype.addListener
;
87 EventEmitter
.prototype.removeListener = function(type
, listener
) {
88 if (!this._events
[type
]) return;
90 var obj
= this._events
[type
]
94 if (obj
[i
] === listener
|| obj
[i
].listener
=== listener
) {
101 EventEmitter
.prototype.off
= EventEmitter
.prototype.removeListener
;
103 EventEmitter
.prototype.removeAllListeners = function(type
) {
104 if (this._events
[type
]) delete this._events
[type
];
107 EventEmitter
.prototype.once = function(type
, listener
) {
110 var args
= Array
.prototype.slice
.call(arguments
);
111 this.removeListener(type
, on
);
112 return listener
.apply(this, args
);
114 on
.listener
= listener
;
115 return this.on(type
, on
);
118 EventEmitter
.prototype.emit = function(type
) {
119 if (!this._events
[type
]) return;
121 var args
= Array
.prototype.slice
.call(arguments
, 1)
122 , obj
= this._events
[type
]
127 obj
[i
].apply(this, args
);
131 EventEmitter
.prototype.listeners = function(type
) {
132 return this._events
[type
] = this._events
[type
] || [];
139 var normal
= 0, escaped
= 1, csi
= 2, osc
= 3, charset
= 4, dcs
= 5, ignore
= 6;
146 * Creates a new `Terminal` object.
148 * @param {object} options An object containing a set of options, the available options are:
149 * - cursorBlink (boolean): Whether the terminal cursor blinks
153 function Terminal(options
) {
156 if (!(this instanceof Terminal
)) {
157 return new Terminal(arguments
[0], arguments
[1], arguments
[2]);
160 self
.cancel
= Terminal
.cancel
;
162 EventEmitter
.call(this);
164 if (typeof options
=== 'number') {
168 handler
: arguments
[2]
172 options
= options
|| {};
175 Object
.keys(Terminal
.defaults
).forEach(function(key
) {
176 if (options
[key
] == null) {
177 options
[key
] = Terminal
.options
[key
];
179 if (Terminal
[key
] !== Terminal
.defaults
[key
]) {
180 options
[key
] = Terminal
[key
];
183 self
[key
] = options
[key
];
186 if (options
.colors
.length
=== 8) {
187 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(8));
188 } else if (options
.colors
.length
=== 16) {
189 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16));
190 } else if (options
.colors
.length
=== 10) {
191 options
.colors
= options
.colors
.slice(0, -2).concat(
192 Terminal
._colors
.slice(8, -2), options
.colors
.slice(-2));
193 } else if (options
.colors
.length
=== 18) {
194 options
.colors
= options
.colors
.concat(
195 Terminal
._colors
.slice(16, -2), options
.colors
.slice(-2));
197 this.colors
= options
.colors
;
199 this.options
= options
;
201 // this.context = options.context || window;
202 // this.document = options.document || document;
203 this.parent
= options
.body
|| options
.parent
204 || (document
? document
.getElementsByTagName('body')[0] : null);
206 this.cols
= options
.cols
|| options
.geometry
[0];
207 this.rows
= options
.rows
|| options
.geometry
[1];
209 if (options
.handler
) {
210 this.on('data', options
.handler
);
214 * The scroll position of the y cursor, ie. ybase + y = the y position within the entire
220 * The scroll position of the viewport
225 * The cursor's x position after ybase
230 * The cursor's y position after ybase
235 * Used to debounce the refresh function
237 this.isRefreshing
= false;
240 * Whether there is a full terminal refresh queued
243 this.cursorState
= 0;
244 this.cursorHidden
= false;
249 this.scrollBottom
= this.rows
- 1;
252 this.applicationKeypad
= false;
253 this.applicationCursor
= false;
254 this.originMode
= false;
255 this.insertMode
= false;
256 this.wraparoundMode
= true; // defaults: xterm - true, vt100 - false
261 this.gcharset
= null;
263 this.charsets
= [null];
287 this.readable
= true;
288 this.writable
= true;
290 this.defAttr
= (0 << 18) | (257 << 9) | (256 << 0);
291 this.curAttr
= this.defAttr
;
294 this.currentParam
= 0;
298 // leftover surrogate high from previous write invocation
299 this.surrogate_high
= '';
302 * An array of all lines in the entire buffer, including the prompt. The lines are array of
303 * characters which are 2-length arrays where [0] is an attribute and [1] is the character.
308 this.lines
.push(this.blankLine());
315 inherits(Terminal
, EventEmitter
);
317 // back_color_erase feature for xterm.
318 Terminal
.prototype.eraseAttr = function() {
319 // if (this.is('screen')) return this.defAttr;
320 return (this.defAttr
& ~0x1ff) | (this.curAttr
& 0x1ff);
328 Terminal
.tangoColors
= [
349 // Colors 0-15 + 16-255
350 // Much thanks to TooTallNate for writing this.
351 Terminal
.colors
= (function() {
352 var colors
= Terminal
.tangoColors
.slice()
353 , r
= [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff]
358 for (; i
< 216; i
++) {
359 out(r
[(i
/ 36) % 6 | 0], r
[(i
/ 6) % 6 | 0], r
[i
% 6]);
364 for (; i
< 24; i
++) {
369 function out(r
, g
, b
) {
370 colors
.push('#' + hex(r
) + hex(g
) + hex(b
));
375 return c
.length
< 2 ? '0' + c
: c
;
381 Terminal
._colors
= Terminal
.colors
.slice();
383 Terminal
.vcolors
= (function() {
385 , colors
= Terminal
.colors
389 for (; i
< 256; i
++) {
390 color
= parseInt(colors
[i
].substring(1), 16);
392 (color
>> 16) & 0xff,
405 Terminal
.defaults
= {
406 colors
: Terminal
.colors
,
418 // programFeatures: false,
422 Terminal
.options
= {};
424 Terminal
.focus
= null;
426 each(keys(Terminal
.defaults
), function(key
) {
427 Terminal
[key
] = Terminal
.defaults
[key
];
428 Terminal
.options
[key
] = Terminal
.defaults
[key
];
432 * Focus the terminal. Delegates focus handling to the terminal's DOM element.
436 Terminal
.prototype.focus = function() {
437 if (document
.activeElement
=== this.textarea
) {
441 if (this.sendFocus
) {
445 this.element
.classList
.add('focus');
447 this.textarea
.focus();
448 Terminal
.focus
= this;
452 * Binds the desired focus behavior on a given terminal object.
456 Terminal
.bindFocus = function (term
) {
457 on(term
.element
, 'focus', function (ev
) {
458 if (term
.sendFocus
) {
463 Terminal
.focus
= term
;
464 term
.emit('focus', {terminal
: term
});
469 * Blur the terminal. Delegates blur handling to the terminal's DOM element.
473 Terminal
.prototype.blur = function() {
474 if (Terminal
.focus
!== this) {
478 this.element
.classList
.remove('focus');
479 this.cursorState
= 0;
480 this.refresh(this.y
, this.y
);
481 this.textarea
.blur();
482 if (this.sendFocus
) {
483 this.send('\x1b[0]');
485 Terminal
.focus
= null;
489 * Binds the desired blur behavior on a given terminal object.
493 Terminal
.bindBlur = function (term
) {
494 on(term
.element
, 'blur', function (ev
) {
495 if (term
.sendFocus
) {
498 Terminal
.focus
= null;
499 term
.emit('blur', {terminal
: term
});
504 * Initialize default behavior
506 Terminal
.prototype.initGlobal = function() {
507 Terminal
.bindPaste(this);
508 Terminal
.bindKeys(this);
509 Terminal
.bindCopy(this);
513 * Bind to paste event and allow both keyboard and right-click pasting, without having the
514 * contentEditable value set to true.
516 Terminal
.bindPaste = function(term
) {
517 on([term
.textarea
, term
.element
], 'paste', function(ev
) {
518 ev
.stopPropagation();
519 if (ev
.clipboardData
) {
520 var text
= ev
.clipboardData
.getData('text/plain');
522 term
.textarea
.value
= '';
523 return term
.cancel(ev
);
529 * Prepares text copied from terminal selection, to be saved in the clipboard by:
530 * 1. stripping all trailing white spaces
531 * 2. converting all non-breaking spaces to regular spaces
532 * @param {string} text The copied text that needs processing for storing in clipboard
536 Terminal
.prepareCopiedTextForClipboard = function (text
) {
537 var space
= String
.fromCharCode(32),
538 nonBreakingSpace
= String
.fromCharCode(160),
539 allNonBreakingSpaces
= new RegExp(nonBreakingSpace
, 'g'),
540 processedText
= text
.split('\n').map(function (line
) {
542 * Strip all trailing white spaces and convert all non-breaking spaces to regular
545 var processedLine
= line
.replace(/\s+$/g, '').replace(allNonBreakingSpaces
, space
);
547 return processedLine
;
550 return processedText
;
554 * Apply key handling to the terminal
556 Terminal
.bindKeys = function(term
) {
557 on(term
.element
, 'keydown', function(ev
) {
558 if (document
.activeElement
!= this) {
564 on(term
.element
, 'keypress', function(ev
) {
565 if (document
.activeElement
!= this) {
571 on(term
.element
, 'keyup', term
.focus
.bind(term
));
573 on(term
.textarea
, 'keydown', function(ev
) {
577 on(term
.textarea
, 'keypress', function(ev
) {
579 // Truncate the textarea's value, since it is not needed
585 * Binds copy functionality to the given terminal.
588 Terminal
.bindCopy = function(term
) {
589 on(term
.element
, 'copy', function(ev
) {
596 * Insert the given row to the terminal or produce a new one
597 * if no row argument is passed. Return the inserted row.
599 Terminal
.prototype.insertRow = function (row
) {
600 if (typeof row
!= 'object') {
601 row
= document
.createElement('div');
604 this.rowContainer
.appendChild(row
);
605 this.children
.push(row
);
612 * Opens the terminal within an element.
614 * @param {HTMLElement} parent The element to create the terminal within.
618 Terminal
.prototype.open = function(parent
) {
619 var self
=this, i
=0, div
;
621 this.parent
= parent
|| this.parent
;
624 throw new Error('Terminal requires a parent element.');
628 * Grab global elements
630 this.context
= this.parent
.ownerDocument
.defaultView
;
631 this.document
= this.parent
.ownerDocument
;
632 this.body
= this.document
.getElementsByTagName('body')[0];
637 if (this.context
.navigator
&& this.context
.navigator
.userAgent
) {
638 this.isMSIE
= !!~this.context
.navigator
.userAgent
.indexOf('MSIE');
642 * Find the users platform. We use this to interpret the meta key
643 * and ISO third level shifts.
644 * http://stackoverflow.com/questions/19877924/what-is-the-list-of-possible-values-for-navigator-platform-as-of-today
646 if (this.context
.navigator
&& this.context
.navigator
.platform
) {
647 this.isMac
= contains(
648 this.context
.navigator
.platform
,
649 ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K']
651 this.isIpad
= this.context
.navigator
.platform
=== 'iPad';
652 this.isIphone
= this.context
.navigator
.platform
=== 'iPhone';
653 this.isMSWindows
= contains(
654 this.context
.navigator
.platform
,
655 ['Windows', 'Win16', 'Win32', 'WinCE']
660 * Create main element container
662 this.element
= this.document
.createElement('div');
663 this.element
.classList
.add('terminal');
664 this.element
.classList
.add('xterm');
665 this.element
.classList
.add('xterm-theme-' + this.theme
);
666 this.element
.setAttribute('tabindex', 0);
669 * Create the container that will hold the lines of the terminal and then
670 * produce the lines the lines.
672 this.rowContainer
= document
.createElement('div');
673 this.rowContainer
.classList
.add('xterm-rows');
674 this.element
.appendChild(this.rowContainer
);
678 * Create the container that will hold helpers like the textarea for
679 * capturing DOM Events. Then produce the helpers.
681 this.helperContainer
= document
.createElement('div');
682 this.helperContainer
.classList
.add('xterm-helpers');
683 this.element
.appendChild(this.helperContainer
);
684 this.textarea
= document
.createElement('textarea');
685 this.textarea
.classList
.add('xterm-helper-textarea');
686 this.textarea
.setAttribute('autocorrect', 'off');
687 this.textarea
.setAttribute('autocapitalize', 'off');
688 this.textarea
.setAttribute('spellcheck', 'false');
689 this.textarea
.tabIndex
= 0;
690 this.textarea
.onfocus = function() {
691 self
.emit('focus', {terminal
: self
});
693 this.textarea
.onblur = function() {
694 self
.emit('blur', {terminal
: self
});
696 this.helperContainer
.appendChild(this.textarea
);
698 for (; i
< this.rows
; i
++) {
701 this.parent
.appendChild(this.element
);
704 this.refresh(0, this.rows
- 1);
706 // Initialize global actions that
707 // need to be taken on the document.
710 // Ensure there is a Terminal.focus.
713 on(this.element
, 'mouseup', function() {
714 var selection
= document
.getSelection(),
715 collapsed
= selection
.isCollapsed
,
716 isRange
= typeof collapsed
== 'boolean' ? !collapsed
: selection
.type
== 'Range';
722 // Listen for mouse events and translate
723 // them into terminal mouse protocols.
726 // Figure out whether boldness affects
727 // the character width of monospace fonts.
728 if (Terminal
.brokenBold
== null) {
729 Terminal
.brokenBold
= isBoldBroken(this.document
);
737 * Attempts to load an add-on using CommonJS or RequireJS (whichever is available).
738 * @param {string} addon The name of the addon to load
741 Terminal
.loadAddon = function(addon
, callback
) {
742 if (typeof exports
=== 'object' && typeof module
=== 'object') {
744 return require(__dirname
+ '/../addons/' + addon
);
745 } else if (typeof define
== 'function') {
747 return require(['../addons/' + addon
+ '/' + addon
], callback
);
749 console
.error('Cannot load a module without a CommonJS or RequireJS environment.');
755 // XTerm mouse events
756 // http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking
757 // To better understand these
758 // the xterm code is very helpful:
760 // button.c, charproc.c, misc.c
761 // Relevant functions in xterm/button.c:
762 // BtnCode, EmitButtonCode, EditorButton, SendMousePosition
763 Terminal
.prototype.bindMouse = function() {
764 var el
= this.element
768 var wheelEvent
= 'onmousewheel' in this.context
772 // mouseup, mousedown, mousewheel
773 // left click: ^[[M 3<^[[M#3<
774 // mousewheel up: ^[[M`3>
775 function sendButton(ev
) {
779 // get the xterm-style button
780 button
= getButton(ev
);
782 // get mouse coordinates
786 sendEvent(button
, pos
);
788 switch (ev
.overrideType
|| ev
.type
) {
793 // keep it at the left
794 // button, just in case.
805 // motion example of a left click:
806 // ^[[M 3<^[[M@4<^[[M@5<^[[M@6<^[[M@7<^[[M#7<
807 function sendMove(ev
) {
814 // buttons marked as motions
815 // are incremented by 32
818 sendEvent(button
, pos
);
822 // position to characters
823 function encode(data
, ch
) {
824 if (!self
.utfMouse
) {
825 if (ch
=== 255) return data
.push(0);
826 if (ch
> 127) ch
= 127;
829 if (ch
=== 2047) return data
.push(0);
833 if (ch
> 2047) ch
= 2047;
834 data
.push(0xC0 | (ch
>> 6));
835 data
.push(0x80 | (ch
& 0x3F));
840 // send a mouse event:
841 // regular/utf8: ^[[M Cb Cx Cy
842 // urxvt: ^[[ Cb ; Cx ; Cy M
843 // sgr: ^[[ Cb ; Cx ; Cy M/m
844 // vt300: ^[[ 24(1/3/5)~ [ Cx , Cy ] \r
845 // locator: CSI P e ; P b ; P r ; P c ; P p & w
846 function sendEvent(button
, pos
) {
847 // self.emit('mouse', {
853 if (self
.vt300Mouse
) {
855 // http://www.vt100.net/docs/vt3xx-gp/chapter15.html
859 var data
= '\x1b[24';
860 if (button
=== 0) data
+= '1';
861 else if (button
=== 1) data
+= '3';
862 else if (button
=== 2) data
+= '5';
863 else if (button
=== 3) return;
865 data
+= '~[' + pos
.x
+ ',' + pos
.y
+ ']\r';
870 if (self
.decLocator
) {
875 if (button
=== 0) button
= 2;
876 else if (button
=== 1) button
= 4;
877 else if (button
=== 2) button
= 6;
878 else if (button
=== 3) button
= 3;
882 + (button
=== 3 ? 4 : 0)
893 if (self
.urxvtMouse
) {
898 self
.send('\x1b[' + button
+ ';' + pos
.x
+ ';' + pos
.y
+ 'M');
906 + ((button
& 3) === 3 ? button
& ~3 : button
)
911 + ((button
& 3) === 3 ? 'm' : 'M'));
917 encode(data
, button
);
921 self
.send('\x1b[M' + String
.fromCharCode
.apply(String
, data
));
924 function getButton(ev
) {
937 // 1, and 2 - with 64 added
938 switch (ev
.overrideType
|| ev
.type
) {
940 button
= ev
.button
!= null
947 button
= button
=== 1 ? 0 : button
=== 4 ? 1 : button
;
953 case 'DOMMouseScroll':
954 button
= ev
.detail
< 0
959 button
= ev
.wheelDeltaY
> 0
965 // next three bits are the modifiers:
966 // 4 = shift, 8 = meta, 16 = control
967 shift
= ev
.shiftKey
? 4 : 0;
968 meta
= ev
.metaKey
? 8 : 0;
969 ctrl
= ev
.ctrlKey
? 16 : 0;
970 mod
= shift
| meta
| ctrl
;
973 if (self
.vt200Mouse
) {
976 } else if (!self
.normalMouse
) {
981 button
= (32 + (mod
<< 2)) + button
;
986 // mouse coordinates measured in cols/rows
987 function getCoords(ev
) {
990 // ignore browsers without pageX for now
991 if (ev
.pageX
== null) return;
997 // should probably check offsetParent
998 // but this is more portable
999 while (el
&& el
!== self
.document
.documentElement
) {
1002 el
= 'offsetParent' in el
1007 // convert to cols/rows
1008 w
= self
.element
.clientWidth
;
1009 h
= self
.element
.clientHeight
;
1010 x
= Math
.round((x
/ w
) * self
.cols
);
1011 y
= Math
.round((y
/ h
) * self
.rows
);
1013 // be sure to avoid sending
1014 // bad positions to the program
1016 if (x
> self
.cols
) x
= self
.cols
;
1018 if (y
> self
.rows
) y
= self
.rows
;
1020 // xterm sends raw bytes and
1021 // starts at 32 (SP) for each.
1028 type
: (ev
.overrideType
|| ev
.type
) === wheelEvent
1030 : (ev
.overrideType
|| ev
.type
)
1034 on(el
, 'mousedown', function(ev
) {
1035 if (!self
.mouseEvents
) return;
1044 //if (self.vt200Mouse && !self.normalMouse) {
1045 if (self
.vt200Mouse
) {
1046 ev
.overrideType
= 'mouseup';
1048 return self
.cancel(ev
);
1052 if (self
.normalMouse
) on(self
.document
, 'mousemove', sendMove
);
1054 // x10 compatibility mode can't send button releases
1055 if (!self
.x10Mouse
) {
1056 on(self
.document
, 'mouseup', function up(ev
) {
1058 if (self
.normalMouse
) off(self
.document
, 'mousemove', sendMove
);
1059 off(self
.document
, 'mouseup', up
);
1060 return self
.cancel(ev
);
1064 return self
.cancel(ev
);
1067 //if (self.normalMouse) {
1068 // on(self.document, 'mousemove', sendMove);
1071 on(el
, wheelEvent
, function(ev
) {
1072 if (!self
.mouseEvents
) return;
1075 || self
.decLocator
) return;
1077 return self
.cancel(ev
);
1080 // allow mousewheel scrolling in
1081 // the shell for example
1082 on(el
, wheelEvent
, function(ev
) {
1083 if (self
.mouseEvents
) return;
1084 if (self
.applicationKeypad
) return;
1085 if (ev
.type
=== 'DOMMouseScroll') {
1086 self
.scrollDisp(ev
.detail
< 0 ? -1 : 1);
1088 self
.scrollDisp(ev
.wheelDeltaY
> 0 ? -1 : 1);
1090 return self
.cancel(ev
);
1095 * Destroys the terminal.
1099 Terminal
.prototype.destroy = function() {
1100 this.readable
= false;
1101 this.writable
= false;
1103 this.handler = function() {};
1104 this.write = function() {};
1105 if (this.element
.parentNode
) {
1106 this.element
.parentNode
.removeChild(this.element
);
1108 //this.emit('close');
1113 * Flags used to render terminal text properly
1126 * In the screen buffer, each character
1127 * is stored as a an array with a character
1128 * and a 32-bit integer.
1129 * First value: a utf-16 character.
1131 * Next 9 bits: background color (0-511).
1132 * Next 9 bits: foreground color (0-511).
1133 * Next 14 bits: a mask for misc. flags:
1134 * 1=bold, 2=underline, 4=blink, 8=inverse, 16=invisible
1138 * Refreshes terminal content within two rows (inclusive).
1140 * @param {number} start The row to start from (between 0 and terminal's height terminal - 1)
1141 * @param {number} end The row to end at (between fromRow and terminal's height terminal - 1)
1142 * @param {boolean} queue Whether the refresh should ran right now or be queued
1146 Terminal
.prototype.refresh = function(start
, end
, queue
) {
1149 // queue defaults to true
1150 queue
= (typeof queue
== 'undefined') ? true : queue
;
1153 * The refresh queue allows refresh to execute only approximately 30 times a second. For
1154 * commands that pass a significant amount of output to the write function, this prevents the
1155 * terminal from maxing out the CPU and making the UI unresponsive. While commands can still
1156 * run beyond what they do on the terminal, it is far better with a debounce in place as
1157 * every single terminal manipulation does not need to be constructed in the DOM.
1159 * A side-effect of this is that it makes ^C to interrupt a process seem more responsive.
1162 // If refresh should be queued, order the refresh and return.
1163 if (this._refreshIsQueued
) {
1164 // If a refresh has already been queued, just order a full refresh next
1165 this._fullRefreshNext
= true;
1167 setTimeout(function () {
1168 self
.refresh(start
, end
, false);
1170 this._refreshIsQueued
= true;
1175 // If refresh should be run right now (not be queued), release the lock
1176 this._refreshIsQueued
= false;
1178 // If multiple refreshes were requested, make a full refresh.
1179 if (this._fullRefreshNext
) {
1181 end
= this.rows
- 1;
1182 this._fullRefreshNext
= false // reset lock
1185 var x
, y
, i
, line
, out
, ch
, ch_width
, width
, data
, attr
, bg
, fg
, flags
, row
, parent
, focused
= document
.activeElement
;
1187 // If this is a big refresh, remove the terminal rows from the DOM for faster calculations
1188 if (end
- start
>= this.rows
/ 2) {
1189 parent
= this.element
.parentNode
;
1191 this.element
.removeChild(this.rowContainer
);
1198 if (end
>= this.rows
.length
) {
1199 this.log('`end` is too large. Most likely a bad CSR.');
1200 end
= this.rows
.length
- 1;
1203 for (; y
<= end
; y
++) {
1204 row
= y
+ this.ydisp
;
1206 line
= this.lines
[row
];
1209 if (this.y
=== y
- (this.ybase
- this.ydisp
)
1211 && !this.cursorHidden
) {
1217 attr
= this.defAttr
;
1220 for (; i
< width
; i
++) {
1223 ch_width
= line
[i
][2];
1227 if (i
=== x
) data
= -1;
1229 if (data
!== attr
) {
1230 if (attr
!== this.defAttr
) {
1233 if (data
!== this.defAttr
) {
1235 out
+= '<span class="reverse-video terminal-cursor';
1236 if (this.cursorBlink
) {
1241 var classNames
= [];
1244 fg
= (data
>> 9) & 0x1ff;
1247 if (flags
& Terminal
.flags
.BOLD
) {
1248 if (!Terminal
.brokenBold
) {
1249 classNames
.push('xterm-bold');
1251 // See: XTerm*boldColors
1252 if (fg
< 8) fg
+= 8;
1255 if (flags
& Terminal
.flags
.UNDERLINE
) {
1256 classNames
.push('xterm-underline');
1259 if (flags
& Terminal
.flags
.BLINK
) {
1260 classNames
.push('xterm-blink');
1264 * If inverse flag is on, then swap the foreground and background variables.
1266 if (flags
& Terminal
.flags
.INVERSE
) {
1267 /* One-line variable swap in JavaScript: http://stackoverflow.com/a/16201730 */
1268 bg = [fg, fg = bg][0];
1269 // Should inverse just be before the
1270 // above boldColors effect instead?
1271 if ((flags & 1) && fg < 8) fg += 8;
1274 if (flags & Terminal.flags.INVISIBLE) {
1275 classNames.push('xterm-hidden');
1279 * Weird situation: Invert flag used black foreground and white background results
1280 * in invalid background color, positioned at the 256 index of the 256 terminal
1281 * color map. Pin the colors manually in such a case.
1283 * Source: https://github.com/sourcelair/xterm.js/issues/57
1285 if (flags
& Terminal
.flags
.INVERSE
) {
1295 classNames
.push('xterm-bg-color-' + bg
);
1299 classNames
.push('xterm-color-' + fg
);
1303 if (classNames
.length
) {
1304 out
+= ' class="' + classNames
.join(' ') + '"';
1333 if (attr
!== this.defAttr
) {
1337 this.children
[y
].innerHTML
= out
;
1341 this.element
.appendChild(this.rowContainer
);
1344 this.emit('refresh', {element
: this.element
, start
: start
, end
: end
});
1347 Terminal
.prototype.showCursor = function() {
1348 if (!this.cursorState
) {
1349 this.cursorState
= 1;
1350 this.refresh(this.y
, this.y
);
1354 Terminal
.prototype.scroll = function() {
1357 if (++this.ybase
=== this.scrollback
) {
1358 this.ybase
= this.ybase
/ 2 | 0;
1359 this.lines
= this.lines
.slice(-(this.ybase
+ this.rows
) + 1);
1362 this.ydisp
= this.ybase
;
1365 row
= this.ybase
+ this.rows
- 1;
1367 // subtract the bottom scroll region
1368 row
-= this.rows
- 1 - this.scrollBottom
;
1370 if (row
=== this.lines
.length
) {
1371 // potential optimization:
1372 // pushing is faster than splicing
1373 // when they amount to the same
1375 this.lines
.push(this.blankLine());
1378 this.lines
.splice(row
, 0, this.blankLine());
1381 if (this.scrollTop
!== 0) {
1382 if (this.ybase
!== 0) {
1384 this.ydisp
= this.ybase
;
1386 this.lines
.splice(this.ybase
+ this.scrollTop
, 1);
1390 this.updateRange(this.scrollTop
);
1391 this.updateRange(this.scrollBottom
);
1394 Terminal
.prototype.scrollDisp = function(disp
) {
1397 if (this.ydisp
> this.ybase
) {
1398 this.ydisp
= this.ybase
;
1399 } else if (this.ydisp
< 0) {
1403 this.refresh(0, this.rows
- 1);
1407 * Writes text to the terminal.
1409 * @param {string} text The text to write to the terminal.
1413 Terminal
.prototype.write = function(data
) {
1414 var l
= data
.length
, i
= 0, j
, cs
, ch
, code
, low
, ch_width
, row
;
1416 this.refreshStart
= this.y
;
1417 this.refreshEnd
= this.y
;
1419 if (this.ybase
!== this.ydisp
) {
1420 this.ydisp
= this.ybase
;
1424 // apply leftover surrogate high from last write
1425 if (this.surrogate_high
) {
1426 data
= this.surrogate_high
+ data
;
1427 this.surrogate_high
= '';
1430 for (; i
< l
; i
++) {
1433 // FIXME: higher chars than 0xa0 are not allowed in escape sequences
1434 // --> maybe move to default
1435 code
= data
.charCodeAt(i
);
1436 if (0xD800 <= code
&& code
<= 0xDBFF) {
1437 // we got a surrogate high
1438 // get surrogate low (next 2 bytes)
1439 low
= data
.charCodeAt(i
+1);
1441 // end of data stream, save surrogate high
1442 this.surrogate_high
= ch
;
1445 code
= ((code
- 0xD800) * 0x400) + (low
- 0xDC00) + 0x10000;
1446 ch
+= data
.charAt(i
+1);
1448 // surrogate low - already handled above
1449 if (0xDC00 <= code
&& code
<= 0xDFFF)
1452 switch (this.state
) {
1463 if (this.convertEol
) {
1467 if (this.y
> this.scrollBottom
) {
1487 this.x
= this.nextStop();
1502 this.state
= escaped
;
1507 // calculate print space
1508 // expensive call, therefore we save width in line buffer
1509 ch_width
= wcwidth(code
);
1512 if (this.charset
&& this.charset
[ch
]) {
1513 ch
= this.charset
[ch
];
1516 row
= this.y
+ this.ybase
;
1518 // insert combining char in last cell
1519 // FIXME: needs handling after cursor jumps
1520 if (!ch_width
&& this.x
) {
1522 // dont overflow left
1523 if (this.lines
[row
][this.x
-1]) {
1524 if (!this.lines
[row
][this.x
-1][2]) {
1526 // found empty cell after fullwidth, need to go 2 cells back
1527 if (this.lines
[row
][this.x
-2])
1528 this.lines
[row
][this.x
-2][1] += ch
;
1531 this.lines
[row
][this.x
-1][1] += ch
;
1533 this.updateRange(this.y
);
1538 // goto next line if ch would overflow
1539 // TODO: needs a global min terminal width of 2
1540 if (this.x
+ch_width
-1 >= this.cols
) {
1541 // autowrap - DECAWM
1542 if (this.wraparoundMode
) {
1545 if (this.y
> this.scrollBottom
) {
1550 this.x
= this.cols
-1;
1551 if(ch_width
===2) // FIXME: check for xterm behavior
1555 row
= this.y
+ this.ybase
;
1557 // insert mode: move characters to right
1558 if (this.insertMode
) {
1559 // do this twice for a fullwidth char
1560 for (var moves
=0; moves
<ch_width
; ++moves
) {
1561 // remove last cell, if it's width is 0
1562 // we have to adjust the second last cell as well
1563 var removed
= this.lines
[this.y
+ this.ybase
].pop();
1565 && this.lines
[row
][this.cols
-2]
1566 && this.lines
[row
][this.cols
-2][2]===2)
1567 this.lines
[row
][this.cols
-2] = [this.curAttr
, ' ', 1];
1569 // insert empty cell at cursor
1570 this.lines
[row
].splice(this.x
, 0, [this.curAttr
, ' ', 1]);
1574 this.lines
[row
][this.x
] = [this.curAttr
, ch
, ch_width
];
1576 this.updateRange(this.y
);
1578 // fullwidth char - set next cell width to zero and advance cursor
1580 this.lines
[row
][this.x
] = [this.curAttr
, '', 0];
1589 // ESC [ Control Sequence Introducer ( CSI is 0x9b).
1592 this.currentParam
= 0;
1596 // ESC ] Operating System Command ( OSC is 0x9d).
1599 this.currentParam
= 0;
1603 // ESC P Device Control String ( DCS is 0x90).
1606 this.currentParam
= 0;
1610 // ESC _ Application Program Command ( APC is 0x9f).
1612 this.state
= ignore
;
1615 // ESC ^ Privacy Message ( PM is 0x9e).
1617 this.state
= ignore
;
1620 // ESC c Full Reset (RIS).
1625 // ESC E Next Line ( NEL is 0x85).
1626 // ESC D Index ( IND is 0x84).
1634 // ESC M Reverse Index ( RI is 0x8d).
1636 this.reverseIndex();
1639 // ESC % Select default/utf-8 character set.
1640 // @ = default, G = utf-8
1642 //this.charset = null;
1644 this.setgCharset(0, Terminal
.charsets
.US
);
1645 this.state
= normal
;
1649 // ESC (,),*,+,-,. Designate G0-G2 Character Set.
1650 case '(': // <-- this seems to get all the attention
1676 this.state
= charset
;
1679 // Designate G3 Character Set (VT300).
1680 // A = ISO Latin-1 Supplemental.
1684 this.state
= charset
;
1689 // Single Shift Select of G2 Character Set
1690 // ( SS2 is 0x8e). This affects next character only.
1694 // Single Shift Select of G3 Character Set
1695 // ( SS3 is 0x8f). This affects next character only.
1699 // Invoke the G2 Character Set as GL (LS2).
1704 // Invoke the G3 Character Set as GL (LS3).
1709 // Invoke the G3 Character Set as GR (LS3R).
1714 // Invoke the G2 Character Set as GR (LS2R).
1719 // Invoke the G1 Character Set as GR (LS1R).
1724 // ESC 7 Save Cursor (DECSC).
1727 this.state
= normal
;
1730 // ESC 8 Restore Cursor (DECRC).
1732 this.restoreCursor();
1733 this.state
= normal
;
1736 // ESC # 3 DEC line height/width
1738 this.state
= normal
;
1742 // ESC H Tab Set (HTS is 0x88).
1747 // ESC = Application Keypad (DECPAM).
1749 this.log('Serial port requested application keypad.');
1750 this.applicationKeypad
= true;
1751 this.state
= normal
;
1754 // ESC > Normal Keypad (DECPNM).
1756 this.log('Switching back to normal keypad.');
1757 this.applicationKeypad
= false;
1758 this.state
= normal
;
1762 this.state
= normal
;
1763 this.error('Unknown ESC control: %s.', ch
);
1770 case '0': // DEC Special Character and Line Drawing Set.
1771 cs
= Terminal
.charsets
.SCLD
;
1774 cs
= Terminal
.charsets
.UK
;
1776 case 'B': // United States (USASCII).
1777 cs
= Terminal
.charsets
.US
;
1780 cs
= Terminal
.charsets
.Dutch
;
1782 case 'C': // Finnish
1784 cs
= Terminal
.charsets
.Finnish
;
1787 cs
= Terminal
.charsets
.French
;
1789 case 'Q': // FrenchCanadian
1790 cs
= Terminal
.charsets
.FrenchCanadian
;
1793 cs
= Terminal
.charsets
.German
;
1795 case 'Y': // Italian
1796 cs
= Terminal
.charsets
.Italian
;
1798 case 'E': // NorwegianDanish
1800 cs
= Terminal
.charsets
.NorwegianDanish
;
1802 case 'Z': // Spanish
1803 cs
= Terminal
.charsets
.Spanish
;
1805 case 'H': // Swedish
1807 cs
= Terminal
.charsets
.Swedish
;
1810 cs
= Terminal
.charsets
.Swiss
;
1812 case '/': // ISOLatin (actually /A)
1813 cs
= Terminal
.charsets
.ISOLatin
;
1817 cs
= Terminal
.charsets
.US
;
1820 this.setgCharset(this.gcharset
, cs
);
1821 this.gcharset
= null;
1822 this.state
= normal
;
1828 // Set Text Parameters.
1829 if (ch
=== '\x1b' || ch
=== '\x07') {
1830 if (ch
=== '\x1b') i
++;
1832 this.params
.push(this.currentParam
);
1834 switch (this.params
[0]) {
1838 if (this.params
[1]) {
1839 this.title
= this.params
[1];
1840 this.handleTitle(this.title
);
1848 // change dynamic colors
1860 // change dynamic ui colors
1872 // manipulate selection data
1890 this.currentParam
= 0;
1891 this.state
= normal
;
1893 if (!this.params
.length
) {
1894 if (ch
>= '0' && ch
<= '9') {
1896 this.currentParam
* 10 + ch
.charCodeAt(0) - 48;
1897 } else if (ch
=== ';') {
1898 this.params
.push(this.currentParam
);
1899 this.currentParam
= '';
1902 this.currentParam
+= ch
;
1909 if (ch
=== '?' || ch
=== '>' || ch
=== '!') {
1915 if (ch
>= '0' && ch
<= '9') {
1916 this.currentParam
= this.currentParam
* 10 + ch
.charCodeAt(0) - 48;
1920 // '$', '"', ' ', '\''
1921 if (ch
=== '$' || ch
=== '"' || ch
=== ' ' || ch
=== '\'') {
1926 this.params
.push(this.currentParam
);
1927 this.currentParam
= 0;
1930 if (ch
=== ';') break;
1932 this.state
= normal
;
1936 // Cursor Up Ps Times (default = 1) (CUU).
1938 this.cursorUp(this.params
);
1942 // Cursor Down Ps Times (default = 1) (CUD).
1944 this.cursorDown(this.params
);
1948 // Cursor Forward Ps Times (default = 1) (CUF).
1950 this.cursorForward(this.params
);
1954 // Cursor Backward Ps Times (default = 1) (CUB).
1956 this.cursorBackward(this.params
);
1960 // Cursor Position [row;column] (default = [1,1]) (CUP).
1962 this.cursorPos(this.params
);
1965 // CSI Ps J Erase in Display (ED).
1967 this.eraseInDisplay(this.params
);
1970 // CSI Ps K Erase in Line (EL).
1972 this.eraseInLine(this.params
);
1975 // CSI Pm m Character Attributes (SGR).
1978 this.charAttributes(this.params
);
1982 // CSI Ps n Device Status Report (DSR).
1985 this.deviceStatus(this.params
);
1994 // Insert Ps (Blank) Character(s) (default = 1) (ICH).
1996 this.insertChars(this.params
);
2000 // Cursor Next Line Ps Times (default = 1) (CNL).
2002 this.cursorNextLine(this.params
);
2006 // Cursor Preceding Line Ps Times (default = 1) (CNL).
2008 this.cursorPrecedingLine(this.params
);
2012 // Cursor Character Absolute [column] (default = [row,1]) (CHA).
2014 this.cursorCharAbsolute(this.params
);
2018 // Insert Ps Line(s) (default = 1) (IL).
2020 this.insertLines(this.params
);
2024 // Delete Ps Line(s) (default = 1) (DL).
2026 this.deleteLines(this.params
);
2030 // Delete Ps Character(s) (default = 1) (DCH).
2032 this.deleteChars(this.params
);
2036 // Erase Ps Character(s) (default = 1) (ECH).
2038 this.eraseChars(this.params
);
2041 // CSI Pm ` Character Position Absolute
2042 // [column] (default = [row,1]) (HPA).
2044 this.charPosAbsolute(this.params
);
2048 // Horizontal Position Relative
2050 this.HPositionRelative(this.params
);
2054 // Send Device Attributes (Primary DA).
2056 // Send Device Attributes (Secondary DA)
2058 this.sendDeviceAttributes(this.params
);
2062 // Line Position Absolute [row] (default = [1,column]) (VPA).
2064 this.linePosAbsolute(this.params
);
2067 // 145 65 e * VPR - Vertical Position Relative
2069 this.VPositionRelative(this.params
);
2073 // Horizontal and Vertical Position [row;column] (default =
2076 this.HVPosition(this.params
);
2079 // CSI Pm h Set Mode (SM).
2080 // CSI ? Pm h - mouse escape codes, cursor escape codes
2082 this.setMode(this.params
);
2085 // CSI Pm l Reset Mode (RM).
2088 this.resetMode(this.params
);
2092 // Set Scrolling Region [top;bottom] (default = full size of win-
2096 this.setScrollRegion(this.params
);
2100 // Save cursor (ANSI.SYS).
2102 this.saveCursor(this.params
);
2106 // Restore cursor (ANSI.SYS).
2108 this.restoreCursor(this.params
);
2116 // Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
2118 this.cursorForwardTab(this.params
);
2121 // CSI Ps S Scroll up Ps lines (default = 1) (SU).
2123 this.scrollUp(this.params
);
2126 // CSI Ps T Scroll down Ps lines (default = 1) (SD).
2127 // CSI Ps ; Ps ; Ps ; Ps ; Ps T
2130 // if (this.prefix === '>') {
2131 // this.resetTitleModes(this.params);
2134 // if (this.params.length > 2) {
2135 // this.initMouseTracking(this.params);
2138 if (this.params
.length
< 2 && !this.prefix
) {
2139 this.scrollDown(this.params
);
2144 // Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
2146 this.cursorBackwardTab(this.params
);
2149 // CSI Ps b Repeat the preceding graphic character Ps times (REP).
2151 this.repeatPrecedingCharacter(this.params
);
2154 // CSI Ps g Tab Clear (TBC).
2156 this.tabClear(this.params
);
2159 // CSI Pm i Media Copy (MC).
2162 // this.mediaCopy(this.params);
2165 // CSI Pm m Character Attributes (SGR).
2167 // case 'm': // duplicate
2168 // if (this.prefix === '>') {
2169 // this.setResources(this.params);
2171 // this.charAttributes(this.params);
2175 // CSI Ps n Device Status Report (DSR).
2177 // case 'n': // duplicate
2178 // if (this.prefix === '>') {
2179 // this.disableModifiers(this.params);
2181 // this.deviceStatus(this.params);
2185 // CSI > Ps p Set pointer mode.
2186 // CSI ! p Soft terminal reset (DECSTR).
2188 // Request ANSI mode (DECRQM).
2190 // Request DEC private mode (DECRQM).
2193 switch (this.prefix
) {
2195 // this.setPointerMode(this.params);
2198 this.softReset(this.params
);
2201 // if (this.postfix === '$') {
2202 // this.requestPrivateMode(this.params);
2206 // if (this.postfix === '"') {
2207 // this.setConformanceLevel(this.params);
2208 // } else if (this.postfix === '$') {
2209 // this.requestAnsiMode(this.params);
2215 // CSI Ps q Load LEDs (DECLL).
2219 // if (this.postfix === ' ') {
2220 // this.setCursorStyle(this.params);
2223 // if (this.postfix === '"') {
2224 // this.setCharProtectionAttr(this.params);
2227 // this.loadLEDs(this.params);
2231 // Set Scrolling Region [top;bottom] (default = full size of win-
2234 // CSI Pt; Pl; Pb; Pr; Ps$ r
2235 // case 'r': // duplicate
2236 // if (this.prefix === '?') {
2237 // this.restorePrivateValues(this.params);
2238 // } else if (this.postfix === '$') {
2239 // this.setAttrInRectangle(this.params);
2241 // this.setScrollRegion(this.params);
2245 // CSI s Save cursor (ANSI.SYS).
2247 // case 's': // duplicate
2248 // if (this.prefix === '?') {
2249 // this.savePrivateValues(this.params);
2251 // this.saveCursor(this.params);
2255 // CSI Ps ; Ps ; Ps t
2256 // CSI Pt; Pl; Pb; Pr; Ps$ t
2260 // if (this.postfix === '$') {
2261 // this.reverseAttrInRectangle(this.params);
2262 // } else if (this.postfix === ' ') {
2263 // this.setWarningBellVolume(this.params);
2265 // if (this.prefix === '>') {
2266 // this.setTitleModeFeature(this.params);
2268 // this.manipulateWindow(this.params);
2273 // CSI u Restore cursor (ANSI.SYS).
2275 // case 'u': // duplicate
2276 // if (this.postfix === ' ') {
2277 // this.setMarginBellVolume(this.params);
2279 // this.restoreCursor(this.params);
2283 // CSI Pt; Pl; Pb; Pr; Pp; Pt; Pl; Pp$ v
2285 // if (this.postfix === '$') {
2286 // this.copyRectagle(this.params);
2290 // CSI Pt ; Pl ; Pb ; Pr ' w
2292 // if (this.postfix === '\'') {
2293 // this.enableFilterRectangle(this.params);
2297 // CSI Ps x Request Terminal Parameters (DECREQTPARM).
2298 // CSI Ps x Select Attribute Change Extent (DECSACE).
2299 // CSI Pc; Pt; Pl; Pb; Pr$ x
2301 // if (this.postfix === '$') {
2302 // this.fillRectangle(this.params);
2304 // this.requestParameters(this.params);
2305 // //this.__(this.params);
2310 // CSI Pt; Pl; Pb; Pr$ z
2312 // if (this.postfix === '\'') {
2313 // this.enableLocatorReporting(this.params);
2314 // } else if (this.postfix === '$') {
2315 // this.eraseRectangle(this.params);
2320 // CSI Pt; Pl; Pb; Pr$ {
2322 // if (this.postfix === '\'') {
2323 // this.setLocatorEvents(this.params);
2324 // } else if (this.postfix === '$') {
2325 // this.selectiveEraseRectangle(this.params);
2331 // if (this.postfix === '\'') {
2332 // this.requestLocatorPosition(this.params);
2337 // Insert P s Column(s) (default = 1) (DECIC), VT420 and up.
2339 // if (this.postfix === ' ') {
2340 // this.insertColumns(this.params);
2345 // Delete P s Column(s) (default = 1) (DECDC), VT420 and up
2347 // if (this.postfix === ' ') {
2348 // this.deleteColumns(this.params);
2353 this.error('Unknown CSI code: %s.', ch
);
2362 if (ch
=== '\x1b' || ch
=== '\x07') {
2363 if (ch
=== '\x1b') i
++;
2365 switch (this.prefix
) {
2366 // User-Defined Keys (DECUDK).
2370 // Request Status String (DECRQSS).
2371 // test: echo -e '\eP$q"p\e\\'
2373 var pt
= this.currentParam
2390 + (this.scrollTop
+ 1)
2392 + (this.scrollBottom
+ 1)
2402 this.error('Unknown DCS Pt: %s.', pt
);
2407 this.send('\x1bP' + +valid
+ '$r' + pt
+ '\x1b\\');
2410 // Set Termcap/Terminfo Data (xterm, experimental).
2414 // Request Termcap/Terminfo String (xterm, experimental)
2415 // Regular xterm does not even respond to this sequence.
2416 // This can cause a small glitch in vim.
2417 // test: echo -ne '\eP+q6b64\e\\'
2419 var pt
= this.currentParam
2422 this.send('\x1bP' + +valid
+ '+r' + pt
+ '\x1b\\');
2426 this.error('Unknown DCS prefix: %s.', this.prefix
);
2430 this.currentParam
= 0;
2432 this.state
= normal
;
2433 } else if (!this.currentParam
) {
2434 if (!this.prefix
&& ch
!== '$' && ch
!== '+') {
2435 this.currentParam
= ch
;
2436 } else if (this.prefix
.length
=== 2) {
2437 this.currentParam
= ch
;
2442 this.currentParam
+= ch
;
2448 if (ch
=== '\x1b' || ch
=== '\x07') {
2449 if (ch
=== '\x1b') i
++;
2450 this.state
= normal
;
2456 this.updateRange(this.y
);
2457 this.refresh(this.refreshStart
, this.refreshEnd
);
2460 Terminal
.prototype.writeln = function(data
) {
2461 this.write(data
+ '\r\n');
2465 // https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
2466 Terminal
.prototype.keyDown = function(ev
) {
2468 var result
= this.evaluateKeyEscapeSequence(ev
);
2470 if (result
.scrollDisp
) {
2471 this.scrollDisp(result
.scrollDisp
);
2472 return this.cancel(ev
);
2475 if (isThirdLevelShift(this, ev
)) {
2479 if (result
.cancel
) {
2480 // The event is canceled at the end already, is this necessary?
2481 this.cancel(ev
, true);
2488 this.emit('keydown', ev
);
2489 this.emit('key', result
.key
, ev
);
2491 this.handler(result
.key
);
2493 return this.cancel(ev
, true);
2497 * Returns an object that determines how a KeyboardEvent should be handled. The key of the
2498 * returned value is the new key code to pass to the PTY.
2500 * Reference: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
2502 Terminal
.prototype.evaluateKeyEscapeSequence = function(ev
) {
2504 // Whether to cancel event propogation (NOTE: this may not be needed since the event is
2505 // canceled at the end of keyDown
2507 // The new key even to emit
2509 // The number of characters to scroll, if this is defined it will cancel the event
2510 scrollDisp
: undefined
2512 switch (ev
.keyCode
) {
2516 result
.key
= '\x08'; // ^H
2519 result
.key
= '\x7f'; // ^?
2524 result
.key
= '\x1b[Z';
2528 result
.cancel
= true;
2533 result
.cancel
= true;
2537 result
.key
= '\x1b';
2538 result
.cancel
= true;
2543 result
.key
= '\x1bb' // Jump a word back
2544 result
.cancel
= true;
2548 result
.key
= '\x1b[5D'; // Jump a word back
2551 if (this.applicationCursor
) {
2552 result
.key
= '\x1bOD'; // SS3 as ^[O for 7-bit
2555 result
.key
= '\x1b[D';
2560 result
.key
= '\x1bf' // Jump a word forward
2561 result
.cancel
= true;
2565 result
.key
= '\x1b[5C'; // Jump a word forward
2568 if (this.applicationCursor
) {
2569 result
.key
= '\x1bOC';
2572 result
.key
= '\x1b[C';
2576 if (this.applicationCursor
) {
2577 result
.key
= '\x1bOA';
2581 result
.scrollDisp
= -1;
2583 result
.key
= '\x1b[A';
2588 if (this.applicationCursor
) {
2589 result
.key
= '\x1bOB';
2593 result
.scrollDisp
= 1;
2595 result
.key
= '\x1b[B';
2600 if (!ev
.shiftKey
&& !ev
.ctrlKey
) {
2601 // <Ctrl> or <Shift> + <Insert> are used to
2602 // copy-paste on some systems.
2603 result
.key
= '\x1b[2~';
2607 case 46: result
.key
= '\x1b[3~'; break;
2610 if (this.applicationKeypad
) {
2611 result
.key
= '\x1bOH';
2614 result
.key
= '\x1bOH';
2618 if (this.applicationKeypad
) {
2619 result
.key
= '\x1bOF';
2622 result
.key
= '\x1bOF';
2627 result
.scrollDisp
= -(this.rows
- 1);
2629 result
.key
= '\x1b[5~';
2635 result
.scrollDisp
= this.rows
- 1;
2637 result
.key
= '\x1b[6~';
2641 case 112: result
.key
= '\x1bOP'; break;
2642 case 113: result
.key
= '\x1bOQ'; break;
2643 case 114: result
.key
= '\x1bOR'; break;
2644 case 115: result
.key
= '\x1bOS'; break;
2645 case 116: result
.key
= '\x1b[15~'; break;
2646 case 117: result
.key
= '\x1b[17~'; break;
2647 case 118: result
.key
= '\x1b[18~'; break;
2648 case 119: result
.key
= '\x1b[19~'; break;
2649 case 120: result
.key
= '\x1b[20~'; break;
2650 case 121: result
.key
= '\x1b[21~'; break;
2651 case 122: result
.key
= '\x1b[23~'; break;
2652 case 123: result
.key
= '\x1b[24~'; break;
2655 if (ev
.ctrlKey
&& !ev
.shiftKey
&& !ev
.altKey
&& !ev
.metaKey
) {
2656 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
2657 result
.key
= String
.fromCharCode(ev
.keyCode
- 64);
2658 } else if (ev
.keyCode
=== 32) {
2660 result
.key
= String
.fromCharCode(0);
2661 } else if (ev
.keyCode
>= 51 && ev
.keyCode
<= 55) {
2662 // escape, file sep, group sep, record sep, unit sep
2663 result
.key
= String
.fromCharCode(ev
.keyCode
- 51 + 27);
2664 } else if (ev
.keyCode
=== 56) {
2666 result
.key
= String
.fromCharCode(127);
2667 } else if (ev
.keyCode
=== 219) {
2669 result
.key
= String
.fromCharCode(27);
2670 } else if (ev
.keyCode
=== 221) {
2672 result
.key
= String
.fromCharCode(29);
2674 } else if (!this.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) {
2675 // On Mac this is a third level shift. Use <Esc> instead.
2676 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
2677 result
.key
= '\x1b' + String
.fromCharCode(ev
.keyCode
+ 32);
2678 } else if (ev
.keyCode
=== 192) {
2679 result
.key
= '\x1b`';
2680 } else if (ev
.keyCode
>= 48 && ev
.keyCode
<= 57) {
2681 result
.key
= '\x1b' + (ev
.keyCode
- 48);
2689 Terminal
.prototype.setgLevel = function(g
) {
2691 this.charset
= this.charsets
[g
];
2694 Terminal
.prototype.setgCharset = function(g
, charset
) {
2695 this.charsets
[g
] = charset
;
2696 if (this.glevel
=== g
) {
2697 this.charset
= charset
;
2701 Terminal
.prototype.keyPress = function(ev
) {
2708 } else if (ev
.which
== null) {
2710 } else if (ev
.which
!== 0 && ev
.charCode
!== 0) {
2717 (ev
.altKey
|| ev
.ctrlKey
|| ev
.metaKey
) && !isThirdLevelShift(this, ev
)
2722 key
= String
.fromCharCode(key
);
2724 this.emit('keypress', key
, ev
);
2725 this.emit('key', key
, ev
);
2732 Terminal
.prototype.send = function(data
) {
2736 setTimeout(function() {
2737 self
.handler(self
.queue
);
2745 Terminal
.prototype.bell = function() {
2746 if (!this.visualBell
) return;
2748 this.element
.style
.borderColor
= 'white';
2749 setTimeout(function() {
2750 self
.element
.style
.borderColor
= '';
2752 if (this.popOnBell
) this.focus();
2755 Terminal
.prototype.log = function() {
2756 if (!this.debug
) return;
2757 if (!this.context
.console
|| !this.context
.console
.log
) return;
2758 var args
= Array
.prototype.slice
.call(arguments
);
2759 this.context
.console
.log
.apply(this.context
.console
, args
);
2762 Terminal
.prototype.error = function() {
2763 if (!this.debug
) return;
2764 if (!this.context
.console
|| !this.context
.console
.error
) return;
2765 var args
= Array
.prototype.slice
.call(arguments
);
2766 this.context
.console
.error
.apply(this.context
.console
, args
);
2770 * Resizes the terminal.
2772 * @param {number} x The number of columns to resize to.
2773 * @param {number} y The number of rows to resize to.
2777 Terminal
.prototype.resize = function(x
, y
) {
2785 if (x
=== this.cols
&& y
=== this.rows
) {
2795 ch
= [this.defAttr
, ' ', 1]; // does xterm use the default attr?
2796 i
= this.lines
.length
;
2798 while (this.lines
[i
].length
< x
) {
2799 this.lines
[i
].push(ch
);
2803 i
= this.lines
.length
;
2805 while (this.lines
[i
].length
> x
) {
2806 this.lines
[i
].pop();
2819 // y is rows, not this.y
2820 if (this.lines
.length
< y
+ this.ybase
) {
2821 if (this.ybase
> 0 && this.lines
.length
<= this.ybase
+ this.y
+ addToY
+ 1) {
2822 // There is room above the buffer and there are no empty elements below the line,
2826 if (this.ydisp
> 0) {
2827 // Viewport is at the top of the buffer, must increase downwards
2831 // Add a blank line if there is no buffer left at the top to scroll to, or if there
2832 // are blank lines after the cursor
2833 this.lines
.push(this.blankLine());
2836 if (this.children
.length
< y
) {
2842 if (this.lines
.length
> y
+ this.ybase
) {
2843 if (this.lines
.length
> this.ybase
+ this.y
+ 1) {
2844 // The line is a blank line below the cursor, remove it
2847 // The line is the cursor, scroll down
2852 if (this.children
.length
> y
) {
2853 el
= this.children
.shift();
2855 el
.parentNode
.removeChild(el
);
2862 * Make sure that the cursor stays on screen
2876 this.scrollBottom
= y
- 1;
2878 this.refresh(0, this.rows
- 1);
2882 this.emit('resize', {terminal
: this, cols
: x
, rows
: y
});
2885 Terminal
.prototype.updateRange = function(y
) {
2886 if (y
< this.refreshStart
) this.refreshStart
= y
;
2887 if (y
> this.refreshEnd
) this.refreshEnd
= y
;
2888 // if (y > this.refreshEnd) {
2889 // this.refreshEnd = y;
2890 // if (y > this.rows - 1) {
2891 // this.refreshEnd = this.rows - 1;
2896 Terminal
.prototype.maxRange = function() {
2897 this.refreshStart
= 0;
2898 this.refreshEnd
= this.rows
- 1;
2901 Terminal
.prototype.setupStops = function(i
) {
2903 if (!this.tabs
[i
]) {
2904 i
= this.prevStop(i
);
2911 for (; i
< this.cols
; i
+= 8) {
2912 this.tabs
[i
] = true;
2916 Terminal
.prototype.prevStop = function(x
) {
2917 if (x
== null) x
= this.x
;
2918 while (!this.tabs
[--x
] && x
> 0);
2919 return x
>= this.cols
2924 Terminal
.prototype.nextStop = function(x
) {
2925 if (x
== null) x
= this.x
;
2926 while (!this.tabs
[++x
] && x
< this.cols
);
2927 return x
>= this.cols
2932 Terminal
.prototype.eraseRight = function(x
, y
) {
2933 var line
= this.lines
[this.ybase
+ y
]
2934 , ch
= [this.eraseAttr(), ' ', 1]; // xterm
2937 for (; x
< this.cols
; x
++) {
2941 this.updateRange(y
);
2944 Terminal
.prototype.eraseLeft = function(x
, y
) {
2945 var line
= this.lines
[this.ybase
+ y
]
2946 , ch
= [this.eraseAttr(), ' ', 1]; // xterm
2949 while (x
--) line
[x
] = ch
;
2951 this.updateRange(y
);
2954 Terminal
.prototype.eraseLine = function(y
) {
2955 this.eraseRight(0, y
);
2958 Terminal
.prototype.blankLine = function(cur
) {
2963 var ch
= [attr
, ' ', 1] // width defaults to 1 halfwidth character
2967 for (; i
< this.cols
; i
++) {
2974 Terminal
.prototype.ch = function(cur
) {
2976 ? [this.eraseAttr(), ' ', 1]
2977 : [this.defAttr
, ' ', 1];
2980 Terminal
.prototype.is = function(term
) {
2981 var name
= this.termName
;
2982 return (name
+ '').indexOf(term
) === 0;
2985 Terminal
.prototype.handler = function(data
) {
2986 this.emit('data', data
);
2989 Terminal
.prototype.handleTitle = function(title
) {
2990 this.emit('title', title
);
2997 // ESC D Index (IND is 0x84).
2998 Terminal
.prototype.index = function() {
3000 if (this.y
> this.scrollBottom
) {
3004 this.state
= normal
;
3007 // ESC M Reverse Index (RI is 0x8d).
3008 Terminal
.prototype.reverseIndex = function() {
3011 if (this.y
< this.scrollTop
) {
3013 // possibly move the code below to term.reverseScroll();
3014 // test: echo -ne '\e[1;1H\e[44m\eM\e[0m'
3015 // blankLine(true) is xterm/linux behavior
3016 this.lines
.splice(this.y
+ this.ybase
, 0, this.blankLine(true));
3017 j
= this.rows
- 1 - this.scrollBottom
;
3018 this.lines
.splice(this.rows
- 1 + this.ybase
- j
+ 1, 1);
3020 this.updateRange(this.scrollTop
);
3021 this.updateRange(this.scrollBottom
);
3023 this.state
= normal
;
3026 // ESC c Full Reset (RIS).
3027 Terminal
.prototype.reset = function() {
3028 this.options
.rows
= this.rows
;
3029 this.options
.cols
= this.cols
;
3030 Terminal
.call(this, this.options
);
3031 this.refresh(0, this.rows
- 1);
3034 // ESC H Tab Set (HTS is 0x88).
3035 Terminal
.prototype.tabSet = function() {
3036 this.tabs
[this.x
] = true;
3037 this.state
= normal
;
3045 // Cursor Up Ps Times (default = 1) (CUU).
3046 Terminal
.prototype.cursorUp = function(params
) {
3047 var param
= params
[0];
3048 if (param
< 1) param
= 1;
3050 if (this.y
< 0) this.y
= 0;
3054 // Cursor Down Ps Times (default = 1) (CUD).
3055 Terminal
.prototype.cursorDown = function(params
) {
3056 var param
= params
[0];
3057 if (param
< 1) param
= 1;
3059 if (this.y
>= this.rows
) {
3060 this.y
= this.rows
- 1;
3065 // Cursor Forward Ps Times (default = 1) (CUF).
3066 Terminal
.prototype.cursorForward = function(params
) {
3067 var param
= params
[0];
3068 if (param
< 1) param
= 1;
3070 if (this.x
>= this.cols
) {
3071 this.x
= this.cols
- 1;
3076 // Cursor Backward Ps Times (default = 1) (CUB).
3077 Terminal
.prototype.cursorBackward = function(params
) {
3078 var param
= params
[0];
3079 if (param
< 1) param
= 1;
3081 if (this.x
< 0) this.x
= 0;
3085 // Cursor Position [row;column] (default = [1,1]) (CUP).
3086 Terminal
.prototype.cursorPos = function(params
) {
3089 row
= params
[0] - 1;
3091 if (params
.length
>= 2) {
3092 col
= params
[1] - 1;
3099 } else if (row
>= this.rows
) {
3100 row
= this.rows
- 1;
3105 } else if (col
>= this.cols
) {
3106 col
= this.cols
- 1;
3113 // CSI Ps J Erase in Display (ED).
3114 // Ps = 0 -> Erase Below (default).
3115 // Ps = 1 -> Erase Above.
3116 // Ps = 2 -> Erase All.
3117 // Ps = 3 -> Erase Saved Lines (xterm).
3119 // Erase in Display (DECSED).
3120 // Ps = 0 -> Selective Erase Below (default).
3121 // Ps = 1 -> Selective Erase Above.
3122 // Ps = 2 -> Selective Erase All.
3123 Terminal
.prototype.eraseInDisplay = function(params
) {
3125 switch (params
[0]) {
3127 this.eraseRight(this.x
, this.y
);
3129 for (; j
< this.rows
; j
++) {
3134 this.eraseLeft(this.x
, this.y
);
3142 while (j
--) this.eraseLine(j
);
3150 // CSI Ps K Erase in Line (EL).
3151 // Ps = 0 -> Erase to Right (default).
3152 // Ps = 1 -> Erase to Left.
3153 // Ps = 2 -> Erase All.
3155 // Erase in Line (DECSEL).
3156 // Ps = 0 -> Selective Erase to Right (default).
3157 // Ps = 1 -> Selective Erase to Left.
3158 // Ps = 2 -> Selective Erase All.
3159 Terminal
.prototype.eraseInLine = function(params
) {
3160 switch (params
[0]) {
3162 this.eraseRight(this.x
, this.y
);
3165 this.eraseLeft(this.x
, this.y
);
3168 this.eraseLine(this.y
);
3173 // CSI Pm m Character Attributes (SGR).
3174 // Ps = 0 -> Normal (default).
3176 // Ps = 4 -> Underlined.
3177 // Ps = 5 -> Blink (appears as Bold).
3178 // Ps = 7 -> Inverse.
3179 // Ps = 8 -> Invisible, i.e., hidden (VT300).
3180 // Ps = 2 2 -> Normal (neither bold nor faint).
3181 // Ps = 2 4 -> Not underlined.
3182 // Ps = 2 5 -> Steady (not blinking).
3183 // Ps = 2 7 -> Positive (not inverse).
3184 // Ps = 2 8 -> Visible, i.e., not hidden (VT300).
3185 // Ps = 3 0 -> Set foreground color to Black.
3186 // Ps = 3 1 -> Set foreground color to Red.
3187 // Ps = 3 2 -> Set foreground color to Green.
3188 // Ps = 3 3 -> Set foreground color to Yellow.
3189 // Ps = 3 4 -> Set foreground color to Blue.
3190 // Ps = 3 5 -> Set foreground color to Magenta.
3191 // Ps = 3 6 -> Set foreground color to Cyan.
3192 // Ps = 3 7 -> Set foreground color to White.
3193 // Ps = 3 9 -> Set foreground color to default (original).
3194 // Ps = 4 0 -> Set background color to Black.
3195 // Ps = 4 1 -> Set background color to Red.
3196 // Ps = 4 2 -> Set background color to Green.
3197 // Ps = 4 3 -> Set background color to Yellow.
3198 // Ps = 4 4 -> Set background color to Blue.
3199 // Ps = 4 5 -> Set background color to Magenta.
3200 // Ps = 4 6 -> Set background color to Cyan.
3201 // Ps = 4 7 -> Set background color to White.
3202 // Ps = 4 9 -> Set background color to default (original).
3204 // If 16-color support is compiled, the following apply. Assume
3205 // that xterm's resources are set so that the ISO color codes are
3206 // the first 8 of a set of 16. Then the aixterm colors are the
3207 // bright versions of the ISO colors:
3208 // Ps = 9 0 -> Set foreground color to Black.
3209 // Ps = 9 1 -> Set foreground color to Red.
3210 // Ps = 9 2 -> Set foreground color to Green.
3211 // Ps = 9 3 -> Set foreground color to Yellow.
3212 // Ps = 9 4 -> Set foreground color to Blue.
3213 // Ps = 9 5 -> Set foreground color to Magenta.
3214 // Ps = 9 6 -> Set foreground color to Cyan.
3215 // Ps = 9 7 -> Set foreground color to White.
3216 // Ps = 1 0 0 -> Set background color to Black.
3217 // Ps = 1 0 1 -> Set background color to Red.
3218 // Ps = 1 0 2 -> Set background color to Green.
3219 // Ps = 1 0 3 -> Set background color to Yellow.
3220 // Ps = 1 0 4 -> Set background color to Blue.
3221 // Ps = 1 0 5 -> Set background color to Magenta.
3222 // Ps = 1 0 6 -> Set background color to Cyan.
3223 // Ps = 1 0 7 -> Set background color to White.
3225 // If xterm is compiled with the 16-color support disabled, it
3226 // supports the following, from rxvt:
3227 // Ps = 1 0 0 -> Set foreground and background color to
3230 // If 88- or 256-color support is compiled, the following apply.
3231 // Ps = 3 8 ; 5 ; Ps -> Set foreground color to the second
3233 // Ps = 4 8 ; 5 ; Ps -> Set background color to the second
3235 Terminal
.prototype.charAttributes = function(params
) {
3236 // Optimize a single SGR0.
3237 if (params
.length
=== 1 && params
[0] === 0) {
3238 this.curAttr
= this.defAttr
;
3242 var l
= params
.length
3244 , flags
= this.curAttr
>> 18
3245 , fg
= (this.curAttr
>> 9) & 0x1ff
3246 , bg
= this.curAttr
& 0x1ff
3249 for (; i
< l
; i
++) {
3251 if (p
>= 30 && p
<= 37) {
3254 } else if (p
>= 40 && p
<= 47) {
3257 } else if (p
>= 90 && p
<= 97) {
3261 } else if (p
>= 100 && p
<= 107) {
3265 } else if (p
=== 0) {
3267 flags
= this.defAttr
>> 18;
3268 fg
= (this.defAttr
>> 9) & 0x1ff;
3269 bg
= this.defAttr
& 0x1ff;
3273 } else if (p
=== 1) {
3276 } else if (p
=== 4) {
3279 } else if (p
=== 5) {
3282 } else if (p
=== 7) {
3283 // inverse and positive
3284 // test with: echo -e '\e[31m\e[42mhello\e[7mworld\e[27mhi\e[m'
3286 } else if (p
=== 8) {
3289 } else if (p
=== 22) {
3292 } else if (p
=== 24) {
3295 } else if (p
=== 25) {
3298 } else if (p
=== 27) {
3301 } else if (p
=== 28) {
3304 } else if (p
=== 39) {
3306 fg
= (this.defAttr
>> 9) & 0x1ff;
3307 } else if (p
=== 49) {
3309 bg
= this.defAttr
& 0x1ff;
3310 } else if (p
=== 38) {
3312 if (params
[i
+ 1] === 2) {
3316 params
[i
+ 1] & 0xff,
3317 params
[i
+ 2] & 0xff);
3318 if (fg
=== -1) fg
= 0x1ff;
3320 } else if (params
[i
+ 1] === 5) {
3322 p
= params
[i
] & 0xff;
3325 } else if (p
=== 48) {
3327 if (params
[i
+ 1] === 2) {
3331 params
[i
+ 1] & 0xff,
3332 params
[i
+ 2] & 0xff);
3333 if (bg
=== -1) bg
= 0x1ff;
3335 } else if (params
[i
+ 1] === 5) {
3337 p
= params
[i
] & 0xff;
3340 } else if (p
=== 100) {
3342 fg
= (this.defAttr
>> 9) & 0x1ff;
3343 bg
= this.defAttr
& 0x1ff;
3345 this.error('Unknown SGR attribute: %d.', p
);
3349 this.curAttr
= (flags
<< 18) | (fg
<< 9) | bg
;
3352 // CSI Ps n Device Status Report (DSR).
3353 // Ps = 5 -> Status Report. Result (``OK'') is
3355 // Ps = 6 -> Report Cursor Position (CPR) [row;column].
3359 // Device Status Report (DSR, DEC-specific).
3360 // Ps = 6 -> Report Cursor Position (CPR) [row;column] as CSI
3361 // ? r ; c R (assumes page is zero).
3362 // Ps = 1 5 -> Report Printer status as CSI ? 1 0 n (ready).
3363 // or CSI ? 1 1 n (not ready).
3364 // Ps = 2 5 -> Report UDK status as CSI ? 2 0 n (unlocked)
3365 // or CSI ? 2 1 n (locked).
3366 // Ps = 2 6 -> Report Keyboard status as
3367 // CSI ? 2 7 ; 1 ; 0 ; 0 n (North American).
3368 // The last two parameters apply to VT400 & up, and denote key-
3369 // board ready and LK01 respectively.
3370 // Ps = 5 3 -> Report Locator status as
3371 // CSI ? 5 3 n Locator available, if compiled-in, or
3372 // CSI ? 5 0 n No Locator, if not.
3373 Terminal
.prototype.deviceStatus = function(params
) {
3375 switch (params
[0]) {
3378 this.send('\x1b[0n');
3389 } else if (this.prefix
=== '?') {
3390 // modern xterm doesnt seem to
3391 // respond to any of these except ?6, 6, and 5
3392 switch (params
[0]) {
3403 // this.send('\x1b[?11n');
3406 // dont support user defined keys
3407 // this.send('\x1b[?21n');
3410 // north american keyboard
3411 // this.send('\x1b[?27;1;0;0n');
3414 // no dec locator/mouse
3415 // this.send('\x1b[?50n');
3426 // Insert Ps (Blank) Character(s) (default = 1) (ICH).
3427 Terminal
.prototype.insertChars = function(params
) {
3428 var param
, row
, j
, ch
;
3431 if (param
< 1) param
= 1;
3433 row
= this.y
+ this.ybase
;
3435 ch
= [this.eraseAttr(), ' ', 1]; // xterm
3437 while (param
-- && j
< this.cols
) {
3438 this.lines
[row
].splice(j
++, 0, ch
);
3439 this.lines
[row
].pop();
3444 // Cursor Next Line Ps Times (default = 1) (CNL).
3445 // same as CSI Ps B ?
3446 Terminal
.prototype.cursorNextLine = function(params
) {
3447 var param
= params
[0];
3448 if (param
< 1) param
= 1;
3450 if (this.y
>= this.rows
) {
3451 this.y
= this.rows
- 1;
3457 // Cursor Preceding Line Ps Times (default = 1) (CNL).
3459 Terminal
.prototype.cursorPrecedingLine = function(params
) {
3460 var param
= params
[0];
3461 if (param
< 1) param
= 1;
3463 if (this.y
< 0) this.y
= 0;
3468 // Cursor Character Absolute [column] (default = [row,1]) (CHA).
3469 Terminal
.prototype.cursorCharAbsolute = function(params
) {
3470 var param
= params
[0];
3471 if (param
< 1) param
= 1;
3476 // Insert Ps Line(s) (default = 1) (IL).
3477 Terminal
.prototype.insertLines = function(params
) {
3481 if (param
< 1) param
= 1;
3482 row
= this.y
+ this.ybase
;
3484 j
= this.rows
- 1 - this.scrollBottom
;
3485 j
= this.rows
- 1 + this.ybase
- j
+ 1;
3488 // test: echo -e '\e[44m\e[1L\e[0m'
3489 // blankLine(true) - xterm/linux behavior
3490 this.lines
.splice(row
, 0, this.blankLine(true));
3491 this.lines
.splice(j
, 1);
3495 this.updateRange(this.y
);
3496 this.updateRange(this.scrollBottom
);
3500 // Delete Ps Line(s) (default = 1) (DL).
3501 Terminal
.prototype.deleteLines = function(params
) {
3505 if (param
< 1) param
= 1;
3506 row
= this.y
+ this.ybase
;
3508 j
= this.rows
- 1 - this.scrollBottom
;
3509 j
= this.rows
- 1 + this.ybase
- j
;
3512 // test: echo -e '\e[44m\e[1M\e[0m'
3513 // blankLine(true) - xterm/linux behavior
3514 this.lines
.splice(j
+ 1, 0, this.blankLine(true));
3515 this.lines
.splice(row
, 1);
3519 this.updateRange(this.y
);
3520 this.updateRange(this.scrollBottom
);
3524 // Delete Ps Character(s) (default = 1) (DCH).
3525 Terminal
.prototype.deleteChars = function(params
) {
3529 if (param
< 1) param
= 1;
3531 row
= this.y
+ this.ybase
;
3532 ch
= [this.eraseAttr(), ' ', 1]; // xterm
3535 this.lines
[row
].splice(this.x
, 1);
3536 this.lines
[row
].push(ch
);
3541 // Erase Ps Character(s) (default = 1) (ECH).
3542 Terminal
.prototype.eraseChars = function(params
) {
3543 var param
, row
, j
, ch
;
3546 if (param
< 1) param
= 1;
3548 row
= this.y
+ this.ybase
;
3550 ch
= [this.eraseAttr(), ' ', 1]; // xterm
3552 while (param
-- && j
< this.cols
) {
3553 this.lines
[row
][j
++] = ch
;
3557 // CSI Pm ` Character Position Absolute
3558 // [column] (default = [row,1]) (HPA).
3559 Terminal
.prototype.charPosAbsolute = function(params
) {
3560 var param
= params
[0];
3561 if (param
< 1) param
= 1;
3563 if (this.x
>= this.cols
) {
3564 this.x
= this.cols
- 1;
3569 // Horizontal Position Relative
3571 Terminal
.prototype.HPositionRelative = function(params
) {
3572 var param
= params
[0];
3573 if (param
< 1) param
= 1;
3575 if (this.x
>= this.cols
) {
3576 this.x
= this.cols
- 1;
3580 // CSI Ps c Send Device Attributes (Primary DA).
3581 // Ps = 0 or omitted -> request attributes from terminal. The
3582 // response depends on the decTerminalID resource setting.
3583 // -> CSI ? 1 ; 2 c (``VT100 with Advanced Video Option'')
3584 // -> CSI ? 1 ; 0 c (``VT101 with No Options'')
3585 // -> CSI ? 6 c (``VT102'')
3586 // -> CSI ? 6 0 ; 1 ; 2 ; 6 ; 8 ; 9 ; 1 5 ; c (``VT220'')
3587 // The VT100-style response parameters do not mean anything by
3588 // themselves. VT220 parameters do, telling the host what fea-
3589 // tures the terminal supports:
3590 // Ps = 1 -> 132-columns.
3591 // Ps = 2 -> Printer.
3592 // Ps = 6 -> Selective erase.
3593 // Ps = 8 -> User-defined keys.
3594 // Ps = 9 -> National replacement character sets.
3595 // Ps = 1 5 -> Technical characters.
3596 // Ps = 2 2 -> ANSI color, e.g., VT525.
3597 // Ps = 2 9 -> ANSI text locator (i.e., DEC Locator mode).
3599 // Send Device Attributes (Secondary DA).
3600 // Ps = 0 or omitted -> request the terminal's identification
3601 // code. The response depends on the decTerminalID resource set-
3602 // ting. It should apply only to VT220 and up, but xterm extends
3604 // -> CSI > Pp ; Pv ; Pc c
3605 // where Pp denotes the terminal type
3606 // Pp = 0 -> ``VT100''.
3607 // Pp = 1 -> ``VT220''.
3608 // and Pv is the firmware version (for xterm, this was originally
3609 // the XFree86 patch number, starting with 95). In a DEC termi-
3610 // nal, Pc indicates the ROM cartridge registration number and is
3612 // More information:
3613 // xterm/charproc.c - line 2012, for more information.
3614 // vim responds with ^[[?0c or ^[[?1c after the terminal's response (?)
3615 Terminal
.prototype.sendDeviceAttributes = function(params
) {
3616 if (params
[0] > 0) return;
3619 if (this.is('xterm')
3620 || this.is('rxvt-unicode')
3621 || this.is('screen')) {
3622 this.send('\x1b[?1;2c');
3623 } else if (this.is('linux')) {
3624 this.send('\x1b[?6c');
3626 } else if (this.prefix
=== '>') {
3628 // seem to spit this
3629 // out around ~370 times (?).
3630 if (this.is('xterm')) {
3631 this.send('\x1b[>0;276;0c');
3632 } else if (this.is('rxvt-unicode')) {
3633 this.send('\x1b[>85;95;0c');
3634 } else if (this.is('linux')) {
3635 // not supported by linux console.
3636 // linux console echoes parameters.
3637 this.send(params
[0] + 'c');
3638 } else if (this.is('screen')) {
3639 this.send('\x1b[>83;40003;0c');
3645 // Line Position Absolute [row] (default = [1,column]) (VPA).
3646 Terminal
.prototype.linePosAbsolute = function(params
) {
3647 var param
= params
[0];
3648 if (param
< 1) param
= 1;
3650 if (this.y
>= this.rows
) {
3651 this.y
= this.rows
- 1;
3655 // 145 65 e * VPR - Vertical Position Relative
3657 Terminal
.prototype.VPositionRelative = function(params
) {
3658 var param
= params
[0];
3659 if (param
< 1) param
= 1;
3661 if (this.y
>= this.rows
) {
3662 this.y
= this.rows
- 1;
3667 // Horizontal and Vertical Position [row;column] (default =
3669 Terminal
.prototype.HVPosition = function(params
) {
3670 if (params
[0] < 1) params
[0] = 1;
3671 if (params
[1] < 1) params
[1] = 1;
3673 this.y
= params
[0] - 1;
3674 if (this.y
>= this.rows
) {
3675 this.y
= this.rows
- 1;
3678 this.x
= params
[1] - 1;
3679 if (this.x
>= this.cols
) {
3680 this.x
= this.cols
- 1;
3684 // CSI Pm h Set Mode (SM).
3685 // Ps = 2 -> Keyboard Action Mode (AM).
3686 // Ps = 4 -> Insert Mode (IRM).
3687 // Ps = 1 2 -> Send/receive (SRM).
3688 // Ps = 2 0 -> Automatic Newline (LNM).
3690 // DEC Private Mode Set (DECSET).
3691 // Ps = 1 -> Application Cursor Keys (DECCKM).
3692 // Ps = 2 -> Designate USASCII for character sets G0-G3
3693 // (DECANM), and set VT100 mode.
3694 // Ps = 3 -> 132 Column Mode (DECCOLM).
3695 // Ps = 4 -> Smooth (Slow) Scroll (DECSCLM).
3696 // Ps = 5 -> Reverse Video (DECSCNM).
3697 // Ps = 6 -> Origin Mode (DECOM).
3698 // Ps = 7 -> Wraparound Mode (DECAWM).
3699 // Ps = 8 -> Auto-repeat Keys (DECARM).
3700 // Ps = 9 -> Send Mouse X & Y on button press. See the sec-
3701 // tion Mouse Tracking.
3702 // Ps = 1 0 -> Show toolbar (rxvt).
3703 // Ps = 1 2 -> Start Blinking Cursor (att610).
3704 // Ps = 1 8 -> Print form feed (DECPFF).
3705 // Ps = 1 9 -> Set print extent to full screen (DECPEX).
3706 // Ps = 2 5 -> Show Cursor (DECTCEM).
3707 // Ps = 3 0 -> Show scrollbar (rxvt).
3708 // Ps = 3 5 -> Enable font-shifting functions (rxvt).
3709 // Ps = 3 8 -> Enter Tektronix Mode (DECTEK).
3710 // Ps = 4 0 -> Allow 80 -> 132 Mode.
3711 // Ps = 4 1 -> more(1) fix (see curses resource).
3712 // Ps = 4 2 -> Enable Nation Replacement Character sets (DECN-
3714 // Ps = 4 4 -> Turn On Margin Bell.
3715 // Ps = 4 5 -> Reverse-wraparound Mode.
3716 // Ps = 4 6 -> Start Logging. This is normally disabled by a
3717 // compile-time option.
3718 // Ps = 4 7 -> Use Alternate Screen Buffer. (This may be dis-
3719 // abled by the titeInhibit resource).
3720 // Ps = 6 6 -> Application keypad (DECNKM).
3721 // Ps = 6 7 -> Backarrow key sends backspace (DECBKM).
3722 // Ps = 1 0 0 0 -> Send Mouse X & Y on button press and
3723 // release. See the section Mouse Tracking.
3724 // Ps = 1 0 0 1 -> Use Hilite Mouse Tracking.
3725 // Ps = 1 0 0 2 -> Use Cell Motion Mouse Tracking.
3726 // Ps = 1 0 0 3 -> Use All Motion Mouse Tracking.
3727 // Ps = 1 0 0 4 -> Send FocusIn/FocusOut events.
3728 // Ps = 1 0 0 5 -> Enable Extended Mouse Mode.
3729 // Ps = 1 0 1 0 -> Scroll to bottom on tty output (rxvt).
3730 // Ps = 1 0 1 1 -> Scroll to bottom on key press (rxvt).
3731 // Ps = 1 0 3 4 -> Interpret "meta" key, sets eighth bit.
3732 // (enables the eightBitInput resource).
3733 // Ps = 1 0 3 5 -> Enable special modifiers for Alt and Num-
3734 // Lock keys. (This enables the numLock resource).
3735 // Ps = 1 0 3 6 -> Send ESC when Meta modifies a key. (This
3736 // enables the metaSendsEscape resource).
3737 // Ps = 1 0 3 7 -> Send DEL from the editing-keypad Delete
3739 // Ps = 1 0 3 9 -> Send ESC when Alt modifies a key. (This
3740 // enables the altSendsEscape resource).
3741 // Ps = 1 0 4 0 -> Keep selection even if not highlighted.
3742 // (This enables the keepSelection resource).
3743 // Ps = 1 0 4 1 -> Use the CLIPBOARD selection. (This enables
3744 // the selectToClipboard resource).
3745 // Ps = 1 0 4 2 -> Enable Urgency window manager hint when
3746 // Control-G is received. (This enables the bellIsUrgent
3748 // Ps = 1 0 4 3 -> Enable raising of the window when Control-G
3749 // is received. (enables the popOnBell resource).
3750 // Ps = 1 0 4 7 -> Use Alternate Screen Buffer. (This may be
3751 // disabled by the titeInhibit resource).
3752 // Ps = 1 0 4 8 -> Save cursor as in DECSC. (This may be dis-
3753 // abled by the titeInhibit resource).
3754 // Ps = 1 0 4 9 -> Save cursor as in DECSC and use Alternate
3755 // Screen Buffer, clearing it first. (This may be disabled by
3756 // the titeInhibit resource). This combines the effects of the 1
3757 // 0 4 7 and 1 0 4 8 modes. Use this with terminfo-based
3758 // applications rather than the 4 7 mode.
3759 // Ps = 1 0 5 0 -> Set terminfo/termcap function-key mode.
3760 // Ps = 1 0 5 1 -> Set Sun function-key mode.
3761 // Ps = 1 0 5 2 -> Set HP function-key mode.
3762 // Ps = 1 0 5 3 -> Set SCO function-key mode.
3763 // Ps = 1 0 6 0 -> Set legacy keyboard emulation (X11R6).
3764 // Ps = 1 0 6 1 -> Set VT220 keyboard emulation.
3765 // Ps = 2 0 0 4 -> Set bracketed paste mode.
3767 // http://vt100.net/docs/vt220-rm/chapter4.html
3768 Terminal
.prototype.setMode = function(params
) {
3769 if (typeof params
=== 'object') {
3770 var l
= params
.length
3773 for (; i
< l
; i
++) {
3774 this.setMode(params
[i
]);
3783 this.insertMode
= true;
3786 //this.convertEol = true;
3789 } else if (this.prefix
=== '?') {
3792 this.applicationCursor
= true;
3795 this.setgCharset(0, Terminal
.charsets
.US
);
3796 this.setgCharset(1, Terminal
.charsets
.US
);
3797 this.setgCharset(2, Terminal
.charsets
.US
);
3798 this.setgCharset(3, Terminal
.charsets
.US
);
3799 // set VT100 mode here
3801 case 3: // 132 col mode
3802 this.savedCols
= this.cols
;
3803 this.resize(132, this.rows
);
3806 this.originMode
= true;
3809 this.wraparoundMode
= true;
3812 // this.cursorBlink = true;
3815 this.log('Serial port requested application keypad.');
3816 this.applicationKeypad
= true;
3818 case 9: // X10 Mouse
3819 // no release, no motion, no wheel, no modifiers.
3820 case 1000: // vt200 mouse
3822 // no modifiers, except control on the wheel.
3823 case 1002: // button event mouse
3824 case 1003: // any event mouse
3825 // any event - sends motion events,
3826 // even if there is no button held down.
3827 this.x10Mouse
= params
=== 9;
3828 this.vt200Mouse
= params
=== 1000;
3829 this.normalMouse
= params
> 1000;
3830 this.mouseEvents
= true;
3831 this.element
.style
.cursor
= 'default';
3832 this.log('Binding to mouse events.');
3834 case 1004: // send focusin/focusout events
3837 this.sendFocus
= true;
3839 case 1005: // utf8 ext mode mouse
3840 this.utfMouse
= true;
3841 // for wide terminals
3842 // simply encodes large values as utf8 characters
3844 case 1006: // sgr ext mode mouse
3845 this.sgrMouse
= true;
3846 // for wide terminals
3847 // does not add 32 to fields
3848 // press: ^[[<b;x;yM
3849 // release: ^[[<b;x;ym
3851 case 1015: // urxvt ext mode mouse
3852 this.urxvtMouse
= true;
3853 // for wide terminals
3854 // numbers for fields
3856 // motion: ^[[b;x;yT
3858 case 25: // show cursor
3859 this.cursorHidden
= false;
3861 case 1049: // alt screen buffer cursor
3862 //this.saveCursor();
3864 case 47: // alt screen buffer
3865 case 1047: // alt screen buffer
3873 scrollTop
: this.scrollTop
,
3874 scrollBottom
: this.scrollBottom
,
3876 // XXX save charset(s) here?
3877 // charset: this.charset,
3878 // glevel: this.glevel,
3879 // charsets: this.charsets
3882 this.normal
= normal
;
3890 // CSI Pm l Reset Mode (RM).
3891 // Ps = 2 -> Keyboard Action Mode (AM).
3892 // Ps = 4 -> Replace Mode (IRM).
3893 // Ps = 1 2 -> Send/receive (SRM).
3894 // Ps = 2 0 -> Normal Linefeed (LNM).
3896 // DEC Private Mode Reset (DECRST).
3897 // Ps = 1 -> Normal Cursor Keys (DECCKM).
3898 // Ps = 2 -> Designate VT52 mode (DECANM).
3899 // Ps = 3 -> 80 Column Mode (DECCOLM).
3900 // Ps = 4 -> Jump (Fast) Scroll (DECSCLM).
3901 // Ps = 5 -> Normal Video (DECSCNM).
3902 // Ps = 6 -> Normal Cursor Mode (DECOM).
3903 // Ps = 7 -> No Wraparound Mode (DECAWM).
3904 // Ps = 8 -> No Auto-repeat Keys (DECARM).
3905 // Ps = 9 -> Don't send Mouse X & Y on button press.
3906 // Ps = 1 0 -> Hide toolbar (rxvt).
3907 // Ps = 1 2 -> Stop Blinking Cursor (att610).
3908 // Ps = 1 8 -> Don't print form feed (DECPFF).
3909 // Ps = 1 9 -> Limit print to scrolling region (DECPEX).
3910 // Ps = 2 5 -> Hide Cursor (DECTCEM).
3911 // Ps = 3 0 -> Don't show scrollbar (rxvt).
3912 // Ps = 3 5 -> Disable font-shifting functions (rxvt).
3913 // Ps = 4 0 -> Disallow 80 -> 132 Mode.
3914 // Ps = 4 1 -> No more(1) fix (see curses resource).
3915 // Ps = 4 2 -> Disable Nation Replacement Character sets (DEC-
3917 // Ps = 4 4 -> Turn Off Margin Bell.
3918 // Ps = 4 5 -> No Reverse-wraparound Mode.
3919 // Ps = 4 6 -> Stop Logging. (This is normally disabled by a
3920 // compile-time option).
3921 // Ps = 4 7 -> Use Normal Screen Buffer.
3922 // Ps = 6 6 -> Numeric keypad (DECNKM).
3923 // Ps = 6 7 -> Backarrow key sends delete (DECBKM).
3924 // Ps = 1 0 0 0 -> Don't send Mouse X & Y on button press and
3925 // release. See the section Mouse Tracking.
3926 // Ps = 1 0 0 1 -> Don't use Hilite Mouse Tracking.
3927 // Ps = 1 0 0 2 -> Don't use Cell Motion Mouse Tracking.
3928 // Ps = 1 0 0 3 -> Don't use All Motion Mouse Tracking.
3929 // Ps = 1 0 0 4 -> Don't send FocusIn/FocusOut events.
3930 // Ps = 1 0 0 5 -> Disable Extended Mouse Mode.
3931 // Ps = 1 0 1 0 -> Don't scroll to bottom on tty output
3933 // Ps = 1 0 1 1 -> Don't scroll to bottom on key press (rxvt).
3934 // Ps = 1 0 3 4 -> Don't interpret "meta" key. (This disables
3935 // the eightBitInput resource).
3936 // Ps = 1 0 3 5 -> Disable special modifiers for Alt and Num-
3937 // Lock keys. (This disables the numLock resource).
3938 // Ps = 1 0 3 6 -> Don't send ESC when Meta modifies a key.
3939 // (This disables the metaSendsEscape resource).
3940 // Ps = 1 0 3 7 -> Send VT220 Remove from the editing-keypad
3942 // Ps = 1 0 3 9 -> Don't send ESC when Alt modifies a key.
3943 // (This disables the altSendsEscape resource).
3944 // Ps = 1 0 4 0 -> Do not keep selection when not highlighted.
3945 // (This disables the keepSelection resource).
3946 // Ps = 1 0 4 1 -> Use the PRIMARY selection. (This disables
3947 // the selectToClipboard resource).
3948 // Ps = 1 0 4 2 -> Disable Urgency window manager hint when
3949 // Control-G is received. (This disables the bellIsUrgent
3951 // Ps = 1 0 4 3 -> Disable raising of the window when Control-
3952 // G is received. (This disables the popOnBell resource).
3953 // Ps = 1 0 4 7 -> Use Normal Screen Buffer, clearing screen
3954 // first if in the Alternate Screen. (This may be disabled by
3955 // the titeInhibit resource).
3956 // Ps = 1 0 4 8 -> Restore cursor as in DECRC. (This may be
3957 // disabled by the titeInhibit resource).
3958 // Ps = 1 0 4 9 -> Use Normal Screen Buffer and restore cursor
3959 // as in DECRC. (This may be disabled by the titeInhibit
3960 // resource). This combines the effects of the 1 0 4 7 and 1 0
3961 // 4 8 modes. Use this with terminfo-based applications rather
3962 // than the 4 7 mode.
3963 // Ps = 1 0 5 0 -> Reset terminfo/termcap function-key mode.
3964 // Ps = 1 0 5 1 -> Reset Sun function-key mode.
3965 // Ps = 1 0 5 2 -> Reset HP function-key mode.
3966 // Ps = 1 0 5 3 -> Reset SCO function-key mode.
3967 // Ps = 1 0 6 0 -> Reset legacy keyboard emulation (X11R6).
3968 // Ps = 1 0 6 1 -> Reset keyboard emulation to Sun/PC style.
3969 // Ps = 2 0 0 4 -> Reset bracketed paste mode.
3970 Terminal
.prototype.resetMode = function(params
) {
3971 if (typeof params
=== 'object') {
3972 var l
= params
.length
3975 for (; i
< l
; i
++) {
3976 this.resetMode(params
[i
]);
3985 this.insertMode
= false;
3988 //this.convertEol = false;
3991 } else if (this.prefix
=== '?') {
3994 this.applicationCursor
= false;
3997 if (this.cols
=== 132 && this.savedCols
) {
3998 this.resize(this.savedCols
, this.rows
);
4000 delete this.savedCols
;
4003 this.originMode
= false;
4006 this.wraparoundMode
= false;
4009 // this.cursorBlink = false;
4012 this.log('Switching back to normal keypad.');
4013 this.applicationKeypad
= false;
4015 case 9: // X10 Mouse
4016 case 1000: // vt200 mouse
4017 case 1002: // button event mouse
4018 case 1003: // any event mouse
4019 this.x10Mouse
= false;
4020 this.vt200Mouse
= false;
4021 this.normalMouse
= false;
4022 this.mouseEvents
= false;
4023 this.element
.style
.cursor
= '';
4025 case 1004: // send focusin/focusout events
4026 this.sendFocus
= false;
4028 case 1005: // utf8 ext mode mouse
4029 this.utfMouse
= false;
4031 case 1006: // sgr ext mode mouse
4032 this.sgrMouse
= false;
4034 case 1015: // urxvt ext mode mouse
4035 this.urxvtMouse
= false;
4037 case 25: // hide cursor
4038 this.cursorHidden
= true;
4040 case 1049: // alt screen buffer cursor
4042 case 47: // normal screen buffer
4043 case 1047: // normal screen buffer - clearing it first
4045 this.lines
= this.normal
.lines
;
4046 this.ybase
= this.normal
.ybase
;
4047 this.ydisp
= this.normal
.ydisp
;
4048 this.x
= this.normal
.x
;
4049 this.y
= this.normal
.y
;
4050 this.scrollTop
= this.normal
.scrollTop
;
4051 this.scrollBottom
= this.normal
.scrollBottom
;
4052 this.tabs
= this.normal
.tabs
;
4054 // if (params === 1049) {
4055 // this.x = this.savedX;
4056 // this.y = this.savedY;
4058 this.refresh(0, this.rows
- 1);
4067 // Set Scrolling Region [top;bottom] (default = full size of win-
4070 Terminal
.prototype.setScrollRegion = function(params
) {
4071 if (this.prefix
) return;
4072 this.scrollTop
= (params
[0] || 1) - 1;
4073 this.scrollBottom
= (params
[1] || this.rows
) - 1;
4079 // Save cursor (ANSI.SYS).
4080 Terminal
.prototype.saveCursor = function(params
) {
4081 this.savedX
= this.x
;
4082 this.savedY
= this.y
;
4086 // Restore cursor (ANSI.SYS).
4087 Terminal
.prototype.restoreCursor = function(params
) {
4088 this.x
= this.savedX
|| 0;
4089 this.y
= this.savedY
|| 0;
4097 // Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
4098 Terminal
.prototype.cursorForwardTab = function(params
) {
4099 var param
= params
[0] || 1;
4101 this.x
= this.nextStop();
4105 // CSI Ps S Scroll up Ps lines (default = 1) (SU).
4106 Terminal
.prototype.scrollUp = function(params
) {
4107 var param
= params
[0] || 1;
4109 this.lines
.splice(this.ybase
+ this.scrollTop
, 1);
4110 this.lines
.splice(this.ybase
+ this.scrollBottom
, 0, this.blankLine());
4113 this.updateRange(this.scrollTop
);
4114 this.updateRange(this.scrollBottom
);
4117 // CSI Ps T Scroll down Ps lines (default = 1) (SD).
4118 Terminal
.prototype.scrollDown = function(params
) {
4119 var param
= params
[0] || 1;
4121 this.lines
.splice(this.ybase
+ this.scrollBottom
, 1);
4122 this.lines
.splice(this.ybase
+ this.scrollTop
, 0, this.blankLine());
4125 this.updateRange(this.scrollTop
);
4126 this.updateRange(this.scrollBottom
);
4129 // CSI Ps ; Ps ; Ps ; Ps ; Ps T
4130 // Initiate highlight mouse tracking. Parameters are
4131 // [func;startx;starty;firstrow;lastrow]. See the section Mouse
4133 Terminal
.prototype.initMouseTracking = function(params
) {
4134 // Relevant: DECSET 1001
4138 // Reset one or more features of the title modes to the default
4139 // value. Normally, "reset" disables the feature. It is possi-
4140 // ble to disable the ability to reset features by compiling a
4141 // different default for the title modes into xterm.
4142 // Ps = 0 -> Do not set window/icon labels using hexadecimal.
4143 // Ps = 1 -> Do not query window/icon labels using hexadeci-
4145 // Ps = 2 -> Do not set window/icon labels using UTF-8.
4146 // Ps = 3 -> Do not query window/icon labels using UTF-8.
4147 // (See discussion of "Title Modes").
4148 Terminal
.prototype.resetTitleModes = function(params
) {
4152 // CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
4153 Terminal
.prototype.cursorBackwardTab = function(params
) {
4154 var param
= params
[0] || 1;
4156 this.x
= this.prevStop();
4160 // CSI Ps b Repeat the preceding graphic character Ps times (REP).
4161 Terminal
.prototype.repeatPrecedingCharacter = function(params
) {
4162 var param
= params
[0] || 1
4163 , line
= this.lines
[this.ybase
+ this.y
]
4164 , ch
= line
[this.x
- 1] || [this.defAttr
, ' ', 1];
4166 while (param
--) line
[this.x
++] = ch
;
4169 // CSI Ps g Tab Clear (TBC).
4170 // Ps = 0 -> Clear Current Column (default).
4171 // Ps = 3 -> Clear All.
4173 // Ps = 2 -> Clear Stops on Line.
4174 // http://vt100.net/annarbor/aaa-ug/section6.html
4175 Terminal
.prototype.tabClear = function(params
) {
4176 var param
= params
[0];
4178 delete this.tabs
[this.x
];
4179 } else if (param
=== 3) {
4184 // CSI Pm i Media Copy (MC).
4185 // Ps = 0 -> Print screen (default).
4186 // Ps = 4 -> Turn off printer controller mode.
4187 // Ps = 5 -> Turn on printer controller mode.
4189 // Media Copy (MC, DEC-specific).
4190 // Ps = 1 -> Print line containing cursor.
4191 // Ps = 4 -> Turn off autoprint mode.
4192 // Ps = 5 -> Turn on autoprint mode.
4193 // Ps = 1 0 -> Print composed display, ignores DECPEX.
4194 // Ps = 1 1 -> Print all pages.
4195 Terminal
.prototype.mediaCopy = function(params
) {
4200 // Set or reset resource-values used by xterm to decide whether
4201 // to construct escape sequences holding information about the
4202 // modifiers pressed with a given key. The first parameter iden-
4203 // tifies the resource to set/reset. The second parameter is the
4204 // value to assign to the resource. If the second parameter is
4205 // omitted, the resource is reset to its initial value.
4206 // Ps = 1 -> modifyCursorKeys.
4207 // Ps = 2 -> modifyFunctionKeys.
4208 // Ps = 4 -> modifyOtherKeys.
4209 // If no parameters are given, all resources are reset to their
4211 Terminal
.prototype.setResources = function(params
) {
4216 // Disable modifiers which may be enabled via the CSI > Ps; Ps m
4217 // sequence. This corresponds to a resource value of "-1", which
4218 // cannot be set with the other sequence. The parameter identi-
4219 // fies the resource to be disabled:
4220 // Ps = 1 -> modifyCursorKeys.
4221 // Ps = 2 -> modifyFunctionKeys.
4222 // Ps = 4 -> modifyOtherKeys.
4223 // If the parameter is omitted, modifyFunctionKeys is disabled.
4224 // When modifyFunctionKeys is disabled, xterm uses the modifier
4225 // keys to make an extended sequence of functions rather than
4226 // adding a parameter to each function key to denote the modi-
4228 Terminal
.prototype.disableModifiers = function(params
) {
4233 // Set resource value pointerMode. This is used by xterm to
4234 // decide whether to hide the pointer cursor as the user types.
4235 // Valid values for the parameter:
4236 // Ps = 0 -> never hide the pointer.
4237 // Ps = 1 -> hide if the mouse tracking mode is not enabled.
4238 // Ps = 2 -> always hide the pointer. If no parameter is
4239 // given, xterm uses the default, which is 1 .
4240 Terminal
.prototype.setPointerMode = function(params
) {
4244 // CSI ! p Soft terminal reset (DECSTR).
4245 // http://vt100.net/docs/vt220-rm/table4-10.html
4246 Terminal
.prototype.softReset = function(params
) {
4247 this.cursorHidden
= false;
4248 this.insertMode
= false;
4249 this.originMode
= false;
4250 this.wraparoundMode
= false; // autowrap
4251 this.applicationKeypad
= false; // ?
4252 this.applicationCursor
= false;
4254 this.scrollBottom
= this.rows
- 1;
4255 this.curAttr
= this.defAttr
;
4256 this.x
= this.y
= 0; // ?
4257 this.charset
= null;
4258 this.glevel
= 0; // ??
4259 this.charsets
= [null]; // ??
4263 // Request ANSI mode (DECRQM). For VT300 and up, reply is
4265 // where Ps is the mode number as in RM, and Pm is the mode
4267 // 0 - not recognized
4270 // 3 - permanently set
4271 // 4 - permanently reset
4272 Terminal
.prototype.requestAnsiMode = function(params
) {
4277 // Request DEC private mode (DECRQM). For VT300 and up, reply is
4279 // where Ps is the mode number as in DECSET, Pm is the mode value
4280 // as in the ANSI DECRQM.
4281 Terminal
.prototype.requestPrivateMode = function(params
) {
4286 // Set conformance level (DECSCL). Valid values for the first
4288 // Ps = 6 1 -> VT100.
4289 // Ps = 6 2 -> VT200.
4290 // Ps = 6 3 -> VT300.
4291 // Valid values for the second parameter:
4292 // Ps = 0 -> 8-bit controls.
4293 // Ps = 1 -> 7-bit controls (always set for VT100).
4294 // Ps = 2 -> 8-bit controls.
4295 Terminal
.prototype.setConformanceLevel = function(params
) {
4299 // CSI Ps q Load LEDs (DECLL).
4300 // Ps = 0 -> Clear all LEDS (default).
4301 // Ps = 1 -> Light Num Lock.
4302 // Ps = 2 -> Light Caps Lock.
4303 // Ps = 3 -> Light Scroll Lock.
4304 // Ps = 2 1 -> Extinguish Num Lock.
4305 // Ps = 2 2 -> Extinguish Caps Lock.
4306 // Ps = 2 3 -> Extinguish Scroll Lock.
4307 Terminal
.prototype.loadLEDs = function(params
) {
4312 // Set cursor style (DECSCUSR, VT520).
4313 // Ps = 0 -> blinking block.
4314 // Ps = 1 -> blinking block (default).
4315 // Ps = 2 -> steady block.
4316 // Ps = 3 -> blinking underline.
4317 // Ps = 4 -> steady underline.
4318 Terminal
.prototype.setCursorStyle = function(params
) {
4323 // Select character protection attribute (DECSCA). Valid values
4324 // for the parameter:
4325 // Ps = 0 -> DECSED and DECSEL can erase (default).
4326 // Ps = 1 -> DECSED and DECSEL cannot erase.
4327 // Ps = 2 -> DECSED and DECSEL can erase.
4328 Terminal
.prototype.setCharProtectionAttr = function(params
) {
4333 // Restore DEC Private Mode Values. The value of Ps previously
4334 // saved is restored. Ps values are the same as for DECSET.
4335 Terminal
.prototype.restorePrivateValues = function(params
) {
4339 // CSI Pt; Pl; Pb; Pr; Ps$ r
4340 // Change Attributes in Rectangular Area (DECCARA), VT400 and up.
4341 // Pt; Pl; Pb; Pr denotes the rectangle.
4342 // Ps denotes the SGR attributes to change: 0, 1, 4, 5, 7.
4343 // NOTE: xterm doesn't enable this code by default.
4344 Terminal
.prototype.setAttrInRectangle = function(params
) {
4354 for (; t
< b
+ 1; t
++) {
4355 line
= this.lines
[this.ybase
+ t
];
4356 for (i
= l
; i
< r
; i
++) {
4357 line
[i
] = [attr
, line
[i
][1]];
4362 this.updateRange(params
[0]);
4363 this.updateRange(params
[2]);
4367 // CSI Pc; Pt; Pl; Pb; Pr$ x
4368 // Fill Rectangular Area (DECFRA), VT420 and up.
4369 // Pc is the character to use.
4370 // Pt; Pl; Pb; Pr denotes the rectangle.
4371 // NOTE: xterm doesn't enable this code by default.
4372 Terminal
.prototype.fillRectangle = function(params
) {
4382 for (; t
< b
+ 1; t
++) {
4383 line
= this.lines
[this.ybase
+ t
];
4384 for (i
= l
; i
< r
; i
++) {
4385 line
[i
] = [line
[i
][0], String
.fromCharCode(ch
)];
4390 this.updateRange(params
[1]);
4391 this.updateRange(params
[3]);
4395 // Enable Locator Reporting (DECELR).
4396 // Valid values for the first parameter:
4397 // Ps = 0 -> Locator disabled (default).
4398 // Ps = 1 -> Locator enabled.
4399 // Ps = 2 -> Locator enabled for one report, then disabled.
4400 // The second parameter specifies the coordinate unit for locator
4402 // Valid values for the second parameter:
4403 // Pu = 0 <- or omitted -> default to character cells.
4404 // Pu = 1 <- device physical pixels.
4405 // Pu = 2 <- character cells.
4406 Terminal
.prototype.enableLocatorReporting = function(params
) {
4407 var val
= params
[0] > 0;
4408 //this.mouseEvents = val;
4409 //this.decLocator = val;
4412 // CSI Pt; Pl; Pb; Pr$ z
4413 // Erase Rectangular Area (DECERA), VT400 and up.
4414 // Pt; Pl; Pb; Pr denotes the rectangle.
4415 // NOTE: xterm doesn't enable this code by default.
4416 Terminal
.prototype.eraseRectangle = function(params
) {
4426 ch
= [this.eraseAttr(), ' ', 1]; // xterm?
4428 for (; t
< b
+ 1; t
++) {
4429 line
= this.lines
[this.ybase
+ t
];
4430 for (i
= l
; i
< r
; i
++) {
4436 this.updateRange(params
[0]);
4437 this.updateRange(params
[2]);
4442 // Insert P s Column(s) (default = 1) (DECIC), VT420 and up.
4443 // NOTE: xterm doesn't enable this code by default.
4444 Terminal
.prototype.insertColumns = function() {
4445 var param
= params
[0]
4446 , l
= this.ybase
+ this.rows
4447 , ch
= [this.eraseAttr(), ' ', 1] // xterm?
4451 for (i
= this.ybase
; i
< l
; i
++) {
4452 this.lines
[i
].splice(this.x
+ 1, 0, ch
);
4453 this.lines
[i
].pop();
4462 // Delete P s Column(s) (default = 1) (DECDC), VT420 and up
4463 // NOTE: xterm doesn't enable this code by default.
4464 Terminal
.prototype.deleteColumns = function() {
4465 var param
= params
[0]
4466 , l
= this.ybase
+ this.rows
4467 , ch
= [this.eraseAttr(), ' ', 1] // xterm?
4471 for (i
= this.ybase
; i
< l
; i
++) {
4472 this.lines
[i
].splice(this.x
, 1);
4473 this.lines
[i
].push(ch
);
4484 Terminal
.charsets
= {};
4486 // DEC Special Character and Line Drawing Set.
4487 // http://vt100.net/docs/vt102-ug/table5-13.html
4488 // A lot of curses apps use this if they see TERM=xterm.
4489 // testing: echo -e '\e(0a\e(B'
4490 // The xterm output sometimes seems to conflict with the
4491 // reference above. xterm seems in line with the reference
4492 // when running vttest however.
4493 // The table below now uses xterm's output from vttest.
4494 Terminal
.charsets
.SCLD
= { // (0
4495 '`': '\u25c6', // '◆'
4496 'a': '\u2592', // '▒'
4497 'b': '\u0009', // '\t'
4498 'c': '\u000c', // '\f'
4499 'd': '\u000d', // '\r'
4500 'e': '\u000a', // '\n'
4501 'f': '\u00b0', // '°'
4502 'g': '\u00b1', // '±'
4503 'h': '\u2424', // '\u2424' (NL)
4504 'i': '\u000b', // '\v'
4505 'j': '\u2518', // '┘'
4506 'k': '\u2510', // '┐'
4507 'l': '\u250c', // '┌'
4508 'm': '\u2514', // '└'
4509 'n': '\u253c', // '┼'
4510 'o': '\u23ba', // '⎺'
4511 'p': '\u23bb', // '⎻'
4512 'q': '\u2500', // '─'
4513 'r': '\u23bc', // '⎼'
4514 's': '\u23bd', // '⎽'
4515 't': '\u251c', // '├'
4516 'u': '\u2524', // '┤'
4517 'v': '\u2534', // '┴'
4518 'w': '\u252c', // '┬'
4519 'x': '\u2502', // '│'
4520 'y': '\u2264', // '≤'
4521 'z': '\u2265', // '≥'
4522 '{': '\u03c0', // 'π'
4523 '|': '\u2260', // '≠'
4524 '}': '\u00a3', // '£'
4525 '~': '\u00b7' // '·'
4528 Terminal
.charsets
.UK
= null; // (A
4529 Terminal
.charsets
.US
= null; // (B (USASCII)
4530 Terminal
.charsets
.Dutch
= null; // (4
4531 Terminal
.charsets
.Finnish
= null; // (C or (5
4532 Terminal
.charsets
.French
= null; // (R
4533 Terminal
.charsets
.FrenchCanadian
= null; // (Q
4534 Terminal
.charsets
.German
= null; // (K
4535 Terminal
.charsets
.Italian
= null; // (Y
4536 Terminal
.charsets
.NorwegianDanish
= null; // (E or (6
4537 Terminal
.charsets
.Spanish
= null; // (Z
4538 Terminal
.charsets
.Swedish
= null; // (H or (7
4539 Terminal
.charsets
.Swiss
= null; // (=
4540 Terminal
.charsets
.ISOLatin
= null; // /A
4546 function contains(el
, arr
) {
4547 for (var i
= 0; i
< arr
.length
; i
+= 1) {
4548 if (el
=== arr
[i
]) {
4555 function on(el
, type
, handler
, capture
) {
4556 if (!Array
.isArray(el
)) {
4559 el
.forEach(function (element
) {
4560 element
.addEventListener(type
, handler
, capture
|| false);
4564 function off(el
, type
, handler
, capture
) {
4565 el
.removeEventListener(type
, handler
, capture
|| false);
4568 function cancel(ev
, force
) {
4569 if (!this.cancelEvents
&& !force
) {
4572 ev
.preventDefault();
4573 ev
.stopPropagation();
4577 function inherits(child
, parent
) {
4579 this.constructor = child
;
4581 f
.prototype = parent
.prototype;
4582 child
.prototype = new f
;
4585 // if bold is broken, we can't
4586 // use it in the terminal.
4587 function isBoldBroken(document
) {
4588 var body
= document
.getElementsByTagName('body')[0];
4589 var el
= document
.createElement('span');
4590 el
.innerHTML
= 'hello world';
4591 body
.appendChild(el
);
4592 var w1
= el
.scrollWidth
;
4593 el
.style
.fontWeight
= 'bold';
4594 var w2
= el
.scrollWidth
;
4595 body
.removeChild(el
);
4599 var String
= this.String
;
4600 var setTimeout
= this.setTimeout
;
4601 var setInterval
= this.setInterval
;
4603 function indexOf(obj
, el
) {
4606 if (obj
[i
] === el
) return i
;
4611 function isThirdLevelShift(term
, ev
) {
4613 (term
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) ||
4614 (term
.isMSWindows
&& ev
.altKey
&& ev
.ctrlKey
&& !ev
.metaKey
);
4616 // Don't invoke for arrows, pageDown, home, backspace, etc.
4617 return thirdLevelKey
&& (!ev
.keyCode
|| ev
.keyCode
> 47);
4620 function matchColor(r1
, g1
, b1
) {
4621 var hash
= (r1
<< 16) | (g1
<< 8) | b1
;
4623 if (matchColor
._cache
[hash
] != null) {
4624 return matchColor
._cache
[hash
];
4627 var ldiff
= Infinity
4636 for (; i
< Terminal
.vcolors
.length
; i
++) {
4637 c
= Terminal
.vcolors
[i
];
4642 diff
= matchColor
.distance(r1
, g1
, b1
, r2
, g2
, b2
);
4655 return matchColor
._cache
[hash
] = li
;
4658 matchColor
._cache
= {};
4660 // http://stackoverflow.com/questions/1633828
4661 matchColor
.distance = function(r1
, g1
, b1
, r2
, g2
, b2
) {
4662 return Math
.pow(30 * (r1
- r2
), 2)
4663 + Math
.pow(59 * (g1
- g2
), 2)
4664 + Math
.pow(11 * (b1
- b2
), 2);
4667 function each(obj
, iter
, con
) {
4668 if (obj
.forEach
) return obj
.forEach(iter
, con
);
4669 for (var i
= 0; i
< obj
.length
; i
++) {
4670 iter
.call(con
, obj
[i
], i
, obj
);
4674 function keys(obj
) {
4675 if (Object
.keys
) return Object
.keys(obj
);
4678 if (Object
.prototype.hasOwnProperty
.call(obj
, key
)) {
4685 var wcwidth
= (function(opts
) {
4686 // extracted from https://www.cl.cam.ac.uk/%7Emgk25/ucs/wcwidth.c
4687 // combining characters
4689 [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
4690 [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
4691 [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
4692 [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670],
4693 [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED],
4694 [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A],
4695 [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902],
4696 [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D],
4697 [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981],
4698 [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD],
4699 [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C],
4700 [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D],
4701 [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC],
4702 [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD],
4703 [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C],
4704 [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D],
4705 [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0],
4706 [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48],
4707 [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC],
4708 [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD],
4709 [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D],
4710 [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6],
4711 [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E],
4712 [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC],
4713 [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35],
4714 [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E],
4715 [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97],
4716 [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030],
4717 [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039],
4718 [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F],
4719 [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753],
4720 [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD],
4721 [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD],
4722 [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922],
4723 [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B],
4724 [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34],
4725 [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42],
4726 [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF],
4727 [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063],
4728 [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F],
4729 [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B],
4730 [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F],
4731 [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB],
4732 [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F],
4733 [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169],
4734 [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD],
4735 [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F],
4739 function bisearch(ucs
) {
4741 var max
= COMBINING
.length
- 1;
4743 if (ucs
< COMBINING
[0][0] || ucs
> COMBINING
[max
][1])
4745 while (max
>= min
) {
4746 mid
= Math
.floor((min
+ max
) / 2);
4747 if (ucs
> COMBINING
[mid
][1])
4749 else if (ucs
< COMBINING
[mid
][0])
4756 function wcwidth(ucs
) {
4757 // test for 8-bit control characters
4760 if (ucs
< 32 || (ucs
>= 0x7f && ucs
< 0xa0))
4761 return opts
.control
;
4762 // binary search in table of non-spacing characters
4765 // if we arrive here, ucs is not a combining or C0/C1 control character
4770 ucs
<= 0x115f || // Hangul Jamo init. consonants
4773 (ucs
>= 0x2e80 && ucs
<= 0xa4cf && ucs
!= 0x303f) || // CJK..Yi
4774 (ucs
>= 0xac00 && ucs
<= 0xd7a3) || // Hangul Syllables
4775 (ucs
>= 0xf900 && ucs
<= 0xfaff) || // CJK Compat Ideographs
4776 (ucs
>= 0xfe10 && ucs
<= 0xfe19) || // Vertical forms
4777 (ucs
>= 0xfe30 && ucs
<= 0xfe6f) || // CJK Compat Forms
4778 (ucs
>= 0xff00 && ucs
<= 0xff60) || // Fullwidth Forms
4779 (ucs
>= 0xffe0 && ucs
<= 0xffe6) ||
4780 (ucs
>= 0x20000 && ucs
<= 0x2fffd) ||
4781 (ucs
>= 0x30000 && ucs
<= 0x3fffd)
4786 })({nul
: 0, control
: 0}); // configurable options
4792 Terminal
.EventEmitter
= EventEmitter
;
4793 Terminal
.inherits
= inherits
;
4796 * Adds an event listener to the terminal.
4798 * @param {string} event The name of the event. TODO: Document all event types
4799 * @param {function} callback The function to call when the event is triggered.
4805 Terminal
.cancel
= cancel
;