]>
git.proxmox.com Git - mirror_xterm.js.git/blob - src/xterm.js
6fab9d2cd054e9543c916fea823d2c2b41bbe28e
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 self
.removeListener(type
, on
);
112 return listener
.apply(self
, 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 * @alias module:xterm/src/xterm
155 function Terminal(options
) {
158 if (!(this instanceof Terminal
)) {
159 return new Terminal(arguments
[0], arguments
[1], arguments
[2]);
162 self
.cancel
= Terminal
.cancel
;
164 EventEmitter
.call(this);
166 if (typeof options
=== 'number') {
170 handler
: arguments
[2]
174 options
= options
|| {};
177 Object
.keys(Terminal
.defaults
).forEach(function(key
) {
178 if (options
[key
] == null) {
179 options
[key
] = Terminal
.options
[key
];
181 if (Terminal
[key
] !== Terminal
.defaults
[key
]) {
182 options
[key
] = Terminal
[key
];
185 self
[key
] = options
[key
];
188 if (options
.colors
.length
=== 8) {
189 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(8));
190 } else if (options
.colors
.length
=== 16) {
191 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16));
192 } else if (options
.colors
.length
=== 10) {
193 options
.colors
= options
.colors
.slice(0, -2).concat(
194 Terminal
._colors
.slice(8, -2), options
.colors
.slice(-2));
195 } else if (options
.colors
.length
=== 18) {
196 options
.colors
= options
.colors
.concat(
197 Terminal
._colors
.slice(16, -2), options
.colors
.slice(-2));
199 this.colors
= options
.colors
;
201 this.options
= options
;
203 // this.context = options.context || window;
204 // this.document = options.document || document;
205 this.parent
= options
.body
|| options
.parent
206 || (document
? document
.getElementsByTagName('body')[0] : null);
208 this.cols
= options
.cols
|| options
.geometry
[0];
209 this.rows
= options
.rows
|| options
.geometry
[1];
211 if (options
.handler
) {
212 this.on('data', options
.handler
);
216 * The scroll position of the y cursor, ie. ybase + y = the y position within the entire
222 * The scroll position of the viewport
227 * The cursor's x position after ybase
232 * The cursor's y position after ybase
237 * Used to debounce the refresh function
239 this.isRefreshing
= false;
242 * Whether there is a full terminal refresh queued
245 this.cursorState
= 0;
246 this.cursorHidden
= false;
251 this.scrollBottom
= this.rows
- 1;
254 this.applicationKeypad
= false;
255 this.applicationCursor
= false;
256 this.originMode
= false;
257 this.insertMode
= false;
258 this.wraparoundMode
= true; // defaults: xterm - true, vt100 - false
263 this.gcharset
= null;
265 this.charsets
= [null];
289 this.readable
= true;
290 this.writable
= true;
292 this.defAttr
= (0 << 18) | (257 << 9) | (256 << 0);
293 this.curAttr
= this.defAttr
;
296 this.currentParam
= 0;
300 // leftover surrogate high from previous write invocation
301 this.surrogate_high
= '';
304 * An array of all lines in the entire buffer, including the prompt. The lines are array of
305 * characters which are 2-length arrays where [0] is an attribute and [1] is the character.
310 this.lines
.push(this.blankLine());
317 inherits(Terminal
, EventEmitter
);
321 * back_color_erase feature for xterm.
323 Terminal
.prototype.eraseAttr = function() {
324 // if (this.is('screen')) return this.defAttr;
325 return (this.defAttr
& ~0x1ff) | (this.curAttr
& 0x1ff);
333 Terminal
.tangoColors
= [
354 // Colors 0-15 + 16-255
355 // Much thanks to TooTallNate for writing this.
356 Terminal
.colors
= (function() {
357 var colors
= Terminal
.tangoColors
.slice()
358 , r
= [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff]
363 for (; i
< 216; i
++) {
364 out(r
[(i
/ 36) % 6 | 0], r
[(i
/ 6) % 6 | 0], r
[i
% 6]);
369 for (; i
< 24; i
++) {
374 function out(r
, g
, b
) {
375 colors
.push('#' + hex(r
) + hex(g
) + hex(b
));
380 return c
.length
< 2 ? '0' + c
: c
;
386 Terminal
._colors
= Terminal
.colors
.slice();
388 Terminal
.vcolors
= (function() {
390 , colors
= Terminal
.colors
394 for (; i
< 256; i
++) {
395 color
= parseInt(colors
[i
].substring(1), 16);
397 (color
>> 16) & 0xff,
410 Terminal
.defaults
= {
411 colors
: Terminal
.colors
,
423 // programFeatures: false,
427 Terminal
.options
= {};
429 Terminal
.focus
= null;
431 each(keys(Terminal
.defaults
), function(key
) {
432 Terminal
[key
] = Terminal
.defaults
[key
];
433 Terminal
.options
[key
] = Terminal
.defaults
[key
];
437 * Focus the terminal. Delegates focus handling to the terminal's DOM element.
439 Terminal
.prototype.focus = function() {
440 return this.element
.focus();
444 * Binds the desired focus behavior on a given terminal object.
448 Terminal
.bindFocus = function (term
) {
449 on(term
.element
, 'focus', function (ev
) {
450 if (term
.sendFocus
) {
455 Terminal
.focus
= term
;
456 term
.emit('focus', {terminal
: term
});
461 * Blur the terminal. Delegates blur handling to the terminal's DOM element.
463 Terminal
.prototype.blur = function() {
464 return this.element
.blur();
468 * Binds the desired blur behavior on a given terminal object.
472 Terminal
.bindBlur = function (term
) {
473 on(term
.element
, 'blur', function (ev
) {
474 if (term
.sendFocus
) {
477 Terminal
.focus
= null;
478 term
.emit('blur', {terminal
: term
});
483 * Initialize default behavior
485 Terminal
.prototype.initGlobal = function() {
486 Terminal
.bindKeys(this);
487 Terminal
.bindPaste(this);
488 Terminal
.bindCopy(this);
489 Terminal
.bindCut(this);
490 Terminal
.bindDrop(this);
491 Terminal
.bindFocus(this);
492 Terminal
.bindBlur(this);
496 * Clears all selected text, inside the terminal.
498 Terminal
.prototype.clearSelection = function() {
499 var selectionBaseNode
= window
.getSelection().baseNode
;
501 if (selectionBaseNode
&& (this.element
.contains(selectionBaseNode
.parentElement
))) {
502 window
.getSelection().removeAllRanges();
507 * This function temporarily enables (leases) the contentEditable value of the terminal, which
508 * should be set back to false within 5 seconds at most.
510 Terminal
.prototype.leaseContentEditable = function (ms
, callback
) {
513 term
.element
.contentEditable
= true;
516 * Blur and re-focus instantly. This is due to a weird focus state on Chrome, when setting
517 * contentEditable to true on a focused element.
522 setTimeout(function () {
523 term
.element
.contentEditable
= false;
524 if (typeof callback
== 'function') {
531 * Bind to paste event and allow both keyboard and right-click pasting, without having the
532 * contentEditable value set to true.
534 Terminal
.bindPaste = function(term
) {
535 on(term
.element
, 'paste', function(ev
) {
536 if (ev
.clipboardData
) {
537 var text
= ev
.clipboardData
.getData('text/plain');
538 term
.emit('paste', text
, ev
);
541 * Cancel the paste event, or else things will be pasted twice:
542 * 1. by the terminal handler
543 * 2. by the browser, because of the contentEditable value being true
545 term
.cancel(ev
, true);
548 * After the paste event is completed, always set the contentEditable value to false.
550 term
.element
.contentEditable
= false;
555 * Hack pasting with keyboard, in order to make it work without contentEditable.
556 * When a user types Ctrl + Shift + V or Shift + Insert on a non Mac or Cmd + V on a Mac,
557 * lease the contentEditable value as true.
559 on(term
.element
, 'keydown', function (ev
) {
560 var isEditable
= term
.element
.contentEditable
=== "true";
563 * If on a Mac, lease the contentEditable value temporarily, when the user presses
564 * the Cmd button, in a keydown event order to paste frictionlessly.
566 if (term
.isMac
&& ev
.metaKey
&& !isEditable
) {
567 term
.leaseContentEditable(5000);
570 if (!term
.isMac
&& !isEditable
) {
571 if ((ev
.keyCode
== 45 && ev
.shiftKey
&& !ev
.ctrlKey
) || // Shift + Insert
572 (ev
.keyCode
== 86 && ev
.shiftKey
&& ev
.ctrlKey
)) { // Ctrl + Shict + V
573 term
.leaseContentEditable();
579 * Hack pasting with right-click in order to allow right-click paste, by leasing the
580 * contentEditable value as true.
582 on(term
.element
, 'contextmenu', function (ev
) {
583 term
.leaseContentEditable();
589 * Apply key handling to the terminal
591 * @param {Xterm} term The terminal on which to bind key handling
594 Terminal
.bindKeys = function(term
) {
595 on(term
.element
, 'keydown', function(ev
) {
599 on(term
.element
, 'keypress', function(ev
) {
605 * Prepares text copied from terminal selection, to be saved in the clipboard by:
606 * 1. stripping all trailing white spaces
607 * 2. converting all non-breaking spaces to regular spaces
608 * @param {string} text The copied text that needs processing for storing in clipboard
612 Terminal
.prepareCopiedTextForClipboard = function (text
) {
613 var space
= String
.fromCharCode(32),
614 nonBreakingSpace
= String
.fromCharCode(160),
615 allNonBreakingSpaces
= new RegExp(nonBreakingSpace
, 'g'),
616 processedText
= text
.split('\n').map(function (line
) {
618 * Strip all trailing white spaces and convert all non-breaking spaces to regular
621 var processedLine
= line
.replace(/\s+$/g, '').replace(allNonBreakingSpaces
, space
);
623 return processedLine
;
626 return processedText
;
630 * Binds copy functionality to the given terminal.
633 Terminal
.bindCopy = function(term
) {
634 on(term
.element
, 'copy', function(ev
) {
635 var copiedText
= window
.getSelection().toString(),
636 text
= Terminal
.prepareCopiedTextForClipboard(copiedText
);
638 ev
.clipboardData
.setData('text/plain', text
);
644 * Cancel the cut event completely.
645 * @param {Xterm} term The terminal on which to bind the cut event handling functionality.
648 Terminal
.bindCut = function(term
) {
649 on(term
.element
, 'cut', function (ev
) {
656 * Do not perform the "drop" event. Altering the contents of the
657 * terminal with drag n drop is unwanted behavior.
658 * @param {Xterm} term The terminal on which to bind the drop event handling functionality.
661 Terminal
.bindDrop = function (term
) {
662 on(term
.element
, 'drop', function (ev
) {
663 term
.cancel(ev
, true);
668 * Cancel click handling on the given terminal
669 * @param {Xterm} term The terminal on which to bind the click event handling functionality.
672 Terminal
.click = function (term
) {
673 on(term
.element
, 'click', function (ev
) {
674 term
.cancel(ev
, true);
680 * Insert the given row to the terminal or produce a new one
681 * if no row argument is passed. Return the inserted row.
682 * @param {HTMLElement} row (optional) The row to append to the terminal.
684 Terminal
.prototype.insertRow = function (row
) {
685 if (typeof row
!= 'object') {
686 row
= document
.createElement('div');
689 this.rowContainer
.appendChild(row
);
690 this.children
.push(row
);
697 * Opens the terminal within an element.
699 * @param {HTMLElement} parent The element to create the terminal within.
701 Terminal
.prototype.open = function(parent
) {
702 var self
=this, i
=0, div
;
704 this.parent
= parent
|| this.parent
;
707 throw new Error('Terminal requires a parent element.');
711 * Grab global elements
713 this.context
= this.parent
.ownerDocument
.defaultView
;
714 this.document
= this.parent
.ownerDocument
;
715 this.body
= this.document
.getElementsByTagName('body')[0];
720 if (this.context
.navigator
&& this.context
.navigator
.userAgent
) {
721 this.isMSIE
= !!~this.context
.navigator
.userAgent
.indexOf('MSIE');
725 * Find the users platform. We use this to interpret the meta key
726 * and ISO third level shifts.
727 * http://stackoverflow.com/questions/19877924/what-is-the-list-of-possible-values-for-navigator-platform-as-of-today
729 if (this.context
.navigator
&& this.context
.navigator
.platform
) {
730 this.isMac
= contains(
731 this.context
.navigator
.platform
,
732 ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K']
734 this.isIpad
= this.context
.navigator
.platform
=== 'iPad';
735 this.isIphone
= this.context
.navigator
.platform
=== 'iPhone';
736 this.isMSWindows
= contains(
737 this.context
.navigator
.platform
,
738 ['Windows', 'Win16', 'Win32', 'WinCE']
743 * Create main element container
745 this.element
= this.document
.createElement('div');
746 this.element
.classList
.add('terminal');
747 this.element
.classList
.add('xterm');
748 this.element
.classList
.add('xterm-theme-' + this.theme
);
749 this.element
.setAttribute('tabindex', 0);
750 this.element
.spellcheck
= false;
753 * Create the container that will hold the lines of the terminal and then
754 * produce the lines the lines.
756 this.rowContainer
= document
.createElement('div');
757 this.rowContainer
.classList
.add('xterm-rows');
758 this.element
.appendChild(this.rowContainer
);
761 for (; i
< this.rows
; i
++) {
764 this.parent
.appendChild(this.element
);
767 this.refresh(0, this.rows
- 1);
769 // Initialize global actions that
770 // need to be taken on the document.
773 // Ensure there is a Terminal.focus.
776 on(this.element
, 'mouseup', function() {
777 var selection
= document
.getSelection(),
778 collapsed
= selection
.isCollapsed
,
779 isRange
= typeof collapsed
== 'boolean' ? !collapsed
: selection
.type
== 'Range';
785 // Listen for mouse events and translate
786 // them into terminal mouse protocols.
789 // Figure out whether boldness affects
790 // the character width of monospace fonts.
791 if (Terminal
.brokenBold
== null) {
792 Terminal
.brokenBold
= isBoldBroken(this.document
);
800 * Attempts to load an add-on using CommonJS or RequireJS (whichever is available).
801 * @param {string} addon The name of the addon to load
804 Terminal
.loadAddon = function(addon
, callback
) {
805 if (typeof exports
=== 'object' && typeof module
=== 'object') {
807 return require(__dirname
+ '/../addons/' + addon
);
808 } else if (typeof define
== 'function') {
810 return require(['../addons/' + addon
+ '/' + addon
], callback
);
812 console
.error('Cannot load a module without a CommonJS or RequireJS environment.');
820 * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking
821 * To better understand these
822 * the xterm code is very helpful:
824 * button.c, charproc.c, misc.c
825 * Relevant functions in xterm/button.c:
826 * BtnCode, EmitButtonCode, EditorButton, SendMousePosition
828 Terminal
.prototype.bindMouse = function() {
829 var el
= this.element
, self
= this, pressed
= 32;
830 var wheelEvent
= ('onmousewheel' in this.context
) ? 'mousewheel' : 'DOMMouseScroll';
832 // mouseup, mousedown, mousewheel
833 // left click: ^[[M 3<^[[M#3<
834 // mousewheel up: ^[[M`3>
835 function sendButton(ev
) {
839 // get the xterm-style button
840 button
= getButton(ev
);
842 // get mouse coordinates
846 sendEvent(button
, pos
);
848 switch (ev
.overrideType
|| ev
.type
) {
853 // keep it at the left
854 // button, just in case.
865 // motion example of a left click:
866 // ^[[M 3<^[[M@4<^[[M@5<^[[M@6<^[[M@7<^[[M#7<
867 function sendMove(ev
) {
874 // buttons marked as motions
875 // are incremented by 32
878 sendEvent(button
, pos
);
882 // position to characters
883 function encode(data
, ch
) {
884 if (!self
.utfMouse
) {
885 if (ch
=== 255) return data
.push(0);
886 if (ch
> 127) ch
= 127;
889 if (ch
=== 2047) return data
.push(0);
893 if (ch
> 2047) ch
= 2047;
894 data
.push(0xC0 | (ch
>> 6));
895 data
.push(0x80 | (ch
& 0x3F));
900 // send a mouse event:
901 // regular/utf8: ^[[M Cb Cx Cy
902 // urxvt: ^[[ Cb ; Cx ; Cy M
903 // sgr: ^[[ Cb ; Cx ; Cy M/m
904 // vt300: ^[[ 24(1/3/5)~ [ Cx , Cy ] \r
905 // locator: CSI P e ; P b ; P r ; P c ; P p & w
906 function sendEvent(button
, pos
) {
907 // self.emit('mouse', {
913 if (self
.vt300Mouse
) {
915 // http://www.vt100.net/docs/vt3xx-gp/chapter15.html
919 var data
= '\x1b[24';
920 if (button
=== 0) data
+= '1';
921 else if (button
=== 1) data
+= '3';
922 else if (button
=== 2) data
+= '5';
923 else if (button
=== 3) return;
925 data
+= '~[' + pos
.x
+ ',' + pos
.y
+ ']\r';
930 if (self
.decLocator
) {
935 if (button
=== 0) button
= 2;
936 else if (button
=== 1) button
= 4;
937 else if (button
=== 2) button
= 6;
938 else if (button
=== 3) button
= 3;
942 + (button
=== 3 ? 4 : 0)
953 if (self
.urxvtMouse
) {
958 self
.send('\x1b[' + button
+ ';' + pos
.x
+ ';' + pos
.y
+ 'M');
966 + ((button
& 3) === 3 ? button
& ~3 : button
)
971 + ((button
& 3) === 3 ? 'm' : 'M'));
977 encode(data
, button
);
981 self
.send('\x1b[M' + String
.fromCharCode
.apply(String
, data
));
984 function getButton(ev
) {
997 // 1, and 2 - with 64 added
998 switch (ev
.overrideType
|| ev
.type
) {
1000 button
= ev
.button
!= null
1007 button
= button
=== 1 ? 0 : button
=== 4 ? 1 : button
;
1013 case 'DOMMouseScroll':
1014 button
= ev
.detail
< 0
1019 button
= ev
.wheelDeltaY
> 0
1025 // next three bits are the modifiers:
1026 // 4 = shift, 8 = meta, 16 = control
1027 shift
= ev
.shiftKey
? 4 : 0;
1028 meta
= ev
.metaKey
? 8 : 0;
1029 ctrl
= ev
.ctrlKey
? 16 : 0;
1030 mod
= shift
| meta
| ctrl
;
1033 if (self
.vt200Mouse
) {
1036 } else if (!self
.normalMouse
) {
1041 button
= (32 + (mod
<< 2)) + button
;
1046 // mouse coordinates measured in cols/rows
1047 function getCoords(ev
) {
1050 // ignore browsers without pageX for now
1051 if (ev
.pageX
== null) return;
1057 // should probably check offsetParent
1058 // but this is more portable
1059 while (el
&& el
!== self
.document
.documentElement
) {
1062 el
= 'offsetParent' in el
1067 // convert to cols/rows
1068 w
= self
.element
.clientWidth
;
1069 h
= self
.element
.clientHeight
;
1070 x
= Math
.round((x
/ w
) * self
.cols
);
1071 y
= Math
.round((y
/ h
) * self
.rows
);
1073 // be sure to avoid sending
1074 // bad positions to the program
1076 if (x
> self
.cols
) x
= self
.cols
;
1078 if (y
> self
.rows
) y
= self
.rows
;
1080 // xterm sends raw bytes and
1081 // starts at 32 (SP) for each.
1088 type
: (ev
.overrideType
|| ev
.type
) === wheelEvent
1090 : (ev
.overrideType
|| ev
.type
)
1094 on(el
, 'mousedown', function(ev
) {
1095 if (!self
.mouseEvents
) return;
1104 //if (self.vt200Mouse && !self.normalMouse) {
1105 if (self
.vt200Mouse
) {
1106 ev
.overrideType
= 'mouseup';
1108 return self
.cancel(ev
);
1112 if (self
.normalMouse
) on(self
.document
, 'mousemove', sendMove
);
1114 // x10 compatibility mode can't send button releases
1115 if (!self
.x10Mouse
) {
1116 on(self
.document
, 'mouseup', function up(ev
) {
1118 if (self
.normalMouse
) off(self
.document
, 'mousemove', sendMove
);
1119 off(self
.document
, 'mouseup', up
);
1120 return self
.cancel(ev
);
1124 return self
.cancel(ev
);
1127 //if (self.normalMouse) {
1128 // on(self.document, 'mousemove', sendMove);
1131 on(el
, wheelEvent
, function(ev
) {
1132 if (!self
.mouseEvents
) return;
1135 || self
.decLocator
) return;
1137 return self
.cancel(ev
);
1140 // allow mousewheel scrolling in
1141 // the shell for example
1142 on(el
, wheelEvent
, function(ev
) {
1143 if (self
.mouseEvents
) return;
1144 if (self
.applicationKeypad
) return;
1145 if (ev
.type
=== 'DOMMouseScroll') {
1146 self
.scrollDisp(ev
.detail
< 0 ? -1 : 1);
1148 self
.scrollDisp(ev
.wheelDeltaY
> 0 ? -1 : 1);
1150 return self
.cancel(ev
);
1155 * Destroys the terminal.
1157 Terminal
.prototype.destroy = function() {
1158 this.readable
= false;
1159 this.writable
= false;
1161 this.handler = function() {};
1162 this.write = function() {};
1163 if (this.element
.parentNode
) {
1164 this.element
.parentNode
.removeChild(this.element
);
1166 //this.emit('close');
1171 * Flags used to render terminal text properly
1182 * Refreshes (re-renders) terminal content within two rows (inclusive)
1186 * In the screen buffer, each character is stored as a an array with a character
1187 * and a 32-bit integer:
1188 * - First value: a utf-16 character.
1190 * - Next 9 bits: background color (0-511).
1191 * - Next 9 bits: foreground color (0-511).
1192 * - Next 14 bits: a mask for misc. flags:
1199 * @param {number} start The row to start from (between 0 and terminal's height terminal - 1)
1200 * @param {number} end The row to end at (between fromRow and terminal's height terminal - 1)
1201 * @param {boolean} queue Whether the refresh should ran right now or be queued
1203 Terminal
.prototype.refresh = function(start
, end
, queue
) {
1206 // queue defaults to true
1207 queue
= (typeof queue
== 'undefined') ? true : queue
;
1210 * The refresh queue allows refresh to execute only approximately 30 times a second. For
1211 * commands that pass a significant amount of output to the write function, this prevents the
1212 * terminal from maxing out the CPU and making the UI unresponsive. While commands can still
1213 * run beyond what they do on the terminal, it is far better with a debounce in place as
1214 * every single terminal manipulation does not need to be constructed in the DOM.
1216 * A side-effect of this is that it makes ^C to interrupt a process seem more responsive.
1219 // If refresh should be queued, order the refresh and return.
1220 if (this._refreshIsQueued
) {
1221 // If a refresh has already been queued, just order a full refresh next
1222 this._fullRefreshNext
= true;
1224 setTimeout(function () {
1225 self
.refresh(start
, end
, false);
1227 this._refreshIsQueued
= true;
1232 // If refresh should be run right now (not be queued), release the lock
1233 this._refreshIsQueued
= false;
1235 // If multiple refreshes were requested, make a full refresh.
1236 if (this._fullRefreshNext
) {
1238 end
= this.rows
- 1;
1239 this._fullRefreshNext
= false // reset lock
1242 var x
, y
, i
, line
, out
, ch
, ch_width
, width
, data
, attr
, bg
, fg
, flags
, row
, parent
, focused
= document
.activeElement
;
1244 // If this is a big refresh, remove the terminal rows from the DOM for faster calculations
1245 if (end
- start
>= this.rows
/ 2) {
1246 parent
= this.element
.parentNode
;
1248 this.element
.removeChild(this.rowContainer
);
1255 if (end
>= this.rows
.length
) {
1256 this.log('`end` is too large. Most likely a bad CSR.');
1257 end
= this.rows
.length
- 1;
1260 for (; y
<= end
; y
++) {
1261 row
= y
+ this.ydisp
;
1263 line
= this.lines
[row
];
1266 if (this.y
=== y
- (this.ybase
- this.ydisp
)
1268 && !this.cursorHidden
) {
1274 attr
= this.defAttr
;
1277 for (; i
< width
; i
++) {
1280 ch_width
= line
[i
][2];
1284 if (i
=== x
) data
= -1;
1286 if (data
!== attr
) {
1287 if (attr
!== this.defAttr
) {
1290 if (data
!== this.defAttr
) {
1292 out
+= '<span class="reverse-video terminal-cursor';
1293 if (this.cursorBlink
) {
1298 var classNames
= [];
1301 fg
= (data
>> 9) & 0x1ff;
1304 if (flags
& Terminal
.flags
.BOLD
) {
1305 if (!Terminal
.brokenBold
) {
1306 classNames
.push('xterm-bold');
1308 // See: XTerm*boldColors
1309 if (fg
< 8) fg
+= 8;
1312 if (flags
& Terminal
.flags
.UNDERLINE
) {
1313 classNames
.push('xterm-underline');
1316 if (flags
& Terminal
.flags
.BLINK
) {
1317 classNames
.push('xterm-blink');
1321 * If inverse flag is on, then swap the foreground and background variables.
1323 if (flags
& Terminal
.flags
.INVERSE
) {
1324 /* One-line variable swap in JavaScript: http://stackoverflow.com/a/16201730 */
1325 bg = [fg, fg = bg][0];
1326 // Should inverse just be before the
1327 // above boldColors effect instead?
1328 if ((flags & 1) && fg < 8) fg += 8;
1331 if (flags & Terminal.flags.INVISIBLE) {
1332 classNames.push('xterm-hidden');
1336 * Weird situation: Invert flag used black foreground and white background results
1337 * in invalid background color, positioned at the 256 index of the 256 terminal
1338 * color map. Pin the colors manually in such a case.
1340 * Source: https://github.com/sourcelair/xterm.js/issues/57
1342 if (flags
& Terminal
.flags
.INVERSE
) {
1352 classNames
.push('xterm-bg-color-' + bg
);
1356 classNames
.push('xterm-color-' + fg
);
1360 if (classNames
.length
) {
1361 out
+= ' class="' + classNames
.join(' ') + '"';
1390 if (attr
!== this.defAttr
) {
1394 this.children
[y
].innerHTML
= out
;
1398 this.element
.appendChild(this.rowContainer
);
1401 this.emit('refresh', {element
: this.element
, start
: start
, end
: end
});
1405 * Display the cursor element
1407 Terminal
.prototype.showCursor = function() {
1408 if (!this.cursorState
) {
1409 this.cursorState
= 1;
1410 this.refresh(this.y
, this.y
);
1415 * Scroll the terminal
1417 Terminal
.prototype.scroll = function() {
1420 if (++this.ybase
=== this.scrollback
) {
1421 this.ybase
= this.ybase
/ 2 | 0;
1422 this.lines
= this.lines
.slice(-(this.ybase
+ this.rows
) + 1);
1425 this.ydisp
= this.ybase
;
1428 row
= this.ybase
+ this.rows
- 1;
1430 // subtract the bottom scroll region
1431 row
-= this.rows
- 1 - this.scrollBottom
;
1433 if (row
=== this.lines
.length
) {
1434 // potential optimization:
1435 // pushing is faster than splicing
1436 // when they amount to the same
1438 this.lines
.push(this.blankLine());
1441 this.lines
.splice(row
, 0, this.blankLine());
1444 if (this.scrollTop
!== 0) {
1445 if (this.ybase
!== 0) {
1447 this.ydisp
= this.ybase
;
1449 this.lines
.splice(this.ybase
+ this.scrollTop
, 1);
1453 this.updateRange(this.scrollTop
);
1454 this.updateRange(this.scrollBottom
);
1458 * Scroll the display of the terminal
1459 * @param {number} disp
1461 Terminal
.prototype.scrollDisp = function(disp
) {
1464 if (this.ydisp
> this.ybase
) {
1465 this.ydisp
= this.ybase
;
1466 } else if (this.ydisp
< 0) {
1470 this.refresh(0, this.rows
- 1);
1474 * Writes text to the terminal.
1475 * @param {string} text The text to write to the terminal.
1477 Terminal
.prototype.write = function(data
) {
1478 var l
= data
.length
, i
= 0, j
, cs
, ch
, code
, low
, ch_width
, row
;
1480 this.refreshStart
= this.y
;
1481 this.refreshEnd
= this.y
;
1483 if (this.ybase
!== this.ydisp
) {
1484 this.ydisp
= this.ybase
;
1488 // apply leftover surrogate high from last write
1489 if (this.surrogate_high
) {
1490 data
= this.surrogate_high
+ data
;
1491 this.surrogate_high
= '';
1494 for (; i
< l
; i
++) {
1497 // FIXME: higher chars than 0xa0 are not allowed in escape sequences
1498 // --> maybe move to default
1499 code
= data
.charCodeAt(i
);
1500 if (0xD800 <= code
&& code
<= 0xDBFF) {
1501 // we got a surrogate high
1502 // get surrogate low (next 2 bytes)
1503 low
= data
.charCodeAt(i
+1);
1505 // end of data stream, save surrogate high
1506 this.surrogate_high
= ch
;
1509 code
= ((code
- 0xD800) * 0x400) + (low
- 0xDC00) + 0x10000;
1510 ch
+= data
.charAt(i
+1);
1512 // surrogate low - already handled above
1513 if (0xDC00 <= code
&& code
<= 0xDFFF)
1516 switch (this.state
) {
1527 if (this.convertEol
) {
1531 if (this.y
> this.scrollBottom
) {
1551 this.x
= this.nextStop();
1566 this.state
= escaped
;
1571 // calculate print space
1572 // expensive call, therefore we save width in line buffer
1573 ch_width
= wcwidth(code
);
1576 if (this.charset
&& this.charset
[ch
]) {
1577 ch
= this.charset
[ch
];
1580 row
= this.y
+ this.ybase
;
1582 // insert combining char in last cell
1583 // FIXME: needs handling after cursor jumps
1584 if (!ch_width
&& this.x
) {
1586 // dont overflow left
1587 if (this.lines
[row
][this.x
-1]) {
1588 if (!this.lines
[row
][this.x
-1][2]) {
1590 // found empty cell after fullwidth, need to go 2 cells back
1591 if (this.lines
[row
][this.x
-2])
1592 this.lines
[row
][this.x
-2][1] += ch
;
1595 this.lines
[row
][this.x
-1][1] += ch
;
1597 this.updateRange(this.y
);
1602 // goto next line if ch would overflow
1603 // TODO: needs a global min terminal width of 2
1604 if (this.x
+ch_width
-1 >= this.cols
) {
1605 // autowrap - DECAWM
1606 if (this.wraparoundMode
) {
1609 if (this.y
> this.scrollBottom
) {
1614 this.x
= this.cols
-1;
1615 if(ch_width
===2) // FIXME: check for xterm behavior
1619 row
= this.y
+ this.ybase
;
1621 // insert mode: move characters to right
1622 if (this.insertMode
) {
1623 // do this twice for a fullwidth char
1624 for (var moves
=0; moves
<ch_width
; ++moves
) {
1625 // remove last cell, if it's width is 0
1626 // we have to adjust the second last cell as well
1627 var removed
= this.lines
[this.y
+ this.ybase
].pop();
1629 && this.lines
[row
][this.cols
-2]
1630 && this.lines
[row
][this.cols
-2][2]===2)
1631 this.lines
[row
][this.cols
-2] = [this.curAttr
, ' ', 1];
1633 // insert empty cell at cursor
1634 this.lines
[row
].splice(this.x
, 0, [this.curAttr
, ' ', 1]);
1638 this.lines
[row
][this.x
] = [this.curAttr
, ch
, ch_width
];
1640 this.updateRange(this.y
);
1642 // fullwidth char - set next cell width to zero and advance cursor
1644 this.lines
[row
][this.x
] = [this.curAttr
, '', 0];
1653 // ESC [ Control Sequence Introducer ( CSI is 0x9b).
1656 this.currentParam
= 0;
1660 // ESC ] Operating System Command ( OSC is 0x9d).
1663 this.currentParam
= 0;
1667 // ESC P Device Control String ( DCS is 0x90).
1670 this.currentParam
= 0;
1674 // ESC _ Application Program Command ( APC is 0x9f).
1676 this.state
= ignore
;
1679 // ESC ^ Privacy Message ( PM is 0x9e).
1681 this.state
= ignore
;
1684 // ESC c Full Reset (RIS).
1689 // ESC E Next Line ( NEL is 0x85).
1690 // ESC D Index ( IND is 0x84).
1698 // ESC M Reverse Index ( RI is 0x8d).
1700 this.reverseIndex();
1703 // ESC % Select default/utf-8 character set.
1704 // @ = default, G = utf-8
1706 //this.charset = null;
1708 this.setgCharset(0, Terminal
.charsets
.US
);
1709 this.state
= normal
;
1713 // ESC (,),*,+,-,. Designate G0-G2 Character Set.
1714 case '(': // <-- this seems to get all the attention
1740 this.state
= charset
;
1743 // Designate G3 Character Set (VT300).
1744 // A = ISO Latin-1 Supplemental.
1748 this.state
= charset
;
1753 // Single Shift Select of G2 Character Set
1754 // ( SS2 is 0x8e). This affects next character only.
1758 // Single Shift Select of G3 Character Set
1759 // ( SS3 is 0x8f). This affects next character only.
1763 // Invoke the G2 Character Set as GL (LS2).
1768 // Invoke the G3 Character Set as GL (LS3).
1773 // Invoke the G3 Character Set as GR (LS3R).
1778 // Invoke the G2 Character Set as GR (LS2R).
1783 // Invoke the G1 Character Set as GR (LS1R).
1788 // ESC 7 Save Cursor (DECSC).
1791 this.state
= normal
;
1794 // ESC 8 Restore Cursor (DECRC).
1796 this.restoreCursor();
1797 this.state
= normal
;
1800 // ESC # 3 DEC line height/width
1802 this.state
= normal
;
1806 // ESC H Tab Set (HTS is 0x88).
1811 // ESC = Application Keypad (DECPAM).
1813 this.log('Serial port requested application keypad.');
1814 this.applicationKeypad
= true;
1815 this.state
= normal
;
1818 // ESC > Normal Keypad (DECPNM).
1820 this.log('Switching back to normal keypad.');
1821 this.applicationKeypad
= false;
1822 this.state
= normal
;
1826 this.state
= normal
;
1827 this.error('Unknown ESC control: %s.', ch
);
1834 case '0': // DEC Special Character and Line Drawing Set.
1835 cs
= Terminal
.charsets
.SCLD
;
1838 cs
= Terminal
.charsets
.UK
;
1840 case 'B': // United States (USASCII).
1841 cs
= Terminal
.charsets
.US
;
1844 cs
= Terminal
.charsets
.Dutch
;
1846 case 'C': // Finnish
1848 cs
= Terminal
.charsets
.Finnish
;
1851 cs
= Terminal
.charsets
.French
;
1853 case 'Q': // FrenchCanadian
1854 cs
= Terminal
.charsets
.FrenchCanadian
;
1857 cs
= Terminal
.charsets
.German
;
1859 case 'Y': // Italian
1860 cs
= Terminal
.charsets
.Italian
;
1862 case 'E': // NorwegianDanish
1864 cs
= Terminal
.charsets
.NorwegianDanish
;
1866 case 'Z': // Spanish
1867 cs
= Terminal
.charsets
.Spanish
;
1869 case 'H': // Swedish
1871 cs
= Terminal
.charsets
.Swedish
;
1874 cs
= Terminal
.charsets
.Swiss
;
1876 case '/': // ISOLatin (actually /A)
1877 cs
= Terminal
.charsets
.ISOLatin
;
1881 cs
= Terminal
.charsets
.US
;
1884 this.setgCharset(this.gcharset
, cs
);
1885 this.gcharset
= null;
1886 this.state
= normal
;
1892 // Set Text Parameters.
1893 if (ch
=== '\x1b' || ch
=== '\x07') {
1894 if (ch
=== '\x1b') i
++;
1896 this.params
.push(this.currentParam
);
1898 switch (this.params
[0]) {
1902 if (this.params
[1]) {
1903 this.title
= this.params
[1];
1904 this.handleTitle(this.title
);
1912 // change dynamic colors
1924 // change dynamic ui colors
1936 // manipulate selection data
1954 this.currentParam
= 0;
1955 this.state
= normal
;
1957 if (!this.params
.length
) {
1958 if (ch
>= '0' && ch
<= '9') {
1960 this.currentParam
* 10 + ch
.charCodeAt(0) - 48;
1961 } else if (ch
=== ';') {
1962 this.params
.push(this.currentParam
);
1963 this.currentParam
= '';
1966 this.currentParam
+= ch
;
1973 if (ch
=== '?' || ch
=== '>' || ch
=== '!') {
1979 if (ch
>= '0' && ch
<= '9') {
1980 this.currentParam
= this.currentParam
* 10 + ch
.charCodeAt(0) - 48;
1984 // '$', '"', ' ', '\''
1985 if (ch
=== '$' || ch
=== '"' || ch
=== ' ' || ch
=== '\'') {
1990 this.params
.push(this.currentParam
);
1991 this.currentParam
= 0;
1994 if (ch
=== ';') break;
1996 this.state
= normal
;
2000 // Cursor Up Ps Times (default = 1) (CUU).
2002 this.cursorUp(this.params
);
2006 // Cursor Down Ps Times (default = 1) (CUD).
2008 this.cursorDown(this.params
);
2012 // Cursor Forward Ps Times (default = 1) (CUF).
2014 this.cursorForward(this.params
);
2018 // Cursor Backward Ps Times (default = 1) (CUB).
2020 this.cursorBackward(this.params
);
2024 // Cursor Position [row;column] (default = [1,1]) (CUP).
2026 this.cursorPos(this.params
);
2029 // CSI Ps J Erase in Display (ED).
2031 this.eraseInDisplay(this.params
);
2034 // CSI Ps K Erase in Line (EL).
2036 this.eraseInLine(this.params
);
2039 // CSI Pm m Character Attributes (SGR).
2042 this.charAttributes(this.params
);
2046 // CSI Ps n Device Status Report (DSR).
2049 this.deviceStatus(this.params
);
2058 // Insert Ps (Blank) Character(s) (default = 1) (ICH).
2060 this.insertChars(this.params
);
2064 // Cursor Next Line Ps Times (default = 1) (CNL).
2066 this.cursorNextLine(this.params
);
2070 // Cursor Preceding Line Ps Times (default = 1) (CNL).
2072 this.cursorPrecedingLine(this.params
);
2076 // Cursor Character Absolute [column] (default = [row,1]) (CHA).
2078 this.cursorCharAbsolute(this.params
);
2082 // Insert Ps Line(s) (default = 1) (IL).
2084 this.insertLines(this.params
);
2088 // Delete Ps Line(s) (default = 1) (DL).
2090 this.deleteLines(this.params
);
2094 // Delete Ps Character(s) (default = 1) (DCH).
2096 this.deleteChars(this.params
);
2100 // Erase Ps Character(s) (default = 1) (ECH).
2102 this.eraseChars(this.params
);
2105 // CSI Pm ` Character Position Absolute
2106 // [column] (default = [row,1]) (HPA).
2108 this.charPosAbsolute(this.params
);
2112 // Horizontal Position Relative
2114 this.HPositionRelative(this.params
);
2118 // Send Device Attributes (Primary DA).
2120 // Send Device Attributes (Secondary DA)
2122 this.sendDeviceAttributes(this.params
);
2126 // Line Position Absolute [row] (default = [1,column]) (VPA).
2128 this.linePosAbsolute(this.params
);
2131 // 145 65 e * VPR - Vertical Position Relative
2133 this.VPositionRelative(this.params
);
2137 // Horizontal and Vertical Position [row;column] (default =
2140 this.HVPosition(this.params
);
2143 // CSI Pm h Set Mode (SM).
2144 // CSI ? Pm h - mouse escape codes, cursor escape codes
2146 this.setMode(this.params
);
2149 // CSI Pm l Reset Mode (RM).
2152 this.resetMode(this.params
);
2156 // Set Scrolling Region [top;bottom] (default = full size of win-
2160 this.setScrollRegion(this.params
);
2164 // Save cursor (ANSI.SYS).
2166 this.saveCursor(this.params
);
2170 // Restore cursor (ANSI.SYS).
2172 this.restoreCursor(this.params
);
2180 // Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
2182 this.cursorForwardTab(this.params
);
2185 // CSI Ps S Scroll up Ps lines (default = 1) (SU).
2187 this.scrollUp(this.params
);
2190 // CSI Ps T Scroll down Ps lines (default = 1) (SD).
2191 // CSI Ps ; Ps ; Ps ; Ps ; Ps T
2194 // if (this.prefix === '>') {
2195 // this.resetTitleModes(this.params);
2198 // if (this.params.length > 2) {
2199 // this.initMouseTracking(this.params);
2202 if (this.params
.length
< 2 && !this.prefix
) {
2203 this.scrollDown(this.params
);
2208 // Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
2210 this.cursorBackwardTab(this.params
);
2213 // CSI Ps b Repeat the preceding graphic character Ps times (REP).
2215 this.repeatPrecedingCharacter(this.params
);
2218 // CSI Ps g Tab Clear (TBC).
2220 this.tabClear(this.params
);
2223 // CSI Pm i Media Copy (MC).
2226 // this.mediaCopy(this.params);
2229 // CSI Pm m Character Attributes (SGR).
2231 // case 'm': // duplicate
2232 // if (this.prefix === '>') {
2233 // this.setResources(this.params);
2235 // this.charAttributes(this.params);
2239 // CSI Ps n Device Status Report (DSR).
2241 // case 'n': // duplicate
2242 // if (this.prefix === '>') {
2243 // this.disableModifiers(this.params);
2245 // this.deviceStatus(this.params);
2249 // CSI > Ps p Set pointer mode.
2250 // CSI ! p Soft terminal reset (DECSTR).
2252 // Request ANSI mode (DECRQM).
2254 // Request DEC private mode (DECRQM).
2257 switch (this.prefix
) {
2259 // this.setPointerMode(this.params);
2262 this.softReset(this.params
);
2265 // if (this.postfix === '$') {
2266 // this.requestPrivateMode(this.params);
2270 // if (this.postfix === '"') {
2271 // this.setConformanceLevel(this.params);
2272 // } else if (this.postfix === '$') {
2273 // this.requestAnsiMode(this.params);
2279 // CSI Ps q Load LEDs (DECLL).
2283 // if (this.postfix === ' ') {
2284 // this.setCursorStyle(this.params);
2287 // if (this.postfix === '"') {
2288 // this.setCharProtectionAttr(this.params);
2291 // this.loadLEDs(this.params);
2295 // Set Scrolling Region [top;bottom] (default = full size of win-
2298 // CSI Pt; Pl; Pb; Pr; Ps$ r
2299 // case 'r': // duplicate
2300 // if (this.prefix === '?') {
2301 // this.restorePrivateValues(this.params);
2302 // } else if (this.postfix === '$') {
2303 // this.setAttrInRectangle(this.params);
2305 // this.setScrollRegion(this.params);
2309 // CSI s Save cursor (ANSI.SYS).
2311 // case 's': // duplicate
2312 // if (this.prefix === '?') {
2313 // this.savePrivateValues(this.params);
2315 // this.saveCursor(this.params);
2319 // CSI Ps ; Ps ; Ps t
2320 // CSI Pt; Pl; Pb; Pr; Ps$ t
2324 // if (this.postfix === '$') {
2325 // this.reverseAttrInRectangle(this.params);
2326 // } else if (this.postfix === ' ') {
2327 // this.setWarningBellVolume(this.params);
2329 // if (this.prefix === '>') {
2330 // this.setTitleModeFeature(this.params);
2332 // this.manipulateWindow(this.params);
2337 // CSI u Restore cursor (ANSI.SYS).
2339 // case 'u': // duplicate
2340 // if (this.postfix === ' ') {
2341 // this.setMarginBellVolume(this.params);
2343 // this.restoreCursor(this.params);
2347 // CSI Pt; Pl; Pb; Pr; Pp; Pt; Pl; Pp$ v
2349 // if (this.postfix === '$') {
2350 // this.copyRectagle(this.params);
2354 // CSI Pt ; Pl ; Pb ; Pr ' w
2356 // if (this.postfix === '\'') {
2357 // this.enableFilterRectangle(this.params);
2361 // CSI Ps x Request Terminal Parameters (DECREQTPARM).
2362 // CSI Ps x Select Attribute Change Extent (DECSACE).
2363 // CSI Pc; Pt; Pl; Pb; Pr$ x
2365 // if (this.postfix === '$') {
2366 // this.fillRectangle(this.params);
2368 // this.requestParameters(this.params);
2369 // //this.__(this.params);
2374 // CSI Pt; Pl; Pb; Pr$ z
2376 // if (this.postfix === '\'') {
2377 // this.enableLocatorReporting(this.params);
2378 // } else if (this.postfix === '$') {
2379 // this.eraseRectangle(this.params);
2384 // CSI Pt; Pl; Pb; Pr$ {
2386 // if (this.postfix === '\'') {
2387 // this.setLocatorEvents(this.params);
2388 // } else if (this.postfix === '$') {
2389 // this.selectiveEraseRectangle(this.params);
2395 // if (this.postfix === '\'') {
2396 // this.requestLocatorPosition(this.params);
2401 // Insert P s Column(s) (default = 1) (DECIC), VT420 and up.
2403 // if (this.postfix === ' ') {
2404 // this.insertColumns(this.params);
2409 // Delete P s Column(s) (default = 1) (DECDC), VT420 and up
2411 // if (this.postfix === ' ') {
2412 // this.deleteColumns(this.params);
2417 this.error('Unknown CSI code: %s.', ch
);
2426 if (ch
=== '\x1b' || ch
=== '\x07') {
2427 if (ch
=== '\x1b') i
++;
2429 switch (this.prefix
) {
2430 // User-Defined Keys (DECUDK).
2434 // Request Status String (DECRQSS).
2435 // test: echo -e '\eP$q"p\e\\'
2437 var pt
= this.currentParam
2454 + (this.scrollTop
+ 1)
2456 + (this.scrollBottom
+ 1)
2466 this.error('Unknown DCS Pt: %s.', pt
);
2471 this.send('\x1bP' + +valid
+ '$r' + pt
+ '\x1b\\');
2474 // Set Termcap/Terminfo Data (xterm, experimental).
2478 // Request Termcap/Terminfo String (xterm, experimental)
2479 // Regular xterm does not even respond to this sequence.
2480 // This can cause a small glitch in vim.
2481 // test: echo -ne '\eP+q6b64\e\\'
2483 var pt
= this.currentParam
2486 this.send('\x1bP' + +valid
+ '+r' + pt
+ '\x1b\\');
2490 this.error('Unknown DCS prefix: %s.', this.prefix
);
2494 this.currentParam
= 0;
2496 this.state
= normal
;
2497 } else if (!this.currentParam
) {
2498 if (!this.prefix
&& ch
!== '$' && ch
!== '+') {
2499 this.currentParam
= ch
;
2500 } else if (this.prefix
.length
=== 2) {
2501 this.currentParam
= ch
;
2506 this.currentParam
+= ch
;
2512 if (ch
=== '\x1b' || ch
=== '\x07') {
2513 if (ch
=== '\x1b') i
++;
2514 this.state
= normal
;
2520 this.updateRange(this.y
);
2521 this.refresh(this.refreshStart
, this.refreshEnd
);
2525 * Writes text to the terminal, followed by a break line character (\n).
2526 * @param {string} text The text to write to the terminal.
2528 Terminal
.prototype.writeln = function(data
) {
2529 this.write(data
+ '\r\n');
2533 * Handle a keydown event
2535 * - https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
2536 * @param {KeyboardEvent} ev The keydown event to be handled.
2538 Terminal
.prototype.keyDown = function(ev
) {
2540 var result
= this.evaluateKeyEscapeSequence(ev
);
2542 if (result
.scrollDisp
) {
2543 this.scrollDisp(result
.scrollDisp
);
2544 return this.cancel(ev
);
2547 if (isThirdLevelShift(this, ev
)) {
2551 if (result
.cancel
) {
2552 // The event is canceled at the end already, is this necessary?
2553 this.cancel(ev
, true);
2560 this.emit('keydown', ev
);
2561 this.emit('key', result
.key
, ev
);
2563 this.handler(result
.key
);
2565 return this.cancel(ev
, true);
2569 * Returns an object that determines how a KeyboardEvent should be handled. The key of the
2570 * returned value is the new key code to pass to the PTY.
2572 * Reference: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
2573 * @param {KeyboardEvent} ev The keyboard event to be translated to key escape sequence.
2575 Terminal
.prototype.evaluateKeyEscapeSequence = function(ev
) {
2577 // Whether to cancel event propogation (NOTE: this may not be needed since the event is
2578 // canceled at the end of keyDown
2580 // The new key even to emit
2582 // The number of characters to scroll, if this is defined it will cancel the event
2583 scrollDisp
: undefined
2585 switch (ev
.keyCode
) {
2589 result
.key
= '\x08'; // ^H
2592 result
.key
= '\x7f'; // ^?
2597 result
.key
= '\x1b[Z';
2601 result
.cancel
= true;
2606 result
.cancel
= true;
2610 result
.key
= '\x1b';
2611 result
.cancel
= true;
2616 result
.key
= '\x1bb' // Jump a word back
2617 result
.cancel
= true;
2621 result
.key
= '\x1b[5D'; // Jump a word back
2624 if (this.applicationCursor
) {
2625 result
.key
= '\x1bOD'; // SS3 as ^[O for 7-bit
2628 result
.key
= '\x1b[D';
2633 result
.key
= '\x1bf' // Jump a word forward
2634 result
.cancel
= true;
2638 result
.key
= '\x1b[5C'; // Jump a word forward
2641 if (this.applicationCursor
) {
2642 result
.key
= '\x1bOC';
2645 result
.key
= '\x1b[C';
2649 if (this.applicationCursor
) {
2650 result
.key
= '\x1bOA';
2654 result
.scrollDisp
= -1;
2656 result
.key
= '\x1b[A';
2661 if (this.applicationCursor
) {
2662 result
.key
= '\x1bOB';
2666 result
.scrollDisp
= 1;
2668 result
.key
= '\x1b[B';
2673 if (!ev
.shiftKey
&& !ev
.ctrlKey
) {
2674 // <Ctrl> or <Shift> + <Insert> are used to
2675 // copy-paste on some systems.
2676 result
.key
= '\x1b[2~';
2680 case 46: result
.key
= '\x1b[3~'; break;
2683 if (this.applicationKeypad
) {
2684 result
.key
= '\x1bOH';
2687 result
.key
= '\x1bOH';
2691 if (this.applicationKeypad
) {
2692 result
.key
= '\x1bOF';
2695 result
.key
= '\x1bOF';
2700 result
.scrollDisp
= -(this.rows
- 1);
2702 result
.key
= '\x1b[5~';
2708 result
.scrollDisp
= this.rows
- 1;
2710 result
.key
= '\x1b[6~';
2714 case 112: result
.key
= '\x1bOP'; break;
2715 case 113: result
.key
= '\x1bOQ'; break;
2716 case 114: result
.key
= '\x1bOR'; break;
2717 case 115: result
.key
= '\x1bOS'; break;
2718 case 116: result
.key
= '\x1b[15~'; break;
2719 case 117: result
.key
= '\x1b[17~'; break;
2720 case 118: result
.key
= '\x1b[18~'; break;
2721 case 119: result
.key
= '\x1b[19~'; break;
2722 case 120: result
.key
= '\x1b[20~'; break;
2723 case 121: result
.key
= '\x1b[21~'; break;
2724 case 122: result
.key
= '\x1b[23~'; break;
2725 case 123: result
.key
= '\x1b[24~'; break;
2728 if (ev
.ctrlKey
&& !ev
.shiftKey
&& !ev
.altKey
&& !ev
.metaKey
) {
2729 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
2730 result
.key
= String
.fromCharCode(ev
.keyCode
- 64);
2731 } else if (ev
.keyCode
=== 32) {
2733 result
.key
= String
.fromCharCode(0);
2734 } else if (ev
.keyCode
>= 51 && ev
.keyCode
<= 55) {
2735 // escape, file sep, group sep, record sep, unit sep
2736 result
.key
= String
.fromCharCode(ev
.keyCode
- 51 + 27);
2737 } else if (ev
.keyCode
=== 56) {
2739 result
.key
= String
.fromCharCode(127);
2740 } else if (ev
.keyCode
=== 219) {
2742 result
.key
= String
.fromCharCode(27);
2743 } else if (ev
.keyCode
=== 221) {
2745 result
.key
= String
.fromCharCode(29);
2747 } else if (!this.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) {
2748 // On Mac this is a third level shift. Use <Esc> instead.
2749 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
2750 result
.key
= '\x1b' + String
.fromCharCode(ev
.keyCode
+ 32);
2751 } else if (ev
.keyCode
=== 192) {
2752 result
.key
= '\x1b`';
2753 } else if (ev
.keyCode
>= 48 && ev
.keyCode
<= 57) {
2754 result
.key
= '\x1b' + (ev
.keyCode
- 48);
2763 * Set the G level of the terminal
2766 Terminal
.prototype.setgLevel = function(g
) {
2768 this.charset
= this.charsets
[g
];
2772 * Set the charset for the given G level of the terminal
2776 Terminal
.prototype.setgCharset = function(g
, charset
) {
2777 this.charsets
[g
] = charset
;
2778 if (this.glevel
=== g
) {
2779 this.charset
= charset
;
2784 * Handle a keypress event.
2786 * - https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
2787 * @param {KeyboardEvent} ev The keypress event to be handled.
2789 Terminal
.prototype.keyPress = function(ev
) {
2794 } else if (ev
.which
== null) {
2796 } else if (ev
.which
!== 0 && ev
.charCode
!== 0) {
2803 (ev
.altKey
|| ev
.ctrlKey
|| ev
.metaKey
) && !isThirdLevelShift(this, ev
)
2808 key
= String
.fromCharCode(key
);
2811 * When a key is pressed and a character is sent to the terminal, then clear any text
2812 * selected in the terminal.
2815 this.clearSelection();
2818 this.emit('keypress', key
, ev
);
2819 this.emit('key', key
, ev
);
2823 this.cancel(ev
, true);
2829 * Send data for handling to the terminal
2830 * @param {string} data
2832 Terminal
.prototype.send = function(data
) {
2836 setTimeout(function() {
2837 self
.handler(self
.queue
);
2847 * Note: We could do sweet things with webaudio here
2849 Terminal
.prototype.bell = function() {
2850 if (!this.visualBell
) return;
2852 this.element
.style
.borderColor
= 'white';
2853 setTimeout(function() {
2854 self
.element
.style
.borderColor
= '';
2856 if (this.popOnBell
) this.focus();
2860 * Log the current state to the console.
2862 Terminal
.prototype.log = function() {
2863 if (!this.debug
) return;
2864 if (!this.context
.console
|| !this.context
.console
.log
) return;
2865 var args
= Array
.prototype.slice
.call(arguments
);
2866 this.context
.console
.log
.apply(this.context
.console
, args
);
2870 * Log the current state as error to the console.
2872 Terminal
.prototype.error = function() {
2873 if (!this.debug
) return;
2874 if (!this.context
.console
|| !this.context
.console
.error
) return;
2875 var args
= Array
.prototype.slice
.call(arguments
);
2876 this.context
.console
.error
.apply(this.context
.console
, args
);
2880 * Resizes the terminal.
2882 * @param {number} x The number of columns to resize to.
2883 * @param {number} y The number of rows to resize to.
2885 Terminal
.prototype.resize = function(x
, y
) {
2893 if (x
=== this.cols
&& y
=== this.rows
) {
2903 ch
= [this.defAttr
, ' ', 1]; // does xterm use the default attr?
2904 i
= this.lines
.length
;
2906 while (this.lines
[i
].length
< x
) {
2907 this.lines
[i
].push(ch
);
2911 i
= this.lines
.length
;
2913 while (this.lines
[i
].length
> x
) {
2914 this.lines
[i
].pop();
2927 // y is rows, not this.y
2928 if (this.lines
.length
< y
+ this.ybase
) {
2929 if (this.ybase
> 0 && this.lines
.length
<= this.ybase
+ this.y
+ addToY
+ 1) {
2930 // There is room above the buffer and there are no empty elements below the line,
2934 if (this.ydisp
> 0) {
2935 // Viewport is at the top of the buffer, must increase downwards
2939 // Add a blank line if there is no buffer left at the top to scroll to, or if there
2940 // are blank lines after the cursor
2941 this.lines
.push(this.blankLine());
2944 if (this.children
.length
< y
) {
2950 if (this.lines
.length
> y
+ this.ybase
) {
2951 if (this.lines
.length
> this.ybase
+ this.y
+ 1) {
2952 // The line is a blank line below the cursor, remove it
2955 // The line is the cursor, scroll down
2960 if (this.children
.length
> y
) {
2961 el
= this.children
.shift();
2963 el
.parentNode
.removeChild(el
);
2970 * Make sure that the cursor stays on screen
2984 this.scrollBottom
= y
- 1;
2986 this.refresh(0, this.rows
- 1);
2990 this.emit('resize', {terminal
: this, cols
: x
, rows
: y
});
2994 * Updates the range of rows to refresh
2995 * @param {number} y The number of rows to refresh next.
2997 Terminal
.prototype.updateRange = function(y
) {
2998 if (y
< this.refreshStart
) this.refreshStart
= y
;
2999 if (y
> this.refreshEnd
) this.refreshEnd
= y
;
3000 // if (y > this.refreshEnd) {
3001 // this.refreshEnd = y;
3002 // if (y > this.rows - 1) {
3003 // this.refreshEnd = this.rows - 1;
3009 * Set the range of refreshing to the maximyum value
3011 Terminal
.prototype.maxRange = function() {
3012 this.refreshStart
= 0;
3013 this.refreshEnd
= this.rows
- 1;
3016 Terminal
.prototype.setupStops = function(i
) {
3018 if (!this.tabs
[i
]) {
3019 i
= this.prevStop(i
);
3026 for (; i
< this.cols
; i
+= 8) {
3027 this.tabs
[i
] = true;
3031 Terminal
.prototype.prevStop = function(x
) {
3032 if (x
== null) x
= this.x
;
3033 while (!this.tabs
[--x
] && x
> 0);
3034 return x
>= this.cols
3039 Terminal
.prototype.nextStop = function(x
) {
3040 if (x
== null) x
= this.x
;
3041 while (!this.tabs
[++x
] && x
< this.cols
);
3042 return x
>= this.cols
3047 Terminal
.prototype.eraseRight = function(x
, y
) {
3048 var line
= this.lines
[this.ybase
+ y
]
3049 , ch
= [this.eraseAttr(), ' ', 1]; // xterm
3052 for (; x
< this.cols
; x
++) {
3056 this.updateRange(y
);
3059 Terminal
.prototype.eraseLeft = function(x
, y
) {
3060 var line
= this.lines
[this.ybase
+ y
]
3061 , ch
= [this.eraseAttr(), ' ', 1]; // xterm
3064 while (x
--) line
[x
] = ch
;
3066 this.updateRange(y
);
3069 Terminal
.prototype.eraseLine = function(y
) {
3070 this.eraseRight(0, y
);
3073 Terminal
.prototype.blankLine = function(cur
) {
3078 var ch
= [attr
, ' ', 1] // width defaults to 1 halfwidth character
3082 for (; i
< this.cols
; i
++) {
3089 Terminal
.prototype.ch = function(cur
) {
3091 ? [this.eraseAttr(), ' ', 1]
3092 : [this.defAttr
, ' ', 1];
3095 Terminal
.prototype.is = function(term
) {
3096 var name
= this.termName
;
3097 return (name
+ '').indexOf(term
) === 0;
3100 Terminal
.prototype.handler = function(data
) {
3101 this.emit('data', data
);
3104 Terminal
.prototype.handleTitle = function(title
) {
3105 this.emit('title', title
);
3112 // ESC D Index (IND is 0x84).
3113 Terminal
.prototype.index = function() {
3115 if (this.y
> this.scrollBottom
) {
3119 this.state
= normal
;
3122 // ESC M Reverse Index (RI is 0x8d).
3123 Terminal
.prototype.reverseIndex = function() {
3126 if (this.y
< this.scrollTop
) {
3128 // possibly move the code below to term.reverseScroll();
3129 // test: echo -ne '\e[1;1H\e[44m\eM\e[0m'
3130 // blankLine(true) is xterm/linux behavior
3131 this.lines
.splice(this.y
+ this.ybase
, 0, this.blankLine(true));
3132 j
= this.rows
- 1 - this.scrollBottom
;
3133 this.lines
.splice(this.rows
- 1 + this.ybase
- j
+ 1, 1);
3135 this.updateRange(this.scrollTop
);
3136 this.updateRange(this.scrollBottom
);
3138 this.state
= normal
;
3141 // ESC c Full Reset (RIS).
3142 Terminal
.prototype.reset = function() {
3143 this.options
.rows
= this.rows
;
3144 this.options
.cols
= this.cols
;
3145 Terminal
.call(this, this.options
);
3146 this.refresh(0, this.rows
- 1);
3149 // ESC H Tab Set (HTS is 0x88).
3150 Terminal
.prototype.tabSet = function() {
3151 this.tabs
[this.x
] = true;
3152 this.state
= normal
;
3160 // Cursor Up Ps Times (default = 1) (CUU).
3161 Terminal
.prototype.cursorUp = function(params
) {
3162 var param
= params
[0];
3163 if (param
< 1) param
= 1;
3165 if (this.y
< 0) this.y
= 0;
3169 // Cursor Down Ps Times (default = 1) (CUD).
3170 Terminal
.prototype.cursorDown = function(params
) {
3171 var param
= params
[0];
3172 if (param
< 1) param
= 1;
3174 if (this.y
>= this.rows
) {
3175 this.y
= this.rows
- 1;
3180 // Cursor Forward Ps Times (default = 1) (CUF).
3181 Terminal
.prototype.cursorForward = function(params
) {
3182 var param
= params
[0];
3183 if (param
< 1) param
= 1;
3185 if (this.x
>= this.cols
) {
3186 this.x
= this.cols
- 1;
3191 // Cursor Backward Ps Times (default = 1) (CUB).
3192 Terminal
.prototype.cursorBackward = function(params
) {
3193 var param
= params
[0];
3194 if (param
< 1) param
= 1;
3196 if (this.x
< 0) this.x
= 0;
3200 // Cursor Position [row;column] (default = [1,1]) (CUP).
3201 Terminal
.prototype.cursorPos = function(params
) {
3204 row
= params
[0] - 1;
3206 if (params
.length
>= 2) {
3207 col
= params
[1] - 1;
3214 } else if (row
>= this.rows
) {
3215 row
= this.rows
- 1;
3220 } else if (col
>= this.cols
) {
3221 col
= this.cols
- 1;
3228 // CSI Ps J Erase in Display (ED).
3229 // Ps = 0 -> Erase Below (default).
3230 // Ps = 1 -> Erase Above.
3231 // Ps = 2 -> Erase All.
3232 // Ps = 3 -> Erase Saved Lines (xterm).
3234 // Erase in Display (DECSED).
3235 // Ps = 0 -> Selective Erase Below (default).
3236 // Ps = 1 -> Selective Erase Above.
3237 // Ps = 2 -> Selective Erase All.
3238 Terminal
.prototype.eraseInDisplay = function(params
) {
3240 switch (params
[0]) {
3242 this.eraseRight(this.x
, this.y
);
3244 for (; j
< this.rows
; j
++) {
3249 this.eraseLeft(this.x
, this.y
);
3257 while (j
--) this.eraseLine(j
);
3265 // CSI Ps K Erase in Line (EL).
3266 // Ps = 0 -> Erase to Right (default).
3267 // Ps = 1 -> Erase to Left.
3268 // Ps = 2 -> Erase All.
3270 // Erase in Line (DECSEL).
3271 // Ps = 0 -> Selective Erase to Right (default).
3272 // Ps = 1 -> Selective Erase to Left.
3273 // Ps = 2 -> Selective Erase All.
3274 Terminal
.prototype.eraseInLine = function(params
) {
3275 switch (params
[0]) {
3277 this.eraseRight(this.x
, this.y
);
3280 this.eraseLeft(this.x
, this.y
);
3283 this.eraseLine(this.y
);
3288 // CSI Pm m Character Attributes (SGR).
3289 // Ps = 0 -> Normal (default).
3291 // Ps = 4 -> Underlined.
3292 // Ps = 5 -> Blink (appears as Bold).
3293 // Ps = 7 -> Inverse.
3294 // Ps = 8 -> Invisible, i.e., hidden (VT300).
3295 // Ps = 2 2 -> Normal (neither bold nor faint).
3296 // Ps = 2 4 -> Not underlined.
3297 // Ps = 2 5 -> Steady (not blinking).
3298 // Ps = 2 7 -> Positive (not inverse).
3299 // Ps = 2 8 -> Visible, i.e., not hidden (VT300).
3300 // Ps = 3 0 -> Set foreground color to Black.
3301 // Ps = 3 1 -> Set foreground color to Red.
3302 // Ps = 3 2 -> Set foreground color to Green.
3303 // Ps = 3 3 -> Set foreground color to Yellow.
3304 // Ps = 3 4 -> Set foreground color to Blue.
3305 // Ps = 3 5 -> Set foreground color to Magenta.
3306 // Ps = 3 6 -> Set foreground color to Cyan.
3307 // Ps = 3 7 -> Set foreground color to White.
3308 // Ps = 3 9 -> Set foreground color to default (original).
3309 // Ps = 4 0 -> Set background color to Black.
3310 // Ps = 4 1 -> Set background color to Red.
3311 // Ps = 4 2 -> Set background color to Green.
3312 // Ps = 4 3 -> Set background color to Yellow.
3313 // Ps = 4 4 -> Set background color to Blue.
3314 // Ps = 4 5 -> Set background color to Magenta.
3315 // Ps = 4 6 -> Set background color to Cyan.
3316 // Ps = 4 7 -> Set background color to White.
3317 // Ps = 4 9 -> Set background color to default (original).
3319 // If 16-color support is compiled, the following apply. Assume
3320 // that xterm's resources are set so that the ISO color codes are
3321 // the first 8 of a set of 16. Then the aixterm colors are the
3322 // bright versions of the ISO colors:
3323 // Ps = 9 0 -> Set foreground color to Black.
3324 // Ps = 9 1 -> Set foreground color to Red.
3325 // Ps = 9 2 -> Set foreground color to Green.
3326 // Ps = 9 3 -> Set foreground color to Yellow.
3327 // Ps = 9 4 -> Set foreground color to Blue.
3328 // Ps = 9 5 -> Set foreground color to Magenta.
3329 // Ps = 9 6 -> Set foreground color to Cyan.
3330 // Ps = 9 7 -> Set foreground color to White.
3331 // Ps = 1 0 0 -> Set background color to Black.
3332 // Ps = 1 0 1 -> Set background color to Red.
3333 // Ps = 1 0 2 -> Set background color to Green.
3334 // Ps = 1 0 3 -> Set background color to Yellow.
3335 // Ps = 1 0 4 -> Set background color to Blue.
3336 // Ps = 1 0 5 -> Set background color to Magenta.
3337 // Ps = 1 0 6 -> Set background color to Cyan.
3338 // Ps = 1 0 7 -> Set background color to White.
3340 // If xterm is compiled with the 16-color support disabled, it
3341 // supports the following, from rxvt:
3342 // Ps = 1 0 0 -> Set foreground and background color to
3345 // If 88- or 256-color support is compiled, the following apply.
3346 // Ps = 3 8 ; 5 ; Ps -> Set foreground color to the second
3348 // Ps = 4 8 ; 5 ; Ps -> Set background color to the second
3350 Terminal
.prototype.charAttributes = function(params
) {
3351 // Optimize a single SGR0.
3352 if (params
.length
=== 1 && params
[0] === 0) {
3353 this.curAttr
= this.defAttr
;
3357 var l
= params
.length
3359 , flags
= this.curAttr
>> 18
3360 , fg
= (this.curAttr
>> 9) & 0x1ff
3361 , bg
= this.curAttr
& 0x1ff
3364 for (; i
< l
; i
++) {
3366 if (p
>= 30 && p
<= 37) {
3369 } else if (p
>= 40 && p
<= 47) {
3372 } else if (p
>= 90 && p
<= 97) {
3376 } else if (p
>= 100 && p
<= 107) {
3380 } else if (p
=== 0) {
3382 flags
= this.defAttr
>> 18;
3383 fg
= (this.defAttr
>> 9) & 0x1ff;
3384 bg
= this.defAttr
& 0x1ff;
3388 } else if (p
=== 1) {
3391 } else if (p
=== 4) {
3394 } else if (p
=== 5) {
3397 } else if (p
=== 7) {
3398 // inverse and positive
3399 // test with: echo -e '\e[31m\e[42mhello\e[7mworld\e[27mhi\e[m'
3401 } else if (p
=== 8) {
3404 } else if (p
=== 22) {
3407 } else if (p
=== 24) {
3410 } else if (p
=== 25) {
3413 } else if (p
=== 27) {
3416 } else if (p
=== 28) {
3419 } else if (p
=== 39) {
3421 fg
= (this.defAttr
>> 9) & 0x1ff;
3422 } else if (p
=== 49) {
3424 bg
= this.defAttr
& 0x1ff;
3425 } else if (p
=== 38) {
3427 if (params
[i
+ 1] === 2) {
3431 params
[i
+ 1] & 0xff,
3432 params
[i
+ 2] & 0xff);
3433 if (fg
=== -1) fg
= 0x1ff;
3435 } else if (params
[i
+ 1] === 5) {
3437 p
= params
[i
] & 0xff;
3440 } else if (p
=== 48) {
3442 if (params
[i
+ 1] === 2) {
3446 params
[i
+ 1] & 0xff,
3447 params
[i
+ 2] & 0xff);
3448 if (bg
=== -1) bg
= 0x1ff;
3450 } else if (params
[i
+ 1] === 5) {
3452 p
= params
[i
] & 0xff;
3455 } else if (p
=== 100) {
3457 fg
= (this.defAttr
>> 9) & 0x1ff;
3458 bg
= this.defAttr
& 0x1ff;
3460 this.error('Unknown SGR attribute: %d.', p
);
3464 this.curAttr
= (flags
<< 18) | (fg
<< 9) | bg
;
3467 // CSI Ps n Device Status Report (DSR).
3468 // Ps = 5 -> Status Report. Result (``OK'') is
3470 // Ps = 6 -> Report Cursor Position (CPR) [row;column].
3474 // Device Status Report (DSR, DEC-specific).
3475 // Ps = 6 -> Report Cursor Position (CPR) [row;column] as CSI
3476 // ? r ; c R (assumes page is zero).
3477 // Ps = 1 5 -> Report Printer status as CSI ? 1 0 n (ready).
3478 // or CSI ? 1 1 n (not ready).
3479 // Ps = 2 5 -> Report UDK status as CSI ? 2 0 n (unlocked)
3480 // or CSI ? 2 1 n (locked).
3481 // Ps = 2 6 -> Report Keyboard status as
3482 // CSI ? 2 7 ; 1 ; 0 ; 0 n (North American).
3483 // The last two parameters apply to VT400 & up, and denote key-
3484 // board ready and LK01 respectively.
3485 // Ps = 5 3 -> Report Locator status as
3486 // CSI ? 5 3 n Locator available, if compiled-in, or
3487 // CSI ? 5 0 n No Locator, if not.
3488 Terminal
.prototype.deviceStatus = function(params
) {
3490 switch (params
[0]) {
3493 this.send('\x1b[0n');
3504 } else if (this.prefix
=== '?') {
3505 // modern xterm doesnt seem to
3506 // respond to any of these except ?6, 6, and 5
3507 switch (params
[0]) {
3518 // this.send('\x1b[?11n');
3521 // dont support user defined keys
3522 // this.send('\x1b[?21n');
3525 // north american keyboard
3526 // this.send('\x1b[?27;1;0;0n');
3529 // no dec locator/mouse
3530 // this.send('\x1b[?50n');
3541 // Insert Ps (Blank) Character(s) (default = 1) (ICH).
3542 Terminal
.prototype.insertChars = 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
].splice(j
++, 0, ch
);
3554 this.lines
[row
].pop();
3559 // Cursor Next Line Ps Times (default = 1) (CNL).
3560 // same as CSI Ps B ?
3561 Terminal
.prototype.cursorNextLine = function(params
) {
3562 var param
= params
[0];
3563 if (param
< 1) param
= 1;
3565 if (this.y
>= this.rows
) {
3566 this.y
= this.rows
- 1;
3572 // Cursor Preceding Line Ps Times (default = 1) (CNL).
3574 Terminal
.prototype.cursorPrecedingLine = function(params
) {
3575 var param
= params
[0];
3576 if (param
< 1) param
= 1;
3578 if (this.y
< 0) this.y
= 0;
3583 // Cursor Character Absolute [column] (default = [row,1]) (CHA).
3584 Terminal
.prototype.cursorCharAbsolute = function(params
) {
3585 var param
= params
[0];
3586 if (param
< 1) param
= 1;
3591 // Insert Ps Line(s) (default = 1) (IL).
3592 Terminal
.prototype.insertLines = function(params
) {
3596 if (param
< 1) param
= 1;
3597 row
= this.y
+ this.ybase
;
3599 j
= this.rows
- 1 - this.scrollBottom
;
3600 j
= this.rows
- 1 + this.ybase
- j
+ 1;
3603 // test: echo -e '\e[44m\e[1L\e[0m'
3604 // blankLine(true) - xterm/linux behavior
3605 this.lines
.splice(row
, 0, this.blankLine(true));
3606 this.lines
.splice(j
, 1);
3610 this.updateRange(this.y
);
3611 this.updateRange(this.scrollBottom
);
3615 // Delete Ps Line(s) (default = 1) (DL).
3616 Terminal
.prototype.deleteLines = function(params
) {
3620 if (param
< 1) param
= 1;
3621 row
= this.y
+ this.ybase
;
3623 j
= this.rows
- 1 - this.scrollBottom
;
3624 j
= this.rows
- 1 + this.ybase
- j
;
3627 // test: echo -e '\e[44m\e[1M\e[0m'
3628 // blankLine(true) - xterm/linux behavior
3629 this.lines
.splice(j
+ 1, 0, this.blankLine(true));
3630 this.lines
.splice(row
, 1);
3634 this.updateRange(this.y
);
3635 this.updateRange(this.scrollBottom
);
3639 // Delete Ps Character(s) (default = 1) (DCH).
3640 Terminal
.prototype.deleteChars = function(params
) {
3644 if (param
< 1) param
= 1;
3646 row
= this.y
+ this.ybase
;
3647 ch
= [this.eraseAttr(), ' ', 1]; // xterm
3650 this.lines
[row
].splice(this.x
, 1);
3651 this.lines
[row
].push(ch
);
3656 // Erase Ps Character(s) (default = 1) (ECH).
3657 Terminal
.prototype.eraseChars = function(params
) {
3658 var param
, row
, j
, ch
;
3661 if (param
< 1) param
= 1;
3663 row
= this.y
+ this.ybase
;
3665 ch
= [this.eraseAttr(), ' ', 1]; // xterm
3667 while (param
-- && j
< this.cols
) {
3668 this.lines
[row
][j
++] = ch
;
3672 // CSI Pm ` Character Position Absolute
3673 // [column] (default = [row,1]) (HPA).
3674 Terminal
.prototype.charPosAbsolute = function(params
) {
3675 var param
= params
[0];
3676 if (param
< 1) param
= 1;
3678 if (this.x
>= this.cols
) {
3679 this.x
= this.cols
- 1;
3684 // Horizontal Position Relative
3686 Terminal
.prototype.HPositionRelative = function(params
) {
3687 var param
= params
[0];
3688 if (param
< 1) param
= 1;
3690 if (this.x
>= this.cols
) {
3691 this.x
= this.cols
- 1;
3695 // CSI Ps c Send Device Attributes (Primary DA).
3696 // Ps = 0 or omitted -> request attributes from terminal. The
3697 // response depends on the decTerminalID resource setting.
3698 // -> CSI ? 1 ; 2 c (``VT100 with Advanced Video Option'')
3699 // -> CSI ? 1 ; 0 c (``VT101 with No Options'')
3700 // -> CSI ? 6 c (``VT102'')
3701 // -> CSI ? 6 0 ; 1 ; 2 ; 6 ; 8 ; 9 ; 1 5 ; c (``VT220'')
3702 // The VT100-style response parameters do not mean anything by
3703 // themselves. VT220 parameters do, telling the host what fea-
3704 // tures the terminal supports:
3705 // Ps = 1 -> 132-columns.
3706 // Ps = 2 -> Printer.
3707 // Ps = 6 -> Selective erase.
3708 // Ps = 8 -> User-defined keys.
3709 // Ps = 9 -> National replacement character sets.
3710 // Ps = 1 5 -> Technical characters.
3711 // Ps = 2 2 -> ANSI color, e.g., VT525.
3712 // Ps = 2 9 -> ANSI text locator (i.e., DEC Locator mode).
3714 // Send Device Attributes (Secondary DA).
3715 // Ps = 0 or omitted -> request the terminal's identification
3716 // code. The response depends on the decTerminalID resource set-
3717 // ting. It should apply only to VT220 and up, but xterm extends
3719 // -> CSI > Pp ; Pv ; Pc c
3720 // where Pp denotes the terminal type
3721 // Pp = 0 -> ``VT100''.
3722 // Pp = 1 -> ``VT220''.
3723 // and Pv is the firmware version (for xterm, this was originally
3724 // the XFree86 patch number, starting with 95). In a DEC termi-
3725 // nal, Pc indicates the ROM cartridge registration number and is
3727 // More information:
3728 // xterm/charproc.c - line 2012, for more information.
3729 // vim responds with ^[[?0c or ^[[?1c after the terminal's response (?)
3730 Terminal
.prototype.sendDeviceAttributes = function(params
) {
3731 if (params
[0] > 0) return;
3734 if (this.is('xterm')
3735 || this.is('rxvt-unicode')
3736 || this.is('screen')) {
3737 this.send('\x1b[?1;2c');
3738 } else if (this.is('linux')) {
3739 this.send('\x1b[?6c');
3741 } else if (this.prefix
=== '>') {
3743 // seem to spit this
3744 // out around ~370 times (?).
3745 if (this.is('xterm')) {
3746 this.send('\x1b[>0;276;0c');
3747 } else if (this.is('rxvt-unicode')) {
3748 this.send('\x1b[>85;95;0c');
3749 } else if (this.is('linux')) {
3750 // not supported by linux console.
3751 // linux console echoes parameters.
3752 this.send(params
[0] + 'c');
3753 } else if (this.is('screen')) {
3754 this.send('\x1b[>83;40003;0c');
3760 // Line Position Absolute [row] (default = [1,column]) (VPA).
3761 Terminal
.prototype.linePosAbsolute = function(params
) {
3762 var param
= params
[0];
3763 if (param
< 1) param
= 1;
3765 if (this.y
>= this.rows
) {
3766 this.y
= this.rows
- 1;
3770 // 145 65 e * VPR - Vertical Position Relative
3772 Terminal
.prototype.VPositionRelative = function(params
) {
3773 var param
= params
[0];
3774 if (param
< 1) param
= 1;
3776 if (this.y
>= this.rows
) {
3777 this.y
= this.rows
- 1;
3782 // Horizontal and Vertical Position [row;column] (default =
3784 Terminal
.prototype.HVPosition = function(params
) {
3785 if (params
[0] < 1) params
[0] = 1;
3786 if (params
[1] < 1) params
[1] = 1;
3788 this.y
= params
[0] - 1;
3789 if (this.y
>= this.rows
) {
3790 this.y
= this.rows
- 1;
3793 this.x
= params
[1] - 1;
3794 if (this.x
>= this.cols
) {
3795 this.x
= this.cols
- 1;
3799 // CSI Pm h Set Mode (SM).
3800 // Ps = 2 -> Keyboard Action Mode (AM).
3801 // Ps = 4 -> Insert Mode (IRM).
3802 // Ps = 1 2 -> Send/receive (SRM).
3803 // Ps = 2 0 -> Automatic Newline (LNM).
3805 // DEC Private Mode Set (DECSET).
3806 // Ps = 1 -> Application Cursor Keys (DECCKM).
3807 // Ps = 2 -> Designate USASCII for character sets G0-G3
3808 // (DECANM), and set VT100 mode.
3809 // Ps = 3 -> 132 Column Mode (DECCOLM).
3810 // Ps = 4 -> Smooth (Slow) Scroll (DECSCLM).
3811 // Ps = 5 -> Reverse Video (DECSCNM).
3812 // Ps = 6 -> Origin Mode (DECOM).
3813 // Ps = 7 -> Wraparound Mode (DECAWM).
3814 // Ps = 8 -> Auto-repeat Keys (DECARM).
3815 // Ps = 9 -> Send Mouse X & Y on button press. See the sec-
3816 // tion Mouse Tracking.
3817 // Ps = 1 0 -> Show toolbar (rxvt).
3818 // Ps = 1 2 -> Start Blinking Cursor (att610).
3819 // Ps = 1 8 -> Print form feed (DECPFF).
3820 // Ps = 1 9 -> Set print extent to full screen (DECPEX).
3821 // Ps = 2 5 -> Show Cursor (DECTCEM).
3822 // Ps = 3 0 -> Show scrollbar (rxvt).
3823 // Ps = 3 5 -> Enable font-shifting functions (rxvt).
3824 // Ps = 3 8 -> Enter Tektronix Mode (DECTEK).
3825 // Ps = 4 0 -> Allow 80 -> 132 Mode.
3826 // Ps = 4 1 -> more(1) fix (see curses resource).
3827 // Ps = 4 2 -> Enable Nation Replacement Character sets (DECN-
3829 // Ps = 4 4 -> Turn On Margin Bell.
3830 // Ps = 4 5 -> Reverse-wraparound Mode.
3831 // Ps = 4 6 -> Start Logging. This is normally disabled by a
3832 // compile-time option.
3833 // Ps = 4 7 -> Use Alternate Screen Buffer. (This may be dis-
3834 // abled by the titeInhibit resource).
3835 // Ps = 6 6 -> Application keypad (DECNKM).
3836 // Ps = 6 7 -> Backarrow key sends backspace (DECBKM).
3837 // Ps = 1 0 0 0 -> Send Mouse X & Y on button press and
3838 // release. See the section Mouse Tracking.
3839 // Ps = 1 0 0 1 -> Use Hilite Mouse Tracking.
3840 // Ps = 1 0 0 2 -> Use Cell Motion Mouse Tracking.
3841 // Ps = 1 0 0 3 -> Use All Motion Mouse Tracking.
3842 // Ps = 1 0 0 4 -> Send FocusIn/FocusOut events.
3843 // Ps = 1 0 0 5 -> Enable Extended Mouse Mode.
3844 // Ps = 1 0 1 0 -> Scroll to bottom on tty output (rxvt).
3845 // Ps = 1 0 1 1 -> Scroll to bottom on key press (rxvt).
3846 // Ps = 1 0 3 4 -> Interpret "meta" key, sets eighth bit.
3847 // (enables the eightBitInput resource).
3848 // Ps = 1 0 3 5 -> Enable special modifiers for Alt and Num-
3849 // Lock keys. (This enables the numLock resource).
3850 // Ps = 1 0 3 6 -> Send ESC when Meta modifies a key. (This
3851 // enables the metaSendsEscape resource).
3852 // Ps = 1 0 3 7 -> Send DEL from the editing-keypad Delete
3854 // Ps = 1 0 3 9 -> Send ESC when Alt modifies a key. (This
3855 // enables the altSendsEscape resource).
3856 // Ps = 1 0 4 0 -> Keep selection even if not highlighted.
3857 // (This enables the keepSelection resource).
3858 // Ps = 1 0 4 1 -> Use the CLIPBOARD selection. (This enables
3859 // the selectToClipboard resource).
3860 // Ps = 1 0 4 2 -> Enable Urgency window manager hint when
3861 // Control-G is received. (This enables the bellIsUrgent
3863 // Ps = 1 0 4 3 -> Enable raising of the window when Control-G
3864 // is received. (enables the popOnBell resource).
3865 // Ps = 1 0 4 7 -> Use Alternate Screen Buffer. (This may be
3866 // disabled by the titeInhibit resource).
3867 // Ps = 1 0 4 8 -> Save cursor as in DECSC. (This may be dis-
3868 // abled by the titeInhibit resource).
3869 // Ps = 1 0 4 9 -> Save cursor as in DECSC and use Alternate
3870 // Screen Buffer, clearing it first. (This may be disabled by
3871 // the titeInhibit resource). This combines the effects of the 1
3872 // 0 4 7 and 1 0 4 8 modes. Use this with terminfo-based
3873 // applications rather than the 4 7 mode.
3874 // Ps = 1 0 5 0 -> Set terminfo/termcap function-key mode.
3875 // Ps = 1 0 5 1 -> Set Sun function-key mode.
3876 // Ps = 1 0 5 2 -> Set HP function-key mode.
3877 // Ps = 1 0 5 3 -> Set SCO function-key mode.
3878 // Ps = 1 0 6 0 -> Set legacy keyboard emulation (X11R6).
3879 // Ps = 1 0 6 1 -> Set VT220 keyboard emulation.
3880 // Ps = 2 0 0 4 -> Set bracketed paste mode.
3882 // http://vt100.net/docs/vt220-rm/chapter4.html
3883 Terminal
.prototype.setMode = function(params
) {
3884 if (typeof params
=== 'object') {
3885 var l
= params
.length
3888 for (; i
< l
; i
++) {
3889 this.setMode(params
[i
]);
3898 this.insertMode
= true;
3901 //this.convertEol = true;
3904 } else if (this.prefix
=== '?') {
3907 this.applicationCursor
= true;
3910 this.setgCharset(0, Terminal
.charsets
.US
);
3911 this.setgCharset(1, Terminal
.charsets
.US
);
3912 this.setgCharset(2, Terminal
.charsets
.US
);
3913 this.setgCharset(3, Terminal
.charsets
.US
);
3914 // set VT100 mode here
3916 case 3: // 132 col mode
3917 this.savedCols
= this.cols
;
3918 this.resize(132, this.rows
);
3921 this.originMode
= true;
3924 this.wraparoundMode
= true;
3927 // this.cursorBlink = true;
3930 this.log('Serial port requested application keypad.');
3931 this.applicationKeypad
= true;
3933 case 9: // X10 Mouse
3934 // no release, no motion, no wheel, no modifiers.
3935 case 1000: // vt200 mouse
3937 // no modifiers, except control on the wheel.
3938 case 1002: // button event mouse
3939 case 1003: // any event mouse
3940 // any event - sends motion events,
3941 // even if there is no button held down.
3942 this.x10Mouse
= params
=== 9;
3943 this.vt200Mouse
= params
=== 1000;
3944 this.normalMouse
= params
> 1000;
3945 this.mouseEvents
= true;
3946 this.element
.style
.cursor
= 'default';
3947 this.log('Binding to mouse events.');
3949 case 1004: // send focusin/focusout events
3952 this.sendFocus
= true;
3954 case 1005: // utf8 ext mode mouse
3955 this.utfMouse
= true;
3956 // for wide terminals
3957 // simply encodes large values as utf8 characters
3959 case 1006: // sgr ext mode mouse
3960 this.sgrMouse
= true;
3961 // for wide terminals
3962 // does not add 32 to fields
3963 // press: ^[[<b;x;yM
3964 // release: ^[[<b;x;ym
3966 case 1015: // urxvt ext mode mouse
3967 this.urxvtMouse
= true;
3968 // for wide terminals
3969 // numbers for fields
3971 // motion: ^[[b;x;yT
3973 case 25: // show cursor
3974 this.cursorHidden
= false;
3976 case 1049: // alt screen buffer cursor
3977 //this.saveCursor();
3979 case 47: // alt screen buffer
3980 case 1047: // alt screen buffer
3988 scrollTop
: this.scrollTop
,
3989 scrollBottom
: this.scrollBottom
,
3991 // XXX save charset(s) here?
3992 // charset: this.charset,
3993 // glevel: this.glevel,
3994 // charsets: this.charsets
3997 this.normal
= normal
;
4005 // CSI Pm l Reset Mode (RM).
4006 // Ps = 2 -> Keyboard Action Mode (AM).
4007 // Ps = 4 -> Replace Mode (IRM).
4008 // Ps = 1 2 -> Send/receive (SRM).
4009 // Ps = 2 0 -> Normal Linefeed (LNM).
4011 // DEC Private Mode Reset (DECRST).
4012 // Ps = 1 -> Normal Cursor Keys (DECCKM).
4013 // Ps = 2 -> Designate VT52 mode (DECANM).
4014 // Ps = 3 -> 80 Column Mode (DECCOLM).
4015 // Ps = 4 -> Jump (Fast) Scroll (DECSCLM).
4016 // Ps = 5 -> Normal Video (DECSCNM).
4017 // Ps = 6 -> Normal Cursor Mode (DECOM).
4018 // Ps = 7 -> No Wraparound Mode (DECAWM).
4019 // Ps = 8 -> No Auto-repeat Keys (DECARM).
4020 // Ps = 9 -> Don't send Mouse X & Y on button press.
4021 // Ps = 1 0 -> Hide toolbar (rxvt).
4022 // Ps = 1 2 -> Stop Blinking Cursor (att610).
4023 // Ps = 1 8 -> Don't print form feed (DECPFF).
4024 // Ps = 1 9 -> Limit print to scrolling region (DECPEX).
4025 // Ps = 2 5 -> Hide Cursor (DECTCEM).
4026 // Ps = 3 0 -> Don't show scrollbar (rxvt).
4027 // Ps = 3 5 -> Disable font-shifting functions (rxvt).
4028 // Ps = 4 0 -> Disallow 80 -> 132 Mode.
4029 // Ps = 4 1 -> No more(1) fix (see curses resource).
4030 // Ps = 4 2 -> Disable Nation Replacement Character sets (DEC-
4032 // Ps = 4 4 -> Turn Off Margin Bell.
4033 // Ps = 4 5 -> No Reverse-wraparound Mode.
4034 // Ps = 4 6 -> Stop Logging. (This is normally disabled by a
4035 // compile-time option).
4036 // Ps = 4 7 -> Use Normal Screen Buffer.
4037 // Ps = 6 6 -> Numeric keypad (DECNKM).
4038 // Ps = 6 7 -> Backarrow key sends delete (DECBKM).
4039 // Ps = 1 0 0 0 -> Don't send Mouse X & Y on button press and
4040 // release. See the section Mouse Tracking.
4041 // Ps = 1 0 0 1 -> Don't use Hilite Mouse Tracking.
4042 // Ps = 1 0 0 2 -> Don't use Cell Motion Mouse Tracking.
4043 // Ps = 1 0 0 3 -> Don't use All Motion Mouse Tracking.
4044 // Ps = 1 0 0 4 -> Don't send FocusIn/FocusOut events.
4045 // Ps = 1 0 0 5 -> Disable Extended Mouse Mode.
4046 // Ps = 1 0 1 0 -> Don't scroll to bottom on tty output
4048 // Ps = 1 0 1 1 -> Don't scroll to bottom on key press (rxvt).
4049 // Ps = 1 0 3 4 -> Don't interpret "meta" key. (This disables
4050 // the eightBitInput resource).
4051 // Ps = 1 0 3 5 -> Disable special modifiers for Alt and Num-
4052 // Lock keys. (This disables the numLock resource).
4053 // Ps = 1 0 3 6 -> Don't send ESC when Meta modifies a key.
4054 // (This disables the metaSendsEscape resource).
4055 // Ps = 1 0 3 7 -> Send VT220 Remove from the editing-keypad
4057 // Ps = 1 0 3 9 -> Don't send ESC when Alt modifies a key.
4058 // (This disables the altSendsEscape resource).
4059 // Ps = 1 0 4 0 -> Do not keep selection when not highlighted.
4060 // (This disables the keepSelection resource).
4061 // Ps = 1 0 4 1 -> Use the PRIMARY selection. (This disables
4062 // the selectToClipboard resource).
4063 // Ps = 1 0 4 2 -> Disable Urgency window manager hint when
4064 // Control-G is received. (This disables the bellIsUrgent
4066 // Ps = 1 0 4 3 -> Disable raising of the window when Control-
4067 // G is received. (This disables the popOnBell resource).
4068 // Ps = 1 0 4 7 -> Use Normal Screen Buffer, clearing screen
4069 // first if in the Alternate Screen. (This may be disabled by
4070 // the titeInhibit resource).
4071 // Ps = 1 0 4 8 -> Restore cursor as in DECRC. (This may be
4072 // disabled by the titeInhibit resource).
4073 // Ps = 1 0 4 9 -> Use Normal Screen Buffer and restore cursor
4074 // as in DECRC. (This may be disabled by the titeInhibit
4075 // resource). This combines the effects of the 1 0 4 7 and 1 0
4076 // 4 8 modes. Use this with terminfo-based applications rather
4077 // than the 4 7 mode.
4078 // Ps = 1 0 5 0 -> Reset terminfo/termcap function-key mode.
4079 // Ps = 1 0 5 1 -> Reset Sun function-key mode.
4080 // Ps = 1 0 5 2 -> Reset HP function-key mode.
4081 // Ps = 1 0 5 3 -> Reset SCO function-key mode.
4082 // Ps = 1 0 6 0 -> Reset legacy keyboard emulation (X11R6).
4083 // Ps = 1 0 6 1 -> Reset keyboard emulation to Sun/PC style.
4084 // Ps = 2 0 0 4 -> Reset bracketed paste mode.
4085 Terminal
.prototype.resetMode = function(params
) {
4086 if (typeof params
=== 'object') {
4087 var l
= params
.length
4090 for (; i
< l
; i
++) {
4091 this.resetMode(params
[i
]);
4100 this.insertMode
= false;
4103 //this.convertEol = false;
4106 } else if (this.prefix
=== '?') {
4109 this.applicationCursor
= false;
4112 if (this.cols
=== 132 && this.savedCols
) {
4113 this.resize(this.savedCols
, this.rows
);
4115 delete this.savedCols
;
4118 this.originMode
= false;
4121 this.wraparoundMode
= false;
4124 // this.cursorBlink = false;
4127 this.log('Switching back to normal keypad.');
4128 this.applicationKeypad
= false;
4130 case 9: // X10 Mouse
4131 case 1000: // vt200 mouse
4132 case 1002: // button event mouse
4133 case 1003: // any event mouse
4134 this.x10Mouse
= false;
4135 this.vt200Mouse
= false;
4136 this.normalMouse
= false;
4137 this.mouseEvents
= false;
4138 this.element
.style
.cursor
= '';
4140 case 1004: // send focusin/focusout events
4141 this.sendFocus
= false;
4143 case 1005: // utf8 ext mode mouse
4144 this.utfMouse
= false;
4146 case 1006: // sgr ext mode mouse
4147 this.sgrMouse
= false;
4149 case 1015: // urxvt ext mode mouse
4150 this.urxvtMouse
= false;
4152 case 25: // hide cursor
4153 this.cursorHidden
= true;
4155 case 1049: // alt screen buffer cursor
4157 case 47: // normal screen buffer
4158 case 1047: // normal screen buffer - clearing it first
4160 this.lines
= this.normal
.lines
;
4161 this.ybase
= this.normal
.ybase
;
4162 this.ydisp
= this.normal
.ydisp
;
4163 this.x
= this.normal
.x
;
4164 this.y
= this.normal
.y
;
4165 this.scrollTop
= this.normal
.scrollTop
;
4166 this.scrollBottom
= this.normal
.scrollBottom
;
4167 this.tabs
= this.normal
.tabs
;
4169 // if (params === 1049) {
4170 // this.x = this.savedX;
4171 // this.y = this.savedY;
4173 this.refresh(0, this.rows
- 1);
4182 // Set Scrolling Region [top;bottom] (default = full size of win-
4185 Terminal
.prototype.setScrollRegion = function(params
) {
4186 if (this.prefix
) return;
4187 this.scrollTop
= (params
[0] || 1) - 1;
4188 this.scrollBottom
= (params
[1] || this.rows
) - 1;
4194 // Save cursor (ANSI.SYS).
4195 Terminal
.prototype.saveCursor = function(params
) {
4196 this.savedX
= this.x
;
4197 this.savedY
= this.y
;
4201 // Restore cursor (ANSI.SYS).
4202 Terminal
.prototype.restoreCursor = function(params
) {
4203 this.x
= this.savedX
|| 0;
4204 this.y
= this.savedY
|| 0;
4212 // Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
4213 Terminal
.prototype.cursorForwardTab = function(params
) {
4214 var param
= params
[0] || 1;
4216 this.x
= this.nextStop();
4220 // CSI Ps S Scroll up Ps lines (default = 1) (SU).
4221 Terminal
.prototype.scrollUp = function(params
) {
4222 var param
= params
[0] || 1;
4224 this.lines
.splice(this.ybase
+ this.scrollTop
, 1);
4225 this.lines
.splice(this.ybase
+ this.scrollBottom
, 0, this.blankLine());
4228 this.updateRange(this.scrollTop
);
4229 this.updateRange(this.scrollBottom
);
4232 // CSI Ps T Scroll down Ps lines (default = 1) (SD).
4233 Terminal
.prototype.scrollDown = function(params
) {
4234 var param
= params
[0] || 1;
4236 this.lines
.splice(this.ybase
+ this.scrollBottom
, 1);
4237 this.lines
.splice(this.ybase
+ this.scrollTop
, 0, this.blankLine());
4240 this.updateRange(this.scrollTop
);
4241 this.updateRange(this.scrollBottom
);
4244 // CSI Ps ; Ps ; Ps ; Ps ; Ps T
4245 // Initiate highlight mouse tracking. Parameters are
4246 // [func;startx;starty;firstrow;lastrow]. See the section Mouse
4248 Terminal
.prototype.initMouseTracking = function(params
) {
4249 // Relevant: DECSET 1001
4253 // Reset one or more features of the title modes to the default
4254 // value. Normally, "reset" disables the feature. It is possi-
4255 // ble to disable the ability to reset features by compiling a
4256 // different default for the title modes into xterm.
4257 // Ps = 0 -> Do not set window/icon labels using hexadecimal.
4258 // Ps = 1 -> Do not query window/icon labels using hexadeci-
4260 // Ps = 2 -> Do not set window/icon labels using UTF-8.
4261 // Ps = 3 -> Do not query window/icon labels using UTF-8.
4262 // (See discussion of "Title Modes").
4263 Terminal
.prototype.resetTitleModes = function(params
) {
4267 // CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
4268 Terminal
.prototype.cursorBackwardTab = function(params
) {
4269 var param
= params
[0] || 1;
4271 this.x
= this.prevStop();
4275 // CSI Ps b Repeat the preceding graphic character Ps times (REP).
4276 Terminal
.prototype.repeatPrecedingCharacter = function(params
) {
4277 var param
= params
[0] || 1
4278 , line
= this.lines
[this.ybase
+ this.y
]
4279 , ch
= line
[this.x
- 1] || [this.defAttr
, ' ', 1];
4281 while (param
--) line
[this.x
++] = ch
;
4284 // CSI Ps g Tab Clear (TBC).
4285 // Ps = 0 -> Clear Current Column (default).
4286 // Ps = 3 -> Clear All.
4288 // Ps = 2 -> Clear Stops on Line.
4289 // http://vt100.net/annarbor/aaa-ug/section6.html
4290 Terminal
.prototype.tabClear = function(params
) {
4291 var param
= params
[0];
4293 delete this.tabs
[this.x
];
4294 } else if (param
=== 3) {
4299 // CSI Pm i Media Copy (MC).
4300 // Ps = 0 -> Print screen (default).
4301 // Ps = 4 -> Turn off printer controller mode.
4302 // Ps = 5 -> Turn on printer controller mode.
4304 // Media Copy (MC, DEC-specific).
4305 // Ps = 1 -> Print line containing cursor.
4306 // Ps = 4 -> Turn off autoprint mode.
4307 // Ps = 5 -> Turn on autoprint mode.
4308 // Ps = 1 0 -> Print composed display, ignores DECPEX.
4309 // Ps = 1 1 -> Print all pages.
4310 Terminal
.prototype.mediaCopy = function(params
) {
4315 // Set or reset resource-values used by xterm to decide whether
4316 // to construct escape sequences holding information about the
4317 // modifiers pressed with a given key. The first parameter iden-
4318 // tifies the resource to set/reset. The second parameter is the
4319 // value to assign to the resource. If the second parameter is
4320 // omitted, the resource is reset to its initial value.
4321 // Ps = 1 -> modifyCursorKeys.
4322 // Ps = 2 -> modifyFunctionKeys.
4323 // Ps = 4 -> modifyOtherKeys.
4324 // If no parameters are given, all resources are reset to their
4326 Terminal
.prototype.setResources = function(params
) {
4331 // Disable modifiers which may be enabled via the CSI > Ps; Ps m
4332 // sequence. This corresponds to a resource value of "-1", which
4333 // cannot be set with the other sequence. The parameter identi-
4334 // fies the resource to be disabled:
4335 // Ps = 1 -> modifyCursorKeys.
4336 // Ps = 2 -> modifyFunctionKeys.
4337 // Ps = 4 -> modifyOtherKeys.
4338 // If the parameter is omitted, modifyFunctionKeys is disabled.
4339 // When modifyFunctionKeys is disabled, xterm uses the modifier
4340 // keys to make an extended sequence of functions rather than
4341 // adding a parameter to each function key to denote the modi-
4343 Terminal
.prototype.disableModifiers = function(params
) {
4348 // Set resource value pointerMode. This is used by xterm to
4349 // decide whether to hide the pointer cursor as the user types.
4350 // Valid values for the parameter:
4351 // Ps = 0 -> never hide the pointer.
4352 // Ps = 1 -> hide if the mouse tracking mode is not enabled.
4353 // Ps = 2 -> always hide the pointer. If no parameter is
4354 // given, xterm uses the default, which is 1 .
4355 Terminal
.prototype.setPointerMode = function(params
) {
4359 // CSI ! p Soft terminal reset (DECSTR).
4360 // http://vt100.net/docs/vt220-rm/table4-10.html
4361 Terminal
.prototype.softReset = function(params
) {
4362 this.cursorHidden
= false;
4363 this.insertMode
= false;
4364 this.originMode
= false;
4365 this.wraparoundMode
= false; // autowrap
4366 this.applicationKeypad
= false; // ?
4367 this.applicationCursor
= false;
4369 this.scrollBottom
= this.rows
- 1;
4370 this.curAttr
= this.defAttr
;
4371 this.x
= this.y
= 0; // ?
4372 this.charset
= null;
4373 this.glevel
= 0; // ??
4374 this.charsets
= [null]; // ??
4378 // Request ANSI mode (DECRQM). For VT300 and up, reply is
4380 // where Ps is the mode number as in RM, and Pm is the mode
4382 // 0 - not recognized
4385 // 3 - permanently set
4386 // 4 - permanently reset
4387 Terminal
.prototype.requestAnsiMode = function(params
) {
4392 // Request DEC private mode (DECRQM). For VT300 and up, reply is
4394 // where Ps is the mode number as in DECSET, Pm is the mode value
4395 // as in the ANSI DECRQM.
4396 Terminal
.prototype.requestPrivateMode = function(params
) {
4401 // Set conformance level (DECSCL). Valid values for the first
4403 // Ps = 6 1 -> VT100.
4404 // Ps = 6 2 -> VT200.
4405 // Ps = 6 3 -> VT300.
4406 // Valid values for the second parameter:
4407 // Ps = 0 -> 8-bit controls.
4408 // Ps = 1 -> 7-bit controls (always set for VT100).
4409 // Ps = 2 -> 8-bit controls.
4410 Terminal
.prototype.setConformanceLevel = function(params
) {
4414 // CSI Ps q Load LEDs (DECLL).
4415 // Ps = 0 -> Clear all LEDS (default).
4416 // Ps = 1 -> Light Num Lock.
4417 // Ps = 2 -> Light Caps Lock.
4418 // Ps = 3 -> Light Scroll Lock.
4419 // Ps = 2 1 -> Extinguish Num Lock.
4420 // Ps = 2 2 -> Extinguish Caps Lock.
4421 // Ps = 2 3 -> Extinguish Scroll Lock.
4422 Terminal
.prototype.loadLEDs = function(params
) {
4427 // Set cursor style (DECSCUSR, VT520).
4428 // Ps = 0 -> blinking block.
4429 // Ps = 1 -> blinking block (default).
4430 // Ps = 2 -> steady block.
4431 // Ps = 3 -> blinking underline.
4432 // Ps = 4 -> steady underline.
4433 Terminal
.prototype.setCursorStyle = function(params
) {
4438 // Select character protection attribute (DECSCA). Valid values
4439 // for the parameter:
4440 // Ps = 0 -> DECSED and DECSEL can erase (default).
4441 // Ps = 1 -> DECSED and DECSEL cannot erase.
4442 // Ps = 2 -> DECSED and DECSEL can erase.
4443 Terminal
.prototype.setCharProtectionAttr = function(params
) {
4448 // Restore DEC Private Mode Values. The value of Ps previously
4449 // saved is restored. Ps values are the same as for DECSET.
4450 Terminal
.prototype.restorePrivateValues = function(params
) {
4454 // CSI Pt; Pl; Pb; Pr; Ps$ r
4455 // Change Attributes in Rectangular Area (DECCARA), VT400 and up.
4456 // Pt; Pl; Pb; Pr denotes the rectangle.
4457 // Ps denotes the SGR attributes to change: 0, 1, 4, 5, 7.
4458 // NOTE: xterm doesn't enable this code by default.
4459 Terminal
.prototype.setAttrInRectangle = function(params
) {
4469 for (; t
< b
+ 1; t
++) {
4470 line
= this.lines
[this.ybase
+ t
];
4471 for (i
= l
; i
< r
; i
++) {
4472 line
[i
] = [attr
, line
[i
][1]];
4477 this.updateRange(params
[0]);
4478 this.updateRange(params
[2]);
4482 // CSI Pc; Pt; Pl; Pb; Pr$ x
4483 // Fill Rectangular Area (DECFRA), VT420 and up.
4484 // Pc is the character to use.
4485 // Pt; Pl; Pb; Pr denotes the rectangle.
4486 // NOTE: xterm doesn't enable this code by default.
4487 Terminal
.prototype.fillRectangle = function(params
) {
4497 for (; t
< b
+ 1; t
++) {
4498 line
= this.lines
[this.ybase
+ t
];
4499 for (i
= l
; i
< r
; i
++) {
4500 line
[i
] = [line
[i
][0], String
.fromCharCode(ch
)];
4505 this.updateRange(params
[1]);
4506 this.updateRange(params
[3]);
4510 // Enable Locator Reporting (DECELR).
4511 // Valid values for the first parameter:
4512 // Ps = 0 -> Locator disabled (default).
4513 // Ps = 1 -> Locator enabled.
4514 // Ps = 2 -> Locator enabled for one report, then disabled.
4515 // The second parameter specifies the coordinate unit for locator
4517 // Valid values for the second parameter:
4518 // Pu = 0 <- or omitted -> default to character cells.
4519 // Pu = 1 <- device physical pixels.
4520 // Pu = 2 <- character cells.
4521 Terminal
.prototype.enableLocatorReporting = function(params
) {
4522 var val
= params
[0] > 0;
4523 //this.mouseEvents = val;
4524 //this.decLocator = val;
4527 // CSI Pt; Pl; Pb; Pr$ z
4528 // Erase Rectangular Area (DECERA), VT400 and up.
4529 // Pt; Pl; Pb; Pr denotes the rectangle.
4530 // NOTE: xterm doesn't enable this code by default.
4531 Terminal
.prototype.eraseRectangle = function(params
) {
4541 ch
= [this.eraseAttr(), ' ', 1]; // xterm?
4543 for (; t
< b
+ 1; t
++) {
4544 line
= this.lines
[this.ybase
+ t
];
4545 for (i
= l
; i
< r
; i
++) {
4551 this.updateRange(params
[0]);
4552 this.updateRange(params
[2]);
4557 // Insert P s Column(s) (default = 1) (DECIC), VT420 and up.
4558 // NOTE: xterm doesn't enable this code by default.
4559 Terminal
.prototype.insertColumns = function() {
4560 var param
= params
[0]
4561 , l
= this.ybase
+ this.rows
4562 , ch
= [this.eraseAttr(), ' ', 1] // xterm?
4566 for (i
= this.ybase
; i
< l
; i
++) {
4567 this.lines
[i
].splice(this.x
+ 1, 0, ch
);
4568 this.lines
[i
].pop();
4577 // Delete P s Column(s) (default = 1) (DECDC), VT420 and up
4578 // NOTE: xterm doesn't enable this code by default.
4579 Terminal
.prototype.deleteColumns = function() {
4580 var param
= params
[0]
4581 , l
= this.ybase
+ this.rows
4582 , ch
= [this.eraseAttr(), ' ', 1] // xterm?
4586 for (i
= this.ybase
; i
< l
; i
++) {
4587 this.lines
[i
].splice(this.x
, 1);
4588 this.lines
[i
].push(ch
);
4599 Terminal
.charsets
= {};
4601 // DEC Special Character and Line Drawing Set.
4602 // http://vt100.net/docs/vt102-ug/table5-13.html
4603 // A lot of curses apps use this if they see TERM=xterm.
4604 // testing: echo -e '\e(0a\e(B'
4605 // The xterm output sometimes seems to conflict with the
4606 // reference above. xterm seems in line with the reference
4607 // when running vttest however.
4608 // The table below now uses xterm's output from vttest.
4609 Terminal
.charsets
.SCLD
= { // (0
4610 '`': '\u25c6', // '◆'
4611 'a': '\u2592', // '▒'
4612 'b': '\u0009', // '\t'
4613 'c': '\u000c', // '\f'
4614 'd': '\u000d', // '\r'
4615 'e': '\u000a', // '\n'
4616 'f': '\u00b0', // '°'
4617 'g': '\u00b1', // '±'
4618 'h': '\u2424', // '\u2424' (NL)
4619 'i': '\u000b', // '\v'
4620 'j': '\u2518', // '┘'
4621 'k': '\u2510', // '┐'
4622 'l': '\u250c', // '┌'
4623 'm': '\u2514', // '└'
4624 'n': '\u253c', // '┼'
4625 'o': '\u23ba', // '⎺'
4626 'p': '\u23bb', // '⎻'
4627 'q': '\u2500', // '─'
4628 'r': '\u23bc', // '⎼'
4629 's': '\u23bd', // '⎽'
4630 't': '\u251c', // '├'
4631 'u': '\u2524', // '┤'
4632 'v': '\u2534', // '┴'
4633 'w': '\u252c', // '┬'
4634 'x': '\u2502', // '│'
4635 'y': '\u2264', // '≤'
4636 'z': '\u2265', // '≥'
4637 '{': '\u03c0', // 'π'
4638 '|': '\u2260', // '≠'
4639 '}': '\u00a3', // '£'
4640 '~': '\u00b7' // '·'
4643 Terminal
.charsets
.UK
= null; // (A
4644 Terminal
.charsets
.US
= null; // (B (USASCII)
4645 Terminal
.charsets
.Dutch
= null; // (4
4646 Terminal
.charsets
.Finnish
= null; // (C or (5
4647 Terminal
.charsets
.French
= null; // (R
4648 Terminal
.charsets
.FrenchCanadian
= null; // (Q
4649 Terminal
.charsets
.German
= null; // (K
4650 Terminal
.charsets
.Italian
= null; // (Y
4651 Terminal
.charsets
.NorwegianDanish
= null; // (E or (6
4652 Terminal
.charsets
.Spanish
= null; // (Z
4653 Terminal
.charsets
.Swedish
= null; // (H or (7
4654 Terminal
.charsets
.Swiss
= null; // (=
4655 Terminal
.charsets
.ISOLatin
= null; // /A
4661 function contains(el
, arr
) {
4662 for (var i
= 0; i
< arr
.length
; i
+= 1) {
4663 if (el
=== arr
[i
]) {
4670 function on(el
, type
, handler
, capture
) {
4671 if (!Array
.isArray(el
)) {
4674 el
.forEach(function (element
) {
4675 element
.addEventListener(type
, handler
, capture
|| false);
4679 function off(el
, type
, handler
, capture
) {
4680 el
.removeEventListener(type
, handler
, capture
|| false);
4683 function cancel(ev
, force
) {
4684 if (!this.cancelEvents
&& !force
) {
4687 ev
.preventDefault();
4688 ev
.stopPropagation();
4692 function inherits(child
, parent
) {
4694 this.constructor = child
;
4696 f
.prototype = parent
.prototype;
4697 child
.prototype = new f
;
4700 // if bold is broken, we can't
4701 // use it in the terminal.
4702 function isBoldBroken(document
) {
4703 var body
= document
.getElementsByTagName('body')[0];
4704 var el
= document
.createElement('span');
4705 el
.innerHTML
= 'hello world';
4706 body
.appendChild(el
);
4707 var w1
= el
.scrollWidth
;
4708 el
.style
.fontWeight
= 'bold';
4709 var w2
= el
.scrollWidth
;
4710 body
.removeChild(el
);
4714 var String
= this.String
;
4715 var setTimeout
= this.setTimeout
;
4716 var setInterval
= this.setInterval
;
4718 function indexOf(obj
, el
) {
4721 if (obj
[i
] === el
) return i
;
4726 function isThirdLevelShift(term
, ev
) {
4728 (term
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) ||
4729 (term
.isMSWindows
&& ev
.altKey
&& ev
.ctrlKey
&& !ev
.metaKey
);
4731 // Don't invoke for arrows, pageDown, home, backspace, etc.
4732 return thirdLevelKey
&& (!ev
.keyCode
|| ev
.keyCode
> 47);
4735 function matchColor(r1
, g1
, b1
) {
4736 var hash
= (r1
<< 16) | (g1
<< 8) | b1
;
4738 if (matchColor
._cache
[hash
] != null) {
4739 return matchColor
._cache
[hash
];
4742 var ldiff
= Infinity
4751 for (; i
< Terminal
.vcolors
.length
; i
++) {
4752 c
= Terminal
.vcolors
[i
];
4757 diff
= matchColor
.distance(r1
, g1
, b1
, r2
, g2
, b2
);
4770 return matchColor
._cache
[hash
] = li
;
4773 matchColor
._cache
= {};
4775 // http://stackoverflow.com/questions/1633828
4776 matchColor
.distance = function(r1
, g1
, b1
, r2
, g2
, b2
) {
4777 return Math
.pow(30 * (r1
- r2
), 2)
4778 + Math
.pow(59 * (g1
- g2
), 2)
4779 + Math
.pow(11 * (b1
- b2
), 2);
4782 function each(obj
, iter
, con
) {
4783 if (obj
.forEach
) return obj
.forEach(iter
, con
);
4784 for (var i
= 0; i
< obj
.length
; i
++) {
4785 iter
.call(con
, obj
[i
], i
, obj
);
4789 function keys(obj
) {
4790 if (Object
.keys
) return Object
.keys(obj
);
4793 if (Object
.prototype.hasOwnProperty
.call(obj
, key
)) {
4800 var wcwidth
= (function(opts
) {
4801 // extracted from https://www.cl.cam.ac.uk/%7Emgk25/ucs/wcwidth.c
4802 // combining characters
4804 [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
4805 [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
4806 [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
4807 [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670],
4808 [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED],
4809 [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A],
4810 [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902],
4811 [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D],
4812 [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981],
4813 [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD],
4814 [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C],
4815 [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D],
4816 [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC],
4817 [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD],
4818 [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C],
4819 [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D],
4820 [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0],
4821 [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48],
4822 [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC],
4823 [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD],
4824 [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D],
4825 [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6],
4826 [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E],
4827 [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC],
4828 [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35],
4829 [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E],
4830 [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97],
4831 [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030],
4832 [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039],
4833 [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F],
4834 [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753],
4835 [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD],
4836 [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD],
4837 [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922],
4838 [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B],
4839 [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34],
4840 [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42],
4841 [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF],
4842 [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063],
4843 [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F],
4844 [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B],
4845 [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F],
4846 [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB],
4847 [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F],
4848 [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169],
4849 [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD],
4850 [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F],
4854 function bisearch(ucs
) {
4856 var max
= COMBINING
.length
- 1;
4858 if (ucs
< COMBINING
[0][0] || ucs
> COMBINING
[max
][1])
4860 while (max
>= min
) {
4861 mid
= Math
.floor((min
+ max
) / 2);
4862 if (ucs
> COMBINING
[mid
][1])
4864 else if (ucs
< COMBINING
[mid
][0])
4871 function wcwidth(ucs
) {
4872 // test for 8-bit control characters
4875 if (ucs
< 32 || (ucs
>= 0x7f && ucs
< 0xa0))
4876 return opts
.control
;
4877 // binary search in table of non-spacing characters
4880 // if we arrive here, ucs is not a combining or C0/C1 control character
4885 ucs
<= 0x115f || // Hangul Jamo init. consonants
4888 (ucs
>= 0x2e80 && ucs
<= 0xa4cf && ucs
!= 0x303f) || // CJK..Yi
4889 (ucs
>= 0xac00 && ucs
<= 0xd7a3) || // Hangul Syllables
4890 (ucs
>= 0xf900 && ucs
<= 0xfaff) || // CJK Compat Ideographs
4891 (ucs
>= 0xfe10 && ucs
<= 0xfe19) || // Vertical forms
4892 (ucs
>= 0xfe30 && ucs
<= 0xfe6f) || // CJK Compat Forms
4893 (ucs
>= 0xff00 && ucs
<= 0xff60) || // Fullwidth Forms
4894 (ucs
>= 0xffe0 && ucs
<= 0xffe6) ||
4895 (ucs
>= 0x20000 && ucs
<= 0x2fffd) ||
4896 (ucs
>= 0x30000 && ucs
<= 0x3fffd)
4901 })({nul
: 0, control
: 0}); // configurable options
4907 Terminal
.EventEmitter
= EventEmitter
;
4908 Terminal
.inherits
= inherits
;
4911 * Adds an event listener to the terminal.
4913 * @param {string} event The name of the event. TODO: Document all event types
4914 * @param {function} callback The function to call when the event is triggered.
4918 Terminal
.cancel
= cancel
;