]>
git.proxmox.com Git - mirror_xterm.js.git/blob - src/xterm.js
2 * xterm.js: xterm, in the browser
3 * Copyright (c) 2014, sourceLair Limited (www.sourcelair.com (MIT License)
4 * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
5 * https://github.com/chjj/term.js
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 * Originally forked from (with the author's permission):
26 * Fabrice Bellard's javascript vt100 for jslinux:
27 * http://bellard.org/jslinux/
28 * Copyright (c) 2011 Fabrice Bellard
29 * The original design remains. The terminal itself
30 * has been extended to include xterm CSI codes, among
35 if (typeof exports
=== 'object' && typeof module
=== 'object') {
37 * CommonJS environment
39 module
.exports
= xterm
.call(this);
40 } else if (typeof define
== 'function') {
42 * Require.js is available
44 define([], xterm
.bind(window
));
47 * Plain browser environment
49 this.Xterm
= xterm
.call(this);
50 this.Terminal
= this.Xterm
; /* Backwards compatibility with term.js */
54 * Terminal Emulation References:
56 * http://invisible-island.net/xterm/ctlseqs/ctlseqs.txt
57 * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
58 * http://invisible-island.net/vttest/
59 * http://www.inwap.com/pdp10/ansicode.txt
60 * http://linux.die.net/man/4/console_codes
61 * http://linux.die.net/man/7/urxvt
70 var window
= this, document
= this.document
;
76 function EventEmitter() {
77 this._events
= this._events
|| {};
80 EventEmitter
.prototype.addListener = function(type
, listener
) {
81 this._events
[type
] = this._events
[type
] || [];
82 this._events
[type
].push(listener
);
85 EventEmitter
.prototype.on
= EventEmitter
.prototype.addListener
;
87 EventEmitter
.prototype.removeListener = function(type
, listener
) {
88 if (!this._events
[type
]) return;
90 var obj
= this._events
[type
]
94 if (obj
[i
] === listener
|| obj
[i
].listener
=== listener
) {
101 EventEmitter
.prototype.off
= EventEmitter
.prototype.removeListener
;
103 EventEmitter
.prototype.removeAllListeners = function(type
) {
104 if (this._events
[type
]) delete this._events
[type
];
107 EventEmitter
.prototype.once = function(type
, listener
) {
110 var args
= Array
.prototype.slice
.call(arguments
);
111 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
);
320 * back_color_erase feature for xterm.
322 Terminal
.prototype.eraseAttr = function() {
323 // if (this.is('screen')) return this.defAttr;
324 return (this.defAttr
& ~0x1ff) | (this.curAttr
& 0x1ff);
332 Terminal
.tangoColors
= [
353 // Colors 0-15 + 16-255
354 // Much thanks to TooTallNate for writing this.
355 Terminal
.colors
= (function() {
356 var colors
= Terminal
.tangoColors
.slice()
357 , r
= [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff]
362 for (; i
< 216; i
++) {
363 out(r
[(i
/ 36) % 6 | 0], r
[(i
/ 6) % 6 | 0], r
[i
% 6]);
368 for (; i
< 24; i
++) {
373 function out(r
, g
, b
) {
374 colors
.push('#' + hex(r
) + hex(g
) + hex(b
));
379 return c
.length
< 2 ? '0' + c
: c
;
385 Terminal
._colors
= Terminal
.colors
.slice();
387 Terminal
.vcolors
= (function() {
389 , colors
= Terminal
.colors
393 for (; i
< 256; i
++) {
394 color
= parseInt(colors
[i
].substring(1), 16);
396 (color
>> 16) & 0xff,
409 Terminal
.defaults
= {
410 colors
: Terminal
.colors
,
422 // programFeatures: false,
426 Terminal
.options
= {};
428 Terminal
.focus
= null;
430 each(keys(Terminal
.defaults
), function(key
) {
431 Terminal
[key
] = Terminal
.defaults
[key
];
432 Terminal
.options
[key
] = Terminal
.defaults
[key
];
436 * Focus the terminal. Delegates focus handling to the terminal's DOM element.
438 Terminal
.prototype.focus = function() {
439 return this.element
.focus();
443 * Binds the desired focus behavior on a given terminal object.
447 Terminal
.bindFocus = function (term
) {
448 on(term
.element
, 'focus', function (ev
) {
449 if (term
.sendFocus
) {
454 Terminal
.focus
= term
;
455 term
.emit('focus', {terminal
: term
});
460 * Blur the terminal. Delegates blur handling to the terminal's DOM element.
462 Terminal
.prototype.blur = function() {
463 return this.element
.blur();
467 * Binds the desired blur behavior on a given terminal object.
471 Terminal
.bindBlur = function (term
) {
472 on(term
.element
, 'blur', function (ev
) {
473 if (term
.sendFocus
) {
476 Terminal
.focus
= null;
477 term
.emit('blur', {terminal
: term
});
482 * Initialize default behavior
484 Terminal
.prototype.initGlobal = function() {
485 Terminal
.bindKeys(this);
486 Terminal
.bindPaste(this);
487 Terminal
.bindCopy(this);
488 Terminal
.bindCut(this);
489 Terminal
.bindDrop(this);
490 Terminal
.bindFocus(this);
491 Terminal
.bindBlur(this);
495 * Clears all selected text, inside the terminal.
497 Terminal
.prototype.clearSelection = function() {
498 var selectionBaseNode
= window
.getSelection().baseNode
;
500 if (selectionBaseNode
&& (this.element
.contains(selectionBaseNode
.parentElement
))) {
501 window
.getSelection().removeAllRanges();
506 * This function temporarily enables (leases) the contentEditable value of the terminal, which
507 * should be set back to false within 5 seconds at most.
509 Terminal
.prototype.leaseContentEditable = function (ms
, callback
) {
512 term
.element
.contentEditable
= true;
515 * Blur and re-focus instantly. This is due to a weird focus state on Chrome, when setting
516 * contentEditable to true on a focused element.
521 setTimeout(function () {
522 term
.element
.contentEditable
= false;
523 if (typeof callback
== 'function') {
530 * Bind to paste event and allow both keyboard and right-click pasting, without having the
531 * contentEditable value set to true.
533 Terminal
.bindPaste = function(term
) {
534 on(term
.element
, 'paste', function(ev
) {
535 if (ev
.clipboardData
) {
536 var text
= ev
.clipboardData
.getData('text/plain');
537 term
.emit('paste', text
, ev
);
540 * Cancel the paste event, or else things will be pasted twice:
541 * 1. by the terminal handler
542 * 2. by the browser, because of the contentEditable value being true
544 term
.cancel(ev
, true);
547 * After the paste event is completed, always set the contentEditable value to false.
549 term
.element
.contentEditable
= false;
554 * Hack pasting with keyboard, in order to make it work without contentEditable.
555 * When a user types Ctrl + Shift + V or Shift + Insert on a non Mac or Cmd + V on a Mac,
556 * lease the contentEditable value as true.
558 on(term
.element
, 'keydown', function (ev
) {
559 var isEditable
= term
.element
.contentEditable
=== "true";
562 * If on a Mac, lease the contentEditable value temporarily, when the user presses
563 * the Cmd button, in a keydown event order to paste frictionlessly.
565 if (term
.isMac
&& ev
.metaKey
&& !isEditable
) {
566 term
.leaseContentEditable(5000);
569 if (!term
.isMac
&& !isEditable
) {
570 if ((ev
.keyCode
== 45 && ev
.shiftKey
&& !ev
.ctrlKey
) || // Shift + Insert
571 (ev
.keyCode
== 86 && ev
.shiftKey
&& ev
.ctrlKey
)) { // Ctrl + Shict + V
572 term
.leaseContentEditable();
578 * Hack pasting with right-click in order to allow right-click paste, by leasing the
579 * contentEditable value as true.
581 on(term
.element
, 'contextmenu', function (ev
) {
582 term
.leaseContentEditable();
588 * Apply key handling to the terminal
590 * @param {Xterm} term The terminal on which to bind key handling
593 Terminal
.bindKeys = function(term
) {
594 on(term
.element
, 'keydown', function(ev
) {
598 on(term
.element
, 'keypress', function(ev
) {
604 * Prepares text copied from terminal selection, to be saved in the clipboard by:
605 * 1. stripping all trailing white spaces
606 * 2. converting all non-breaking spaces to regular spaces
607 * @param {string} text The copied text that needs processing for storing in clipboard
611 Terminal
.prepareCopiedTextForClipboard = function (text
) {
612 var space
= String
.fromCharCode(32),
613 nonBreakingSpace
= String
.fromCharCode(160),
614 allNonBreakingSpaces
= new RegExp(nonBreakingSpace
, 'g'),
615 processedText
= text
.split('\n').map(function (line
) {
617 * Strip all trailing white spaces and convert all non-breaking spaces to regular
620 var processedLine
= line
.replace(/\s+$/g, '').replace(allNonBreakingSpaces
, space
);
622 return processedLine
;
625 return processedText
;
629 * Binds copy functionality to the given terminal.
632 Terminal
.bindCopy = function(term
) {
633 on(term
.element
, 'copy', function(ev
) {
634 var copiedText
= window
.getSelection().toString(),
635 text
= Terminal
.prepareCopiedTextForClipboard(copiedText
);
637 ev
.clipboardData
.setData('text/plain', text
);
643 * Cancel the cut event completely.
644 * @param {Xterm} term The terminal on which to bind the cut event handling functionality.
647 Terminal
.bindCut = function(term
) {
648 on(term
.element
, 'cut', function (ev
) {
655 * Do not perform the "drop" event. Altering the contents of the
656 * terminal with drag n drop is unwanted behavior.
657 * @param {Xterm} term The terminal on which to bind the drop event handling functionality.
660 Terminal
.bindDrop = function (term
) {
661 on(term
.element
, 'drop', function (ev
) {
662 term
.cancel(ev
, true);
667 * Cancel click handling on the given terminal
668 * @param {Xterm} term The terminal on which to bind the click event handling functionality.
671 Terminal
.click = function (term
) {
672 on(term
.element
, 'click', function (ev
) {
673 term
.cancel(ev
, true);
679 * Insert the given row to the terminal or produce a new one
680 * if no row argument is passed. Return the inserted row.
681 * @param {HTMLElement} row (optional) The row to append to the terminal.
683 Terminal
.prototype.insertRow = function (row
) {
684 if (typeof row
!= 'object') {
685 row
= document
.createElement('div');
688 this.rowContainer
.appendChild(row
);
689 this.children
.push(row
);
696 * Opens the terminal within an element.
698 * @param {HTMLElement} parent The element to create the terminal within.
700 Terminal
.prototype.open = function(parent
) {
701 var self
=this, i
=0, div
;
703 this.parent
= parent
|| this.parent
;
706 throw new Error('Terminal requires a parent element.');
710 * Grab global elements
712 this.context
= this.parent
.ownerDocument
.defaultView
;
713 this.document
= this.parent
.ownerDocument
;
714 this.body
= this.document
.getElementsByTagName('body')[0];
719 if (this.context
.navigator
&& this.context
.navigator
.userAgent
) {
720 this.isMSIE
= !!~this.context
.navigator
.userAgent
.indexOf('MSIE');
724 * Find the users platform. We use this to interpret the meta key
725 * and ISO third level shifts.
726 * http://stackoverflow.com/questions/19877924/what-is-the-list-of-possible-values-for-navigator-platform-as-of-today
728 if (this.context
.navigator
&& this.context
.navigator
.platform
) {
729 this.isMac
= contains(
730 this.context
.navigator
.platform
,
731 ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K']
733 this.isIpad
= this.context
.navigator
.platform
=== 'iPad';
734 this.isIphone
= this.context
.navigator
.platform
=== 'iPhone';
735 this.isMSWindows
= contains(
736 this.context
.navigator
.platform
,
737 ['Windows', 'Win16', 'Win32', 'WinCE']
742 * Create main element container
744 this.element
= this.document
.createElement('div');
745 this.element
.classList
.add('terminal');
746 this.element
.classList
.add('xterm');
747 this.element
.classList
.add('xterm-theme-' + this.theme
);
748 this.element
.setAttribute('tabindex', 0);
749 this.element
.spellcheck
= false;
752 * Create the container that will hold the lines of the terminal and then
753 * produce the lines the lines.
755 this.rowContainer
= document
.createElement('div');
756 this.rowContainer
.classList
.add('xterm-rows');
757 this.element
.appendChild(this.rowContainer
);
760 for (; i
< this.rows
; i
++) {
763 this.parent
.appendChild(this.element
);
766 this.refresh(0, this.rows
- 1);
768 // Initialize global actions that
769 // need to be taken on the document.
772 // Ensure there is a Terminal.focus.
775 on(this.element
, 'mouseup', function() {
776 var selection
= document
.getSelection(),
777 collapsed
= selection
.isCollapsed
,
778 isRange
= typeof collapsed
== 'boolean' ? !collapsed
: selection
.type
== 'Range';
784 // Listen for mouse events and translate
785 // them into terminal mouse protocols.
788 // Figure out whether boldness affects
789 // the character width of monospace fonts.
790 if (Terminal
.brokenBold
== null) {
791 Terminal
.brokenBold
= isBoldBroken(this.document
);
799 * Attempts to load an add-on using CommonJS or RequireJS (whichever is available).
800 * @param {string} addon The name of the addon to load
803 Terminal
.loadAddon = function(addon
, callback
) {
804 if (typeof exports
=== 'object' && typeof module
=== 'object') {
806 return require(__dirname
+ '/../addons/' + addon
);
807 } else if (typeof define
== 'function') {
809 return require(['../addons/' + addon
+ '/' + addon
], callback
);
811 console
.error('Cannot load a module without a CommonJS or RequireJS environment.');
819 * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking
820 * To better understand these
821 * the xterm code is very helpful:
823 * button.c, charproc.c, misc.c
824 * Relevant functions in xterm/button.c:
825 * BtnCode, EmitButtonCode, EditorButton, SendMousePosition
827 Terminal
.prototype.bindMouse = function() {
828 var el
= this.element
, self
= this, pressed
= 32;
829 var wheelEvent
= ('onmousewheel' in this.context
) ? 'mousewheel' : 'DOMMouseScroll';
831 // mouseup, mousedown, mousewheel
832 // left click: ^[[M 3<^[[M#3<
833 // mousewheel up: ^[[M`3>
834 function sendButton(ev
) {
838 // get the xterm-style button
839 button
= getButton(ev
);
841 // get mouse coordinates
845 sendEvent(button
, pos
);
847 switch (ev
.overrideType
|| ev
.type
) {
852 // keep it at the left
853 // button, just in case.
864 // motion example of a left click:
865 // ^[[M 3<^[[M@4<^[[M@5<^[[M@6<^[[M@7<^[[M#7<
866 function sendMove(ev
) {
873 // buttons marked as motions
874 // are incremented by 32
877 sendEvent(button
, pos
);
881 // position to characters
882 function encode(data
, ch
) {
883 if (!self
.utfMouse
) {
884 if (ch
=== 255) return data
.push(0);
885 if (ch
> 127) ch
= 127;
888 if (ch
=== 2047) return data
.push(0);
892 if (ch
> 2047) ch
= 2047;
893 data
.push(0xC0 | (ch
>> 6));
894 data
.push(0x80 | (ch
& 0x3F));
899 // send a mouse event:
900 // regular/utf8: ^[[M Cb Cx Cy
901 // urxvt: ^[[ Cb ; Cx ; Cy M
902 // sgr: ^[[ Cb ; Cx ; Cy M/m
903 // vt300: ^[[ 24(1/3/5)~ [ Cx , Cy ] \r
904 // locator: CSI P e ; P b ; P r ; P c ; P p & w
905 function sendEvent(button
, pos
) {
906 // self.emit('mouse', {
912 if (self
.vt300Mouse
) {
914 // http://www.vt100.net/docs/vt3xx-gp/chapter15.html
918 var data
= '\x1b[24';
919 if (button
=== 0) data
+= '1';
920 else if (button
=== 1) data
+= '3';
921 else if (button
=== 2) data
+= '5';
922 else if (button
=== 3) return;
924 data
+= '~[' + pos
.x
+ ',' + pos
.y
+ ']\r';
929 if (self
.decLocator
) {
934 if (button
=== 0) button
= 2;
935 else if (button
=== 1) button
= 4;
936 else if (button
=== 2) button
= 6;
937 else if (button
=== 3) button
= 3;
941 + (button
=== 3 ? 4 : 0)
952 if (self
.urxvtMouse
) {
957 self
.send('\x1b[' + button
+ ';' + pos
.x
+ ';' + pos
.y
+ 'M');
965 + ((button
& 3) === 3 ? button
& ~3 : button
)
970 + ((button
& 3) === 3 ? 'm' : 'M'));
976 encode(data
, button
);
980 self
.send('\x1b[M' + String
.fromCharCode
.apply(String
, data
));
983 function getButton(ev
) {
996 // 1, and 2 - with 64 added
997 switch (ev
.overrideType
|| ev
.type
) {
999 button
= ev
.button
!= null
1006 button
= button
=== 1 ? 0 : button
=== 4 ? 1 : button
;
1012 case 'DOMMouseScroll':
1013 button
= ev
.detail
< 0
1018 button
= ev
.wheelDeltaY
> 0
1024 // next three bits are the modifiers:
1025 // 4 = shift, 8 = meta, 16 = control
1026 shift
= ev
.shiftKey
? 4 : 0;
1027 meta
= ev
.metaKey
? 8 : 0;
1028 ctrl
= ev
.ctrlKey
? 16 : 0;
1029 mod
= shift
| meta
| ctrl
;
1032 if (self
.vt200Mouse
) {
1035 } else if (!self
.normalMouse
) {
1040 button
= (32 + (mod
<< 2)) + button
;
1045 // mouse coordinates measured in cols/rows
1046 function getCoords(ev
) {
1049 // ignore browsers without pageX for now
1050 if (ev
.pageX
== null) return;
1056 // should probably check offsetParent
1057 // but this is more portable
1058 while (el
&& el
!== self
.document
.documentElement
) {
1061 el
= 'offsetParent' in el
1066 // convert to cols/rows
1067 w
= self
.element
.clientWidth
;
1068 h
= self
.element
.clientHeight
;
1069 x
= Math
.round((x
/ w
) * self
.cols
);
1070 y
= Math
.round((y
/ h
) * self
.rows
);
1072 // be sure to avoid sending
1073 // bad positions to the program
1075 if (x
> self
.cols
) x
= self
.cols
;
1077 if (y
> self
.rows
) y
= self
.rows
;
1079 // xterm sends raw bytes and
1080 // starts at 32 (SP) for each.
1087 type
: (ev
.overrideType
|| ev
.type
) === wheelEvent
1089 : (ev
.overrideType
|| ev
.type
)
1093 on(el
, 'mousedown', function(ev
) {
1094 if (!self
.mouseEvents
) return;
1103 //if (self.vt200Mouse && !self.normalMouse) {
1104 if (self
.vt200Mouse
) {
1105 ev
.overrideType
= 'mouseup';
1107 return self
.cancel(ev
);
1111 if (self
.normalMouse
) on(self
.document
, 'mousemove', sendMove
);
1113 // x10 compatibility mode can't send button releases
1114 if (!self
.x10Mouse
) {
1115 on(self
.document
, 'mouseup', function up(ev
) {
1117 if (self
.normalMouse
) off(self
.document
, 'mousemove', sendMove
);
1118 off(self
.document
, 'mouseup', up
);
1119 return self
.cancel(ev
);
1123 return self
.cancel(ev
);
1126 //if (self.normalMouse) {
1127 // on(self.document, 'mousemove', sendMove);
1130 on(el
, wheelEvent
, function(ev
) {
1131 if (!self
.mouseEvents
) return;
1134 || self
.decLocator
) return;
1136 return self
.cancel(ev
);
1139 // allow mousewheel scrolling in
1140 // the shell for example
1141 on(el
, wheelEvent
, function(ev
) {
1142 if (self
.mouseEvents
) return;
1143 if (self
.applicationKeypad
) return;
1144 if (ev
.type
=== 'DOMMouseScroll') {
1145 self
.scrollDisp(ev
.detail
< 0 ? -1 : 1);
1147 self
.scrollDisp(ev
.wheelDeltaY
> 0 ? -1 : 1);
1149 return self
.cancel(ev
);
1154 * Destroys the terminal.
1156 Terminal
.prototype.destroy = function() {
1157 this.readable
= false;
1158 this.writable
= false;
1160 this.handler = function() {};
1161 this.write = function() {};
1162 if (this.element
.parentNode
) {
1163 this.element
.parentNode
.removeChild(this.element
);
1165 //this.emit('close');
1170 * Flags used to render terminal text properly
1181 * Refreshes (re-renders) terminal content within two rows (inclusive)
1185 * In the screen buffer, each character is stored as a an array with a character
1186 * and a 32-bit integer:
1187 * - First value: a utf-16 character.
1189 * - Next 9 bits: background color (0-511).
1190 * - Next 9 bits: foreground color (0-511).
1191 * - Next 14 bits: a mask for misc. flags:
1198 * @param {number} start The row to start from (between 0 and terminal's height terminal - 1)
1199 * @param {number} end The row to end at (between fromRow and terminal's height terminal - 1)
1200 * @param {boolean} queue Whether the refresh should ran right now or be queued
1202 Terminal
.prototype.refresh = function(start
, end
, queue
) {
1205 // queue defaults to true
1206 queue
= (typeof queue
== 'undefined') ? true : queue
;
1209 * The refresh queue allows refresh to execute only approximately 30 times a second. For
1210 * commands that pass a significant amount of output to the write function, this prevents the
1211 * terminal from maxing out the CPU and making the UI unresponsive. While commands can still
1212 * run beyond what they do on the terminal, it is far better with a debounce in place as
1213 * every single terminal manipulation does not need to be constructed in the DOM.
1215 * A side-effect of this is that it makes ^C to interrupt a process seem more responsive.
1218 // If refresh should be queued, order the refresh and return.
1219 if (this._refreshIsQueued
) {
1220 // If a refresh has already been queued, just order a full refresh next
1221 this._fullRefreshNext
= true;
1223 setTimeout(function () {
1224 self
.refresh(start
, end
, false);
1226 this._refreshIsQueued
= true;
1231 // If refresh should be run right now (not be queued), release the lock
1232 this._refreshIsQueued
= false;
1234 // If multiple refreshes were requested, make a full refresh.
1235 if (this._fullRefreshNext
) {
1237 end
= this.rows
- 1;
1238 this._fullRefreshNext
= false // reset lock
1241 var x
, y
, i
, line
, out
, ch
, ch_width
, width
, data
, attr
, bg
, fg
, flags
, row
, parent
, focused
= document
.activeElement
;
1243 // If this is a big refresh, remove the terminal rows from the DOM for faster calculations
1244 if (end
- start
>= this.rows
/ 2) {
1245 parent
= this.element
.parentNode
;
1247 this.element
.removeChild(this.rowContainer
);
1254 if (end
>= this.rows
.length
) {
1255 this.log('`end` is too large. Most likely a bad CSR.');
1256 end
= this.rows
.length
- 1;
1259 for (; y
<= end
; y
++) {
1260 row
= y
+ this.ydisp
;
1262 line
= this.lines
[row
];
1265 if (this.y
=== y
- (this.ybase
- this.ydisp
)
1267 && !this.cursorHidden
) {
1273 attr
= this.defAttr
;
1276 for (; i
< width
; i
++) {
1279 ch_width
= line
[i
][2];
1283 if (i
=== x
) data
= -1;
1285 if (data
!== attr
) {
1286 if (attr
!== this.defAttr
) {
1289 if (data
!== this.defAttr
) {
1291 out
+= '<span class="reverse-video terminal-cursor';
1292 if (this.cursorBlink
) {
1297 var classNames
= [];
1300 fg
= (data
>> 9) & 0x1ff;
1303 if (flags
& Terminal
.flags
.BOLD
) {
1304 if (!Terminal
.brokenBold
) {
1305 classNames
.push('xterm-bold');
1307 // See: XTerm*boldColors
1308 if (fg
< 8) fg
+= 8;
1311 if (flags
& Terminal
.flags
.UNDERLINE
) {
1312 classNames
.push('xterm-underline');
1315 if (flags
& Terminal
.flags
.BLINK
) {
1316 classNames
.push('xterm-blink');
1320 * If inverse flag is on, then swap the foreground and background variables.
1322 if (flags
& Terminal
.flags
.INVERSE
) {
1323 /* One-line variable swap in JavaScript: http://stackoverflow.com/a/16201730 */
1324 bg = [fg, fg = bg][0];
1325 // Should inverse just be before the
1326 // above boldColors effect instead?
1327 if ((flags & 1) && fg < 8) fg += 8;
1330 if (flags & Terminal.flags.INVISIBLE) {
1331 classNames.push('xterm-hidden');
1335 * Weird situation: Invert flag used black foreground and white background results
1336 * in invalid background color, positioned at the 256 index of the 256 terminal
1337 * color map. Pin the colors manually in such a case.
1339 * Source: https://github.com/sourcelair/xterm.js/issues/57
1341 if (flags
& Terminal
.flags
.INVERSE
) {
1351 classNames
.push('xterm-bg-color-' + bg
);
1355 classNames
.push('xterm-color-' + fg
);
1359 if (classNames
.length
) {
1360 out
+= ' class="' + classNames
.join(' ') + '"';
1389 if (attr
!== this.defAttr
) {
1393 this.children
[y
].innerHTML
= out
;
1397 this.element
.appendChild(this.rowContainer
);
1400 this.emit('refresh', {element
: this.element
, start
: start
, end
: end
});
1404 * Display the cursor element
1406 Terminal
.prototype.showCursor = function() {
1407 if (!this.cursorState
) {
1408 this.cursorState
= 1;
1409 this.refresh(this.y
, this.y
);
1414 * Scroll the terminal
1416 Terminal
.prototype.scroll = function() {
1419 if (++this.ybase
=== this.scrollback
) {
1420 this.ybase
= this.ybase
/ 2 | 0;
1421 this.lines
= this.lines
.slice(-(this.ybase
+ this.rows
) + 1);
1424 this.ydisp
= this.ybase
;
1427 row
= this.ybase
+ this.rows
- 1;
1429 // subtract the bottom scroll region
1430 row
-= this.rows
- 1 - this.scrollBottom
;
1432 if (row
=== this.lines
.length
) {
1433 // potential optimization:
1434 // pushing is faster than splicing
1435 // when they amount to the same
1437 this.lines
.push(this.blankLine());
1440 this.lines
.splice(row
, 0, this.blankLine());
1443 if (this.scrollTop
!== 0) {
1444 if (this.ybase
!== 0) {
1446 this.ydisp
= this.ybase
;
1448 this.lines
.splice(this.ybase
+ this.scrollTop
, 1);
1452 this.updateRange(this.scrollTop
);
1453 this.updateRange(this.scrollBottom
);
1457 * Scroll the display of the terminal
1458 * @param {number} disp The number of lines to scroll down (negatives scroll up).
1460 Terminal
.prototype.scrollDisp = function(disp
) {
1463 if (this.ydisp
> this.ybase
) {
1464 this.ydisp
= this.ybase
;
1465 } else if (this.ydisp
< 0) {
1469 this.refresh(0, this.rows
- 1);
1473 * Writes text to the terminal.
1474 * @param {string} text The text to write to the terminal.
1476 Terminal
.prototype.write = function(data
) {
1477 var l
= data
.length
, i
= 0, j
, cs
, ch
, code
, low
, ch_width
, row
;
1479 this.refreshStart
= this.y
;
1480 this.refreshEnd
= this.y
;
1482 if (this.ybase
!== this.ydisp
) {
1483 this.ydisp
= this.ybase
;
1487 // apply leftover surrogate high from last write
1488 if (this.surrogate_high
) {
1489 data
= this.surrogate_high
+ data
;
1490 this.surrogate_high
= '';
1493 for (; i
< l
; i
++) {
1496 // FIXME: higher chars than 0xa0 are not allowed in escape sequences
1497 // --> maybe move to default
1498 code
= data
.charCodeAt(i
);
1499 if (0xD800 <= code
&& code
<= 0xDBFF) {
1500 // we got a surrogate high
1501 // get surrogate low (next 2 bytes)
1502 low
= data
.charCodeAt(i
+1);
1504 // end of data stream, save surrogate high
1505 this.surrogate_high
= ch
;
1508 code
= ((code
- 0xD800) * 0x400) + (low
- 0xDC00) + 0x10000;
1509 ch
+= data
.charAt(i
+1);
1511 // surrogate low - already handled above
1512 if (0xDC00 <= code
&& code
<= 0xDFFF)
1515 switch (this.state
) {
1526 if (this.convertEol
) {
1530 if (this.y
> this.scrollBottom
) {
1550 this.x
= this.nextStop();
1565 this.state
= escaped
;
1570 // calculate print space
1571 // expensive call, therefore we save width in line buffer
1572 ch_width
= wcwidth(code
);
1575 if (this.charset
&& this.charset
[ch
]) {
1576 ch
= this.charset
[ch
];
1579 row
= this.y
+ this.ybase
;
1581 // insert combining char in last cell
1582 // FIXME: needs handling after cursor jumps
1583 if (!ch_width
&& this.x
) {
1585 // dont overflow left
1586 if (this.lines
[row
][this.x
-1]) {
1587 if (!this.lines
[row
][this.x
-1][2]) {
1589 // found empty cell after fullwidth, need to go 2 cells back
1590 if (this.lines
[row
][this.x
-2])
1591 this.lines
[row
][this.x
-2][1] += ch
;
1594 this.lines
[row
][this.x
-1][1] += ch
;
1596 this.updateRange(this.y
);
1601 // goto next line if ch would overflow
1602 // TODO: needs a global min terminal width of 2
1603 if (this.x
+ch_width
-1 >= this.cols
) {
1604 // autowrap - DECAWM
1605 if (this.wraparoundMode
) {
1608 if (this.y
> this.scrollBottom
) {
1613 this.x
= this.cols
-1;
1614 if(ch_width
===2) // FIXME: check for xterm behavior
1618 row
= this.y
+ this.ybase
;
1620 // insert mode: move characters to right
1621 if (this.insertMode
) {
1622 // do this twice for a fullwidth char
1623 for (var moves
=0; moves
<ch_width
; ++moves
) {
1624 // remove last cell, if it's width is 0
1625 // we have to adjust the second last cell as well
1626 var removed
= this.lines
[this.y
+ this.ybase
].pop();
1628 && this.lines
[row
][this.cols
-2]
1629 && this.lines
[row
][this.cols
-2][2]===2)
1630 this.lines
[row
][this.cols
-2] = [this.curAttr
, ' ', 1];
1632 // insert empty cell at cursor
1633 this.lines
[row
].splice(this.x
, 0, [this.curAttr
, ' ', 1]);
1637 this.lines
[row
][this.x
] = [this.curAttr
, ch
, ch_width
];
1639 this.updateRange(this.y
);
1641 // fullwidth char - set next cell width to zero and advance cursor
1643 this.lines
[row
][this.x
] = [this.curAttr
, '', 0];
1652 // ESC [ Control Sequence Introducer ( CSI is 0x9b).
1655 this.currentParam
= 0;
1659 // ESC ] Operating System Command ( OSC is 0x9d).
1662 this.currentParam
= 0;
1666 // ESC P Device Control String ( DCS is 0x90).
1669 this.currentParam
= 0;
1673 // ESC _ Application Program Command ( APC is 0x9f).
1675 this.state
= ignore
;
1678 // ESC ^ Privacy Message ( PM is 0x9e).
1680 this.state
= ignore
;
1683 // ESC c Full Reset (RIS).
1688 // ESC E Next Line ( NEL is 0x85).
1689 // ESC D Index ( IND is 0x84).
1697 // ESC M Reverse Index ( RI is 0x8d).
1699 this.reverseIndex();
1702 // ESC % Select default/utf-8 character set.
1703 // @ = default, G = utf-8
1705 //this.charset = null;
1707 this.setgCharset(0, Terminal
.charsets
.US
);
1708 this.state
= normal
;
1712 // ESC (,),*,+,-,. Designate G0-G2 Character Set.
1713 case '(': // <-- this seems to get all the attention
1739 this.state
= charset
;
1742 // Designate G3 Character Set (VT300).
1743 // A = ISO Latin-1 Supplemental.
1747 this.state
= charset
;
1752 // Single Shift Select of G2 Character Set
1753 // ( SS2 is 0x8e). This affects next character only.
1757 // Single Shift Select of G3 Character Set
1758 // ( SS3 is 0x8f). This affects next character only.
1762 // Invoke the G2 Character Set as GL (LS2).
1767 // Invoke the G3 Character Set as GL (LS3).
1772 // Invoke the G3 Character Set as GR (LS3R).
1777 // Invoke the G2 Character Set as GR (LS2R).
1782 // Invoke the G1 Character Set as GR (LS1R).
1787 // ESC 7 Save Cursor (DECSC).
1790 this.state
= normal
;
1793 // ESC 8 Restore Cursor (DECRC).
1795 this.restoreCursor();
1796 this.state
= normal
;
1799 // ESC # 3 DEC line height/width
1801 this.state
= normal
;
1805 // ESC H Tab Set (HTS is 0x88).
1810 // ESC = Application Keypad (DECPAM).
1812 this.log('Serial port requested application keypad.');
1813 this.applicationKeypad
= true;
1814 this.state
= normal
;
1817 // ESC > Normal Keypad (DECPNM).
1819 this.log('Switching back to normal keypad.');
1820 this.applicationKeypad
= false;
1821 this.state
= normal
;
1825 this.state
= normal
;
1826 this.error('Unknown ESC control: %s.', ch
);
1833 case '0': // DEC Special Character and Line Drawing Set.
1834 cs
= Terminal
.charsets
.SCLD
;
1837 cs
= Terminal
.charsets
.UK
;
1839 case 'B': // United States (USASCII).
1840 cs
= Terminal
.charsets
.US
;
1843 cs
= Terminal
.charsets
.Dutch
;
1845 case 'C': // Finnish
1847 cs
= Terminal
.charsets
.Finnish
;
1850 cs
= Terminal
.charsets
.French
;
1852 case 'Q': // FrenchCanadian
1853 cs
= Terminal
.charsets
.FrenchCanadian
;
1856 cs
= Terminal
.charsets
.German
;
1858 case 'Y': // Italian
1859 cs
= Terminal
.charsets
.Italian
;
1861 case 'E': // NorwegianDanish
1863 cs
= Terminal
.charsets
.NorwegianDanish
;
1865 case 'Z': // Spanish
1866 cs
= Terminal
.charsets
.Spanish
;
1868 case 'H': // Swedish
1870 cs
= Terminal
.charsets
.Swedish
;
1873 cs
= Terminal
.charsets
.Swiss
;
1875 case '/': // ISOLatin (actually /A)
1876 cs
= Terminal
.charsets
.ISOLatin
;
1880 cs
= Terminal
.charsets
.US
;
1883 this.setgCharset(this.gcharset
, cs
);
1884 this.gcharset
= null;
1885 this.state
= normal
;
1891 // Set Text Parameters.
1892 if (ch
=== '\x1b' || ch
=== '\x07') {
1893 if (ch
=== '\x1b') i
++;
1895 this.params
.push(this.currentParam
);
1897 switch (this.params
[0]) {
1901 if (this.params
[1]) {
1902 this.title
= this.params
[1];
1903 this.handleTitle(this.title
);
1911 // change dynamic colors
1923 // change dynamic ui colors
1935 // manipulate selection data
1953 this.currentParam
= 0;
1954 this.state
= normal
;
1956 if (!this.params
.length
) {
1957 if (ch
>= '0' && ch
<= '9') {
1959 this.currentParam
* 10 + ch
.charCodeAt(0) - 48;
1960 } else if (ch
=== ';') {
1961 this.params
.push(this.currentParam
);
1962 this.currentParam
= '';
1965 this.currentParam
+= ch
;
1972 if (ch
=== '?' || ch
=== '>' || ch
=== '!') {
1978 if (ch
>= '0' && ch
<= '9') {
1979 this.currentParam
= this.currentParam
* 10 + ch
.charCodeAt(0) - 48;
1983 // '$', '"', ' ', '\''
1984 if (ch
=== '$' || ch
=== '"' || ch
=== ' ' || ch
=== '\'') {
1989 this.params
.push(this.currentParam
);
1990 this.currentParam
= 0;
1993 if (ch
=== ';') break;
1995 this.state
= normal
;
1999 // Cursor Up Ps Times (default = 1) (CUU).
2001 this.cursorUp(this.params
);
2005 // Cursor Down Ps Times (default = 1) (CUD).
2007 this.cursorDown(this.params
);
2011 // Cursor Forward Ps Times (default = 1) (CUF).
2013 this.cursorForward(this.params
);
2017 // Cursor Backward Ps Times (default = 1) (CUB).
2019 this.cursorBackward(this.params
);
2023 // Cursor Position [row;column] (default = [1,1]) (CUP).
2025 this.cursorPos(this.params
);
2028 // CSI Ps J Erase in Display (ED).
2030 this.eraseInDisplay(this.params
);
2033 // CSI Ps K Erase in Line (EL).
2035 this.eraseInLine(this.params
);
2038 // CSI Pm m Character Attributes (SGR).
2041 this.charAttributes(this.params
);
2045 // CSI Ps n Device Status Report (DSR).
2048 this.deviceStatus(this.params
);
2057 // Insert Ps (Blank) Character(s) (default = 1) (ICH).
2059 this.insertChars(this.params
);
2063 // Cursor Next Line Ps Times (default = 1) (CNL).
2065 this.cursorNextLine(this.params
);
2069 // Cursor Preceding Line Ps Times (default = 1) (CNL).
2071 this.cursorPrecedingLine(this.params
);
2075 // Cursor Character Absolute [column] (default = [row,1]) (CHA).
2077 this.cursorCharAbsolute(this.params
);
2081 // Insert Ps Line(s) (default = 1) (IL).
2083 this.insertLines(this.params
);
2087 // Delete Ps Line(s) (default = 1) (DL).
2089 this.deleteLines(this.params
);
2093 // Delete Ps Character(s) (default = 1) (DCH).
2095 this.deleteChars(this.params
);
2099 // Erase Ps Character(s) (default = 1) (ECH).
2101 this.eraseChars(this.params
);
2104 // CSI Pm ` Character Position Absolute
2105 // [column] (default = [row,1]) (HPA).
2107 this.charPosAbsolute(this.params
);
2111 // Horizontal Position Relative
2113 this.HPositionRelative(this.params
);
2117 // Send Device Attributes (Primary DA).
2119 // Send Device Attributes (Secondary DA)
2121 this.sendDeviceAttributes(this.params
);
2125 // Line Position Absolute [row] (default = [1,column]) (VPA).
2127 this.linePosAbsolute(this.params
);
2130 // 145 65 e * VPR - Vertical Position Relative
2132 this.VPositionRelative(this.params
);
2136 // Horizontal and Vertical Position [row;column] (default =
2139 this.HVPosition(this.params
);
2142 // CSI Pm h Set Mode (SM).
2143 // CSI ? Pm h - mouse escape codes, cursor escape codes
2145 this.setMode(this.params
);
2148 // CSI Pm l Reset Mode (RM).
2151 this.resetMode(this.params
);
2155 // Set Scrolling Region [top;bottom] (default = full size of win-
2159 this.setScrollRegion(this.params
);
2163 // Save cursor (ANSI.SYS).
2165 this.saveCursor(this.params
);
2169 // Restore cursor (ANSI.SYS).
2171 this.restoreCursor(this.params
);
2179 // Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
2181 this.cursorForwardTab(this.params
);
2184 // CSI Ps S Scroll up Ps lines (default = 1) (SU).
2186 this.scrollUp(this.params
);
2189 // CSI Ps T Scroll down Ps lines (default = 1) (SD).
2190 // CSI Ps ; Ps ; Ps ; Ps ; Ps T
2193 // if (this.prefix === '>') {
2194 // this.resetTitleModes(this.params);
2197 // if (this.params.length > 2) {
2198 // this.initMouseTracking(this.params);
2201 if (this.params
.length
< 2 && !this.prefix
) {
2202 this.scrollDown(this.params
);
2207 // Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
2209 this.cursorBackwardTab(this.params
);
2212 // CSI Ps b Repeat the preceding graphic character Ps times (REP).
2214 this.repeatPrecedingCharacter(this.params
);
2217 // CSI Ps g Tab Clear (TBC).
2219 this.tabClear(this.params
);
2222 // CSI Pm i Media Copy (MC).
2225 // this.mediaCopy(this.params);
2228 // CSI Pm m Character Attributes (SGR).
2230 // case 'm': // duplicate
2231 // if (this.prefix === '>') {
2232 // this.setResources(this.params);
2234 // this.charAttributes(this.params);
2238 // CSI Ps n Device Status Report (DSR).
2240 // case 'n': // duplicate
2241 // if (this.prefix === '>') {
2242 // this.disableModifiers(this.params);
2244 // this.deviceStatus(this.params);
2248 // CSI > Ps p Set pointer mode.
2249 // CSI ! p Soft terminal reset (DECSTR).
2251 // Request ANSI mode (DECRQM).
2253 // Request DEC private mode (DECRQM).
2256 switch (this.prefix
) {
2258 // this.setPointerMode(this.params);
2261 this.softReset(this.params
);
2264 // if (this.postfix === '$') {
2265 // this.requestPrivateMode(this.params);
2269 // if (this.postfix === '"') {
2270 // this.setConformanceLevel(this.params);
2271 // } else if (this.postfix === '$') {
2272 // this.requestAnsiMode(this.params);
2278 // CSI Ps q Load LEDs (DECLL).
2282 // if (this.postfix === ' ') {
2283 // this.setCursorStyle(this.params);
2286 // if (this.postfix === '"') {
2287 // this.setCharProtectionAttr(this.params);
2290 // this.loadLEDs(this.params);
2294 // Set Scrolling Region [top;bottom] (default = full size of win-
2297 // CSI Pt; Pl; Pb; Pr; Ps$ r
2298 // case 'r': // duplicate
2299 // if (this.prefix === '?') {
2300 // this.restorePrivateValues(this.params);
2301 // } else if (this.postfix === '$') {
2302 // this.setAttrInRectangle(this.params);
2304 // this.setScrollRegion(this.params);
2308 // CSI s Save cursor (ANSI.SYS).
2310 // case 's': // duplicate
2311 // if (this.prefix === '?') {
2312 // this.savePrivateValues(this.params);
2314 // this.saveCursor(this.params);
2318 // CSI Ps ; Ps ; Ps t
2319 // CSI Pt; Pl; Pb; Pr; Ps$ t
2323 // if (this.postfix === '$') {
2324 // this.reverseAttrInRectangle(this.params);
2325 // } else if (this.postfix === ' ') {
2326 // this.setWarningBellVolume(this.params);
2328 // if (this.prefix === '>') {
2329 // this.setTitleModeFeature(this.params);
2331 // this.manipulateWindow(this.params);
2336 // CSI u Restore cursor (ANSI.SYS).
2338 // case 'u': // duplicate
2339 // if (this.postfix === ' ') {
2340 // this.setMarginBellVolume(this.params);
2342 // this.restoreCursor(this.params);
2346 // CSI Pt; Pl; Pb; Pr; Pp; Pt; Pl; Pp$ v
2348 // if (this.postfix === '$') {
2349 // this.copyRectagle(this.params);
2353 // CSI Pt ; Pl ; Pb ; Pr ' w
2355 // if (this.postfix === '\'') {
2356 // this.enableFilterRectangle(this.params);
2360 // CSI Ps x Request Terminal Parameters (DECREQTPARM).
2361 // CSI Ps x Select Attribute Change Extent (DECSACE).
2362 // CSI Pc; Pt; Pl; Pb; Pr$ x
2364 // if (this.postfix === '$') {
2365 // this.fillRectangle(this.params);
2367 // this.requestParameters(this.params);
2368 // //this.__(this.params);
2373 // CSI Pt; Pl; Pb; Pr$ z
2375 // if (this.postfix === '\'') {
2376 // this.enableLocatorReporting(this.params);
2377 // } else if (this.postfix === '$') {
2378 // this.eraseRectangle(this.params);
2383 // CSI Pt; Pl; Pb; Pr$ {
2385 // if (this.postfix === '\'') {
2386 // this.setLocatorEvents(this.params);
2387 // } else if (this.postfix === '$') {
2388 // this.selectiveEraseRectangle(this.params);
2394 // if (this.postfix === '\'') {
2395 // this.requestLocatorPosition(this.params);
2400 // Insert P s Column(s) (default = 1) (DECIC), VT420 and up.
2402 // if (this.postfix === ' ') {
2403 // this.insertColumns(this.params);
2408 // Delete P s Column(s) (default = 1) (DECDC), VT420 and up
2410 // if (this.postfix === ' ') {
2411 // this.deleteColumns(this.params);
2416 this.error('Unknown CSI code: %s.', ch
);
2425 if (ch
=== '\x1b' || ch
=== '\x07') {
2426 if (ch
=== '\x1b') i
++;
2428 switch (this.prefix
) {
2429 // User-Defined Keys (DECUDK).
2433 // Request Status String (DECRQSS).
2434 // test: echo -e '\eP$q"p\e\\'
2436 var pt
= this.currentParam
2453 + (this.scrollTop
+ 1)
2455 + (this.scrollBottom
+ 1)
2465 this.error('Unknown DCS Pt: %s.', pt
);
2470 this.send('\x1bP' + +valid
+ '$r' + pt
+ '\x1b\\');
2473 // Set Termcap/Terminfo Data (xterm, experimental).
2477 // Request Termcap/Terminfo String (xterm, experimental)
2478 // Regular xterm does not even respond to this sequence.
2479 // This can cause a small glitch in vim.
2480 // test: echo -ne '\eP+q6b64\e\\'
2482 var pt
= this.currentParam
2485 this.send('\x1bP' + +valid
+ '+r' + pt
+ '\x1b\\');
2489 this.error('Unknown DCS prefix: %s.', this.prefix
);
2493 this.currentParam
= 0;
2495 this.state
= normal
;
2496 } else if (!this.currentParam
) {
2497 if (!this.prefix
&& ch
!== '$' && ch
!== '+') {
2498 this.currentParam
= ch
;
2499 } else if (this.prefix
.length
=== 2) {
2500 this.currentParam
= ch
;
2505 this.currentParam
+= ch
;
2511 if (ch
=== '\x1b' || ch
=== '\x07') {
2512 if (ch
=== '\x1b') i
++;
2513 this.state
= normal
;
2519 this.updateRange(this.y
);
2520 this.refresh(this.refreshStart
, this.refreshEnd
);
2524 * Writes text to the terminal, followed by a break line character (\n).
2525 * @param {string} text The text to write to the terminal.
2527 Terminal
.prototype.writeln = function(data
) {
2528 this.write(data
+ '\r\n');
2532 * Handle a keydown event
2534 * - https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
2535 * @param {KeyboardEvent} ev The keydown event to be handled.
2537 Terminal
.prototype.keyDown = function(ev
) {
2539 var result
= this.evaluateKeyEscapeSequence(ev
);
2541 if (result
.scrollDisp
) {
2542 this.scrollDisp(result
.scrollDisp
);
2543 return this.cancel(ev
);
2546 if (isThirdLevelShift(this, ev
)) {
2550 if (result
.cancel
) {
2551 // The event is canceled at the end already, is this necessary?
2552 this.cancel(ev
, true);
2559 this.emit('keydown', ev
);
2560 this.emit('key', result
.key
, ev
);
2562 this.handler(result
.key
);
2564 return this.cancel(ev
, true);
2568 * Returns an object that determines how a KeyboardEvent should be handled. The key of the
2569 * returned value is the new key code to pass to the PTY.
2571 * Reference: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
2572 * @param {KeyboardEvent} ev The keyboard event to be translated to key escape sequence.
2574 Terminal
.prototype.evaluateKeyEscapeSequence = function(ev
) {
2576 // Whether to cancel event propogation (NOTE: this may not be needed since the event is
2577 // canceled at the end of keyDown
2579 // The new key even to emit
2581 // The number of characters to scroll, if this is defined it will cancel the event
2582 scrollDisp
: undefined
2584 switch (ev
.keyCode
) {
2588 result
.key
= '\x08'; // ^H
2591 result
.key
= '\x7f'; // ^?
2596 result
.key
= '\x1b[Z';
2600 result
.cancel
= true;
2605 result
.cancel
= true;
2609 result
.key
= '\x1b';
2610 result
.cancel
= true;
2615 result
.key
= '\x1bb' // Jump a word back
2616 result
.cancel
= true;
2620 result
.key
= '\x1b[5D'; // Jump a word back
2623 if (this.applicationCursor
) {
2624 result
.key
= '\x1bOD'; // SS3 as ^[O for 7-bit
2627 result
.key
= '\x1b[D';
2632 result
.key
= '\x1bf' // Jump a word forward
2633 result
.cancel
= true;
2637 result
.key
= '\x1b[5C'; // Jump a word forward
2640 if (this.applicationCursor
) {
2641 result
.key
= '\x1bOC';
2644 result
.key
= '\x1b[C';
2648 if (this.applicationCursor
) {
2649 result
.key
= '\x1bOA';
2653 result
.scrollDisp
= -1;
2655 result
.key
= '\x1b[A';
2660 if (this.applicationCursor
) {
2661 result
.key
= '\x1bOB';
2665 result
.scrollDisp
= 1;
2667 result
.key
= '\x1b[B';
2672 if (!ev
.shiftKey
&& !ev
.ctrlKey
) {
2673 // <Ctrl> or <Shift> + <Insert> are used to
2674 // copy-paste on some systems.
2675 result
.key
= '\x1b[2~';
2679 case 46: result
.key
= '\x1b[3~'; break;
2682 if (this.applicationKeypad
) {
2683 result
.key
= '\x1bOH';
2686 result
.key
= '\x1bOH';
2690 if (this.applicationKeypad
) {
2691 result
.key
= '\x1bOF';
2694 result
.key
= '\x1bOF';
2699 result
.scrollDisp
= -(this.rows
- 1);
2701 result
.key
= '\x1b[5~';
2707 result
.scrollDisp
= this.rows
- 1;
2709 result
.key
= '\x1b[6~';
2713 case 112: result
.key
= '\x1bOP'; break;
2714 case 113: result
.key
= '\x1bOQ'; break;
2715 case 114: result
.key
= '\x1bOR'; break;
2716 case 115: result
.key
= '\x1bOS'; break;
2717 case 116: result
.key
= '\x1b[15~'; break;
2718 case 117: result
.key
= '\x1b[17~'; break;
2719 case 118: result
.key
= '\x1b[18~'; break;
2720 case 119: result
.key
= '\x1b[19~'; break;
2721 case 120: result
.key
= '\x1b[20~'; break;
2722 case 121: result
.key
= '\x1b[21~'; break;
2723 case 122: result
.key
= '\x1b[23~'; break;
2724 case 123: result
.key
= '\x1b[24~'; break;
2727 if (ev
.ctrlKey
&& !ev
.shiftKey
&& !ev
.altKey
&& !ev
.metaKey
) {
2728 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
2729 result
.key
= String
.fromCharCode(ev
.keyCode
- 64);
2730 } else if (ev
.keyCode
=== 32) {
2732 result
.key
= String
.fromCharCode(0);
2733 } else if (ev
.keyCode
>= 51 && ev
.keyCode
<= 55) {
2734 // escape, file sep, group sep, record sep, unit sep
2735 result
.key
= String
.fromCharCode(ev
.keyCode
- 51 + 27);
2736 } else if (ev
.keyCode
=== 56) {
2738 result
.key
= String
.fromCharCode(127);
2739 } else if (ev
.keyCode
=== 219) {
2741 result
.key
= String
.fromCharCode(27);
2742 } else if (ev
.keyCode
=== 221) {
2744 result
.key
= String
.fromCharCode(29);
2746 } else if (!this.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) {
2747 // On Mac this is a third level shift. Use <Esc> instead.
2748 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
2749 result
.key
= '\x1b' + String
.fromCharCode(ev
.keyCode
+ 32);
2750 } else if (ev
.keyCode
=== 192) {
2751 result
.key
= '\x1b`';
2752 } else if (ev
.keyCode
>= 48 && ev
.keyCode
<= 57) {
2753 result
.key
= '\x1b' + (ev
.keyCode
- 48);
2762 * Set the G level of the terminal
2765 Terminal
.prototype.setgLevel = function(g
) {
2767 this.charset
= this.charsets
[g
];
2771 * Set the charset for the given G level of the terminal
2775 Terminal
.prototype.setgCharset = function(g
, charset
) {
2776 this.charsets
[g
] = charset
;
2777 if (this.glevel
=== g
) {
2778 this.charset
= charset
;
2783 * Handle a keypress event.
2785 * - https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
2786 * @param {KeyboardEvent} ev The keypress event to be handled.
2788 Terminal
.prototype.keyPress = function(ev
) {
2793 } else if (ev
.which
== null) {
2795 } else if (ev
.which
!== 0 && ev
.charCode
!== 0) {
2802 (ev
.altKey
|| ev
.ctrlKey
|| ev
.metaKey
) && !isThirdLevelShift(this, ev
)
2807 key
= String
.fromCharCode(key
);
2810 * When a key is pressed and a character is sent to the terminal, then clear any text
2811 * selected in the terminal.
2814 this.clearSelection();
2817 this.emit('keypress', key
, ev
);
2818 this.emit('key', key
, ev
);
2822 this.cancel(ev
, true);
2828 * Send data for handling to the terminal
2829 * @param {string} data
2831 Terminal
.prototype.send = function(data
) {
2835 setTimeout(function() {
2836 self
.handler(self
.queue
);
2846 * Note: We could do sweet things with webaudio here
2848 Terminal
.prototype.bell = function() {
2849 if (!this.visualBell
) return;
2851 this.element
.style
.borderColor
= 'white';
2852 setTimeout(function() {
2853 self
.element
.style
.borderColor
= '';
2855 if (this.popOnBell
) this.focus();
2859 * Log the current state to the console.
2861 Terminal
.prototype.log = function() {
2862 if (!this.debug
) return;
2863 if (!this.context
.console
|| !this.context
.console
.log
) return;
2864 var args
= Array
.prototype.slice
.call(arguments
);
2865 this.context
.console
.log
.apply(this.context
.console
, args
);
2869 * Log the current state as error to the console.
2871 Terminal
.prototype.error = function() {
2872 if (!this.debug
) return;
2873 if (!this.context
.console
|| !this.context
.console
.error
) return;
2874 var args
= Array
.prototype.slice
.call(arguments
);
2875 this.context
.console
.error
.apply(this.context
.console
, args
);
2879 * Resizes the terminal.
2881 * @param {number} x The number of columns to resize to.
2882 * @param {number} y The number of rows to resize to.
2884 Terminal
.prototype.resize = function(x
, y
) {
2892 if (x
=== this.cols
&& y
=== this.rows
) {
2902 ch
= [this.defAttr
, ' ', 1]; // does xterm use the default attr?
2903 i
= this.lines
.length
;
2905 while (this.lines
[i
].length
< x
) {
2906 this.lines
[i
].push(ch
);
2910 i
= this.lines
.length
;
2912 while (this.lines
[i
].length
> x
) {
2913 this.lines
[i
].pop();
2926 // y is rows, not this.y
2927 if (this.lines
.length
< y
+ this.ybase
) {
2928 if (this.ybase
> 0 && this.lines
.length
<= this.ybase
+ this.y
+ addToY
+ 1) {
2929 // There is room above the buffer and there are no empty elements below the line,
2933 if (this.ydisp
> 0) {
2934 // Viewport is at the top of the buffer, must increase downwards
2938 // Add a blank line if there is no buffer left at the top to scroll to, or if there
2939 // are blank lines after the cursor
2940 this.lines
.push(this.blankLine());
2943 if (this.children
.length
< y
) {
2949 if (this.lines
.length
> y
+ this.ybase
) {
2950 if (this.lines
.length
> this.ybase
+ this.y
+ 1) {
2951 // The line is a blank line below the cursor, remove it
2954 // The line is the cursor, scroll down
2959 if (this.children
.length
> y
) {
2960 el
= this.children
.shift();
2962 el
.parentNode
.removeChild(el
);
2969 * Make sure that the cursor stays on screen
2983 this.scrollBottom
= y
- 1;
2985 this.refresh(0, this.rows
- 1);
2989 this.emit('resize', {terminal
: this, cols
: x
, rows
: y
});
2993 * Updates the range of rows to refresh
2994 * @param {number} y The number of rows to refresh next.
2996 Terminal
.prototype.updateRange = function(y
) {
2997 if (y
< this.refreshStart
) this.refreshStart
= y
;
2998 if (y
> this.refreshEnd
) this.refreshEnd
= y
;
2999 // if (y > this.refreshEnd) {
3000 // this.refreshEnd = y;
3001 // if (y > this.rows - 1) {
3002 // this.refreshEnd = this.rows - 1;
3008 * Set the range of refreshing to the maximyum value
3010 Terminal
.prototype.maxRange = function() {
3011 this.refreshStart
= 0;
3012 this.refreshEnd
= this.rows
- 1;
3018 * Setup the tab stops.
3021 Terminal
.prototype.setupStops = function(i
) {
3023 if (!this.tabs
[i
]) {
3024 i
= this.prevStop(i
);
3031 for (; i
< this.cols
; i
+= 8) {
3032 this.tabs
[i
] = true;
3038 * Move the cursor to the previous tab stop from the given position (default is current).
3039 * @param {number} x The position to move the cursor to the previous tab stop.
3041 Terminal
.prototype.prevStop = function(x
) {
3042 if (x
== null) x
= this.x
;
3043 while (!this.tabs
[--x
] && x
> 0);
3044 return x
>= this.cols
3051 * Move the cursor one tab stop forward from the given position (default is current).
3052 * @param {number} x The position to move the cursor one tab stop forward.
3054 Terminal
.prototype.nextStop = function(x
) {
3055 if (x
== null) x
= this.x
;
3056 while (!this.tabs
[++x
] && x
< this.cols
);
3057 return x
>= this.cols
3064 * Erase in the identified line everything from "x" to the end of the line (right).
3065 * @param {number} x The column from which to start erasing to the end of the line.
3066 * @param {number} y The line in which to operate.
3068 Terminal
.prototype.eraseRight = function(x
, y
) {
3069 var line
= this.lines
[this.ybase
+ y
]
3070 , ch
= [this.eraseAttr(), ' ', 1]; // xterm
3073 for (; x
< this.cols
; x
++) {
3077 this.updateRange(y
);
3083 * Erase in the identified line everything from "x" to the start of the line (left).
3084 * @param {number} x The column from which to start erasing to the start of the line.
3085 * @param {number} y The line in which to operate.
3087 Terminal
.prototype.eraseLeft = function(x
, y
) {
3088 var line
= this.lines
[this.ybase
+ y
]
3089 , ch
= [this.eraseAttr(), ' ', 1]; // xterm
3092 while (x
--) line
[x
] = ch
;
3094 this.updateRange(y
);
3099 * Erase all content in the given line
3100 * @param {number} y The line to erase all of its contents.
3102 Terminal
.prototype.eraseLine = function(y
) {
3103 this.eraseRight(0, y
);
3108 * Return the data array of a blank line/
3109 * @param {number} cur First bunch of data for each "blank" character.
3111 Terminal
.prototype.blankLine = function(cur
) {
3116 var ch
= [attr
, ' ', 1] // width defaults to 1 halfwidth character
3120 for (; i
< this.cols
; i
++) {
3129 * If cur return the back color xterm feature attribute. Else return defAttr.
3130 * @param {object} cur
3132 Terminal
.prototype.ch = function(cur
) {
3134 ? [this.eraseAttr(), ' ', 1]
3135 : [this.defAttr
, ' ', 1];
3140 * Evaluate if the current erminal is the given argument.
3141 * @param {object} term The terminal to evaluate
3143 Terminal
.prototype.is = function(term
) {
3144 var name
= this.termName
;
3145 return (name
+ '').indexOf(term
) === 0;
3150 * Emit the 'data' event and populate the given data.
3151 * @param {string} data The data to populate in the event.
3153 Terminal
.prototype.handler = function(data
) {
3154 this.emit('data', data
);
3159 * Emit the 'title' event and populate the given title.
3160 * @param {string} title The title to populate in the event.
3162 Terminal
.prototype.handleTitle = function(title
) {
3163 this.emit('title', title
);
3172 * ESC D Index (IND is 0x84).
3174 Terminal
.prototype.index = function() {
3176 if (this.y
> this.scrollBottom
) {
3180 this.state
= normal
;
3185 * ESC M Reverse Index (RI is 0x8d).
3187 Terminal
.prototype.reverseIndex = function() {
3190 if (this.y
< this.scrollTop
) {
3192 // possibly move the code below to term.reverseScroll();
3193 // test: echo -ne '\e[1;1H\e[44m\eM\e[0m'
3194 // blankLine(true) is xterm/linux behavior
3195 this.lines
.splice(this.y
+ this.ybase
, 0, this.blankLine(true));
3196 j
= this.rows
- 1 - this.scrollBottom
;
3197 this.lines
.splice(this.rows
- 1 + this.ybase
- j
+ 1, 1);
3199 this.updateRange(this.scrollTop
);
3200 this.updateRange(this.scrollBottom
);
3202 this.state
= normal
;
3207 * ESC c Full Reset (RIS).
3209 Terminal
.prototype.reset = function() {
3210 this.options
.rows
= this.rows
;
3211 this.options
.cols
= this.cols
;
3212 Terminal
.call(this, this.options
);
3213 this.refresh(0, this.rows
- 1);
3218 * ESC H Tab Set (HTS is 0x88).
3220 Terminal
.prototype.tabSet = function() {
3221 this.tabs
[this.x
] = true;
3222 this.state
= normal
;
3232 * Cursor Up Ps Times (default = 1) (CUU).
3234 Terminal
.prototype.cursorUp = function(params
) {
3235 var param
= params
[0];
3236 if (param
< 1) param
= 1;
3238 if (this.y
< 0) this.y
= 0;
3244 * Cursor Down Ps Times (default = 1) (CUD).
3246 Terminal
.prototype.cursorDown = function(params
) {
3247 var param
= params
[0];
3248 if (param
< 1) param
= 1;
3250 if (this.y
>= this.rows
) {
3251 this.y
= this.rows
- 1;
3258 * Cursor Forward Ps Times (default = 1) (CUF).
3260 Terminal
.prototype.cursorForward = function(params
) {
3261 var param
= params
[0];
3262 if (param
< 1) param
= 1;
3264 if (this.x
>= this.cols
) {
3265 this.x
= this.cols
- 1;
3272 * Cursor Backward Ps Times (default = 1) (CUB).
3274 Terminal
.prototype.cursorBackward = function(params
) {
3275 var param
= params
[0];
3276 if (param
< 1) param
= 1;
3278 if (this.x
< 0) this.x
= 0;
3284 * Cursor Position [row;column] (default = [1,1]) (CUP).
3286 Terminal
.prototype.cursorPos = function(params
) {
3289 row
= params
[0] - 1;
3291 if (params
.length
>= 2) {
3292 col
= params
[1] - 1;
3299 } else if (row
>= this.rows
) {
3300 row
= this.rows
- 1;
3305 } else if (col
>= this.cols
) {
3306 col
= this.cols
- 1;
3315 * CSI Ps J Erase in Display (ED).
3316 * Ps = 0 -> Erase Below (default).
3317 * Ps = 1 -> Erase Above.
3318 * Ps = 2 -> Erase All.
3319 * Ps = 3 -> Erase Saved Lines (xterm).
3321 * Erase in Display (DECSED).
3322 * Ps = 0 -> Selective Erase Below (default).
3323 * Ps = 1 -> Selective Erase Above.
3324 * Ps = 2 -> Selective Erase All.
3326 Terminal
.prototype.eraseInDisplay = function(params
) {
3328 switch (params
[0]) {
3330 this.eraseRight(this.x
, this.y
);
3332 for (; j
< this.rows
; j
++) {
3337 this.eraseLeft(this.x
, this.y
);
3345 while (j
--) this.eraseLine(j
);
3355 * CSI Ps K Erase in Line (EL).
3356 * Ps = 0 -> Erase to Right (default).
3357 * Ps = 1 -> Erase to Left.
3358 * Ps = 2 -> Erase All.
3360 * Erase in Line (DECSEL).
3361 * Ps = 0 -> Selective Erase to Right (default).
3362 * Ps = 1 -> Selective Erase to Left.
3363 * Ps = 2 -> Selective Erase All.
3365 Terminal
.prototype.eraseInLine = function(params
) {
3366 switch (params
[0]) {
3368 this.eraseRight(this.x
, this.y
);
3371 this.eraseLeft(this.x
, this.y
);
3374 this.eraseLine(this.y
);
3381 * CSI Pm m Character Attributes (SGR).
3382 * Ps = 0 -> Normal (default).
3384 * Ps = 4 -> Underlined.
3385 * Ps = 5 -> Blink (appears as Bold).
3386 * Ps = 7 -> Inverse.
3387 * Ps = 8 -> Invisible, i.e., hidden (VT300).
3388 * Ps = 2 2 -> Normal (neither bold nor faint).
3389 * Ps = 2 4 -> Not underlined.
3390 * Ps = 2 5 -> Steady (not blinking).
3391 * Ps = 2 7 -> Positive (not inverse).
3392 * Ps = 2 8 -> Visible, i.e., not hidden (VT300).
3393 * Ps = 3 0 -> Set foreground color to Black.
3394 * Ps = 3 1 -> Set foreground color to Red.
3395 * Ps = 3 2 -> Set foreground color to Green.
3396 * Ps = 3 3 -> Set foreground color to Yellow.
3397 * Ps = 3 4 -> Set foreground color to Blue.
3398 * Ps = 3 5 -> Set foreground color to Magenta.
3399 * Ps = 3 6 -> Set foreground color to Cyan.
3400 * Ps = 3 7 -> Set foreground color to White.
3401 * Ps = 3 9 -> Set foreground color to default (original).
3402 * Ps = 4 0 -> Set background color to Black.
3403 * Ps = 4 1 -> Set background color to Red.
3404 * Ps = 4 2 -> Set background color to Green.
3405 * Ps = 4 3 -> Set background color to Yellow.
3406 * Ps = 4 4 -> Set background color to Blue.
3407 * Ps = 4 5 -> Set background color to Magenta.
3408 * Ps = 4 6 -> Set background color to Cyan.
3409 * Ps = 4 7 -> Set background color to White.
3410 * Ps = 4 9 -> Set background color to default (original).
3412 * If 16-color support is compiled, the following apply. Assume
3413 * that xterm's resources are set so that the ISO color codes are
3414 * the first 8 of a set of 16. Then the aixterm colors are the
3415 * bright versions of the ISO colors:
3416 * Ps = 9 0 -> Set foreground color to Black.
3417 * Ps = 9 1 -> Set foreground color to Red.
3418 * Ps = 9 2 -> Set foreground color to Green.
3419 * Ps = 9 3 -> Set foreground color to Yellow.
3420 * Ps = 9 4 -> Set foreground color to Blue.
3421 * Ps = 9 5 -> Set foreground color to Magenta.
3422 * Ps = 9 6 -> Set foreground color to Cyan.
3423 * Ps = 9 7 -> Set foreground color to White.
3424 * Ps = 1 0 0 -> Set background color to Black.
3425 * Ps = 1 0 1 -> Set background color to Red.
3426 * Ps = 1 0 2 -> Set background color to Green.
3427 * Ps = 1 0 3 -> Set background color to Yellow.
3428 * Ps = 1 0 4 -> Set background color to Blue.
3429 * Ps = 1 0 5 -> Set background color to Magenta.
3430 * Ps = 1 0 6 -> Set background color to Cyan.
3431 * Ps = 1 0 7 -> Set background color to White.
3433 * If xterm is compiled with the 16-color support disabled, it
3434 * supports the following, from rxvt:
3435 * Ps = 1 0 0 -> Set foreground and background color to
3438 * If 88- or 256-color support is compiled, the following apply.
3439 * Ps = 3 8 ; 5 ; Ps -> Set foreground color to the second
3441 * Ps = 4 8 ; 5 ; Ps -> Set background color to the second
3444 Terminal
.prototype.charAttributes = function(params
) {
3445 // Optimize a single SGR0.
3446 if (params
.length
=== 1 && params
[0] === 0) {
3447 this.curAttr
= this.defAttr
;
3451 var l
= params
.length
3453 , flags
= this.curAttr
>> 18
3454 , fg
= (this.curAttr
>> 9) & 0x1ff
3455 , bg
= this.curAttr
& 0x1ff
3458 for (; i
< l
; i
++) {
3460 if (p
>= 30 && p
<= 37) {
3463 } else if (p
>= 40 && p
<= 47) {
3466 } else if (p
>= 90 && p
<= 97) {
3470 } else if (p
>= 100 && p
<= 107) {
3474 } else if (p
=== 0) {
3476 flags
= this.defAttr
>> 18;
3477 fg
= (this.defAttr
>> 9) & 0x1ff;
3478 bg
= this.defAttr
& 0x1ff;
3482 } else if (p
=== 1) {
3485 } else if (p
=== 4) {
3488 } else if (p
=== 5) {
3491 } else if (p
=== 7) {
3492 // inverse and positive
3493 // test with: echo -e '\e[31m\e[42mhello\e[7mworld\e[27mhi\e[m'
3495 } else if (p
=== 8) {
3498 } else if (p
=== 22) {
3501 } else if (p
=== 24) {
3504 } else if (p
=== 25) {
3507 } else if (p
=== 27) {
3510 } else if (p
=== 28) {
3513 } else if (p
=== 39) {
3515 fg
= (this.defAttr
>> 9) & 0x1ff;
3516 } else if (p
=== 49) {
3518 bg
= this.defAttr
& 0x1ff;
3519 } else if (p
=== 38) {
3521 if (params
[i
+ 1] === 2) {
3525 params
[i
+ 1] & 0xff,
3526 params
[i
+ 2] & 0xff);
3527 if (fg
=== -1) fg
= 0x1ff;
3529 } else if (params
[i
+ 1] === 5) {
3531 p
= params
[i
] & 0xff;
3534 } else if (p
=== 48) {
3536 if (params
[i
+ 1] === 2) {
3540 params
[i
+ 1] & 0xff,
3541 params
[i
+ 2] & 0xff);
3542 if (bg
=== -1) bg
= 0x1ff;
3544 } else if (params
[i
+ 1] === 5) {
3546 p
= params
[i
] & 0xff;
3549 } else if (p
=== 100) {
3551 fg
= (this.defAttr
>> 9) & 0x1ff;
3552 bg
= this.defAttr
& 0x1ff;
3554 this.error('Unknown SGR attribute: %d.', p
);
3558 this.curAttr
= (flags
<< 18) | (fg
<< 9) | bg
;
3563 * CSI Ps n Device Status Report (DSR).
3564 * Ps = 5 -> Status Report. Result (``OK'') is
3566 * Ps = 6 -> Report Cursor Position (CPR) [row;column].
3570 * Device Status Report (DSR, DEC-specific).
3571 * Ps = 6 -> Report Cursor Position (CPR) [row;column] as CSI
3572 * ? r ; c R (assumes page is zero).
3573 * Ps = 1 5 -> Report Printer status as CSI ? 1 0 n (ready).
3574 * or CSI ? 1 1 n (not ready).
3575 * Ps = 2 5 -> Report UDK status as CSI ? 2 0 n (unlocked)
3576 * or CSI ? 2 1 n (locked).
3577 * Ps = 2 6 -> Report Keyboard status as
3578 * CSI ? 2 7 ; 1 ; 0 ; 0 n (North American).
3579 * The last two parameters apply to VT400 & up, and denote key-
3580 * board ready and LK01 respectively.
3581 * Ps = 5 3 -> Report Locator status as
3582 * CSI ? 5 3 n Locator available, if compiled-in, or
3583 * CSI ? 5 0 n No Locator, if not.
3585 Terminal
.prototype.deviceStatus = function(params
) {
3587 switch (params
[0]) {
3590 this.send('\x1b[0n');
3601 } else if (this.prefix
=== '?') {
3602 // modern xterm doesnt seem to
3603 // respond to any of these except ?6, 6, and 5
3604 switch (params
[0]) {
3615 // this.send('\x1b[?11n');
3618 // dont support user defined keys
3619 // this.send('\x1b[?21n');
3622 // north american keyboard
3623 // this.send('\x1b[?27;1;0;0n');
3626 // no dec locator/mouse
3627 // this.send('\x1b[?50n');
3640 * Insert Ps (Blank) Character(s) (default = 1) (ICH).
3642 Terminal
.prototype.insertChars = function(params
) {
3643 var param
, row
, j
, ch
;
3646 if (param
< 1) param
= 1;
3648 row
= this.y
+ this.ybase
;
3650 ch
= [this.eraseAttr(), ' ', 1]; // xterm
3652 while (param
-- && j
< this.cols
) {
3653 this.lines
[row
].splice(j
++, 0, ch
);
3654 this.lines
[row
].pop();
3660 * Cursor Next Line Ps Times (default = 1) (CNL).
3661 * same as CSI Ps B ?
3663 Terminal
.prototype.cursorNextLine = function(params
) {
3664 var param
= params
[0];
3665 if (param
< 1) param
= 1;
3667 if (this.y
>= this.rows
) {
3668 this.y
= this.rows
- 1;
3676 * Cursor Preceding Line Ps Times (default = 1) (CNL).
3679 Terminal
.prototype.cursorPrecedingLine = function(params
) {
3680 var param
= params
[0];
3681 if (param
< 1) param
= 1;
3683 if (this.y
< 0) this.y
= 0;
3690 * Cursor Character Absolute [column] (default = [row,1]) (CHA).
3692 Terminal
.prototype.cursorCharAbsolute = function(params
) {
3693 var param
= params
[0];
3694 if (param
< 1) param
= 1;
3701 * Insert Ps Line(s) (default = 1) (IL).
3703 Terminal
.prototype.insertLines = function(params
) {
3707 if (param
< 1) param
= 1;
3708 row
= this.y
+ this.ybase
;
3710 j
= this.rows
- 1 - this.scrollBottom
;
3711 j
= this.rows
- 1 + this.ybase
- j
+ 1;
3714 // test: echo -e '\e[44m\e[1L\e[0m'
3715 // blankLine(true) - xterm/linux behavior
3716 this.lines
.splice(row
, 0, this.blankLine(true));
3717 this.lines
.splice(j
, 1);
3721 this.updateRange(this.y
);
3722 this.updateRange(this.scrollBottom
);
3728 * Delete Ps Line(s) (default = 1) (DL).
3730 Terminal
.prototype.deleteLines = function(params
) {
3734 if (param
< 1) param
= 1;
3735 row
= this.y
+ this.ybase
;
3737 j
= this.rows
- 1 - this.scrollBottom
;
3738 j
= this.rows
- 1 + this.ybase
- j
;
3741 // test: echo -e '\e[44m\e[1M\e[0m'
3742 // blankLine(true) - xterm/linux behavior
3743 this.lines
.splice(j
+ 1, 0, this.blankLine(true));
3744 this.lines
.splice(row
, 1);
3748 this.updateRange(this.y
);
3749 this.updateRange(this.scrollBottom
);
3755 * Delete Ps Character(s) (default = 1) (DCH).
3757 Terminal
.prototype.deleteChars = function(params
) {
3761 if (param
< 1) param
= 1;
3763 row
= this.y
+ this.ybase
;
3764 ch
= [this.eraseAttr(), ' ', 1]; // xterm
3767 this.lines
[row
].splice(this.x
, 1);
3768 this.lines
[row
].push(ch
);
3774 * Erase Ps Character(s) (default = 1) (ECH).
3776 Terminal
.prototype.eraseChars = function(params
) {
3777 var param
, row
, j
, ch
;
3780 if (param
< 1) param
= 1;
3782 row
= this.y
+ this.ybase
;
3784 ch
= [this.eraseAttr(), ' ', 1]; // xterm
3786 while (param
-- && j
< this.cols
) {
3787 this.lines
[row
][j
++] = ch
;
3792 * CSI Pm ` Character Position Absolute
3793 * [column] (default = [row,1]) (HPA).
3795 Terminal
.prototype.charPosAbsolute = function(params
) {
3796 var param
= params
[0];
3797 if (param
< 1) param
= 1;
3799 if (this.x
>= this.cols
) {
3800 this.x
= this.cols
- 1;
3807 * Horizontal Position Relative
3810 Terminal
.prototype.HPositionRelative = function(params
) {
3811 var param
= params
[0];
3812 if (param
< 1) param
= 1;
3814 if (this.x
>= this.cols
) {
3815 this.x
= this.cols
- 1;
3821 * CSI Ps c Send Device Attributes (Primary DA).
3822 * Ps = 0 or omitted -> request attributes from terminal. The
3823 * response depends on the decTerminalID resource setting.
3824 * -> CSI ? 1 ; 2 c (``VT100 with Advanced Video Option'')
3825 * -> CSI ? 1 ; 0 c (``VT101 with No Options'')
3826 * -> CSI ? 6 c (``VT102'')
3827 * -> CSI ? 6 0 ; 1 ; 2 ; 6 ; 8 ; 9 ; 1 5 ; c (``VT220'')
3828 * The VT100-style response parameters do not mean anything by
3829 * themselves. VT220 parameters do, telling the host what fea-
3830 * tures the terminal supports:
3831 * Ps = 1 -> 132-columns.
3832 * Ps = 2 -> Printer.
3833 * Ps = 6 -> Selective erase.
3834 * Ps = 8 -> User-defined keys.
3835 * Ps = 9 -> National replacement character sets.
3836 * Ps = 1 5 -> Technical characters.
3837 * Ps = 2 2 -> ANSI color, e.g., VT525.
3838 * Ps = 2 9 -> ANSI text locator (i.e., DEC Locator mode).
3840 * Send Device Attributes (Secondary DA).
3841 * Ps = 0 or omitted -> request the terminal's identification
3842 * code. The response depends on the decTerminalID resource set-
3843 * ting. It should apply only to VT220 and up, but xterm extends
3845 * -> CSI > Pp ; Pv ; Pc c
3846 * where Pp denotes the terminal type
3847 * Pp = 0 -> ``VT100''.
3848 * Pp = 1 -> ``VT220''.
3849 * and Pv is the firmware version (for xterm, this was originally
3850 * the XFree86 patch number, starting with 95). In a DEC termi-
3851 * nal, Pc indicates the ROM cartridge registration number and is
3854 * xterm/charproc.c - line 2012, for more information.
3855 * vim responds with ^[[?0c or ^[[?1c after the terminal's response (?)
3857 Terminal
.prototype.sendDeviceAttributes = function(params
) {
3858 if (params
[0] > 0) return;
3861 if (this.is('xterm')
3862 || this.is('rxvt-unicode')
3863 || this.is('screen')) {
3864 this.send('\x1b[?1;2c');
3865 } else if (this.is('linux')) {
3866 this.send('\x1b[?6c');
3868 } else if (this.prefix
=== '>') {
3870 // seem to spit this
3871 // out around ~370 times (?).
3872 if (this.is('xterm')) {
3873 this.send('\x1b[>0;276;0c');
3874 } else if (this.is('rxvt-unicode')) {
3875 this.send('\x1b[>85;95;0c');
3876 } else if (this.is('linux')) {
3877 // not supported by linux console.
3878 // linux console echoes parameters.
3879 this.send(params
[0] + 'c');
3880 } else if (this.is('screen')) {
3881 this.send('\x1b[>83;40003;0c');
3889 * Line Position Absolute [row] (default = [1,column]) (VPA).
3891 Terminal
.prototype.linePosAbsolute = function(params
) {
3892 var param
= params
[0];
3893 if (param
< 1) param
= 1;
3895 if (this.y
>= this.rows
) {
3896 this.y
= this.rows
- 1;
3902 * 145 65 e * VPR - Vertical Position Relative
3905 Terminal
.prototype.VPositionRelative = function(params
) {
3906 var param
= params
[0];
3907 if (param
< 1) param
= 1;
3909 if (this.y
>= this.rows
) {
3910 this.y
= this.rows
- 1;
3917 * Horizontal and Vertical Position [row;column] (default =
3920 Terminal
.prototype.HVPosition = function(params
) {
3921 if (params
[0] < 1) params
[0] = 1;
3922 if (params
[1] < 1) params
[1] = 1;
3924 this.y
= params
[0] - 1;
3925 if (this.y
>= this.rows
) {
3926 this.y
= this.rows
- 1;
3929 this.x
= params
[1] - 1;
3930 if (this.x
>= this.cols
) {
3931 this.x
= this.cols
- 1;
3937 * CSI Pm h Set Mode (SM).
3938 * Ps = 2 -> Keyboard Action Mode (AM).
3939 * Ps = 4 -> Insert Mode (IRM).
3940 * Ps = 1 2 -> Send/receive (SRM).
3941 * Ps = 2 0 -> Automatic Newline (LNM).
3943 * DEC Private Mode Set (DECSET).
3944 * Ps = 1 -> Application Cursor Keys (DECCKM).
3945 * Ps = 2 -> Designate USASCII for character sets G0-G3
3946 * (DECANM), and set VT100 mode.
3947 * Ps = 3 -> 132 Column Mode (DECCOLM).
3948 * Ps = 4 -> Smooth (Slow) Scroll (DECSCLM).
3949 * Ps = 5 -> Reverse Video (DECSCNM).
3950 * Ps = 6 -> Origin Mode (DECOM).
3951 * Ps = 7 -> Wraparound Mode (DECAWM).
3952 * Ps = 8 -> Auto-repeat Keys (DECARM).
3953 * Ps = 9 -> Send Mouse X & Y on button press. See the sec-
3954 * tion Mouse Tracking.
3955 * Ps = 1 0 -> Show toolbar (rxvt).
3956 * Ps = 1 2 -> Start Blinking Cursor (att610).
3957 * Ps = 1 8 -> Print form feed (DECPFF).
3958 * Ps = 1 9 -> Set print extent to full screen (DECPEX).
3959 * Ps = 2 5 -> Show Cursor (DECTCEM).
3960 * Ps = 3 0 -> Show scrollbar (rxvt).
3961 * Ps = 3 5 -> Enable font-shifting functions (rxvt).
3962 * Ps = 3 8 -> Enter Tektronix Mode (DECTEK).
3963 * Ps = 4 0 -> Allow 80 -> 132 Mode.
3964 * Ps = 4 1 -> more(1) fix (see curses resource).
3965 * Ps = 4 2 -> Enable Nation Replacement Character sets (DECN-
3967 * Ps = 4 4 -> Turn On Margin Bell.
3968 * Ps = 4 5 -> Reverse-wraparound Mode.
3969 * Ps = 4 6 -> Start Logging. This is normally disabled by a
3970 * compile-time option.
3971 * Ps = 4 7 -> Use Alternate Screen Buffer. (This may be dis-
3972 * abled by the titeInhibit resource).
3973 * Ps = 6 6 -> Application keypad (DECNKM).
3974 * Ps = 6 7 -> Backarrow key sends backspace (DECBKM).
3975 * Ps = 1 0 0 0 -> Send Mouse X & Y on button press and
3976 * release. See the section Mouse Tracking.
3977 * Ps = 1 0 0 1 -> Use Hilite Mouse Tracking.
3978 * Ps = 1 0 0 2 -> Use Cell Motion Mouse Tracking.
3979 * Ps = 1 0 0 3 -> Use All Motion Mouse Tracking.
3980 * Ps = 1 0 0 4 -> Send FocusIn/FocusOut events.
3981 * Ps = 1 0 0 5 -> Enable Extended Mouse Mode.
3982 * Ps = 1 0 1 0 -> Scroll to bottom on tty output (rxvt).
3983 * Ps = 1 0 1 1 -> Scroll to bottom on key press (rxvt).
3984 * Ps = 1 0 3 4 -> Interpret "meta" key, sets eighth bit.
3985 * (enables the eightBitInput resource).
3986 * Ps = 1 0 3 5 -> Enable special modifiers for Alt and Num-
3987 * Lock keys. (This enables the numLock resource).
3988 * Ps = 1 0 3 6 -> Send ESC when Meta modifies a key. (This
3989 * enables the metaSendsEscape resource).
3990 * Ps = 1 0 3 7 -> Send DEL from the editing-keypad Delete
3992 * Ps = 1 0 3 9 -> Send ESC when Alt modifies a key. (This
3993 * enables the altSendsEscape resource).
3994 * Ps = 1 0 4 0 -> Keep selection even if not highlighted.
3995 * (This enables the keepSelection resource).
3996 * Ps = 1 0 4 1 -> Use the CLIPBOARD selection. (This enables
3997 * the selectToClipboard resource).
3998 * Ps = 1 0 4 2 -> Enable Urgency window manager hint when
3999 * Control-G is received. (This enables the bellIsUrgent
4001 * Ps = 1 0 4 3 -> Enable raising of the window when Control-G
4002 * is received. (enables the popOnBell resource).
4003 * Ps = 1 0 4 7 -> Use Alternate Screen Buffer. (This may be
4004 * disabled by the titeInhibit resource).
4005 * Ps = 1 0 4 8 -> Save cursor as in DECSC. (This may be dis-
4006 * abled by the titeInhibit resource).
4007 * Ps = 1 0 4 9 -> Save cursor as in DECSC and use Alternate
4008 * Screen Buffer, clearing it first. (This may be disabled by
4009 * the titeInhibit resource). This combines the effects of the 1
4010 * 0 4 7 and 1 0 4 8 modes. Use this with terminfo-based
4011 * applications rather than the 4 7 mode.
4012 * Ps = 1 0 5 0 -> Set terminfo/termcap function-key mode.
4013 * Ps = 1 0 5 1 -> Set Sun function-key mode.
4014 * Ps = 1 0 5 2 -> Set HP function-key mode.
4015 * Ps = 1 0 5 3 -> Set SCO function-key mode.
4016 * Ps = 1 0 6 0 -> Set legacy keyboard emulation (X11R6).
4017 * Ps = 1 0 6 1 -> Set VT220 keyboard emulation.
4018 * Ps = 2 0 0 4 -> Set bracketed paste mode.
4020 * http: *vt100.net/docs/vt220-rm/chapter4.html
4022 Terminal
.prototype.setMode = function(params
) {
4023 if (typeof params
=== 'object') {
4024 var l
= params
.length
4027 for (; i
< l
; i
++) {
4028 this.setMode(params
[i
]);
4037 this.insertMode
= true;
4040 //this.convertEol = true;
4043 } else if (this.prefix
=== '?') {
4046 this.applicationCursor
= true;
4049 this.setgCharset(0, Terminal
.charsets
.US
);
4050 this.setgCharset(1, Terminal
.charsets
.US
);
4051 this.setgCharset(2, Terminal
.charsets
.US
);
4052 this.setgCharset(3, Terminal
.charsets
.US
);
4053 // set VT100 mode here
4055 case 3: // 132 col mode
4056 this.savedCols
= this.cols
;
4057 this.resize(132, this.rows
);
4060 this.originMode
= true;
4063 this.wraparoundMode
= true;
4066 // this.cursorBlink = true;
4069 this.log('Serial port requested application keypad.');
4070 this.applicationKeypad
= true;
4072 case 9: // X10 Mouse
4073 // no release, no motion, no wheel, no modifiers.
4074 case 1000: // vt200 mouse
4076 // no modifiers, except control on the wheel.
4077 case 1002: // button event mouse
4078 case 1003: // any event mouse
4079 // any event - sends motion events,
4080 // even if there is no button held down.
4081 this.x10Mouse
= params
=== 9;
4082 this.vt200Mouse
= params
=== 1000;
4083 this.normalMouse
= params
> 1000;
4084 this.mouseEvents
= true;
4085 this.element
.style
.cursor
= 'default';
4086 this.log('Binding to mouse events.');
4088 case 1004: // send focusin/focusout events
4091 this.sendFocus
= true;
4093 case 1005: // utf8 ext mode mouse
4094 this.utfMouse
= true;
4095 // for wide terminals
4096 // simply encodes large values as utf8 characters
4098 case 1006: // sgr ext mode mouse
4099 this.sgrMouse
= true;
4100 // for wide terminals
4101 // does not add 32 to fields
4102 // press: ^[[<b;x;yM
4103 // release: ^[[<b;x;ym
4105 case 1015: // urxvt ext mode mouse
4106 this.urxvtMouse
= true;
4107 // for wide terminals
4108 // numbers for fields
4110 // motion: ^[[b;x;yT
4112 case 25: // show cursor
4113 this.cursorHidden
= false;
4115 case 1049: // alt screen buffer cursor
4116 //this.saveCursor();
4118 case 47: // alt screen buffer
4119 case 1047: // alt screen buffer
4127 scrollTop
: this.scrollTop
,
4128 scrollBottom
: this.scrollBottom
,
4130 // XXX save charset(s) here?
4131 // charset: this.charset,
4132 // glevel: this.glevel,
4133 // charsets: this.charsets
4136 this.normal
= normal
;
4145 * CSI Pm l Reset Mode (RM).
4146 * Ps = 2 -> Keyboard Action Mode (AM).
4147 * Ps = 4 -> Replace Mode (IRM).
4148 * Ps = 1 2 -> Send/receive (SRM).
4149 * Ps = 2 0 -> Normal Linefeed (LNM).
4151 * DEC Private Mode Reset (DECRST).
4152 * Ps = 1 -> Normal Cursor Keys (DECCKM).
4153 * Ps = 2 -> Designate VT52 mode (DECANM).
4154 * Ps = 3 -> 80 Column Mode (DECCOLM).
4155 * Ps = 4 -> Jump (Fast) Scroll (DECSCLM).
4156 * Ps = 5 -> Normal Video (DECSCNM).
4157 * Ps = 6 -> Normal Cursor Mode (DECOM).
4158 * Ps = 7 -> No Wraparound Mode (DECAWM).
4159 * Ps = 8 -> No Auto-repeat Keys (DECARM).
4160 * Ps = 9 -> Don't send Mouse X & Y on button press.
4161 * Ps = 1 0 -> Hide toolbar (rxvt).
4162 * Ps = 1 2 -> Stop Blinking Cursor (att610).
4163 * Ps = 1 8 -> Don't print form feed (DECPFF).
4164 * Ps = 1 9 -> Limit print to scrolling region (DECPEX).
4165 * Ps = 2 5 -> Hide Cursor (DECTCEM).
4166 * Ps = 3 0 -> Don't show scrollbar (rxvt).
4167 * Ps = 3 5 -> Disable font-shifting functions (rxvt).
4168 * Ps = 4 0 -> Disallow 80 -> 132 Mode.
4169 * Ps = 4 1 -> No more(1) fix (see curses resource).
4170 * Ps = 4 2 -> Disable Nation Replacement Character sets (DEC-
4172 * Ps = 4 4 -> Turn Off Margin Bell.
4173 * Ps = 4 5 -> No Reverse-wraparound Mode.
4174 * Ps = 4 6 -> Stop Logging. (This is normally disabled by a
4175 * compile-time option).
4176 * Ps = 4 7 -> Use Normal Screen Buffer.
4177 * Ps = 6 6 -> Numeric keypad (DECNKM).
4178 * Ps = 6 7 -> Backarrow key sends delete (DECBKM).
4179 * Ps = 1 0 0 0 -> Don't send Mouse X & Y on button press and
4180 * release. See the section Mouse Tracking.
4181 * Ps = 1 0 0 1 -> Don't use Hilite Mouse Tracking.
4182 * Ps = 1 0 0 2 -> Don't use Cell Motion Mouse Tracking.
4183 * Ps = 1 0 0 3 -> Don't use All Motion Mouse Tracking.
4184 * Ps = 1 0 0 4 -> Don't send FocusIn/FocusOut events.
4185 * Ps = 1 0 0 5 -> Disable Extended Mouse Mode.
4186 * Ps = 1 0 1 0 -> Don't scroll to bottom on tty output
4188 * Ps = 1 0 1 1 -> Don't scroll to bottom on key press (rxvt).
4189 * Ps = 1 0 3 4 -> Don't interpret "meta" key. (This disables
4190 * the eightBitInput resource).
4191 * Ps = 1 0 3 5 -> Disable special modifiers for Alt and Num-
4192 * Lock keys. (This disables the numLock resource).
4193 * Ps = 1 0 3 6 -> Don't send ESC when Meta modifies a key.
4194 * (This disables the metaSendsEscape resource).
4195 * Ps = 1 0 3 7 -> Send VT220 Remove from the editing-keypad
4197 * Ps = 1 0 3 9 -> Don't send ESC when Alt modifies a key.
4198 * (This disables the altSendsEscape resource).
4199 * Ps = 1 0 4 0 -> Do not keep selection when not highlighted.
4200 * (This disables the keepSelection resource).
4201 * Ps = 1 0 4 1 -> Use the PRIMARY selection. (This disables
4202 * the selectToClipboard resource).
4203 * Ps = 1 0 4 2 -> Disable Urgency window manager hint when
4204 * Control-G is received. (This disables the bellIsUrgent
4206 * Ps = 1 0 4 3 -> Disable raising of the window when Control-
4207 * G is received. (This disables the popOnBell resource).
4208 * Ps = 1 0 4 7 -> Use Normal Screen Buffer, clearing screen
4209 * first if in the Alternate Screen. (This may be disabled by
4210 * the titeInhibit resource).
4211 * Ps = 1 0 4 8 -> Restore cursor as in DECRC. (This may be
4212 * disabled by the titeInhibit resource).
4213 * Ps = 1 0 4 9 -> Use Normal Screen Buffer and restore cursor
4214 * as in DECRC. (This may be disabled by the titeInhibit
4215 * resource). This combines the effects of the 1 0 4 7 and 1 0
4216 * 4 8 modes. Use this with terminfo-based applications rather
4217 * than the 4 7 mode.
4218 * Ps = 1 0 5 0 -> Reset terminfo/termcap function-key mode.
4219 * Ps = 1 0 5 1 -> Reset Sun function-key mode.
4220 * Ps = 1 0 5 2 -> Reset HP function-key mode.
4221 * Ps = 1 0 5 3 -> Reset SCO function-key mode.
4222 * Ps = 1 0 6 0 -> Reset legacy keyboard emulation (X11R6).
4223 * Ps = 1 0 6 1 -> Reset keyboard emulation to Sun/PC style.
4224 * Ps = 2 0 0 4 -> Reset bracketed paste mode.
4226 Terminal
.prototype.resetMode = function(params
) {
4227 if (typeof params
=== 'object') {
4228 var l
= params
.length
4231 for (; i
< l
; i
++) {
4232 this.resetMode(params
[i
]);
4241 this.insertMode
= false;
4244 //this.convertEol = false;
4247 } else if (this.prefix
=== '?') {
4250 this.applicationCursor
= false;
4253 if (this.cols
=== 132 && this.savedCols
) {
4254 this.resize(this.savedCols
, this.rows
);
4256 delete this.savedCols
;
4259 this.originMode
= false;
4262 this.wraparoundMode
= false;
4265 // this.cursorBlink = false;
4268 this.log('Switching back to normal keypad.');
4269 this.applicationKeypad
= false;
4271 case 9: // X10 Mouse
4272 case 1000: // vt200 mouse
4273 case 1002: // button event mouse
4274 case 1003: // any event mouse
4275 this.x10Mouse
= false;
4276 this.vt200Mouse
= false;
4277 this.normalMouse
= false;
4278 this.mouseEvents
= false;
4279 this.element
.style
.cursor
= '';
4281 case 1004: // send focusin/focusout events
4282 this.sendFocus
= false;
4284 case 1005: // utf8 ext mode mouse
4285 this.utfMouse
= false;
4287 case 1006: // sgr ext mode mouse
4288 this.sgrMouse
= false;
4290 case 1015: // urxvt ext mode mouse
4291 this.urxvtMouse
= false;
4293 case 25: // hide cursor
4294 this.cursorHidden
= true;
4296 case 1049: // alt screen buffer cursor
4298 case 47: // normal screen buffer
4299 case 1047: // normal screen buffer - clearing it first
4301 this.lines
= this.normal
.lines
;
4302 this.ybase
= this.normal
.ybase
;
4303 this.ydisp
= this.normal
.ydisp
;
4304 this.x
= this.normal
.x
;
4305 this.y
= this.normal
.y
;
4306 this.scrollTop
= this.normal
.scrollTop
;
4307 this.scrollBottom
= this.normal
.scrollBottom
;
4308 this.tabs
= this.normal
.tabs
;
4310 // if (params === 1049) {
4311 // this.x = this.savedX;
4312 // this.y = this.savedY;
4314 this.refresh(0, this.rows
- 1);
4325 * Set Scrolling Region [top;bottom] (default = full size of win-
4329 Terminal
.prototype.setScrollRegion = function(params
) {
4330 if (this.prefix
) return;
4331 this.scrollTop
= (params
[0] || 1) - 1;
4332 this.scrollBottom
= (params
[1] || this.rows
) - 1;
4340 * Save cursor (ANSI.SYS).
4342 Terminal
.prototype.saveCursor = function(params
) {
4343 this.savedX
= this.x
;
4344 this.savedY
= this.y
;
4350 * Restore cursor (ANSI.SYS).
4352 Terminal
.prototype.restoreCursor = function(params
) {
4353 this.x
= this.savedX
|| 0;
4354 this.y
= this.savedY
|| 0;
4364 * Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
4366 Terminal
.prototype.cursorForwardTab = function(params
) {
4367 var param
= params
[0] || 1;
4369 this.x
= this.nextStop();
4375 * CSI Ps S Scroll up Ps lines (default = 1) (SU).
4377 Terminal
.prototype.scrollUp = function(params
) {
4378 var param
= params
[0] || 1;
4380 this.lines
.splice(this.ybase
+ this.scrollTop
, 1);
4381 this.lines
.splice(this.ybase
+ this.scrollBottom
, 0, this.blankLine());
4384 this.updateRange(this.scrollTop
);
4385 this.updateRange(this.scrollBottom
);
4390 * CSI Ps T Scroll down Ps lines (default = 1) (SD).
4392 Terminal
.prototype.scrollDown = function(params
) {
4393 var param
= params
[0] || 1;
4395 this.lines
.splice(this.ybase
+ this.scrollBottom
, 1);
4396 this.lines
.splice(this.ybase
+ this.scrollTop
, 0, this.blankLine());
4399 this.updateRange(this.scrollTop
);
4400 this.updateRange(this.scrollBottom
);
4405 * CSI Ps ; Ps ; Ps ; Ps ; Ps T
4406 * Initiate highlight mouse tracking. Parameters are
4407 * [func;startx;starty;firstrow;lastrow]. See the section Mouse
4410 Terminal
.prototype.initMouseTracking = function(params
) {
4411 // Relevant: DECSET 1001
4417 * Reset one or more features of the title modes to the default
4418 * value. Normally, "reset" disables the feature. It is possi-
4419 * ble to disable the ability to reset features by compiling a
4420 * different default for the title modes into xterm.
4421 * Ps = 0 -> Do not set window/icon labels using hexadecimal.
4422 * Ps = 1 -> Do not query window/icon labels using hexadeci-
4424 * Ps = 2 -> Do not set window/icon labels using UTF-8.
4425 * Ps = 3 -> Do not query window/icon labels using UTF-8.
4426 * (See discussion of "Title Modes").
4428 Terminal
.prototype.resetTitleModes = function(params
) {
4434 * CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
4436 Terminal
.prototype.cursorBackwardTab = function(params
) {
4437 var param
= params
[0] || 1;
4439 this.x
= this.prevStop();
4445 * CSI Ps b Repeat the preceding graphic character Ps times (REP).
4447 Terminal
.prototype.repeatPrecedingCharacter = function(params
) {
4448 var param
= params
[0] || 1
4449 , line
= this.lines
[this.ybase
+ this.y
]
4450 , ch
= line
[this.x
- 1] || [this.defAttr
, ' ', 1];
4452 while (param
--) line
[this.x
++] = ch
;
4457 * CSI Ps g Tab Clear (TBC).
4458 * Ps = 0 -> Clear Current Column (default).
4459 * Ps = 3 -> Clear All.
4461 * Ps = 2 -> Clear Stops on Line.
4462 * http://vt100.net/annarbor/aaa-ug/section6.html
4464 Terminal
.prototype.tabClear = function(params
) {
4465 var param
= params
[0];
4467 delete this.tabs
[this.x
];
4468 } else if (param
=== 3) {
4475 * CSI Pm i Media Copy (MC).
4476 * Ps = 0 -> Print screen (default).
4477 * Ps = 4 -> Turn off printer controller mode.
4478 * Ps = 5 -> Turn on printer controller mode.
4480 * Media Copy (MC, DEC-specific).
4481 * Ps = 1 -> Print line containing cursor.
4482 * Ps = 4 -> Turn off autoprint mode.
4483 * Ps = 5 -> Turn on autoprint mode.
4484 * Ps = 1 0 -> Print composed display, ignores DECPEX.
4485 * Ps = 1 1 -> Print all pages.
4487 Terminal
.prototype.mediaCopy = function(params
) {
4494 * Set or reset resource-values used by xterm to decide whether
4495 * to construct escape sequences holding information about the
4496 * modifiers pressed with a given key. The first parameter iden-
4497 * tifies the resource to set/reset. The second parameter is the
4498 * value to assign to the resource. If the second parameter is
4499 * omitted, the resource is reset to its initial value.
4500 * Ps = 1 -> modifyCursorKeys.
4501 * Ps = 2 -> modifyFunctionKeys.
4502 * Ps = 4 -> modifyOtherKeys.
4503 * If no parameters are given, all resources are reset to their
4506 Terminal
.prototype.setResources = function(params
) {
4513 * Disable modifiers which may be enabled via the CSI > Ps; Ps m
4514 * sequence. This corresponds to a resource value of "-1", which
4515 * cannot be set with the other sequence. The parameter identi-
4516 * fies the resource to be disabled:
4517 * Ps = 1 -> modifyCursorKeys.
4518 * Ps = 2 -> modifyFunctionKeys.
4519 * Ps = 4 -> modifyOtherKeys.
4520 * If the parameter is omitted, modifyFunctionKeys is disabled.
4521 * When modifyFunctionKeys is disabled, xterm uses the modifier
4522 * keys to make an extended sequence of functions rather than
4523 * adding a parameter to each function key to denote the modi-
4526 Terminal
.prototype.disableModifiers = function(params
) {
4533 * Set resource value pointerMode. This is used by xterm to
4534 * decide whether to hide the pointer cursor as the user types.
4535 * Valid values for the parameter:
4536 * Ps = 0 -> never hide the pointer.
4537 * Ps = 1 -> hide if the mouse tracking mode is not enabled.
4538 * Ps = 2 -> always hide the pointer. If no parameter is
4539 * given, xterm uses the default, which is 1 .
4541 Terminal
.prototype.setPointerMode = function(params
) {
4547 * CSI ! p Soft terminal reset (DECSTR).
4548 * http://vt100.net/docs/vt220-rm/table4-10.html
4550 Terminal
.prototype.softReset = function(params
) {
4551 this.cursorHidden
= false;
4552 this.insertMode
= false;
4553 this.originMode
= false;
4554 this.wraparoundMode
= false; // autowrap
4555 this.applicationKeypad
= false; // ?
4556 this.applicationCursor
= false;
4558 this.scrollBottom
= this.rows
- 1;
4559 this.curAttr
= this.defAttr
;
4560 this.x
= this.y
= 0; // ?
4561 this.charset
= null;
4562 this.glevel
= 0; // ??
4563 this.charsets
= [null]; // ??
4569 * Request ANSI mode (DECRQM). For VT300 and up, reply is
4571 * where Ps is the mode number as in RM, and Pm is the mode
4573 * 0 - not recognized
4576 * 3 - permanently set
4577 * 4 - permanently reset
4579 Terminal
.prototype.requestAnsiMode = function(params
) {
4586 * Request DEC private mode (DECRQM). For VT300 and up, reply is
4588 * where Ps is the mode number as in DECSET, Pm is the mode value
4589 * as in the ANSI DECRQM.
4591 Terminal
.prototype.requestPrivateMode = function(params
) {
4598 * Set conformance level (DECSCL). Valid values for the first
4600 * Ps = 6 1 -> VT100.
4601 * Ps = 6 2 -> VT200.
4602 * Ps = 6 3 -> VT300.
4603 * Valid values for the second parameter:
4604 * Ps = 0 -> 8-bit controls.
4605 * Ps = 1 -> 7-bit controls (always set for VT100).
4606 * Ps = 2 -> 8-bit controls.
4608 Terminal
.prototype.setConformanceLevel = function(params
) {
4614 * CSI Ps q Load LEDs (DECLL).
4615 * Ps = 0 -> Clear all LEDS (default).
4616 * Ps = 1 -> Light Num Lock.
4617 * Ps = 2 -> Light Caps Lock.
4618 * Ps = 3 -> Light Scroll Lock.
4619 * Ps = 2 1 -> Extinguish Num Lock.
4620 * Ps = 2 2 -> Extinguish Caps Lock.
4621 * Ps = 2 3 -> Extinguish Scroll Lock.
4623 Terminal
.prototype.loadLEDs = function(params
) {
4630 * Set cursor style (DECSCUSR, VT520).
4631 * Ps = 0 -> blinking block.
4632 * Ps = 1 -> blinking block (default).
4633 * Ps = 2 -> steady block.
4634 * Ps = 3 -> blinking underline.
4635 * Ps = 4 -> steady underline.
4637 Terminal
.prototype.setCursorStyle = function(params
) {
4644 * Select character protection attribute (DECSCA). Valid values
4645 * for the parameter:
4646 * Ps = 0 -> DECSED and DECSEL can erase (default).
4647 * Ps = 1 -> DECSED and DECSEL cannot erase.
4648 * Ps = 2 -> DECSED and DECSEL can erase.
4650 Terminal
.prototype.setCharProtectionAttr = function(params
) {
4657 * Restore DEC Private Mode Values. The value of Ps previously
4658 * saved is restored. Ps values are the same as for DECSET.
4660 Terminal
.prototype.restorePrivateValues = function(params
) {
4666 * CSI Pt; Pl; Pb; Pr; Ps$ r
4667 * Change Attributes in Rectangular Area (DECCARA), VT400 and up.
4668 * Pt; Pl; Pb; Pr denotes the rectangle.
4669 * Ps denotes the SGR attributes to change: 0, 1, 4, 5, 7.
4670 * NOTE: xterm doesn't enable this code by default.
4672 Terminal
.prototype.setAttrInRectangle = function(params
) {
4682 for (; t
< b
+ 1; t
++) {
4683 line
= this.lines
[this.ybase
+ t
];
4684 for (i
= l
; i
< r
; i
++) {
4685 line
[i
] = [attr
, line
[i
][1]];
4690 this.updateRange(params
[0]);
4691 this.updateRange(params
[2]);
4696 * CSI Pc; Pt; Pl; Pb; Pr$ x
4697 * Fill Rectangular Area (DECFRA), VT420 and up.
4698 * Pc is the character to use.
4699 * Pt; Pl; Pb; Pr denotes the rectangle.
4700 * NOTE: xterm doesn't enable this code by default.
4702 Terminal
.prototype.fillRectangle = function(params
) {
4712 for (; t
< b
+ 1; t
++) {
4713 line
= this.lines
[this.ybase
+ t
];
4714 for (i
= l
; i
< r
; i
++) {
4715 line
[i
] = [line
[i
][0], String
.fromCharCode(ch
)];
4720 this.updateRange(params
[1]);
4721 this.updateRange(params
[3]);
4727 * Enable Locator Reporting (DECELR).
4728 * Valid values for the first parameter:
4729 * Ps = 0 -> Locator disabled (default).
4730 * Ps = 1 -> Locator enabled.
4731 * Ps = 2 -> Locator enabled for one report, then disabled.
4732 * The second parameter specifies the coordinate unit for locator
4734 * Valid values for the second parameter:
4735 * Pu = 0 <- or omitted -> default to character cells.
4736 * Pu = 1 <- device physical pixels.
4737 * Pu = 2 <- character cells.
4739 Terminal
.prototype.enableLocatorReporting = function(params
) {
4740 var val
= params
[0] > 0;
4741 //this.mouseEvents = val;
4742 //this.decLocator = val;
4747 * CSI Pt; Pl; Pb; Pr$ z
4748 * Erase Rectangular Area (DECERA), VT400 and up.
4749 * Pt; Pl; Pb; Pr denotes the rectangle.
4750 * NOTE: xterm doesn't enable this code by default.
4752 Terminal
.prototype.eraseRectangle = function(params
) {
4762 ch
= [this.eraseAttr(), ' ', 1]; // xterm?
4764 for (; t
< b
+ 1; t
++) {
4765 line
= this.lines
[this.ybase
+ t
];
4766 for (i
= l
; i
< r
; i
++) {
4772 this.updateRange(params
[0]);
4773 this.updateRange(params
[2]);
4779 * Insert P s Column(s) (default = 1) (DECIC), VT420 and up.
4780 * NOTE: xterm doesn't enable this code by default.
4782 Terminal
.prototype.insertColumns = function() {
4783 var param
= params
[0]
4784 , l
= this.ybase
+ this.rows
4785 , ch
= [this.eraseAttr(), ' ', 1] // xterm?
4789 for (i
= this.ybase
; i
< l
; i
++) {
4790 this.lines
[i
].splice(this.x
+ 1, 0, ch
);
4791 this.lines
[i
].pop();
4801 * Delete P s Column(s) (default = 1) (DECDC), VT420 and up
4802 * NOTE: xterm doesn't enable this code by default.
4804 Terminal
.prototype.deleteColumns = function() {
4805 var param
= params
[0]
4806 , l
= this.ybase
+ this.rows
4807 , ch
= [this.eraseAttr(), ' ', 1] // xterm?
4811 for (i
= this.ybase
; i
< l
; i
++) {
4812 this.lines
[i
].splice(this.x
, 1);
4813 this.lines
[i
].push(ch
);
4824 Terminal
.charsets
= {};
4826 // DEC Special Character and Line Drawing Set.
4827 // http://vt100.net/docs/vt102-ug/table5-13.html
4828 // A lot of curses apps use this if they see TERM=xterm.
4829 // testing: echo -e '\e(0a\e(B'
4830 // The xterm output sometimes seems to conflict with the
4831 // reference above. xterm seems in line with the reference
4832 // when running vttest however.
4833 // The table below now uses xterm's output from vttest.
4834 Terminal
.charsets
.SCLD
= { // (0
4835 '`': '\u25c6', // '◆'
4836 'a': '\u2592', // '▒'
4837 'b': '\u0009', // '\t'
4838 'c': '\u000c', // '\f'
4839 'd': '\u000d', // '\r'
4840 'e': '\u000a', // '\n'
4841 'f': '\u00b0', // '°'
4842 'g': '\u00b1', // '±'
4843 'h': '\u2424', // '\u2424' (NL)
4844 'i': '\u000b', // '\v'
4845 'j': '\u2518', // '┘'
4846 'k': '\u2510', // '┐'
4847 'l': '\u250c', // '┌'
4848 'm': '\u2514', // '└'
4849 'n': '\u253c', // '┼'
4850 'o': '\u23ba', // '⎺'
4851 'p': '\u23bb', // '⎻'
4852 'q': '\u2500', // '─'
4853 'r': '\u23bc', // '⎼'
4854 's': '\u23bd', // '⎽'
4855 't': '\u251c', // '├'
4856 'u': '\u2524', // '┤'
4857 'v': '\u2534', // '┴'
4858 'w': '\u252c', // '┬'
4859 'x': '\u2502', // '│'
4860 'y': '\u2264', // '≤'
4861 'z': '\u2265', // '≥'
4862 '{': '\u03c0', // 'π'
4863 '|': '\u2260', // '≠'
4864 '}': '\u00a3', // '£'
4865 '~': '\u00b7' // '·'
4868 Terminal
.charsets
.UK
= null; // (A
4869 Terminal
.charsets
.US
= null; // (B (USASCII)
4870 Terminal
.charsets
.Dutch
= null; // (4
4871 Terminal
.charsets
.Finnish
= null; // (C or (5
4872 Terminal
.charsets
.French
= null; // (R
4873 Terminal
.charsets
.FrenchCanadian
= null; // (Q
4874 Terminal
.charsets
.German
= null; // (K
4875 Terminal
.charsets
.Italian
= null; // (Y
4876 Terminal
.charsets
.NorwegianDanish
= null; // (E or (6
4877 Terminal
.charsets
.Spanish
= null; // (Z
4878 Terminal
.charsets
.Swedish
= null; // (H or (7
4879 Terminal
.charsets
.Swiss
= null; // (=
4880 Terminal
.charsets
.ISOLatin
= null; // /A
4886 function contains(el
, arr
) {
4887 for (var i
= 0; i
< arr
.length
; i
+= 1) {
4888 if (el
=== arr
[i
]) {
4895 function on(el
, type
, handler
, capture
) {
4896 if (!Array
.isArray(el
)) {
4899 el
.forEach(function (element
) {
4900 element
.addEventListener(type
, handler
, capture
|| false);
4904 function off(el
, type
, handler
, capture
) {
4905 el
.removeEventListener(type
, handler
, capture
|| false);
4908 function cancel(ev
, force
) {
4909 if (!this.cancelEvents
&& !force
) {
4912 ev
.preventDefault();
4913 ev
.stopPropagation();
4917 function inherits(child
, parent
) {
4919 this.constructor = child
;
4921 f
.prototype = parent
.prototype;
4922 child
.prototype = new f
;
4925 // if bold is broken, we can't
4926 // use it in the terminal.
4927 function isBoldBroken(document
) {
4928 var body
= document
.getElementsByTagName('body')[0];
4929 var el
= document
.createElement('span');
4930 el
.innerHTML
= 'hello world';
4931 body
.appendChild(el
);
4932 var w1
= el
.scrollWidth
;
4933 el
.style
.fontWeight
= 'bold';
4934 var w2
= el
.scrollWidth
;
4935 body
.removeChild(el
);
4939 var String
= this.String
;
4940 var setTimeout
= this.setTimeout
;
4941 var setInterval
= this.setInterval
;
4943 function indexOf(obj
, el
) {
4946 if (obj
[i
] === el
) return i
;
4951 function isThirdLevelShift(term
, ev
) {
4953 (term
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) ||
4954 (term
.isMSWindows
&& ev
.altKey
&& ev
.ctrlKey
&& !ev
.metaKey
);
4956 if (ev
.type
== 'keypress') {
4957 return thirdLevelKey
;
4960 // Don't invoke for arrows, pageDown, home, backspace, etc. (on non-keypress events)
4961 return thirdLevelKey
&& (!ev
.keyCode
|| ev
.keyCode
> 47);
4964 function matchColor(r1
, g1
, b1
) {
4965 var hash
= (r1
<< 16) | (g1
<< 8) | b1
;
4967 if (matchColor
._cache
[hash
] != null) {
4968 return matchColor
._cache
[hash
];
4971 var ldiff
= Infinity
4980 for (; i
< Terminal
.vcolors
.length
; i
++) {
4981 c
= Terminal
.vcolors
[i
];
4986 diff
= matchColor
.distance(r1
, g1
, b1
, r2
, g2
, b2
);
4999 return matchColor
._cache
[hash
] = li
;
5002 matchColor
._cache
= {};
5004 // http://stackoverflow.com/questions/1633828
5005 matchColor
.distance = function(r1
, g1
, b1
, r2
, g2
, b2
) {
5006 return Math
.pow(30 * (r1
- r2
), 2)
5007 + Math
.pow(59 * (g1
- g2
), 2)
5008 + Math
.pow(11 * (b1
- b2
), 2);
5011 function each(obj
, iter
, con
) {
5012 if (obj
.forEach
) return obj
.forEach(iter
, con
);
5013 for (var i
= 0; i
< obj
.length
; i
++) {
5014 iter
.call(con
, obj
[i
], i
, obj
);
5018 function keys(obj
) {
5019 if (Object
.keys
) return Object
.keys(obj
);
5022 if (Object
.prototype.hasOwnProperty
.call(obj
, key
)) {
5029 var wcwidth
= (function(opts
) {
5030 // extracted from https://www.cl.cam.ac.uk/%7Emgk25/ucs/wcwidth.c
5031 // combining characters
5033 [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
5034 [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
5035 [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
5036 [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670],
5037 [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED],
5038 [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A],
5039 [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902],
5040 [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D],
5041 [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981],
5042 [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD],
5043 [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C],
5044 [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D],
5045 [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC],
5046 [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD],
5047 [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C],
5048 [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D],
5049 [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0],
5050 [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48],
5051 [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC],
5052 [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD],
5053 [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D],
5054 [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6],
5055 [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E],
5056 [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC],
5057 [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35],
5058 [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E],
5059 [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97],
5060 [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030],
5061 [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039],
5062 [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F],
5063 [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753],
5064 [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD],
5065 [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD],
5066 [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922],
5067 [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B],
5068 [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34],
5069 [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42],
5070 [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF],
5071 [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063],
5072 [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F],
5073 [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B],
5074 [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F],
5075 [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB],
5076 [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F],
5077 [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169],
5078 [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD],
5079 [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F],
5083 function bisearch(ucs
) {
5085 var max
= COMBINING
.length
- 1;
5087 if (ucs
< COMBINING
[0][0] || ucs
> COMBINING
[max
][1])
5089 while (max
>= min
) {
5090 mid
= Math
.floor((min
+ max
) / 2);
5091 if (ucs
> COMBINING
[mid
][1])
5093 else if (ucs
< COMBINING
[mid
][0])
5100 function wcwidth(ucs
) {
5101 // test for 8-bit control characters
5104 if (ucs
< 32 || (ucs
>= 0x7f && ucs
< 0xa0))
5105 return opts
.control
;
5106 // binary search in table of non-spacing characters
5109 // if we arrive here, ucs is not a combining or C0/C1 control character
5114 ucs
<= 0x115f || // Hangul Jamo init. consonants
5117 (ucs
>= 0x2e80 && ucs
<= 0xa4cf && ucs
!= 0x303f) || // CJK..Yi
5118 (ucs
>= 0xac00 && ucs
<= 0xd7a3) || // Hangul Syllables
5119 (ucs
>= 0xf900 && ucs
<= 0xfaff) || // CJK Compat Ideographs
5120 (ucs
>= 0xfe10 && ucs
<= 0xfe19) || // Vertical forms
5121 (ucs
>= 0xfe30 && ucs
<= 0xfe6f) || // CJK Compat Forms
5122 (ucs
>= 0xff00 && ucs
<= 0xff60) || // Fullwidth Forms
5123 (ucs
>= 0xffe0 && ucs
<= 0xffe6) ||
5124 (ucs
>= 0x20000 && ucs
<= 0x2fffd) ||
5125 (ucs
>= 0x30000 && ucs
<= 0x3fffd)
5130 })({nul
: 0, control
: 0}); // configurable options
5136 Terminal
.EventEmitter
= EventEmitter
;
5137 Terminal
.inherits
= inherits
;
5140 * Adds an event listener to the terminal.
5142 * @param {string} event The name of the event. TODO: Document all event types
5143 * @param {function} callback The function to call when the event is triggered.
5147 Terminal
.cancel
= cancel
;