1 (function(f
){if(typeof exports
==="object"&&typeof module
!=="undefined"){module
.exports
=f()}else if(typeof define
==="function"&&define
.amd
){define([],f
)}else{var g
;if(typeof window
!=="undefined"){g
=window
}else if(typeof global
!=="undefined"){g
=global
}else if(typeof self
!=="undefined"){g
=self
}else{g
=this}g
.Terminal
= f()}})(function(){var define
,module
,exports
;return (function e(t
,n
,r
){function s(o
,u
){if(!n
[o
]){if(!t
[o
]){var a
=typeof require
=="function"&&require
;if(!u
&&a
)return a(o
,!0);if(i
)return i(o
,!0);var f
=new Error("Cannot find module '"+o
+"'");throw f
.code
="MODULE_NOT_FOUND",f
}var l
=n
[o
]={exports
:{}};t
[o
][0].call(l
.exports
,function(e
){var n
=t
[o
][1][e
];return s(n
?n
:e
)},l
,l
.exports
,e
,t
,n
,r
)}return n
[o
].exports
}var i
=typeof require
=="function"&&require
;for(var o
=0;o
<r
.length
;o
++)s(r
[o
]);return s
})({1:[function(require
,module
,exports
){
7 * Encapsulates the logic for handling compositionstart, compositionupdate and compositionend
8 * events, displaying the in-progress composition to the UI and forwarding the final composition
11 var CompositionHelper
= (function () {
13 * Creates a new CompositionHelper.
14 * @param textarea The textarea that xterm uses for input.
15 * @param compositionView The element to display the in-progress composition in.
16 * @param terminal The Terminal to forward the finished composition to.
18 function CompositionHelper(textarea
, compositionView
, terminal
) {
19 this.textarea
= textarea
;
20 this.compositionView
= compositionView
;
21 this.terminal
= terminal
;
22 this.isComposing
= false;
23 this.isSendingComposition
= false;
24 this.compositionPosition
= { start
: null, end
: null };
28 * Handles the compositionstart event, activating the composition view.
30 CompositionHelper
.prototype.compositionstart = function () {
31 this.isComposing
= true;
32 this.compositionPosition
.start
= this.textarea
.value
.length
;
33 this.compositionView
.textContent
= '';
34 this.compositionView
.classList
.add('active');
37 * Handles the compositionupdate event, updating the composition view.
38 * @param {CompositionEvent} ev The event.
40 CompositionHelper
.prototype.compositionupdate = function (ev
) {
41 this.compositionView
.textContent
= ev
.data
;
42 this.updateCompositionElements();
44 setTimeout(function () {
45 self
.compositionPosition
.end
= self
.textarea
.value
.length
;
49 * Handles the compositionend event, hiding the composition view and sending the composition to
52 CompositionHelper
.prototype.compositionend = function () {
53 this.finalizeComposition(true);
56 * Handles the keydown event, routing any necessary events to the CompositionHelper functions.
57 * @param ev The keydown event.
58 * @return Whether the Terminal should continue processing the keydown event.
60 CompositionHelper
.prototype.keydown = function (ev
) {
61 if (this.isComposing
|| this.isSendingComposition
) {
62 if (ev
.keyCode
=== 229) {
63 // Continue composing if the keyCode is the "composition character"
66 else if (ev
.keyCode
=== 16 || ev
.keyCode
=== 17 || ev
.keyCode
=== 18) {
67 // Continue composing if the keyCode is a modifier key
71 // Finish composition immediately. This is mainly here for the case where enter is
72 // pressed and the handler needs to be triggered before the command is executed.
73 this.finalizeComposition(false);
76 if (ev
.keyCode
=== 229) {
77 // If the "composition character" is used but gets to this point it means a non-composition
78 // character (eg. numbers and punctuation) was pressed when the IME was active.
79 this.handleAnyTextareaChanges();
85 * Finalizes the composition, resuming regular input actions. This is called when a composition
87 * @param waitForPropogation Whether to wait for events to propogate before sending
88 * the input. This should be false if a non-composition keystroke is entered before the
89 * compositionend event is triggered, such as enter, so that the composition is send before
90 * the command is executed.
92 CompositionHelper
.prototype.finalizeComposition = function (waitForPropogation
) {
93 this.compositionView
.classList
.remove('active');
94 this.isComposing
= false;
95 this.clearTextareaPosition();
96 if (!waitForPropogation
) {
97 // Cancel any delayed composition send requests and send the input immediately.
98 this.isSendingComposition
= false;
99 var input
= this.textarea
.value
.substring(this.compositionPosition
.start
, this.compositionPosition
.end
);
100 this.terminal
.handler(input
);
103 // Make a deep copy of the composition position here as a new compositionstart event may
104 // fire before the setTimeout executes.
105 var currentCompositionPosition
= {
106 start
: this.compositionPosition
.start
,
107 end
: this.compositionPosition
.end
,
109 // Since composition* events happen before the changes take place in the textarea on most
110 // browsers, use a setTimeout with 0ms time to allow the native compositionend event to
111 // complete. This ensures the correct character is retrieved, this solution was used
113 // - The compositionend event's data property is unreliable, at least on Chromium
114 // - The last compositionupdate event's data property does not always accurately describe
115 // the character, a counter example being Korean where an ending consonsant can move to
116 // the following character if the following input is a vowel.
118 this.isSendingComposition
= true;
119 setTimeout(function () {
120 // Ensure that the input has not already been sent
121 if (self
.isSendingComposition
) {
122 self
.isSendingComposition
= false;
124 if (self
.isComposing
) {
125 // Use the end position to get the string if a new composition has started.
126 input
= self
.textarea
.value
.substring(currentCompositionPosition
.start
, currentCompositionPosition
.end
);
129 // Don't use the end position here in order to pick up any characters after the
130 // composition has finished, for example when typing a non-composition character
131 // (eg. 2) after a composition character.
132 input
= self
.textarea
.value
.substring(currentCompositionPosition
.start
);
134 self
.terminal
.handler(input
);
140 * Apply any changes made to the textarea after the current event chain is allowed to complete.
141 * This should be called when not currently composing but a keydown event with the "composition
142 * character" (229) is triggered, in order to allow non-composition text to be entered when an
145 CompositionHelper
.prototype.handleAnyTextareaChanges = function () {
146 var oldValue
= this.textarea
.value
;
148 setTimeout(function () {
149 // Ignore if a composition has started since the timeout
150 if (!self
.isComposing
) {
151 var newValue
= self
.textarea
.value
;
152 var diff
= newValue
.replace(oldValue
, '');
153 if (diff
.length
> 0) {
154 self
.terminal
.handler(diff
);
160 * Positions the composition view on top of the cursor and the textarea just below it (so the
161 * IME helper dialog is positioned correctly).
162 * @param dontRecurse Whether to use setTimeout to recursively trigger another update, this is
163 * necessary as the IME events across browsers are not consistently triggered.
165 CompositionHelper
.prototype.updateCompositionElements = function (dontRecurse
) {
166 if (!this.isComposing
) {
169 var cursor
= this.terminal
.element
.querySelector('.terminal-cursor');
171 // Take .xterm-rows offsetTop into account as well in case it's positioned absolutely within
172 // the .xterm element.
173 var xtermRows
= this.terminal
.element
.querySelector('.xterm-rows');
174 var cursorTop
= xtermRows
.offsetTop
+ cursor
.offsetTop
;
175 this.compositionView
.style
.left
= cursor
.offsetLeft
+ 'px';
176 this.compositionView
.style
.top
= cursorTop
+ 'px';
177 this.compositionView
.style
.height
= cursor
.offsetHeight
+ 'px';
178 this.compositionView
.style
.lineHeight
= cursor
.offsetHeight
+ 'px';
179 // Sync the textarea to the exact position of the composition view so the IME knows where the
181 var compositionViewBounds
= this.compositionView
.getBoundingClientRect();
182 this.textarea
.style
.left
= cursor
.offsetLeft
+ 'px';
183 this.textarea
.style
.top
= cursorTop
+ 'px';
184 this.textarea
.style
.width
= compositionViewBounds
.width
+ 'px';
185 this.textarea
.style
.height
= compositionViewBounds
.height
+ 'px';
186 this.textarea
.style
.lineHeight
= compositionViewBounds
.height
+ 'px';
189 setTimeout(this.updateCompositionElements
.bind(this, true), 0);
194 * Clears the textarea's position so that the cursor does not blink on IE.
197 CompositionHelper
.prototype.clearTextareaPosition = function () {
198 this.textarea
.style
.left
= '';
199 this.textarea
.style
.top
= '';
202 return CompositionHelper
;
204 exports
.CompositionHelper
= CompositionHelper
;
206 },{}],2:[function(require
,module
,exports
){
211 function EventEmitter() {
212 this._events
= this._events
|| {};
214 exports
.EventEmitter
= EventEmitter
;
215 EventEmitter
.prototype.addListener = function (type
, listener
) {
216 this._events
[type
] = this._events
[type
] || [];
217 this._events
[type
].push(listener
);
219 EventEmitter
.prototype.on
= EventEmitter
.prototype.addListener
;
220 EventEmitter
.prototype.removeListener = function (type
, listener
) {
221 if (!this._events
[type
])
223 var obj
= this._events
[type
], i
= obj
.length
;
225 if (obj
[i
] === listener
|| obj
[i
].listener
=== listener
) {
231 EventEmitter
.prototype.off
= EventEmitter
.prototype.removeListener
;
232 EventEmitter
.prototype.removeAllListeners = function (type
) {
233 if (this._events
[type
])
234 delete this._events
[type
];
236 EventEmitter
.prototype.once = function (type
, listener
) {
239 var args
= Array
.prototype.slice
.call(arguments
);
240 this.removeListener(type
, on
);
241 return listener
.apply(this, args
);
243 on
.listener
= listener
;
244 return this.on(type
, on
);
246 EventEmitter
.prototype.emit = function (type
) {
247 if (!this._events
[type
])
249 var args
= Array
.prototype.slice
.call(arguments
, 1), obj
= this._events
[type
], l
= obj
.length
, i
= 0;
251 obj
[i
].apply(this, args
);
254 EventEmitter
.prototype.listeners = function (type
) {
255 return this._events
[type
] = this._events
[type
] || [];
258 },{}],3:[function(require
,module
,exports
){
264 * Represents the viewport of a terminal, the visible area within the larger buffer of output.
265 * Logic for the virtual scroll bar is included in this object.
267 var Viewport
= (function () {
269 * Creates a new Viewport.
270 * @param terminal The terminal this viewport belongs to.
271 * @param viewportElement The DOM element acting as the viewport.
272 * @param scrollArea The DOM element acting as the scroll area.
273 * @param charMeasureElement A DOM element used to measure the character size of. the terminal.
275 function Viewport(terminal
, viewportElement
, scrollArea
, charMeasureElement
) {
276 this.terminal
= terminal
;
277 this.viewportElement
= viewportElement
;
278 this.scrollArea
= scrollArea
;
279 this.charMeasureElement
= charMeasureElement
;
280 this.currentRowHeight
= 0;
281 this.lastRecordedBufferLength
= 0;
282 this.lastRecordedViewportHeight
= 0;
283 this.terminal
.on('scroll', this.syncScrollArea
.bind(this));
284 this.terminal
.on('resize', this.syncScrollArea
.bind(this));
285 this.viewportElement
.addEventListener('scroll', this.onScroll
.bind(this));
286 this.syncScrollArea();
289 * Refreshes row height, setting line-height, viewport height and scroll area height if
291 * @param charSize A character size measurement bounding rect object, if it doesn't exist it will
294 Viewport
.prototype.refresh = function (charSize
) {
295 var size
= charSize
|| this.charMeasureElement
.getBoundingClientRect();
296 if (size
.height
> 0) {
297 var rowHeightChanged
= size
.height
!== this.currentRowHeight
;
298 if (rowHeightChanged
) {
299 this.currentRowHeight
= size
.height
;
300 this.viewportElement
.style
.lineHeight
= size
.height
+ 'px';
301 this.terminal
.rowContainer
.style
.lineHeight
= size
.height
+ 'px';
303 var viewportHeightChanged
= this.lastRecordedViewportHeight
!== this.terminal
.rows
;
304 if (rowHeightChanged
|| viewportHeightChanged
) {
305 this.lastRecordedViewportHeight
= this.terminal
.rows
;
306 this.viewportElement
.style
.height
= size
.height
* this.terminal
.rows
+ 'px';
308 this.scrollArea
.style
.height
= (size
.height
* this.lastRecordedBufferLength
) + 'px';
312 * Updates dimensions and synchronizes the scroll area if necessary.
314 Viewport
.prototype.syncScrollArea = function () {
315 if (this.lastRecordedBufferLength
!== this.terminal
.lines
.length
) {
316 // If buffer height changed
317 this.lastRecordedBufferLength
= this.terminal
.lines
.length
;
320 else if (this.lastRecordedViewportHeight
!== this.terminal
.rows
) {
321 // If viewport height changed
325 // If size has changed, refresh viewport
326 var size
= this.charMeasureElement
.getBoundingClientRect();
327 if (size
.height
!== this.currentRowHeight
) {
332 var scrollTop
= this.terminal
.ydisp
* this.currentRowHeight
;
333 if (this.viewportElement
.scrollTop
!== scrollTop
) {
334 this.viewportElement
.scrollTop
= scrollTop
;
338 * Handles scroll events on the viewport, calculating the new viewport and requesting the
339 * terminal to scroll to it.
340 * @param ev The scroll event.
342 Viewport
.prototype.onScroll = function (ev
) {
343 var newRow
= Math
.round(this.viewportElement
.scrollTop
/ this.currentRowHeight
);
344 var diff
= newRow
- this.terminal
.ydisp
;
345 this.terminal
.scrollDisp(diff
, true);
348 * Handles mouse wheel events by adjusting the viewport's scrollTop and delegating the actual
349 * scrolling to `onScroll`, this event needs to be attached manually by the consumer of
351 * @param ev The mouse wheel event.
353 Viewport
.prototype.onWheel = function (ev
) {
354 if (ev
.deltaY
=== 0) {
355 // Do nothing if it's not a vertical scroll event
358 // Fallback to WheelEvent.DOM_DELTA_PIXEL
360 if (ev
.deltaMode
=== WheelEvent
.DOM_DELTA_LINE
) {
361 multiplier
= this.currentRowHeight
;
363 else if (ev
.deltaMode
=== WheelEvent
.DOM_DELTA_PAGE
) {
364 multiplier
= this.currentRowHeight
* this.terminal
.rows
;
366 this.viewportElement
.scrollTop
+= ev
.deltaY
* multiplier
;
367 // Prevent the page from scrolling when the terminal scrolls
373 exports
.Viewport
= Viewport
;
375 },{}],4:[function(require
,module
,exports
){
377 * Clipboard handler module: exports methods for handling all clipboard-related events in the
379 * @module xterm/handlers/Clipboard
384 * Prepares text copied from terminal selection, to be saved in the clipboard by:
385 * 1. stripping all trailing white spaces
386 * 2. converting all non-breaking spaces to regular spaces
387 * @param {string} text The copied text that needs processing for storing in clipboard
390 function prepareTextForClipboard(text
) {
391 var space
= String
.fromCharCode(32), nonBreakingSpace
= String
.fromCharCode(160), allNonBreakingSpaces
= new RegExp(nonBreakingSpace
, 'g'), processedText
= text
.split('\n').map(function (line
) {
392 // Strip all trailing white spaces and convert all non-breaking spaces
393 // to regular spaces.
394 var processedLine
= line
.replace(/\s+$/g, '').replace(allNonBreakingSpaces
, space
);
395 return processedLine
;
397 return processedText
;
399 exports
.prepareTextForClipboard
= prepareTextForClipboard
;
401 * Binds copy functionality to the given terminal.
402 * @param {ClipboardEvent} ev The original copy event to be handled
404 function copyHandler(ev
, term
) {
405 // We cast `window` to `any` type, because TypeScript has not declared the `clipboardData`
406 // property that we use below for Internet Explorer.
407 var copiedText
= window
.getSelection().toString(), text
= prepareTextForClipboard(copiedText
);
408 if (term
.browser
.isMSIE
) {
409 window
.clipboardData
.setData('Text', text
);
412 ev
.clipboardData
.setData('text/plain', text
);
414 ev
.preventDefault(); // Prevent or the original text will be copied.
416 exports
.copyHandler
= copyHandler
;
418 * Redirect the clipboard's data to the terminal's input handler.
419 * @param {ClipboardEvent} ev The original paste event to be handled
420 * @param {Terminal} term The terminal on which to apply the handled paste event
422 function pasteHandler(ev
, term
) {
423 ev
.stopPropagation();
425 var dispatchPaste = function (text
) {
427 term
.textarea
.value
= '';
428 return term
.cancel(ev
);
430 if (term
.browser
.isMSIE
) {
431 if (window
.clipboardData
) {
432 text
= window
.clipboardData
.getData('Text');
437 if (ev
.clipboardData
) {
438 text
= ev
.clipboardData
.getData('text/plain');
443 exports
.pasteHandler
= pasteHandler
;
445 * Bind to right-click event and allow right-click copy and paste.
448 * If text is selected and right-click happens on selected text, then
449 * do nothing to allow seamless copying.
450 * If no text is selected or right-click is outside of the selection
451 * area, then bring the terminal's input below the cursor, in order to
452 * trigger the event on the textarea and allow-right click paste, without
453 * caring about disappearing selection.
454 * @param {MouseEvent} ev The original right click event to be handled
455 * @param {Terminal} term The terminal on which to apply the handled paste event
457 function rightClickHandler(ev
, term
) {
458 var s
= document
.getSelection(), selectedText
= prepareTextForClipboard(s
.toString()), clickIsOnSelection
= false, x
= ev
.clientX
, y
= ev
.clientY
;
460 var r
= s
.getRangeAt(0), cr
= r
.getClientRects();
461 for (var i
= 0; i
< cr
.length
; i
++) {
463 clickIsOnSelection
= ((x
> rect
.left
) && (x
< rect
.right
) &&
464 (y
> rect
.top
) && (y
< rect
.bottom
));
465 if (clickIsOnSelection
) {
469 // If we clicked on selection and selection is not a single space,
470 // then mark the right click as copy-only. We check for the single
471 // space selection, as this can happen when clicking on an
472 // and there is not much pointing in copying a single space.
473 if (selectedText
.match(/^\s$/) || !selectedText
.length
) {
474 clickIsOnSelection
= false;
477 // Bring textarea at the cursor position
478 if (!clickIsOnSelection
) {
479 term
.textarea
.style
.position
= 'fixed';
480 term
.textarea
.style
.width
= '20px';
481 term
.textarea
.style
.height
= '20px';
482 term
.textarea
.style
.left
= (x
- 10) + 'px';
483 term
.textarea
.style
.top
= (y
- 10) + 'px';
484 term
.textarea
.style
.zIndex
= '1000';
485 term
.textarea
.focus();
486 // Reset the terminal textarea's styling
487 setTimeout(function () {
488 term
.textarea
.style
.position
= null;
489 term
.textarea
.style
.width
= null;
490 term
.textarea
.style
.height
= null;
491 term
.textarea
.style
.left
= null;
492 term
.textarea
.style
.top
= null;
493 term
.textarea
.style
.zIndex
= null;
497 exports
.rightClickHandler
= rightClickHandler
;
499 },{}],5:[function(require
,module
,exports
){
501 * Attributes and methods to help with identifying the current browser and platform.
502 * @module xterm/utils/Browser
506 var Generic_js_1
= require('./Generic.js');
507 var isNode
= (typeof navigator
== 'undefined') ? true : false;
508 var userAgent
= (isNode
) ? 'node' : navigator
.userAgent
;
509 var platform
= (isNode
) ? 'node' : navigator
.platform
;
510 exports
.isFirefox
= !!~userAgent
.indexOf('Firefox');
511 exports
.isMSIE
= !!~userAgent
.indexOf('MSIE') || !!~userAgent
.indexOf('Trident');
512 // Find the users platform. We use this to interpret the meta key
513 // and ISO third level shifts.
514 // http://stackoverflow.com/q/19877924/577598
515 exports
.isMac
= Generic_js_1
.contains(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], platform
);
516 exports
.isIpad
= platform
=== 'iPad';
517 exports
.isIphone
= platform
=== 'iPhone';
518 exports
.isMSWindows
= Generic_js_1
.contains(['Windows', 'Win16', 'Win32', 'WinCE'], platform
);
520 },{"./Generic.js":6}],6:[function(require
,module
,exports
){
522 * Generic utilities module with methods that can be helpful at different parts of the code base.
523 * @module xterm/utils/Generic
528 * Return if the given array contains the given element
529 * @param {Array} array The array to search for the given element.
530 * @param {Object} el The element to look for into the array
532 exports
.contains = function (arr
, el
) {
533 return arr
.indexOf(el
) >= 0;
536 },{}],7:[function(require
,module
,exports
){
538 * xterm.js: xterm, in the browser
539 * Originally forked from (with the author's permission):
540 * Fabrice Bellard's javascript vt100 for jslinux:
541 * http://bellard.org/jslinux/
542 * Copyright (c) 2011 Fabrice Bellard
543 * The original design remains. The terminal itself
544 * has been extended to include xterm CSI codes, among
549 var CompositionHelper_js_1
= require('./CompositionHelper.js');
550 var EventEmitter_js_1
= require('./EventEmitter.js');
551 var Viewport_js_1
= require('./Viewport.js');
552 var Clipboard_js_1
= require('./handlers/Clipboard.js');
553 var Browser
= require('./utils/Browser');
555 * Terminal Emulation References:
557 * http://invisible-island.net/xterm/ctlseqs/ctlseqs.txt
558 * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
559 * http://invisible-island.net/vttest/
560 * http://www.inwap.com/pdp10/ansicode.txt
561 * http://linux.die.net/man/4/console_codes
562 * http://linux.die.net/man/7/urxvt
564 // Let it work inside Node.js for automated testing purposes.
565 var document
= (typeof window
!= 'undefined') ? window
.document
: null;
569 var normal
= 0, escaped
= 1, csi
= 2, osc
= 3, charset
= 4, dcs
= 5, ignore
= 6;
574 * Creates a new `Terminal` object.
576 * @param {object} options An object containing a set of options, the available options are:
577 * - `cursorBlink` (boolean): Whether the terminal cursor blinks
578 * - `cols` (number): The number of columns of the terminal (horizontal size)
579 * - `rows` (number): The number of rows of the terminal (vertical size)
583 * @alias module:xterm/src/xterm
585 function Terminal(options
) {
587 if (!(this instanceof Terminal
)) {
588 return new Terminal(arguments
[0], arguments
[1], arguments
[2]);
590 self
.browser
= Browser
;
591 self
.cancel
= Terminal
.cancel
;
592 EventEmitter_js_1
.EventEmitter
.call(this);
593 if (typeof options
=== 'number') {
597 handler
: arguments
[2]
600 options
= options
|| {};
601 Object
.keys(Terminal
.defaults
).forEach(function (key
) {
602 if (options
[key
] == null) {
603 options
[key
] = Terminal
.options
[key
];
604 if (Terminal
[key
] !== Terminal
.defaults
[key
]) {
605 options
[key
] = Terminal
[key
];
608 self
[key
] = options
[key
];
610 if (options
.colors
.length
=== 8) {
611 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(8));
613 else if (options
.colors
.length
=== 16) {
614 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16));
616 else if (options
.colors
.length
=== 10) {
617 options
.colors
= options
.colors
.slice(0, -2).concat(Terminal
._colors
.slice(8, -2), options
.colors
.slice(-2));
619 else if (options
.colors
.length
=== 18) {
620 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16, -2), options
.colors
.slice(-2));
622 this.colors
= options
.colors
;
623 this.options
= options
;
624 // this.context = options.context || window;
625 // this.document = options.document || document;
626 this.parent
= options
.body
|| options
.parent
|| (document
? document
.getElementsByTagName('body')[0] : null);
627 this.cols
= options
.cols
|| options
.geometry
[0];
628 this.rows
= options
.rows
|| options
.geometry
[1];
629 this.geometry
= [this.cols
, this.rows
];
630 if (options
.handler
) {
631 this.on('data', options
.handler
);
634 * The scroll position of the y cursor, ie. ybase + y = the y position within the entire
639 * The scroll position of the viewport
643 * The cursor's x position after ybase
647 * The cursor's y position after ybase
651 * Used to debounce the refresh function
653 this.isRefreshing
= false;
655 * Whether there is a full terminal refresh queued
657 this.cursorState
= 0;
658 this.cursorHidden
= false;
663 this.scrollBottom
= this.rows
- 1;
664 this.customKeydownHandler
= null;
666 this.applicationKeypad
= false;
667 this.applicationCursor
= false;
668 this.originMode
= false;
669 this.insertMode
= false;
670 this.wraparoundMode
= true; // defaults: xterm - true, vt100 - false
674 this.gcharset
= null;
676 this.charsets
= [null];
697 this.readable
= true;
698 this.writable
= true;
699 this.defAttr
= (0 << 18) | (257 << 9) | (256 << 0);
700 this.curAttr
= this.defAttr
;
702 this.currentParam
= 0;
705 // leftover surrogate high from previous write invocation
706 this.surrogate_high
= '';
708 * An array of all lines in the entire buffer, including the prompt. The lines are array of
709 * characters which are 2-length arrays where [0] is an attribute and [1] is the character.
714 this.lines
.push(this.blankLine());
718 // Store if user went browsing history in scrollback
719 this.userScrolling
= false;
721 inherits(Terminal
, EventEmitter_js_1
.EventEmitter
);
723 * back_color_erase feature for xterm.
725 Terminal
.prototype.eraseAttr = function () {
726 // if (this.is('screen')) return this.defAttr;
727 return (this.defAttr
& ~0x1ff) | (this.curAttr
& 0x1ff);
733 Terminal
.tangoColors
= [
753 // Colors 0-15 + 16-255
754 // Much thanks to TooTallNate for writing this.
755 Terminal
.colors
= (function () {
756 var colors
= Terminal
.tangoColors
.slice(), r
= [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff], i
;
759 for (; i
< 216; i
++) {
760 out(r
[(i
/ 36) % 6 | 0], r
[(i
/ 6) % 6 | 0], r
[i
% 6]);
764 for (; i
< 24; i
++) {
768 function out(r
, g
, b
) {
769 colors
.push('#' + hex(r
) + hex(g
) + hex(b
));
773 return c
.length
< 2 ? '0' + c
: c
;
777 Terminal
._colors
= Terminal
.colors
.slice();
778 Terminal
.vcolors
= (function () {
779 var out
= [], colors
= Terminal
.colors
, i
= 0, color
;
780 for (; i
< 256; i
++) {
781 color
= parseInt(colors
[i
].substring(1), 16);
783 (color
>> 16) & 0xff,
793 Terminal
.defaults
= {
794 colors
: Terminal
.colors
,
807 Terminal
.options
= {};
808 Terminal
.focus
= null;
809 each(keys(Terminal
.defaults
), function (key
) {
810 Terminal
[key
] = Terminal
.defaults
[key
];
811 Terminal
.options
[key
] = Terminal
.defaults
[key
];
814 * Focus the terminal. Delegates focus handling to the terminal's DOM element.
816 Terminal
.prototype.focus = function () {
817 return this.textarea
.focus();
820 * Retrieves an option's value from the terminal.
821 * @param {string} key The option key.
823 Terminal
.prototype.getOption = function (key
, value
) {
824 if (!(key
in Terminal
.defaults
)) {
825 throw new Error('No option with key "' + key
+ '"');
827 if (typeof this.options
[key
] !== 'undefined') {
828 return this.options
[key
];
833 * Sets an option on the terminal.
834 * @param {string} key The option key.
835 * @param {string} value The option value.
837 Terminal
.prototype.setOption = function (key
, value
) {
838 if (!(key
in Terminal
.defaults
)) {
839 throw new Error('No option with key "' + key
+ '"');
842 this.options
[key
] = value
;
845 * Binds the desired focus behavior on a given terminal object.
849 Terminal
.bindFocus = function (term
) {
850 on(term
.textarea
, 'focus', function (ev
) {
851 if (term
.sendFocus
) {
854 term
.element
.classList
.add('focus');
856 Terminal
.focus
= term
;
857 term
.emit('focus', { terminal
: term
});
861 * Blur the terminal. Delegates blur handling to the terminal's DOM element.
863 Terminal
.prototype.blur = function () {
864 return this.textarea
.blur();
867 * Binds the desired blur behavior on a given terminal object.
871 Terminal
.bindBlur = function (term
) {
872 on(term
.textarea
, 'blur', function (ev
) {
873 term
.refresh(term
.y
, term
.y
);
874 if (term
.sendFocus
) {
877 term
.element
.classList
.remove('focus');
878 Terminal
.focus
= null;
879 term
.emit('blur', { terminal
: term
});
883 * Initialize default behavior
885 Terminal
.prototype.initGlobal = function () {
887 Terminal
.bindKeys(this);
888 Terminal
.bindFocus(this);
889 Terminal
.bindBlur(this);
890 // Bind clipboard functionality
891 on(this.element
, 'copy', function (ev
) {
892 Clipboard_js_1
.copyHandler
.call(this, ev
, term
);
894 on(this.textarea
, 'paste', function (ev
) {
895 Clipboard_js_1
.pasteHandler
.call(this, ev
, term
);
897 on(this.element
, 'paste', function (ev
) {
898 Clipboard_js_1
.pasteHandler
.call(this, ev
, term
);
900 function rightClickHandlerWrapper(ev
) {
901 Clipboard_js_1
.rightClickHandler
.call(this, ev
, term
);
903 if (term
.browser
.isFirefox
) {
904 on(this.element
, 'mousedown', function (ev
) {
905 if (ev
.button
== 2) {
906 rightClickHandlerWrapper(ev
);
911 on(this.element
, 'contextmenu', rightClickHandlerWrapper
);
915 * Apply key handling to the terminal
917 Terminal
.bindKeys = function (term
) {
918 on(term
.element
, 'keydown', function (ev
) {
919 if (document
.activeElement
!= this) {
924 on(term
.element
, 'keypress', function (ev
) {
925 if (document
.activeElement
!= this) {
930 on(term
.element
, 'keyup', term
.focus
.bind(term
));
931 on(term
.textarea
, 'keydown', function (ev
) {
934 on(term
.textarea
, 'keypress', function (ev
) {
936 // Truncate the textarea's value, since it is not needed
939 on(term
.textarea
, 'compositionstart', term
.compositionHelper
.compositionstart
.bind(term
.compositionHelper
));
940 on(term
.textarea
, 'compositionupdate', term
.compositionHelper
.compositionupdate
.bind(term
.compositionHelper
));
941 on(term
.textarea
, 'compositionend', term
.compositionHelper
.compositionend
.bind(term
.compositionHelper
));
942 term
.on('refresh', term
.compositionHelper
.updateCompositionElements
.bind(term
.compositionHelper
));
945 * Insert the given row to the terminal or produce a new one
946 * if no row argument is passed. Return the inserted row.
947 * @param {HTMLElement} row (optional) The row to append to the terminal.
949 Terminal
.prototype.insertRow = function (row
) {
950 if (typeof row
!= 'object') {
951 row
= document
.createElement('div');
953 this.rowContainer
.appendChild(row
);
954 this.children
.push(row
);
958 * Opens the terminal within an element.
960 * @param {HTMLElement} parent The element to create the terminal within.
962 Terminal
.prototype.open = function (parent
) {
963 var self
= this, i
= 0, div
;
964 this.parent
= parent
|| this.parent
;
966 throw new Error('Terminal requires a parent element.');
968 // Grab global elements
969 this.context
= this.parent
.ownerDocument
.defaultView
;
970 this.document
= this.parent
.ownerDocument
;
971 this.body
= this.document
.getElementsByTagName('body')[0];
972 //Create main element container
973 this.element
= this.document
.createElement('div');
974 this.element
.classList
.add('terminal');
975 this.element
.classList
.add('xterm');
976 this.element
.classList
.add('xterm-theme-' + this.theme
);
977 this.element
.style
.height
;
978 this.element
.setAttribute('tabindex', 0);
979 this.viewportElement
= document
.createElement('div');
980 this.viewportElement
.classList
.add('xterm-viewport');
981 this.element
.appendChild(this.viewportElement
);
982 this.viewportScrollArea
= document
.createElement('div');
983 this.viewportScrollArea
.classList
.add('xterm-scroll-area');
984 this.viewportElement
.appendChild(this.viewportScrollArea
);
985 // Create the container that will hold the lines of the terminal and then
986 // produce the lines the lines.
987 this.rowContainer
= document
.createElement('div');
988 this.rowContainer
.classList
.add('xterm-rows');
989 this.element
.appendChild(this.rowContainer
);
991 // Create the container that will hold helpers like the textarea for
992 // capturing DOM Events. Then produce the helpers.
993 this.helperContainer
= document
.createElement('div');
994 this.helperContainer
.classList
.add('xterm-helpers');
995 // TODO: This should probably be inserted once it's filled to prevent an additional layout
996 this.element
.appendChild(this.helperContainer
);
997 this.textarea
= document
.createElement('textarea');
998 this.textarea
.classList
.add('xterm-helper-textarea');
999 this.textarea
.setAttribute('autocorrect', 'off');
1000 this.textarea
.setAttribute('autocapitalize', 'off');
1001 this.textarea
.setAttribute('spellcheck', 'false');
1002 this.textarea
.tabIndex
= 0;
1003 this.textarea
.addEventListener('focus', function () {
1004 self
.emit('focus', { terminal
: self
});
1006 this.textarea
.addEventListener('blur', function () {
1007 self
.emit('blur', { terminal
: self
});
1009 this.helperContainer
.appendChild(this.textarea
);
1010 this.compositionView
= document
.createElement('div');
1011 this.compositionView
.classList
.add('composition-view');
1012 this.compositionHelper
= new CompositionHelper_js_1
.CompositionHelper(this.textarea
, this.compositionView
, this);
1013 this.helperContainer
.appendChild(this.compositionView
);
1014 this.charMeasureElement
= document
.createElement('div');
1015 this.charMeasureElement
.classList
.add('xterm-char-measure-element');
1016 this.charMeasureElement
.innerHTML
= 'W';
1017 this.helperContainer
.appendChild(this.charMeasureElement
);
1018 for (; i
< this.rows
; i
++) {
1021 this.parent
.appendChild(this.element
);
1022 this.viewport
= new Viewport_js_1
.Viewport(this, this.viewportElement
, this.viewportScrollArea
, this.charMeasureElement
);
1024 this.refresh(0, this.rows
- 1);
1025 // Initialize global actions that
1026 // need to be taken on the document.
1028 // Ensure there is a Terminal.focus.
1030 on(this.element
, 'click', function () {
1031 var selection
= document
.getSelection(), collapsed
= selection
.isCollapsed
, isRange
= typeof collapsed
== 'boolean' ? !collapsed
: selection
.type
== 'Range';
1036 // Listen for mouse events and translate
1037 // them into terminal mouse protocols.
1039 // Figure out whether boldness affects
1040 // the character width of monospace fonts.
1041 if (Terminal
.brokenBold
== null) {
1042 Terminal
.brokenBold
= isBoldBroken(this.document
);
1045 * This event is emitted when terminal has completed opening.
1052 * Attempts to load an add-on using CommonJS or RequireJS (whichever is available).
1053 * @param {string} addon The name of the addon to load
1056 Terminal
.loadAddon = function (addon
, callback
) {
1057 if (typeof exports
=== 'object' && typeof module
=== 'object') {
1059 return require('./addons/' + addon
+ '/' + addon
);
1061 else if (typeof define
== 'function') {
1063 return require(['./addons/' + addon
+ '/' + addon
], callback
);
1066 console
.error('Cannot load a module without a CommonJS or RequireJS environment.');
1071 * XTerm mouse events
1072 * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking
1073 * To better understand these
1074 * the xterm code is very helpful:
1076 * button.c, charproc.c, misc.c
1077 * Relevant functions in xterm/button.c:
1078 * BtnCode, EmitButtonCode, EditorButton, SendMousePosition
1080 Terminal
.prototype.bindMouse = function () {
1081 var el
= this.element
, self
= this, pressed
= 32;
1082 // mouseup, mousedown, wheel
1083 // left click: ^[[M 3<^[[M#3<
1084 // wheel up: ^[[M`3>
1085 function sendButton(ev
) {
1087 // get the xterm-style button
1088 button
= getButton(ev
);
1089 // get mouse coordinates
1090 pos
= getCoords(ev
);
1093 sendEvent(button
, pos
);
1094 switch (ev
.overrideType
|| ev
.type
) {
1099 // keep it at the left
1100 // button, just in case.
1110 // motion example of a left click:
1111 // ^[[M 3<^[[M@4<^[[M@5<^[[M@6<^[[M@7<^[[M#7<
1112 function sendMove(ev
) {
1113 var button
= pressed
, pos
;
1114 pos
= getCoords(ev
);
1117 // buttons marked as motions
1118 // are incremented by 32
1120 sendEvent(button
, pos
);
1122 // encode button and
1123 // position to characters
1124 function encode(data
, ch
) {
1125 if (!self
.utfMouse
) {
1127 return data
.push(0);
1134 return data
.push(0);
1141 data
.push(0xC0 | (ch
>> 6));
1142 data
.push(0x80 | (ch
& 0x3F));
1146 // send a mouse event:
1147 // regular/utf8: ^[[M Cb Cx Cy
1148 // urxvt: ^[[ Cb ; Cx ; Cy M
1149 // sgr: ^[[ Cb ; Cx ; Cy M/m
1150 // vt300: ^[[ 24(1/3/5)~ [ Cx , Cy ] \r
1151 // locator: CSI P e ; P b ; P r ; P c ; P p & w
1152 function sendEvent(button
, pos
) {
1153 // self.emit('mouse', {
1158 if (self
.vt300Mouse
) {
1160 // http://www.vt100.net/docs/vt3xx-gp/chapter15.html
1164 var data
= '\x1b[24';
1167 else if (button
=== 1)
1169 else if (button
=== 2)
1171 else if (button
=== 3)
1175 data
+= '~[' + pos
.x
+ ',' + pos
.y
+ ']\r';
1179 if (self
.decLocator
) {
1186 else if (button
=== 1)
1188 else if (button
=== 2)
1190 else if (button
=== 3)
1195 + (button
=== 3 ? 4 : 0)
1205 if (self
.urxvtMouse
) {
1210 self
.send('\x1b[' + button
+ ';' + pos
.x
+ ';' + pos
.y
+ 'M');
1213 if (self
.sgrMouse
) {
1217 + (((button
& 3) === 3 ? button
& ~3 : button
) - 32)
1222 + ((button
& 3) === 3 ? 'm' : 'M'));
1226 encode(data
, button
);
1227 encode(data
, pos
.x
);
1228 encode(data
, pos
.y
);
1229 self
.send('\x1b[M' + String
.fromCharCode
.apply(String
, data
));
1231 function getButton(ev
) {
1232 var button
, shift
, meta
, ctrl
, mod
;
1239 // 1, and 2 - with 64 added
1240 switch (ev
.overrideType
|| ev
.type
) {
1242 button
= ev
.button
!= null
1247 if (self
.browser
.isMSIE
) {
1248 button
= button
=== 1 ? 0 : button
=== 4 ? 1 : button
;
1254 case 'DOMMouseScroll':
1255 button
= ev
.detail
< 0
1260 button
= ev
.wheelDeltaY
> 0
1265 // next three bits are the modifiers:
1266 // 4 = shift, 8 = meta, 16 = control
1267 shift
= ev
.shiftKey
? 4 : 0;
1268 meta
= ev
.metaKey
? 8 : 0;
1269 ctrl
= ev
.ctrlKey
? 16 : 0;
1270 mod
= shift
| meta
| ctrl
;
1272 if (self
.vt200Mouse
) {
1276 else if (!self
.normalMouse
) {
1280 button
= (32 + (mod
<< 2)) + button
;
1283 // mouse coordinates measured in cols/rows
1284 function getCoords(ev
) {
1286 // ignore browsers without pageX for now
1287 if (ev
.pageX
== null)
1292 // should probably check offsetParent
1293 // but this is more portable
1294 while (el
&& el
!== self
.document
.documentElement
) {
1297 el
= 'offsetParent' in el
1301 // convert to cols/rows
1302 w
= self
.element
.clientWidth
;
1303 h
= self
.element
.clientHeight
;
1304 x
= Math
.ceil((x
/ w
) * self
.cols
);
1305 y
= Math
.ceil((y
/ h
) * self
.rows
);
1306 // be sure to avoid sending
1307 // bad positions to the program
1316 // xterm sends raw bytes and
1317 // starts at 32 (SP) for each.
1326 on(el
, 'mousedown', function (ev
) {
1327 if (!self
.mouseEvents
)
1334 //if (self.vt200Mouse && !self.normalMouse) {
1335 if (self
.vt200Mouse
) {
1336 ev
.overrideType
= 'mouseup';
1338 return self
.cancel(ev
);
1341 if (self
.normalMouse
)
1342 on(self
.document
, 'mousemove', sendMove
);
1343 // x10 compatibility mode can't send button releases
1344 if (!self
.x10Mouse
) {
1345 on(self
.document
, 'mouseup', function up(ev
) {
1347 if (self
.normalMouse
)
1348 off(self
.document
, 'mousemove', sendMove
);
1349 off(self
.document
, 'mouseup', up
);
1350 return self
.cancel(ev
);
1353 return self
.cancel(ev
);
1355 //if (self.normalMouse) {
1356 // on(self.document, 'mousemove', sendMove);
1358 on(el
, 'wheel', function (ev
) {
1359 if (!self
.mouseEvents
)
1366 return self
.cancel(ev
);
1368 // allow wheel scrolling in
1369 // the shell for example
1370 on(el
, 'wheel', function (ev
) {
1371 if (self
.mouseEvents
)
1373 self
.viewport
.onWheel(ev
);
1374 return self
.cancel(ev
);
1378 * Destroys the terminal.
1380 Terminal
.prototype.destroy = function () {
1381 this.readable
= false;
1382 this.writable
= false;
1384 this.handler = function () { };
1385 this.write = function () { };
1386 if (this.element
.parentNode
) {
1387 this.element
.parentNode
.removeChild(this.element
);
1389 //this.emit('close');
1392 * Flags used to render terminal text properly
1402 * Refreshes (re-renders) terminal content within two rows (inclusive)
1406 * In the screen buffer, each character is stored as a an array with a character
1407 * and a 32-bit integer:
1408 * - First value: a utf-16 character.
1410 * - Next 9 bits: background color (0-511).
1411 * - Next 9 bits: foreground color (0-511).
1412 * - Next 14 bits: a mask for misc. flags:
1419 * @param {number} start The row to start from (between 0 and terminal's height terminal - 1)
1420 * @param {number} end The row to end at (between fromRow and terminal's height terminal - 1)
1421 * @param {boolean} queue Whether the refresh should ran right now or be queued
1423 Terminal
.prototype.refresh = function (start
, end
, queue
) {
1425 // queue defaults to true
1426 queue
= (typeof queue
== 'undefined') ? true : queue
;
1428 * The refresh queue allows refresh to execute only approximately 30 times a second. For
1429 * commands that pass a significant amount of output to the write function, this prevents the
1430 * terminal from maxing out the CPU and making the UI unresponsive. While commands can still
1431 * run beyond what they do on the terminal, it is far better with a debounce in place as
1432 * every single terminal manipulation does not need to be constructed in the DOM.
1434 * A side-effect of this is that it makes ^C to interrupt a process seem more responsive.
1437 // If refresh should be queued, order the refresh and return.
1438 if (this._refreshIsQueued
) {
1439 // If a refresh has already been queued, just order a full refresh next
1440 this._fullRefreshNext
= true;
1443 setTimeout(function () {
1444 self
.refresh(start
, end
, false);
1446 this._refreshIsQueued
= true;
1450 // If refresh should be run right now (not be queued), release the lock
1451 this._refreshIsQueued
= false;
1452 // If multiple refreshes were requested, make a full refresh.
1453 if (this._fullRefreshNext
) {
1455 end
= this.rows
- 1;
1456 this._fullRefreshNext
= false; // reset lock
1458 var x
, y
, i
, line
, out
, ch
, ch_width
, width
, data
, attr
, bg
, fg
, flags
, row
, parent
, focused
= document
.activeElement
;
1459 // If this is a big refresh, remove the terminal rows from the DOM for faster calculations
1460 if (end
- start
>= this.rows
/ 2) {
1461 parent
= this.element
.parentNode
;
1463 this.element
.removeChild(this.rowContainer
);
1468 if (end
>= this.rows
.length
) {
1469 this.log('`end` is too large. Most likely a bad CSR.');
1470 end
= this.rows
.length
- 1;
1472 for (; y
<= end
; y
++) {
1473 row
= y
+ this.ydisp
;
1474 line
= this.lines
[row
];
1476 if (this.y
=== y
- (this.ybase
- this.ydisp
)
1478 && !this.cursorHidden
) {
1484 attr
= this.defAttr
;
1486 for (; i
< width
; i
++) {
1489 ch_width
= line
[i
][2];
1494 if (data
!== attr
) {
1495 if (attr
!== this.defAttr
) {
1498 if (data
!== this.defAttr
) {
1500 out
+= '<span class="reverse-video terminal-cursor';
1501 if (this.cursorBlink
) {
1507 var classNames
= [];
1509 fg
= (data
>> 9) & 0x1ff;
1511 if (flags
& Terminal
.flags
.BOLD
) {
1512 if (!Terminal
.brokenBold
) {
1513 classNames
.push('xterm-bold');
1515 // See: XTerm*boldColors
1519 if (flags
& Terminal
.flags
.UNDERLINE
) {
1520 classNames
.push('xterm-underline');
1522 if (flags
& Terminal
.flags
.BLINK
) {
1523 classNames
.push('xterm-blink');
1525 // If inverse flag is on, then swap the foreground and background variables.
1526 if (flags
& Terminal
.flags
.INVERSE
) {
1527 /* One-line variable swap in JavaScript: http://stackoverflow.com/a/16201730 */
1528 bg = [fg, fg = bg][0];
1529 // Should inverse just be before the
1530 // above boldColors effect instead?
1531 if ((flags & 1) && fg < 8)
1534 if (flags & Terminal.flags.INVISIBLE) {
1535 classNames.push('xterm-hidden');
1538 * Weird situation: Invert flag used black foreground and white background results
1539 * in invalid background color, positioned at the 256 index of the 256 terminal
1540 * color map. Pin the colors manually in such a case.
1542 * Source: https://github.com/sourcelair/xterm.js/issues/57
1544 if (flags
& Terminal
.flags
.INVERSE
) {
1553 classNames
.push('xterm-bg-color-' + bg
);
1556 classNames
.push('xterm-color-' + fg
);
1559 if (classNames
.length
) {
1560 out
+= ' class="' + classNames
.join(' ') + '"';
1587 if (attr
!== this.defAttr
) {
1590 this.children
[y
].innerHTML
= out
;
1593 this.element
.appendChild(this.rowContainer
);
1595 this.emit('refresh', { element
: this.element
, start
: start
, end
: end
});
1598 * Display the cursor element
1600 Terminal
.prototype.showCursor = function () {
1601 if (!this.cursorState
) {
1602 this.cursorState
= 1;
1603 this.refresh(this.y
, this.y
);
1607 * Scroll the terminal
1609 Terminal
.prototype.scroll = function () {
1611 if (++this.ybase
=== this.scrollback
) {
1612 this.ybase
= this.ybase
/ 2 | 0;
1613 this.lines
= this.lines
.slice(-(this.ybase
+ this.rows
) + 1);
1615 if (!this.userScrolling
) {
1616 this.ydisp
= this.ybase
;
1619 row
= this.ybase
+ this.rows
- 1;
1620 // subtract the bottom scroll region
1621 row
-= this.rows
- 1 - this.scrollBottom
;
1622 if (row
=== this.lines
.length
) {
1623 // potential optimization:
1624 // pushing is faster than splicing
1625 // when they amount to the same
1627 this.lines
.push(this.blankLine());
1631 this.lines
.splice(row
, 0, this.blankLine());
1633 if (this.scrollTop
!== 0) {
1634 if (this.ybase
!== 0) {
1636 if (!this.userScrolling
) {
1637 this.ydisp
= this.ybase
;
1640 this.lines
.splice(this.ybase
+ this.scrollTop
, 1);
1643 this.updateRange(this.scrollTop
);
1644 this.updateRange(this.scrollBottom
);
1646 * This event is emitted whenever the terminal is scrolled.
1647 * The one parameter passed is the new y display position.
1651 this.emit('scroll', this.ydisp
);
1654 * Scroll the display of the terminal
1655 * @param {number} disp The number of lines to scroll down (negatives scroll up).
1656 * @param {boolean} suppressScrollEvent Don't emit the scroll event as scrollDisp. This is used
1657 * to avoid unwanted events being handled by the veiwport when the event was triggered from the
1658 * viewport originally.
1660 Terminal
.prototype.scrollDisp = function (disp
, suppressScrollEvent
) {
1662 this.userScrolling
= true;
1664 else if (disp
+ this.ydisp
>= this.ybase
) {
1665 this.userScrolling
= false;
1668 if (this.ydisp
> this.ybase
) {
1669 this.ydisp
= this.ybase
;
1671 else if (this.ydisp
< 0) {
1674 if (!suppressScrollEvent
) {
1675 this.emit('scroll', this.ydisp
);
1677 this.refresh(0, this.rows
- 1);
1680 * Scroll the display of the terminal by a number of pages.
1681 * @param {number} pageCount The number of pages to scroll (negative scrolls up).
1683 Terminal
.prototype.scrollPages = function (pageCount
) {
1684 this.scrollDisp(pageCount
* (this.rows
- 1));
1687 * Scrolls the display of the terminal to the top.
1689 Terminal
.prototype.scrollToTop = function () {
1690 this.scrollDisp(-this.ydisp
);
1693 * Scrolls the display of the terminal to the bottom.
1695 Terminal
.prototype.scrollToBottom = function () {
1696 this.scrollDisp(this.ybase
- this.ydisp
);
1699 * Writes text to the terminal.
1700 * @param {string} text The text to write to the terminal.
1702 Terminal
.prototype.write = function (data
) {
1703 var l
= data
.length
, i
= 0, j
, cs
, ch
, code
, low
, ch_width
, row
;
1704 this.refreshStart
= this.y
;
1705 this.refreshEnd
= this.y
;
1706 // apply leftover surrogate high from last write
1707 if (this.surrogate_high
) {
1708 data
= this.surrogate_high
+ data
;
1709 this.surrogate_high
= '';
1711 for (; i
< l
; i
++) {
1713 // FIXME: higher chars than 0xa0 are not allowed in escape sequences
1714 // --> maybe move to default
1715 code
= data
.charCodeAt(i
);
1716 if (0xD800 <= code
&& code
<= 0xDBFF) {
1717 // we got a surrogate high
1718 // get surrogate low (next 2 bytes)
1719 low
= data
.charCodeAt(i
+ 1);
1721 // end of data stream, save surrogate high
1722 this.surrogate_high
= ch
;
1725 code
= ((code
- 0xD800) * 0x400) + (low
- 0xDC00) + 0x10000;
1726 ch
+= data
.charAt(i
+ 1);
1728 // surrogate low - already handled above
1729 if (0xDC00 <= code
&& code
<= 0xDFFF)
1731 switch (this.state
) {
1741 if (this.convertEol
) {
1745 if (this.y
> this.scrollBottom
) {
1762 this.x
= this.nextStop();
1774 this.state
= escaped
;
1778 // calculate print space
1779 // expensive call, therefore we save width in line buffer
1780 ch_width
= wcwidth(code
);
1782 if (this.charset
&& this.charset
[ch
]) {
1783 ch
= this.charset
[ch
];
1785 row
= this.y
+ this.ybase
;
1786 // insert combining char in last cell
1787 // FIXME: needs handling after cursor jumps
1788 if (!ch_width
&& this.x
) {
1789 // dont overflow left
1790 if (this.lines
[row
][this.x
- 1]) {
1791 if (!this.lines
[row
][this.x
- 1][2]) {
1792 // found empty cell after fullwidth, need to go 2 cells back
1793 if (this.lines
[row
][this.x
- 2])
1794 this.lines
[row
][this.x
- 2][1] += ch
;
1797 this.lines
[row
][this.x
- 1][1] += ch
;
1799 this.updateRange(this.y
);
1803 // goto next line if ch would overflow
1804 // TODO: needs a global min terminal width of 2
1805 if (this.x
+ ch_width
- 1 >= this.cols
) {
1806 // autowrap - DECAWM
1807 if (this.wraparoundMode
) {
1810 if (this.y
> this.scrollBottom
) {
1816 this.x
= this.cols
- 1;
1821 row
= this.y
+ this.ybase
;
1822 // insert mode: move characters to right
1823 if (this.insertMode
) {
1824 // do this twice for a fullwidth char
1825 for (var moves
= 0; moves
< ch_width
; ++moves
) {
1826 // remove last cell, if it's width is 0
1827 // we have to adjust the second last cell as well
1828 var removed
= this.lines
[this.y
+ this.ybase
].pop();
1829 if (removed
[2] === 0
1830 && this.lines
[row
][this.cols
- 2]
1831 && this.lines
[row
][this.cols
- 2][2] === 2)
1832 this.lines
[row
][this.cols
- 2] = [this.curAttr
, ' ', 1];
1833 // insert empty cell at cursor
1834 this.lines
[row
].splice(this.x
, 0, [this.curAttr
, ' ', 1]);
1837 this.lines
[row
][this.x
] = [this.curAttr
, ch
, ch_width
];
1839 this.updateRange(this.y
);
1840 // fullwidth char - set next cell width to zero and advance cursor
1841 if (ch_width
=== 2) {
1842 this.lines
[row
][this.x
] = [this.curAttr
, '', 0];
1851 // ESC [ Control Sequence Introducer ( CSI is 0x9b).
1854 this.currentParam
= 0;
1857 // ESC ] Operating System Command ( OSC is 0x9d).
1860 this.currentParam
= 0;
1863 // ESC P Device Control String ( DCS is 0x90).
1866 this.currentParam
= 0;
1869 // ESC _ Application Program Command ( APC is 0x9f).
1871 this.state
= ignore
;
1873 // ESC ^ Privacy Message ( PM is 0x9e).
1875 this.state
= ignore
;
1877 // ESC c Full Reset (RIS).
1881 // ESC E Next Line ( NEL is 0x85).
1882 // ESC D Index ( IND is 0x84).
1889 // ESC M Reverse Index ( RI is 0x8d).
1891 this.reverseIndex();
1893 // ESC % Select default/utf-8 character set.
1894 // @ = default, G = utf-8
1896 //this.charset = null;
1898 this.setgCharset(0, Terminal
.charsets
.US
);
1899 this.state
= normal
;
1902 // ESC (,),*,+,-,. Designate G0-G2 Character Set.
1903 case '(': // <-- this seems to get all the attention
1929 this.state
= charset
;
1931 // Designate G3 Character Set (VT300).
1932 // A = ISO Latin-1 Supplemental.
1936 this.state
= charset
;
1940 // Single Shift Select of G2 Character Set
1941 // ( SS2 is 0x8e). This affects next character only.
1945 // Single Shift Select of G3 Character Set
1946 // ( SS3 is 0x8f). This affects next character only.
1950 // Invoke the G2 Character Set as GL (LS2).
1955 // Invoke the G3 Character Set as GL (LS3).
1960 // Invoke the G3 Character Set as GR (LS3R).
1965 // Invoke the G2 Character Set as GR (LS2R).
1970 // Invoke the G1 Character Set as GR (LS1R).
1974 // ESC 7 Save Cursor (DECSC).
1977 this.state
= normal
;
1979 // ESC 8 Restore Cursor (DECRC).
1981 this.restoreCursor();
1982 this.state
= normal
;
1984 // ESC # 3 DEC line height/width
1986 this.state
= normal
;
1989 // ESC H Tab Set (HTS is 0x88).
1993 // ESC = Application Keypad (DECKPAM).
1995 this.log('Serial port requested application keypad.');
1996 this.applicationKeypad
= true;
1997 this.viewport
.syncScrollArea();
1998 this.state
= normal
;
2000 // ESC > Normal Keypad (DECKPNM).
2002 this.log('Switching back to normal keypad.');
2003 this.applicationKeypad
= false;
2004 this.viewport
.syncScrollArea();
2005 this.state
= normal
;
2008 this.state
= normal
;
2009 this.error('Unknown ESC control: %s.', ch
);
2016 cs
= Terminal
.charsets
.SCLD
;
2019 cs
= Terminal
.charsets
.UK
;
2022 cs
= Terminal
.charsets
.US
;
2025 cs
= Terminal
.charsets
.Dutch
;
2027 case 'C': // Finnish
2029 cs
= Terminal
.charsets
.Finnish
;
2032 cs
= Terminal
.charsets
.French
;
2035 cs
= Terminal
.charsets
.FrenchCanadian
;
2038 cs
= Terminal
.charsets
.German
;
2041 cs
= Terminal
.charsets
.Italian
;
2043 case 'E': // NorwegianDanish
2045 cs
= Terminal
.charsets
.NorwegianDanish
;
2048 cs
= Terminal
.charsets
.Spanish
;
2050 case 'H': // Swedish
2052 cs
= Terminal
.charsets
.Swedish
;
2055 cs
= Terminal
.charsets
.Swiss
;
2058 cs
= Terminal
.charsets
.ISOLatin
;
2062 cs
= Terminal
.charsets
.US
;
2065 this.setgCharset(this.gcharset
, cs
);
2066 this.gcharset
= null;
2067 this.state
= normal
;
2072 // Set Text Parameters.
2073 if (ch
=== '\x1b' || ch
=== '\x07') {
2076 this.params
.push(this.currentParam
);
2077 switch (this.params
[0]) {
2081 if (this.params
[1]) {
2082 this.title
= this.params
[1];
2083 this.handleTitle(this.title
);
2091 // change dynamic colors
2103 // change dynamic ui colors
2115 // manipulate selection data
2132 this.currentParam
= 0;
2133 this.state
= normal
;
2136 if (!this.params
.length
) {
2137 if (ch
>= '0' && ch
<= '9') {
2139 this.currentParam
* 10 + ch
.charCodeAt(0) - 48;
2141 else if (ch
=== ';') {
2142 this.params
.push(this.currentParam
);
2143 this.currentParam
= '';
2147 this.currentParam
+= ch
;
2153 if (ch
=== '?' || ch
=== '>' || ch
=== '!') {
2158 if (ch
>= '0' && ch
<= '9') {
2159 this.currentParam
= this.currentParam
* 10 + ch
.charCodeAt(0) - 48;
2162 // '$', '"', ' ', '\''
2163 if (ch
=== '$' || ch
=== '"' || ch
=== ' ' || ch
=== '\'') {
2167 this.params
.push(this.currentParam
);
2168 this.currentParam
= 0;
2172 this.state
= normal
;
2175 // Cursor Up Ps Times (default = 1) (CUU).
2177 this.cursorUp(this.params
);
2180 // Cursor Down Ps Times (default = 1) (CUD).
2182 this.cursorDown(this.params
);
2185 // Cursor Forward Ps Times (default = 1) (CUF).
2187 this.cursorForward(this.params
);
2190 // Cursor Backward Ps Times (default = 1) (CUB).
2192 this.cursorBackward(this.params
);
2195 // Cursor Position [row;column] (default = [1,1]) (CUP).
2197 this.cursorPos(this.params
);
2199 // CSI Ps J Erase in Display (ED).
2201 this.eraseInDisplay(this.params
);
2203 // CSI Ps K Erase in Line (EL).
2205 this.eraseInLine(this.params
);
2207 // CSI Pm m Character Attributes (SGR).
2210 this.charAttributes(this.params
);
2213 // CSI Ps n Device Status Report (DSR).
2216 this.deviceStatus(this.params
);
2223 // Insert Ps (Blank) Character(s) (default = 1) (ICH).
2225 this.insertChars(this.params
);
2228 // Cursor Next Line Ps Times (default = 1) (CNL).
2230 this.cursorNextLine(this.params
);
2233 // Cursor Preceding Line Ps Times (default = 1) (CNL).
2235 this.cursorPrecedingLine(this.params
);
2238 // Cursor Character Absolute [column] (default = [row,1]) (CHA).
2240 this.cursorCharAbsolute(this.params
);
2243 // Insert Ps Line(s) (default = 1) (IL).
2245 this.insertLines(this.params
);
2248 // Delete Ps Line(s) (default = 1) (DL).
2250 this.deleteLines(this.params
);
2253 // Delete Ps Character(s) (default = 1) (DCH).
2255 this.deleteChars(this.params
);
2258 // Erase Ps Character(s) (default = 1) (ECH).
2260 this.eraseChars(this.params
);
2262 // CSI Pm ` Character Position Absolute
2263 // [column] (default = [row,1]) (HPA).
2265 this.charPosAbsolute(this.params
);
2268 // Horizontal Position Relative
2270 this.HPositionRelative(this.params
);
2273 // Send Device Attributes (Primary DA).
2275 // Send Device Attributes (Secondary DA)
2277 this.sendDeviceAttributes(this.params
);
2280 // Line Position Absolute [row] (default = [1,column]) (VPA).
2282 this.linePosAbsolute(this.params
);
2284 // 145 65 e * VPR - Vertical Position Relative
2286 this.VPositionRelative(this.params
);
2289 // Horizontal and Vertical Position [row;column] (default =
2292 this.HVPosition(this.params
);
2294 // CSI Pm h Set Mode (SM).
2295 // CSI ? Pm h - mouse escape codes, cursor escape codes
2297 this.setMode(this.params
);
2299 // CSI Pm l Reset Mode (RM).
2302 this.resetMode(this.params
);
2305 // Set Scrolling Region [top;bottom] (default = full size of win-
2309 this.setScrollRegion(this.params
);
2312 // Save cursor (ANSI.SYS).
2314 this.saveCursor(this.params
);
2317 // Restore cursor (ANSI.SYS).
2319 this.restoreCursor(this.params
);
2325 // Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
2327 this.cursorForwardTab(this.params
);
2329 // CSI Ps S Scroll up Ps lines (default = 1) (SU).
2331 this.scrollUp(this.params
);
2333 // CSI Ps T Scroll down Ps lines (default = 1) (SD).
2334 // CSI Ps ; Ps ; Ps ; Ps ; Ps T
2337 // if (this.prefix === '>') {
2338 // this.resetTitleModes(this.params);
2341 // if (this.params.length > 2) {
2342 // this.initMouseTracking(this.params);
2345 if (this.params
.length
< 2 && !this.prefix
) {
2346 this.scrollDown(this.params
);
2350 // Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
2352 this.cursorBackwardTab(this.params
);
2354 // CSI Ps b Repeat the preceding graphic character Ps times (REP).
2356 this.repeatPrecedingCharacter(this.params
);
2358 // CSI Ps g Tab Clear (TBC).
2360 this.tabClear(this.params
);
2362 // CSI Pm i Media Copy (MC).
2365 // this.mediaCopy(this.params);
2367 // CSI Pm m Character Attributes (SGR).
2369 // case 'm': // duplicate
2370 // if (this.prefix === '>') {
2371 // this.setResources(this.params);
2373 // this.charAttributes(this.params);
2376 // CSI Ps n Device Status Report (DSR).
2378 // case 'n': // duplicate
2379 // if (this.prefix === '>') {
2380 // this.disableModifiers(this.params);
2382 // this.deviceStatus(this.params);
2385 // CSI > Ps p Set pointer mode.
2386 // CSI ! p Soft terminal reset (DECSTR).
2388 // Request ANSI mode (DECRQM).
2390 // Request DEC private mode (DECRQM).
2393 switch (this.prefix
) {
2395 // this.setPointerMode(this.params);
2398 this.softReset(this.params
);
2402 // CSI Ps q Load LEDs (DECLL).
2406 // if (this.postfix === ' ') {
2407 // this.setCursorStyle(this.params);
2410 // if (this.postfix === '"') {
2411 // this.setCharProtectionAttr(this.params);
2414 // this.loadLEDs(this.params);
2417 // Set Scrolling Region [top;bottom] (default = full size of win-
2420 // CSI Pt; Pl; Pb; Pr; Ps$ r
2421 // case 'r': // duplicate
2422 // if (this.prefix === '?') {
2423 // this.restorePrivateValues(this.params);
2424 // } else if (this.postfix === '$') {
2425 // this.setAttrInRectangle(this.params);
2427 // this.setScrollRegion(this.params);
2430 // CSI s Save cursor (ANSI.SYS).
2432 // case 's': // duplicate
2433 // if (this.prefix === '?') {
2434 // this.savePrivateValues(this.params);
2436 // this.saveCursor(this.params);
2439 // CSI Ps ; Ps ; Ps t
2440 // CSI Pt; Pl; Pb; Pr; Ps$ t
2444 // if (this.postfix === '$') {
2445 // this.reverseAttrInRectangle(this.params);
2446 // } else if (this.postfix === ' ') {
2447 // this.setWarningBellVolume(this.params);
2449 // if (this.prefix === '>') {
2450 // this.setTitleModeFeature(this.params);
2452 // this.manipulateWindow(this.params);
2456 // CSI u Restore cursor (ANSI.SYS).
2458 // case 'u': // duplicate
2459 // if (this.postfix === ' ') {
2460 // this.setMarginBellVolume(this.params);
2462 // this.restoreCursor(this.params);
2465 // CSI Pt; Pl; Pb; Pr; Pp; Pt; Pl; Pp$ v
2467 // if (this.postfix === '$') {
2468 // this.copyRectagle(this.params);
2471 // CSI Pt ; Pl ; Pb ; Pr ' w
2473 // if (this.postfix === '\'') {
2474 // this.enableFilterRectangle(this.params);
2477 // CSI Ps x Request Terminal Parameters (DECREQTPARM).
2478 // CSI Ps x Select Attribute Change Extent (DECSACE).
2479 // CSI Pc; Pt; Pl; Pb; Pr$ x
2481 // if (this.postfix === '$') {
2482 // this.fillRectangle(this.params);
2484 // this.requestParameters(this.params);
2485 // //this.__(this.params);
2489 // CSI Pt; Pl; Pb; Pr$ z
2491 // if (this.postfix === '\'') {
2492 // this.enableLocatorReporting(this.params);
2493 // } else if (this.postfix === '$') {
2494 // this.eraseRectangle(this.params);
2498 // CSI Pt; Pl; Pb; Pr$ {
2500 // if (this.postfix === '\'') {
2501 // this.setLocatorEvents(this.params);
2502 // } else if (this.postfix === '$') {
2503 // this.selectiveEraseRectangle(this.params);
2508 // if (this.postfix === '\'') {
2509 // this.requestLocatorPosition(this.params);
2513 // Insert P s Column(s) (default = 1) (DECIC), VT420 and up.
2515 // if (this.postfix === ' ') {
2516 // this.insertColumns(this.params);
2520 // Delete P s Column(s) (default = 1) (DECDC), VT420 and up
2522 // if (this.postfix === ' ') {
2523 // this.deleteColumns(this.params);
2527 this.error('Unknown CSI code: %s.', ch
);
2534 if (ch
=== '\x1b' || ch
=== '\x07') {
2537 switch (this.prefix
) {
2538 // User-Defined Keys (DECUDK).
2541 // Request Status String (DECRQSS).
2542 // test: echo -e '\eP$q"p\e\\'
2544 var pt
= this.currentParam
, valid
= false;
2557 + (this.scrollTop
+ 1)
2559 + (this.scrollBottom
+ 1)
2567 this.error('Unknown DCS Pt: %s.', pt
);
2571 this.send('\x1bP' + +valid
+ '$r' + pt
+ '\x1b\\');
2573 // Set Termcap/Terminfo Data (xterm, experimental).
2576 // Request Termcap/Terminfo String (xterm, experimental)
2577 // Regular xterm does not even respond to this sequence.
2578 // This can cause a small glitch in vim.
2579 // test: echo -ne '\eP+q6b64\e\\'
2581 var pt
= this.currentParam
, valid
= false;
2582 this.send('\x1bP' + +valid
+ '+r' + pt
+ '\x1b\\');
2585 this.error('Unknown DCS prefix: %s.', this.prefix
);
2588 this.currentParam
= 0;
2590 this.state
= normal
;
2592 else if (!this.currentParam
) {
2593 if (!this.prefix
&& ch
!== '$' && ch
!== '+') {
2594 this.currentParam
= ch
;
2596 else if (this.prefix
.length
=== 2) {
2597 this.currentParam
= ch
;
2604 this.currentParam
+= ch
;
2609 if (ch
=== '\x1b' || ch
=== '\x07') {
2612 this.state
= normal
;
2617 this.updateRange(this.y
);
2618 this.refresh(this.refreshStart
, this.refreshEnd
);
2621 * Writes text to the terminal, followed by a break line character (\n).
2622 * @param {string} text The text to write to the terminal.
2624 Terminal
.prototype.writeln = function (data
) {
2625 this.write(data
+ '\r\n');
2628 * Attaches a custom keydown handler which is run before keys are processed, giving consumers of
2629 * xterm.js ultimate control as to what keys should be processed by the terminal and what keys
2631 * @param {function} customKeydownHandler The custom KeyboardEvent handler to attach. This is a
2632 * function that takes a KeyboardEvent, allowing consumers to stop propogation and/or prevent
2633 * the default action. The function returns whether the event should be processed by xterm.js.
2635 Terminal
.prototype.attachCustomKeydownHandler = function (customKeydownHandler
) {
2636 this.customKeydownHandler
= customKeydownHandler
;
2639 * Handle a keydown event
2641 * - https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
2642 * @param {KeyboardEvent} ev The keydown event to be handled.
2644 Terminal
.prototype.keyDown = function (ev
) {
2645 if (this.customKeydownHandler
&& this.customKeydownHandler(ev
) === false) {
2648 if (!this.compositionHelper
.keydown
.bind(this.compositionHelper
)(ev
)) {
2649 if (this.ybase
!== this.ydisp
) {
2650 this.scrollToBottom();
2655 var result
= this.evaluateKeyEscapeSequence(ev
);
2656 if (result
.scrollDisp
) {
2657 this.scrollDisp(result
.scrollDisp
);
2658 return this.cancel(ev
, true);
2660 if (isThirdLevelShift(this, ev
)) {
2663 if (result
.cancel
) {
2664 // The event is canceled at the end already, is this necessary?
2665 this.cancel(ev
, true);
2670 this.emit('keydown', ev
);
2671 this.emit('key', result
.key
, ev
);
2673 this.handler(result
.key
);
2674 return this.cancel(ev
, true);
2677 * Returns an object that determines how a KeyboardEvent should be handled. The key of the
2678 * returned value is the new key code to pass to the PTY.
2680 * Reference: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
2681 * @param {KeyboardEvent} ev The keyboard event to be translated to key escape sequence.
2683 Terminal
.prototype.evaluateKeyEscapeSequence = function (ev
) {
2685 // Whether to cancel event propogation (NOTE: this may not be needed since the event is
2686 // canceled at the end of keyDown
2688 // The new key even to emit
2690 // The number of characters to scroll, if this is defined it will cancel the event
2691 scrollDisp
: undefined
2693 var modifiers
= ev
.shiftKey
<< 0 | ev
.altKey
<< 1 | ev
.ctrlKey
<< 2 | ev
.metaKey
<< 3;
2694 switch (ev
.keyCode
) {
2698 result
.key
= '\x08'; // ^H
2701 result
.key
= '\x7f'; // ^?
2706 result
.key
= '\x1b[Z';
2710 result
.cancel
= true;
2715 result
.cancel
= true;
2719 result
.key
= '\x1b';
2720 result
.cancel
= true;
2725 result
.key
= '\x1b[1;' + (modifiers
+ 1) + 'D';
2726 // HACK: Make Alt + left-arrow behave like Ctrl + left-arrow: move one word backwards
2727 // http://unix.stackexchange.com/a/108106
2728 if (result
.key
== '\x1b[1;3D') {
2729 result
.key
= '\x1b[1;5D';
2732 else if (this.applicationCursor
) {
2733 result
.key
= '\x1bOD';
2736 result
.key
= '\x1b[D';
2742 result
.key
= '\x1b[1;' + (modifiers
+ 1) + 'C';
2743 // HACK: Make Alt + right-arrow behave like Ctrl + right-arrow: move one word forward
2744 // http://unix.stackexchange.com/a/108106
2745 if (result
.key
== '\x1b[1;3C') {
2746 result
.key
= '\x1b[1;5C';
2749 else if (this.applicationCursor
) {
2750 result
.key
= '\x1bOC';
2753 result
.key
= '\x1b[C';
2759 result
.key
= '\x1b[1;' + (modifiers
+ 1) + 'A';
2760 // HACK: Make Alt + up-arrow behave like Ctrl + up-arrow
2761 // http://unix.stackexchange.com/a/108106
2762 if (result
.key
== '\x1b[1;3A') {
2763 result
.key
= '\x1b[1;5A';
2766 else if (this.applicationCursor
) {
2767 result
.key
= '\x1bOA';
2770 result
.key
= '\x1b[A';
2776 result
.key
= '\x1b[1;' + (modifiers
+ 1) + 'B';
2777 // HACK: Make Alt + down-arrow behave like Ctrl + down-arrow
2778 // http://unix.stackexchange.com/a/108106
2779 if (result
.key
== '\x1b[1;3B') {
2780 result
.key
= '\x1b[1;5B';
2783 else if (this.applicationCursor
) {
2784 result
.key
= '\x1bOB';
2787 result
.key
= '\x1b[B';
2792 if (!ev
.shiftKey
&& !ev
.ctrlKey
) {
2793 // <Ctrl> or <Shift> + <Insert> are used to
2794 // copy-paste on some systems.
2795 result
.key
= '\x1b[2~';
2801 result
.key
= '\x1b[3;' + (modifiers
+ 1) + '~';
2804 result
.key
= '\x1b[3~';
2810 result
.key
= '\x1b[1;' + (modifiers
+ 1) + 'H';
2811 else if (this.applicationCursor
)
2812 result
.key
= '\x1bOH';
2814 result
.key
= '\x1b[H';
2819 result
.key
= '\x1b[1;' + (modifiers
+ 1) + 'F';
2820 else if (this.applicationCursor
)
2821 result
.key
= '\x1bOF';
2823 result
.key
= '\x1b[F';
2828 result
.scrollDisp
= -(this.rows
- 1);
2831 result
.key
= '\x1b[5~';
2837 result
.scrollDisp
= this.rows
- 1;
2840 result
.key
= '\x1b[6~';
2846 result
.key
= '\x1b[1;' + (modifiers
+ 1) + 'P';
2849 result
.key
= '\x1bOP';
2854 result
.key
= '\x1b[1;' + (modifiers
+ 1) + 'Q';
2857 result
.key
= '\x1bOQ';
2862 result
.key
= '\x1b[1;' + (modifiers
+ 1) + 'R';
2865 result
.key
= '\x1bOR';
2870 result
.key
= '\x1b[1;' + (modifiers
+ 1) + 'S';
2873 result
.key
= '\x1bOS';
2878 result
.key
= '\x1b[15;' + (modifiers
+ 1) + '~';
2881 result
.key
= '\x1b[15~';
2886 result
.key
= '\x1b[17;' + (modifiers
+ 1) + '~';
2889 result
.key
= '\x1b[17~';
2894 result
.key
= '\x1b[18;' + (modifiers
+ 1) + '~';
2897 result
.key
= '\x1b[18~';
2902 result
.key
= '\x1b[19;' + (modifiers
+ 1) + '~';
2905 result
.key
= '\x1b[19~';
2910 result
.key
= '\x1b[20;' + (modifiers
+ 1) + '~';
2913 result
.key
= '\x1b[20~';
2918 result
.key
= '\x1b[21;' + (modifiers
+ 1) + '~';
2921 result
.key
= '\x1b[21~';
2926 result
.key
= '\x1b[23;' + (modifiers
+ 1) + '~';
2929 result
.key
= '\x1b[23~';
2934 result
.key
= '\x1b[24;' + (modifiers
+ 1) + '~';
2937 result
.key
= '\x1b[24~';
2942 if (ev
.ctrlKey
&& !ev
.shiftKey
&& !ev
.altKey
&& !ev
.metaKey
) {
2943 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
2944 result
.key
= String
.fromCharCode(ev
.keyCode
- 64);
2946 else if (ev
.keyCode
=== 32) {
2948 result
.key
= String
.fromCharCode(0);
2950 else if (ev
.keyCode
>= 51 && ev
.keyCode
<= 55) {
2951 // escape, file sep, group sep, record sep, unit sep
2952 result
.key
= String
.fromCharCode(ev
.keyCode
- 51 + 27);
2954 else if (ev
.keyCode
=== 56) {
2956 result
.key
= String
.fromCharCode(127);
2958 else if (ev
.keyCode
=== 219) {
2959 // ^[ - Control Sequence Introducer (CSI)
2960 result
.key
= String
.fromCharCode(27);
2962 else if (ev
.keyCode
=== 220) {
2963 // ^\ - String Terminator (ST)
2964 result
.key
= String
.fromCharCode(28);
2966 else if (ev
.keyCode
=== 221) {
2967 // ^] - Operating System Command (OSC)
2968 result
.key
= String
.fromCharCode(29);
2971 else if (!this.browser
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) {
2972 // On Mac this is a third level shift. Use <Esc> instead.
2973 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
2974 result
.key
= '\x1b' + String
.fromCharCode(ev
.keyCode
+ 32);
2976 else if (ev
.keyCode
=== 192) {
2977 result
.key
= '\x1b`';
2979 else if (ev
.keyCode
>= 48 && ev
.keyCode
<= 57) {
2980 result
.key
= '\x1b' + (ev
.keyCode
- 48);
2988 * Set the G level of the terminal
2991 Terminal
.prototype.setgLevel = function (g
) {
2993 this.charset
= this.charsets
[g
];
2996 * Set the charset for the given G level of the terminal
3000 Terminal
.prototype.setgCharset = function (g
, charset
) {
3001 this.charsets
[g
] = charset
;
3002 if (this.glevel
=== g
) {
3003 this.charset
= charset
;
3007 * Handle a keypress event.
3009 * - https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
3010 * @param {KeyboardEvent} ev The keypress event to be handled.
3012 Terminal
.prototype.keyPress = function (ev
) {
3018 else if (ev
.which
== null) {
3021 else if (ev
.which
!== 0 && ev
.charCode
!== 0) {
3027 if (!key
|| ((ev
.altKey
|| ev
.ctrlKey
|| ev
.metaKey
) && !isThirdLevelShift(this, ev
))) {
3030 key
= String
.fromCharCode(key
);
3031 this.emit('keypress', key
, ev
);
3032 this.emit('key', key
, ev
);
3038 * Send data for handling to the terminal
3039 * @param {string} data
3041 Terminal
.prototype.send = function (data
) {
3044 setTimeout(function () {
3045 self
.handler(self
.queue
);
3053 * Note: We could do sweet things with webaudio here
3055 Terminal
.prototype.bell = function () {
3056 if (!this.visualBell
)
3059 this.element
.style
.borderColor
= 'white';
3060 setTimeout(function () {
3061 self
.element
.style
.borderColor
= '';
3067 * Log the current state to the console.
3069 Terminal
.prototype.log = function () {
3072 if (!this.context
.console
|| !this.context
.console
.log
)
3074 var args
= Array
.prototype.slice
.call(arguments
);
3075 this.context
.console
.log
.apply(this.context
.console
, args
);
3078 * Log the current state as error to the console.
3080 Terminal
.prototype.error = function () {
3083 if (!this.context
.console
|| !this.context
.console
.error
)
3085 var args
= Array
.prototype.slice
.call(arguments
);
3086 this.context
.console
.error
.apply(this.context
.console
, args
);
3089 * Resizes the terminal.
3091 * @param {number} x The number of columns to resize to.
3092 * @param {number} y The number of rows to resize to.
3094 Terminal
.prototype.resize = function (x
, y
) {
3095 var line
, el
, i
, j
, ch
, addToY
;
3096 if (x
=== this.cols
&& y
=== this.rows
) {
3106 ch
= [this.defAttr
, ' ', 1]; // does xterm use the default attr?
3107 i
= this.lines
.length
;
3109 while (this.lines
[i
].length
< x
) {
3110 this.lines
[i
].push(ch
);
3115 i
= this.lines
.length
;
3117 while (this.lines
[i
].length
> x
) {
3118 this.lines
[i
].pop();
3130 // y is rows, not this.y
3131 if (this.lines
.length
< y
+ this.ybase
) {
3132 if (this.ybase
> 0 && this.lines
.length
<= this.ybase
+ this.y
+ addToY
+ 1) {
3133 // There is room above the buffer and there are no empty elements below the line,
3137 if (this.ydisp
> 0) {
3138 // Viewport is at the top of the buffer, must increase downwards
3143 // Add a blank line if there is no buffer left at the top to scroll to, or if there
3144 // are blank lines after the cursor
3145 this.lines
.push(this.blankLine());
3148 if (this.children
.length
< y
) {
3155 if (this.lines
.length
> y
+ this.ybase
) {
3156 if (this.lines
.length
> this.ybase
+ this.y
+ 1) {
3157 // The line is a blank line below the cursor, remove it
3161 // The line is the cursor, scroll down
3166 if (this.children
.length
> y
) {
3167 el
= this.children
.shift();
3170 el
.parentNode
.removeChild(el
);
3175 // Make sure that the cursor stays on screen
3186 this.scrollBottom
= y
- 1;
3187 this.refresh(0, this.rows
- 1);
3189 this.geometry
= [this.cols
, this.rows
];
3190 this.emit('resize', { terminal
: this, cols
: x
, rows
: y
});
3193 * Updates the range of rows to refresh
3194 * @param {number} y The number of rows to refresh next.
3196 Terminal
.prototype.updateRange = function (y
) {
3197 if (y
< this.refreshStart
)
3198 this.refreshStart
= y
;
3199 if (y
> this.refreshEnd
)
3200 this.refreshEnd
= y
;
3201 // if (y > this.refreshEnd) {
3202 // this.refreshEnd = y;
3203 // if (y > this.rows - 1) {
3204 // this.refreshEnd = this.rows - 1;
3209 * Set the range of refreshing to the maximum value
3211 Terminal
.prototype.maxRange = function () {
3212 this.refreshStart
= 0;
3213 this.refreshEnd
= this.rows
- 1;
3216 * Setup the tab stops.
3219 Terminal
.prototype.setupStops = function (i
) {
3221 if (!this.tabs
[i
]) {
3222 i
= this.prevStop(i
);
3229 for (; i
< this.cols
; i
+= 8) {
3230 this.tabs
[i
] = true;
3234 * Move the cursor to the previous tab stop from the given position (default is current).
3235 * @param {number} x The position to move the cursor to the previous tab stop.
3237 Terminal
.prototype.prevStop = function (x
) {
3240 while (!this.tabs
[--x
] && x
> 0)
3242 return x
>= this.cols
3247 * Move the cursor one tab stop forward from the given position (default is current).
3248 * @param {number} x The position to move the cursor one tab stop forward.
3250 Terminal
.prototype.nextStop = function (x
) {
3253 while (!this.tabs
[++x
] && x
< this.cols
)
3255 return x
>= this.cols
3260 * Erase in the identified line everything from "x" to the end of the line (right).
3261 * @param {number} x The column from which to start erasing to the end of the line.
3262 * @param {number} y The line in which to operate.
3264 Terminal
.prototype.eraseRight = function (x
, y
) {
3265 var line
= this.lines
[this.ybase
+ y
], ch
= [this.eraseAttr(), ' ', 1]; // xterm
3266 for (; x
< this.cols
; x
++) {
3269 this.updateRange(y
);
3272 * Erase in the identified line everything from "x" to the start of the line (left).
3273 * @param {number} x The column from which to start erasing to the start of the line.
3274 * @param {number} y The line in which to operate.
3276 Terminal
.prototype.eraseLeft = function (x
, y
) {
3277 var line
= this.lines
[this.ybase
+ y
], ch
= [this.eraseAttr(), ' ', 1]; // xterm
3281 this.updateRange(y
);
3284 * Clears the entire buffer, making the prompt line the new first line.
3286 Terminal
.prototype.clear = function () {
3287 if (this.ybase
=== 0 && this.y
=== 0) {
3288 // Don't clear if it's already clear
3291 this.lines
= [this.lines
[this.ybase
+ this.y
]];
3295 for (var i
= 1; i
< this.rows
; i
++) {
3296 this.lines
.push(this.blankLine());
3298 this.refresh(0, this.rows
- 1);
3299 this.emit('scroll', this.ydisp
);
3302 * Erase all content in the given line
3303 * @param {number} y The line to erase all of its contents.
3305 Terminal
.prototype.eraseLine = function (y
) {
3306 this.eraseRight(0, y
);
3309 * Return the data array of a blank line/
3310 * @param {number} cur First bunch of data for each "blank" character.
3312 Terminal
.prototype.blankLine = function (cur
) {
3316 var ch
= [attr
, ' ', 1] // width defaults to 1 halfwidth character
3318 for (; i
< this.cols
; i
++) {
3324 * If cur return the back color xterm feature attribute. Else return defAttr.
3325 * @param {object} cur
3327 Terminal
.prototype.ch = function (cur
) {
3329 ? [this.eraseAttr(), ' ', 1]
3330 : [this.defAttr
, ' ', 1];
3333 * Evaluate if the current erminal is the given argument.
3334 * @param {object} term The terminal to evaluate
3336 Terminal
.prototype.is = function (term
) {
3337 var name
= this.termName
;
3338 return (name
+ '').indexOf(term
) === 0;
3341 * Emit the 'data' event and populate the given data.
3342 * @param {string} data The data to populate in the event.
3344 Terminal
.prototype.handler = function (data
) {
3345 // Input is being sent to the terminal, the terminal should focus the prompt.
3346 if (this.ybase
!== this.ydisp
) {
3347 this.scrollToBottom();
3349 this.emit('data', data
);
3352 * Emit the 'title' event and populate the given title.
3353 * @param {string} title The title to populate in the event.
3355 Terminal
.prototype.handleTitle = function (title
) {
3357 * This event is emitted when the title of the terminal is changed
3358 * from inside the terminal. The parameter is the new title.
3362 this.emit('title', title
);
3368 * ESC D Index (IND is 0x84).
3370 Terminal
.prototype.index = function () {
3372 if (this.y
> this.scrollBottom
) {
3376 this.state
= normal
;
3379 * ESC M Reverse Index (RI is 0x8d).
3381 Terminal
.prototype.reverseIndex = function () {
3384 if (this.y
< this.scrollTop
) {
3386 // possibly move the code below to term.reverseScroll();
3387 // test: echo -ne '\e[1;1H\e[44m\eM\e[0m'
3388 // blankLine(true) is xterm/linux behavior
3389 this.lines
.splice(this.y
+ this.ybase
, 0, this.blankLine(true));
3390 j
= this.rows
- 1 - this.scrollBottom
;
3391 this.lines
.splice(this.rows
- 1 + this.ybase
- j
+ 1, 1);
3393 this.updateRange(this.scrollTop
);
3394 this.updateRange(this.scrollBottom
);
3396 this.state
= normal
;
3399 * ESC c Full Reset (RIS).
3401 Terminal
.prototype.reset = function () {
3402 this.options
.rows
= this.rows
;
3403 this.options
.cols
= this.cols
;
3404 var customKeydownHandler
= this.customKeydownHandler
;
3405 Terminal
.call(this, this.options
);
3406 this.customKeydownHandler
= customKeydownHandler
;
3407 this.refresh(0, this.rows
- 1);
3408 this.viewport
.syncScrollArea();
3411 * ESC H Tab Set (HTS is 0x88).
3413 Terminal
.prototype.tabSet = function () {
3414 this.tabs
[this.x
] = true;
3415 this.state
= normal
;
3422 * Cursor Up Ps Times (default = 1) (CUU).
3424 Terminal
.prototype.cursorUp = function (params
) {
3425 var param
= params
[0];
3434 * Cursor Down Ps Times (default = 1) (CUD).
3436 Terminal
.prototype.cursorDown = function (params
) {
3437 var param
= params
[0];
3441 if (this.y
>= this.rows
) {
3442 this.y
= this.rows
- 1;
3447 * Cursor Forward Ps Times (default = 1) (CUF).
3449 Terminal
.prototype.cursorForward = function (params
) {
3450 var param
= params
[0];
3454 if (this.x
>= this.cols
) {
3455 this.x
= this.cols
- 1;
3460 * Cursor Backward Ps Times (default = 1) (CUB).
3462 Terminal
.prototype.cursorBackward = function (params
) {
3463 var param
= params
[0];
3472 * Cursor Position [row;column] (default = [1,1]) (CUP).
3474 Terminal
.prototype.cursorPos = function (params
) {
3476 row
= params
[0] - 1;
3477 if (params
.length
>= 2) {
3478 col
= params
[1] - 1;
3486 else if (row
>= this.rows
) {
3487 row
= this.rows
- 1;
3492 else if (col
>= this.cols
) {
3493 col
= this.cols
- 1;
3499 * CSI Ps J Erase in Display (ED).
3500 * Ps = 0 -> Erase Below (default).
3501 * Ps = 1 -> Erase Above.
3502 * Ps = 2 -> Erase All.
3503 * Ps = 3 -> Erase Saved Lines (xterm).
3505 * Erase in Display (DECSED).
3506 * Ps = 0 -> Selective Erase Below (default).
3507 * Ps = 1 -> Selective Erase Above.
3508 * Ps = 2 -> Selective Erase All.
3510 Terminal
.prototype.eraseInDisplay = function (params
) {
3512 switch (params
[0]) {
3514 this.eraseRight(this.x
, this.y
);
3516 for (; j
< this.rows
; j
++) {
3521 this.eraseLeft(this.x
, this.y
);
3538 * CSI Ps K Erase in Line (EL).
3539 * Ps = 0 -> Erase to Right (default).
3540 * Ps = 1 -> Erase to Left.
3541 * Ps = 2 -> Erase All.
3543 * Erase in Line (DECSEL).
3544 * Ps = 0 -> Selective Erase to Right (default).
3545 * Ps = 1 -> Selective Erase to Left.
3546 * Ps = 2 -> Selective Erase All.
3548 Terminal
.prototype.eraseInLine = function (params
) {
3549 switch (params
[0]) {
3551 this.eraseRight(this.x
, this.y
);
3554 this.eraseLeft(this.x
, this.y
);
3557 this.eraseLine(this.y
);
3562 * CSI Pm m Character Attributes (SGR).
3563 * Ps = 0 -> Normal (default).
3565 * Ps = 4 -> Underlined.
3566 * Ps = 5 -> Blink (appears as Bold).
3567 * Ps = 7 -> Inverse.
3568 * Ps = 8 -> Invisible, i.e., hidden (VT300).
3569 * Ps = 2 2 -> Normal (neither bold nor faint).
3570 * Ps = 2 4 -> Not underlined.
3571 * Ps = 2 5 -> Steady (not blinking).
3572 * Ps = 2 7 -> Positive (not inverse).
3573 * Ps = 2 8 -> Visible, i.e., not hidden (VT300).
3574 * Ps = 3 0 -> Set foreground color to Black.
3575 * Ps = 3 1 -> Set foreground color to Red.
3576 * Ps = 3 2 -> Set foreground color to Green.
3577 * Ps = 3 3 -> Set foreground color to Yellow.
3578 * Ps = 3 4 -> Set foreground color to Blue.
3579 * Ps = 3 5 -> Set foreground color to Magenta.
3580 * Ps = 3 6 -> Set foreground color to Cyan.
3581 * Ps = 3 7 -> Set foreground color to White.
3582 * Ps = 3 9 -> Set foreground color to default (original).
3583 * Ps = 4 0 -> Set background color to Black.
3584 * Ps = 4 1 -> Set background color to Red.
3585 * Ps = 4 2 -> Set background color to Green.
3586 * Ps = 4 3 -> Set background color to Yellow.
3587 * Ps = 4 4 -> Set background color to Blue.
3588 * Ps = 4 5 -> Set background color to Magenta.
3589 * Ps = 4 6 -> Set background color to Cyan.
3590 * Ps = 4 7 -> Set background color to White.
3591 * Ps = 4 9 -> Set background color to default (original).
3593 * If 16-color support is compiled, the following apply. Assume
3594 * that xterm's resources are set so that the ISO color codes are
3595 * the first 8 of a set of 16. Then the aixterm colors are the
3596 * bright versions of the ISO colors:
3597 * Ps = 9 0 -> Set foreground color to Black.
3598 * Ps = 9 1 -> Set foreground color to Red.
3599 * Ps = 9 2 -> Set foreground color to Green.
3600 * Ps = 9 3 -> Set foreground color to Yellow.
3601 * Ps = 9 4 -> Set foreground color to Blue.
3602 * Ps = 9 5 -> Set foreground color to Magenta.
3603 * Ps = 9 6 -> Set foreground color to Cyan.
3604 * Ps = 9 7 -> Set foreground color to White.
3605 * Ps = 1 0 0 -> Set background color to Black.
3606 * Ps = 1 0 1 -> Set background color to Red.
3607 * Ps = 1 0 2 -> Set background color to Green.
3608 * Ps = 1 0 3 -> Set background color to Yellow.
3609 * Ps = 1 0 4 -> Set background color to Blue.
3610 * Ps = 1 0 5 -> Set background color to Magenta.
3611 * Ps = 1 0 6 -> Set background color to Cyan.
3612 * Ps = 1 0 7 -> Set background color to White.
3614 * If xterm is compiled with the 16-color support disabled, it
3615 * supports the following, from rxvt:
3616 * Ps = 1 0 0 -> Set foreground and background color to
3619 * If 88- or 256-color support is compiled, the following apply.
3620 * Ps = 3 8 ; 5 ; Ps -> Set foreground color to the second
3622 * Ps = 4 8 ; 5 ; Ps -> Set background color to the second
3625 Terminal
.prototype.charAttributes = function (params
) {
3626 // Optimize a single SGR0.
3627 if (params
.length
=== 1 && params
[0] === 0) {
3628 this.curAttr
= this.defAttr
;
3631 var l
= params
.length
, i
= 0, flags
= this.curAttr
>> 18, fg
= (this.curAttr
>> 9) & 0x1ff, bg
= this.curAttr
& 0x1ff, p
;
3632 for (; i
< l
; i
++) {
3634 if (p
>= 30 && p
<= 37) {
3638 else if (p
>= 40 && p
<= 47) {
3642 else if (p
>= 90 && p
<= 97) {
3647 else if (p
>= 100 && p
<= 107) {
3654 flags
= this.defAttr
>> 18;
3655 fg
= (this.defAttr
>> 9) & 0x1ff;
3656 bg
= this.defAttr
& 0x1ff;
3671 // inverse and positive
3672 // test with: echo -e '\e[31m\e[42mhello\e[7mworld\e[27mhi\e[m'
3679 else if (p
=== 22) {
3683 else if (p
=== 24) {
3687 else if (p
=== 25) {
3691 else if (p
=== 27) {
3695 else if (p
=== 28) {
3699 else if (p
=== 39) {
3701 fg
= (this.defAttr
>> 9) & 0x1ff;
3703 else if (p
=== 49) {
3705 bg
= this.defAttr
& 0x1ff;
3707 else if (p
=== 38) {
3709 if (params
[i
+ 1] === 2) {
3711 fg
= matchColor(params
[i
] & 0xff, params
[i
+ 1] & 0xff, params
[i
+ 2] & 0xff);
3716 else if (params
[i
+ 1] === 5) {
3718 p
= params
[i
] & 0xff;
3722 else if (p
=== 48) {
3724 if (params
[i
+ 1] === 2) {
3726 bg
= matchColor(params
[i
] & 0xff, params
[i
+ 1] & 0xff, params
[i
+ 2] & 0xff);
3731 else if (params
[i
+ 1] === 5) {
3733 p
= params
[i
] & 0xff;
3737 else if (p
=== 100) {
3739 fg
= (this.defAttr
>> 9) & 0x1ff;
3740 bg
= this.defAttr
& 0x1ff;
3743 this.error('Unknown SGR attribute: %d.', p
);
3746 this.curAttr
= (flags
<< 18) | (fg
<< 9) | bg
;
3749 * CSI Ps n Device Status Report (DSR).
3750 * Ps = 5 -> Status Report. Result (``OK'') is
3752 * Ps = 6 -> Report Cursor Position (CPR) [row;column].
3756 * Device Status Report (DSR, DEC-specific).
3757 * Ps = 6 -> Report Cursor Position (CPR) [row;column] as CSI
3758 * ? r ; c R (assumes page is zero).
3759 * Ps = 1 5 -> Report Printer status as CSI ? 1 0 n (ready).
3760 * or CSI ? 1 1 n (not ready).
3761 * Ps = 2 5 -> Report UDK status as CSI ? 2 0 n (unlocked)
3762 * or CSI ? 2 1 n (locked).
3763 * Ps = 2 6 -> Report Keyboard status as
3764 * CSI ? 2 7 ; 1 ; 0 ; 0 n (North American).
3765 * The last two parameters apply to VT400 & up, and denote key-
3766 * board ready and LK01 respectively.
3767 * Ps = 5 3 -> Report Locator status as
3768 * CSI ? 5 3 n Locator available, if compiled-in, or
3769 * CSI ? 5 0 n No Locator, if not.
3771 Terminal
.prototype.deviceStatus = function (params
) {
3773 switch (params
[0]) {
3776 this.send('\x1b[0n');
3788 else if (this.prefix
=== '?') {
3789 // modern xterm doesnt seem to
3790 // respond to any of these except ?6, 6, and 5
3791 switch (params
[0]) {
3802 // this.send('\x1b[?11n');
3805 // dont support user defined keys
3806 // this.send('\x1b[?21n');
3809 // north american keyboard
3810 // this.send('\x1b[?27;1;0;0n');
3813 // no dec locator/mouse
3814 // this.send('\x1b[?50n');
3824 * Insert Ps (Blank) Character(s) (default = 1) (ICH).
3826 Terminal
.prototype.insertChars = function (params
) {
3827 var param
, row
, j
, ch
;
3831 row
= this.y
+ this.ybase
;
3833 ch
= [this.eraseAttr(), ' ', 1]; // xterm
3834 while (param
-- && j
< this.cols
) {
3835 this.lines
[row
].splice(j
++, 0, ch
);
3836 this.lines
[row
].pop();
3841 * Cursor Next Line Ps Times (default = 1) (CNL).
3842 * same as CSI Ps B ?
3844 Terminal
.prototype.cursorNextLine = function (params
) {
3845 var param
= params
[0];
3849 if (this.y
>= this.rows
) {
3850 this.y
= this.rows
- 1;
3856 * Cursor Preceding Line Ps Times (default = 1) (CNL).
3859 Terminal
.prototype.cursorPrecedingLine = function (params
) {
3860 var param
= params
[0];
3870 * Cursor Character Absolute [column] (default = [row,1]) (CHA).
3872 Terminal
.prototype.cursorCharAbsolute = function (params
) {
3873 var param
= params
[0];
3880 * Insert Ps Line(s) (default = 1) (IL).
3882 Terminal
.prototype.insertLines = function (params
) {
3887 row
= this.y
+ this.ybase
;
3888 j
= this.rows
- 1 - this.scrollBottom
;
3889 j
= this.rows
- 1 + this.ybase
- j
+ 1;
3891 // test: echo -e '\e[44m\e[1L\e[0m'
3892 // blankLine(true) - xterm/linux behavior
3893 this.lines
.splice(row
, 0, this.blankLine(true));
3894 this.lines
.splice(j
, 1);
3897 this.updateRange(this.y
);
3898 this.updateRange(this.scrollBottom
);
3902 * Delete Ps Line(s) (default = 1) (DL).
3904 Terminal
.prototype.deleteLines = function (params
) {
3909 row
= this.y
+ this.ybase
;
3910 j
= this.rows
- 1 - this.scrollBottom
;
3911 j
= this.rows
- 1 + this.ybase
- j
;
3913 // test: echo -e '\e[44m\e[1M\e[0m'
3914 // blankLine(true) - xterm/linux behavior
3915 this.lines
.splice(j
+ 1, 0, this.blankLine(true));
3916 this.lines
.splice(row
, 1);
3919 this.updateRange(this.y
);
3920 this.updateRange(this.scrollBottom
);
3924 * Delete Ps Character(s) (default = 1) (DCH).
3926 Terminal
.prototype.deleteChars = function (params
) {
3931 row
= this.y
+ this.ybase
;
3932 ch
= [this.eraseAttr(), ' ', 1]; // xterm
3934 this.lines
[row
].splice(this.x
, 1);
3935 this.lines
[row
].push(ch
);
3940 * Erase Ps Character(s) (default = 1) (ECH).
3942 Terminal
.prototype.eraseChars = function (params
) {
3943 var param
, row
, j
, ch
;
3947 row
= this.y
+ this.ybase
;
3949 ch
= [this.eraseAttr(), ' ', 1]; // xterm
3950 while (param
-- && j
< this.cols
) {
3951 this.lines
[row
][j
++] = ch
;
3955 * CSI Pm ` Character Position Absolute
3956 * [column] (default = [row,1]) (HPA).
3958 Terminal
.prototype.charPosAbsolute = function (params
) {
3959 var param
= params
[0];
3963 if (this.x
>= this.cols
) {
3964 this.x
= this.cols
- 1;
3969 * Horizontal Position Relative
3972 Terminal
.prototype.HPositionRelative = function (params
) {
3973 var param
= params
[0];
3977 if (this.x
>= this.cols
) {
3978 this.x
= this.cols
- 1;
3982 * CSI Ps c Send Device Attributes (Primary DA).
3983 * Ps = 0 or omitted -> request attributes from terminal. The
3984 * response depends on the decTerminalID resource setting.
3985 * -> CSI ? 1 ; 2 c (``VT100 with Advanced Video Option'')
3986 * -> CSI ? 1 ; 0 c (``VT101 with No Options'')
3987 * -> CSI ? 6 c (``VT102'')
3988 * -> CSI ? 6 0 ; 1 ; 2 ; 6 ; 8 ; 9 ; 1 5 ; c (``VT220'')
3989 * The VT100-style response parameters do not mean anything by
3990 * themselves. VT220 parameters do, telling the host what fea-
3991 * tures the terminal supports:
3992 * Ps = 1 -> 132-columns.
3993 * Ps = 2 -> Printer.
3994 * Ps = 6 -> Selective erase.
3995 * Ps = 8 -> User-defined keys.
3996 * Ps = 9 -> National replacement character sets.
3997 * Ps = 1 5 -> Technical characters.
3998 * Ps = 2 2 -> ANSI color, e.g., VT525.
3999 * Ps = 2 9 -> ANSI text locator (i.e., DEC Locator mode).
4001 * Send Device Attributes (Secondary DA).
4002 * Ps = 0 or omitted -> request the terminal's identification
4003 * code. The response depends on the decTerminalID resource set-
4004 * ting. It should apply only to VT220 and up, but xterm extends
4006 * -> CSI > Pp ; Pv ; Pc c
4007 * where Pp denotes the terminal type
4008 * Pp = 0 -> ``VT100''.
4009 * Pp = 1 -> ``VT220''.
4010 * and Pv is the firmware version (for xterm, this was originally
4011 * the XFree86 patch number, starting with 95). In a DEC termi-
4012 * nal, Pc indicates the ROM cartridge registration number and is
4015 * xterm/charproc.c - line 2012, for more information.
4016 * vim responds with ^[[?0c or ^[[?1c after the terminal's response (?)
4018 Terminal
.prototype.sendDeviceAttributes = function (params
) {
4022 if (this.is('xterm')
4023 || this.is('rxvt-unicode')
4024 || this.is('screen')) {
4025 this.send('\x1b[?1;2c');
4027 else if (this.is('linux')) {
4028 this.send('\x1b[?6c');
4031 else if (this.prefix
=== '>') {
4033 // seem to spit this
4034 // out around ~370 times (?).
4035 if (this.is('xterm')) {
4036 this.send('\x1b[>0;276;0c');
4038 else if (this.is('rxvt-unicode')) {
4039 this.send('\x1b[>85;95;0c');
4041 else if (this.is('linux')) {
4042 // not supported by linux console.
4043 // linux console echoes parameters.
4044 this.send(params
[0] + 'c');
4046 else if (this.is('screen')) {
4047 this.send('\x1b[>83;40003;0c');
4053 * Line Position Absolute [row] (default = [1,column]) (VPA).
4055 Terminal
.prototype.linePosAbsolute = function (params
) {
4056 var param
= params
[0];
4060 if (this.y
>= this.rows
) {
4061 this.y
= this.rows
- 1;
4065 * 145 65 e * VPR - Vertical Position Relative
4068 Terminal
.prototype.VPositionRelative = function (params
) {
4069 var param
= params
[0];
4073 if (this.y
>= this.rows
) {
4074 this.y
= this.rows
- 1;
4079 * Horizontal and Vertical Position [row;column] (default =
4082 Terminal
.prototype.HVPosition = function (params
) {
4087 this.y
= params
[0] - 1;
4088 if (this.y
>= this.rows
) {
4089 this.y
= this.rows
- 1;
4091 this.x
= params
[1] - 1;
4092 if (this.x
>= this.cols
) {
4093 this.x
= this.cols
- 1;
4097 * CSI Pm h Set Mode (SM).
4098 * Ps = 2 -> Keyboard Action Mode (AM).
4099 * Ps = 4 -> Insert Mode (IRM).
4100 * Ps = 1 2 -> Send/receive (SRM).
4101 * Ps = 2 0 -> Automatic Newline (LNM).
4103 * DEC Private Mode Set (DECSET).
4104 * Ps = 1 -> Application Cursor Keys (DECCKM).
4105 * Ps = 2 -> Designate USASCII for character sets G0-G3
4106 * (DECANM), and set VT100 mode.
4107 * Ps = 3 -> 132 Column Mode (DECCOLM).
4108 * Ps = 4 -> Smooth (Slow) Scroll (DECSCLM).
4109 * Ps = 5 -> Reverse Video (DECSCNM).
4110 * Ps = 6 -> Origin Mode (DECOM).
4111 * Ps = 7 -> Wraparound Mode (DECAWM).
4112 * Ps = 8 -> Auto-repeat Keys (DECARM).
4113 * Ps = 9 -> Send Mouse X & Y on button press. See the sec-
4114 * tion Mouse Tracking.
4115 * Ps = 1 0 -> Show toolbar (rxvt).
4116 * Ps = 1 2 -> Start Blinking Cursor (att610).
4117 * Ps = 1 8 -> Print form feed (DECPFF).
4118 * Ps = 1 9 -> Set print extent to full screen (DECPEX).
4119 * Ps = 2 5 -> Show Cursor (DECTCEM).
4120 * Ps = 3 0 -> Show scrollbar (rxvt).
4121 * Ps = 3 5 -> Enable font-shifting functions (rxvt).
4122 * Ps = 3 8 -> Enter Tektronix Mode (DECTEK).
4123 * Ps = 4 0 -> Allow 80 -> 132 Mode.
4124 * Ps = 4 1 -> more(1) fix (see curses resource).
4125 * Ps = 4 2 -> Enable Nation Replacement Character sets (DECN-
4127 * Ps = 4 4 -> Turn On Margin Bell.
4128 * Ps = 4 5 -> Reverse-wraparound Mode.
4129 * Ps = 4 6 -> Start Logging. This is normally disabled by a
4130 * compile-time option.
4131 * Ps = 4 7 -> Use Alternate Screen Buffer. (This may be dis-
4132 * abled by the titeInhibit resource).
4133 * Ps = 6 6 -> Application keypad (DECNKM).
4134 * Ps = 6 7 -> Backarrow key sends backspace (DECBKM).
4135 * Ps = 1 0 0 0 -> Send Mouse X & Y on button press and
4136 * release. See the section Mouse Tracking.
4137 * Ps = 1 0 0 1 -> Use Hilite Mouse Tracking.
4138 * Ps = 1 0 0 2 -> Use Cell Motion Mouse Tracking.
4139 * Ps = 1 0 0 3 -> Use All Motion Mouse Tracking.
4140 * Ps = 1 0 0 4 -> Send FocusIn/FocusOut events.
4141 * Ps = 1 0 0 5 -> Enable Extended Mouse Mode.
4142 * Ps = 1 0 1 0 -> Scroll to bottom on tty output (rxvt).
4143 * Ps = 1 0 1 1 -> Scroll to bottom on key press (rxvt).
4144 * Ps = 1 0 3 4 -> Interpret "meta" key, sets eighth bit.
4145 * (enables the eightBitInput resource).
4146 * Ps = 1 0 3 5 -> Enable special modifiers for Alt and Num-
4147 * Lock keys. (This enables the numLock resource).
4148 * Ps = 1 0 3 6 -> Send ESC when Meta modifies a key. (This
4149 * enables the metaSendsEscape resource).
4150 * Ps = 1 0 3 7 -> Send DEL from the editing-keypad Delete
4152 * Ps = 1 0 3 9 -> Send ESC when Alt modifies a key. (This
4153 * enables the altSendsEscape resource).
4154 * Ps = 1 0 4 0 -> Keep selection even if not highlighted.
4155 * (This enables the keepSelection resource).
4156 * Ps = 1 0 4 1 -> Use the CLIPBOARD selection. (This enables
4157 * the selectToClipboard resource).
4158 * Ps = 1 0 4 2 -> Enable Urgency window manager hint when
4159 * Control-G is received. (This enables the bellIsUrgent
4161 * Ps = 1 0 4 3 -> Enable raising of the window when Control-G
4162 * is received. (enables the popOnBell resource).
4163 * Ps = 1 0 4 7 -> Use Alternate Screen Buffer. (This may be
4164 * disabled by the titeInhibit resource).
4165 * Ps = 1 0 4 8 -> Save cursor as in DECSC. (This may be dis-
4166 * abled by the titeInhibit resource).
4167 * Ps = 1 0 4 9 -> Save cursor as in DECSC and use Alternate
4168 * Screen Buffer, clearing it first. (This may be disabled by
4169 * the titeInhibit resource). This combines the effects of the 1
4170 * 0 4 7 and 1 0 4 8 modes. Use this with terminfo-based
4171 * applications rather than the 4 7 mode.
4172 * Ps = 1 0 5 0 -> Set terminfo/termcap function-key mode.
4173 * Ps = 1 0 5 1 -> Set Sun function-key mode.
4174 * Ps = 1 0 5 2 -> Set HP function-key mode.
4175 * Ps = 1 0 5 3 -> Set SCO function-key mode.
4176 * Ps = 1 0 6 0 -> Set legacy keyboard emulation (X11R6).
4177 * Ps = 1 0 6 1 -> Set VT220 keyboard emulation.
4178 * Ps = 2 0 0 4 -> Set bracketed paste mode.
4180 * http: *vt100.net/docs/vt220-rm/chapter4.html
4182 Terminal
.prototype.setMode = function (params
) {
4183 if (typeof params
=== 'object') {
4184 var l
= params
.length
, i
= 0;
4185 for (; i
< l
; i
++) {
4186 this.setMode(params
[i
]);
4193 this.insertMode
= true;
4196 //this.convertEol = true;
4200 else if (this.prefix
=== '?') {
4203 this.applicationCursor
= true;
4206 this.setgCharset(0, Terminal
.charsets
.US
);
4207 this.setgCharset(1, Terminal
.charsets
.US
);
4208 this.setgCharset(2, Terminal
.charsets
.US
);
4209 this.setgCharset(3, Terminal
.charsets
.US
);
4210 // set VT100 mode here
4213 this.savedCols
= this.cols
;
4214 this.resize(132, this.rows
);
4217 this.originMode
= true;
4220 this.wraparoundMode
= true;
4223 // this.cursorBlink = true;
4226 this.log('Serial port requested application keypad.');
4227 this.applicationKeypad
= true;
4228 this.viewport
.syncScrollArea();
4230 case 9: // X10 Mouse
4231 // no release, no motion, no wheel, no modifiers.
4232 case 1000: // vt200 mouse
4234 // no modifiers, except control on the wheel.
4235 case 1002: // button event mouse
4237 // any event - sends motion events,
4238 // even if there is no button held down.
4239 this.x10Mouse
= params
=== 9;
4240 this.vt200Mouse
= params
=== 1000;
4241 this.normalMouse
= params
> 1000;
4242 this.mouseEvents
= true;
4243 this.element
.style
.cursor
= 'default';
4244 this.log('Binding to mouse events.');
4249 this.sendFocus
= true;
4252 this.utfMouse
= true;
4253 // for wide terminals
4254 // simply encodes large values as utf8 characters
4257 this.sgrMouse
= true;
4258 // for wide terminals
4259 // does not add 32 to fields
4260 // press: ^[[<b;x;yM
4261 // release: ^[[<b;x;ym
4264 this.urxvtMouse
= true;
4265 // for wide terminals
4266 // numbers for fields
4268 // motion: ^[[b;x;yT
4271 this.cursorHidden
= false;
4274 //this.saveCursor();
4276 case 47: // alt screen buffer
4285 scrollTop
: this.scrollTop
,
4286 scrollBottom
: this.scrollBottom
,
4290 this.normal
= normal
;
4298 * CSI Pm l Reset Mode (RM).
4299 * Ps = 2 -> Keyboard Action Mode (AM).
4300 * Ps = 4 -> Replace Mode (IRM).
4301 * Ps = 1 2 -> Send/receive (SRM).
4302 * Ps = 2 0 -> Normal Linefeed (LNM).
4304 * DEC Private Mode Reset (DECRST).
4305 * Ps = 1 -> Normal Cursor Keys (DECCKM).
4306 * Ps = 2 -> Designate VT52 mode (DECANM).
4307 * Ps = 3 -> 80 Column Mode (DECCOLM).
4308 * Ps = 4 -> Jump (Fast) Scroll (DECSCLM).
4309 * Ps = 5 -> Normal Video (DECSCNM).
4310 * Ps = 6 -> Normal Cursor Mode (DECOM).
4311 * Ps = 7 -> No Wraparound Mode (DECAWM).
4312 * Ps = 8 -> No Auto-repeat Keys (DECARM).
4313 * Ps = 9 -> Don't send Mouse X & Y on button press.
4314 * Ps = 1 0 -> Hide toolbar (rxvt).
4315 * Ps = 1 2 -> Stop Blinking Cursor (att610).
4316 * Ps = 1 8 -> Don't print form feed (DECPFF).
4317 * Ps = 1 9 -> Limit print to scrolling region (DECPEX).
4318 * Ps = 2 5 -> Hide Cursor (DECTCEM).
4319 * Ps = 3 0 -> Don't show scrollbar (rxvt).
4320 * Ps = 3 5 -> Disable font-shifting functions (rxvt).
4321 * Ps = 4 0 -> Disallow 80 -> 132 Mode.
4322 * Ps = 4 1 -> No more(1) fix (see curses resource).
4323 * Ps = 4 2 -> Disable Nation Replacement Character sets (DEC-
4325 * Ps = 4 4 -> Turn Off Margin Bell.
4326 * Ps = 4 5 -> No Reverse-wraparound Mode.
4327 * Ps = 4 6 -> Stop Logging. (This is normally disabled by a
4328 * compile-time option).
4329 * Ps = 4 7 -> Use Normal Screen Buffer.
4330 * Ps = 6 6 -> Numeric keypad (DECNKM).
4331 * Ps = 6 7 -> Backarrow key sends delete (DECBKM).
4332 * Ps = 1 0 0 0 -> Don't send Mouse X & Y on button press and
4333 * release. See the section Mouse Tracking.
4334 * Ps = 1 0 0 1 -> Don't use Hilite Mouse Tracking.
4335 * Ps = 1 0 0 2 -> Don't use Cell Motion Mouse Tracking.
4336 * Ps = 1 0 0 3 -> Don't use All Motion Mouse Tracking.
4337 * Ps = 1 0 0 4 -> Don't send FocusIn/FocusOut events.
4338 * Ps = 1 0 0 5 -> Disable Extended Mouse Mode.
4339 * Ps = 1 0 1 0 -> Don't scroll to bottom on tty output
4341 * Ps = 1 0 1 1 -> Don't scroll to bottom on key press (rxvt).
4342 * Ps = 1 0 3 4 -> Don't interpret "meta" key. (This disables
4343 * the eightBitInput resource).
4344 * Ps = 1 0 3 5 -> Disable special modifiers for Alt and Num-
4345 * Lock keys. (This disables the numLock resource).
4346 * Ps = 1 0 3 6 -> Don't send ESC when Meta modifies a key.
4347 * (This disables the metaSendsEscape resource).
4348 * Ps = 1 0 3 7 -> Send VT220 Remove from the editing-keypad
4350 * Ps = 1 0 3 9 -> Don't send ESC when Alt modifies a key.
4351 * (This disables the altSendsEscape resource).
4352 * Ps = 1 0 4 0 -> Do not keep selection when not highlighted.
4353 * (This disables the keepSelection resource).
4354 * Ps = 1 0 4 1 -> Use the PRIMARY selection. (This disables
4355 * the selectToClipboard resource).
4356 * Ps = 1 0 4 2 -> Disable Urgency window manager hint when
4357 * Control-G is received. (This disables the bellIsUrgent
4359 * Ps = 1 0 4 3 -> Disable raising of the window when Control-
4360 * G is received. (This disables the popOnBell resource).
4361 * Ps = 1 0 4 7 -> Use Normal Screen Buffer, clearing screen
4362 * first if in the Alternate Screen. (This may be disabled by
4363 * the titeInhibit resource).
4364 * Ps = 1 0 4 8 -> Restore cursor as in DECRC. (This may be
4365 * disabled by the titeInhibit resource).
4366 * Ps = 1 0 4 9 -> Use Normal Screen Buffer and restore cursor
4367 * as in DECRC. (This may be disabled by the titeInhibit
4368 * resource). This combines the effects of the 1 0 4 7 and 1 0
4369 * 4 8 modes. Use this with terminfo-based applications rather
4370 * than the 4 7 mode.
4371 * Ps = 1 0 5 0 -> Reset terminfo/termcap function-key mode.
4372 * Ps = 1 0 5 1 -> Reset Sun function-key mode.
4373 * Ps = 1 0 5 2 -> Reset HP function-key mode.
4374 * Ps = 1 0 5 3 -> Reset SCO function-key mode.
4375 * Ps = 1 0 6 0 -> Reset legacy keyboard emulation (X11R6).
4376 * Ps = 1 0 6 1 -> Reset keyboard emulation to Sun/PC style.
4377 * Ps = 2 0 0 4 -> Reset bracketed paste mode.
4379 Terminal
.prototype.resetMode = function (params
) {
4380 if (typeof params
=== 'object') {
4381 var l
= params
.length
, i
= 0;
4382 for (; i
< l
; i
++) {
4383 this.resetMode(params
[i
]);
4390 this.insertMode
= false;
4393 //this.convertEol = false;
4397 else if (this.prefix
=== '?') {
4400 this.applicationCursor
= false;
4403 if (this.cols
=== 132 && this.savedCols
) {
4404 this.resize(this.savedCols
, this.rows
);
4406 delete this.savedCols
;
4409 this.originMode
= false;
4412 this.wraparoundMode
= false;
4415 // this.cursorBlink = false;
4418 this.log('Switching back to normal keypad.');
4419 this.applicationKeypad
= false;
4420 this.viewport
.syncScrollArea();
4422 case 9: // X10 Mouse
4423 case 1000: // vt200 mouse
4424 case 1002: // button event mouse
4426 this.x10Mouse
= false;
4427 this.vt200Mouse
= false;
4428 this.normalMouse
= false;
4429 this.mouseEvents
= false;
4430 this.element
.style
.cursor
= '';
4433 this.sendFocus
= false;
4436 this.utfMouse
= false;
4439 this.sgrMouse
= false;
4442 this.urxvtMouse
= false;
4445 this.cursorHidden
= true;
4449 case 47: // normal screen buffer
4452 this.lines
= this.normal
.lines
;
4453 this.ybase
= this.normal
.ybase
;
4454 this.ydisp
= this.normal
.ydisp
;
4455 this.x
= this.normal
.x
;
4456 this.y
= this.normal
.y
;
4457 this.scrollTop
= this.normal
.scrollTop
;
4458 this.scrollBottom
= this.normal
.scrollBottom
;
4459 this.tabs
= this.normal
.tabs
;
4461 // if (params === 1049) {
4462 // this.x = this.savedX;
4463 // this.y = this.savedY;
4465 this.refresh(0, this.rows
- 1);
4474 * Set Scrolling Region [top;bottom] (default = full size of win-
4478 Terminal
.prototype.setScrollRegion = function (params
) {
4481 this.scrollTop
= (params
[0] || 1) - 1;
4482 this.scrollBottom
= (params
[1] || this.rows
) - 1;
4488 * Save cursor (ANSI.SYS).
4490 Terminal
.prototype.saveCursor = function (params
) {
4491 this.savedX
= this.x
;
4492 this.savedY
= this.y
;
4496 * Restore cursor (ANSI.SYS).
4498 Terminal
.prototype.restoreCursor = function (params
) {
4499 this.x
= this.savedX
|| 0;
4500 this.y
= this.savedY
|| 0;
4507 * Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
4509 Terminal
.prototype.cursorForwardTab = function (params
) {
4510 var param
= params
[0] || 1;
4512 this.x
= this.nextStop();
4516 * CSI Ps S Scroll up Ps lines (default = 1) (SU).
4518 Terminal
.prototype.scrollUp = function (params
) {
4519 var param
= params
[0] || 1;
4521 this.lines
.splice(this.ybase
+ this.scrollTop
, 1);
4522 this.lines
.splice(this.ybase
+ this.scrollBottom
, 0, this.blankLine());
4525 this.updateRange(this.scrollTop
);
4526 this.updateRange(this.scrollBottom
);
4529 * CSI Ps T Scroll down Ps lines (default = 1) (SD).
4531 Terminal
.prototype.scrollDown = function (params
) {
4532 var param
= params
[0] || 1;
4534 this.lines
.splice(this.ybase
+ this.scrollBottom
, 1);
4535 this.lines
.splice(this.ybase
+ this.scrollTop
, 0, this.blankLine());
4538 this.updateRange(this.scrollTop
);
4539 this.updateRange(this.scrollBottom
);
4542 * CSI Ps ; Ps ; Ps ; Ps ; Ps T
4543 * Initiate highlight mouse tracking. Parameters are
4544 * [func;startx;starty;firstrow;lastrow]. See the section Mouse
4547 Terminal
.prototype.initMouseTracking = function (params
) {
4548 // Relevant: DECSET 1001
4552 * Reset one or more features of the title modes to the default
4553 * value. Normally, "reset" disables the feature. It is possi-
4554 * ble to disable the ability to reset features by compiling a
4555 * different default for the title modes into xterm.
4556 * Ps = 0 -> Do not set window/icon labels using hexadecimal.
4557 * Ps = 1 -> Do not query window/icon labels using hexadeci-
4559 * Ps = 2 -> Do not set window/icon labels using UTF-8.
4560 * Ps = 3 -> Do not query window/icon labels using UTF-8.
4561 * (See discussion of "Title Modes").
4563 Terminal
.prototype.resetTitleModes = function (params
) {
4567 * CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
4569 Terminal
.prototype.cursorBackwardTab = function (params
) {
4570 var param
= params
[0] || 1;
4572 this.x
= this.prevStop();
4576 * CSI Ps b Repeat the preceding graphic character Ps times (REP).
4578 Terminal
.prototype.repeatPrecedingCharacter = function (params
) {
4579 var param
= params
[0] || 1, line
= this.lines
[this.ybase
+ this.y
], ch
= line
[this.x
- 1] || [this.defAttr
, ' ', 1];
4581 line
[this.x
++] = ch
;
4584 * CSI Ps g Tab Clear (TBC).
4585 * Ps = 0 -> Clear Current Column (default).
4586 * Ps = 3 -> Clear All.
4588 * Ps = 2 -> Clear Stops on Line.
4589 * http://vt100.net/annarbor/aaa-ug/section6.html
4591 Terminal
.prototype.tabClear = function (params
) {
4592 var param
= params
[0];
4594 delete this.tabs
[this.x
];
4596 else if (param
=== 3) {
4601 * CSI Pm i Media Copy (MC).
4602 * Ps = 0 -> Print screen (default).
4603 * Ps = 4 -> Turn off printer controller mode.
4604 * Ps = 5 -> Turn on printer controller mode.
4606 * Media Copy (MC, DEC-specific).
4607 * Ps = 1 -> Print line containing cursor.
4608 * Ps = 4 -> Turn off autoprint mode.
4609 * Ps = 5 -> Turn on autoprint mode.
4610 * Ps = 1 0 -> Print composed display, ignores DECPEX.
4611 * Ps = 1 1 -> Print all pages.
4613 Terminal
.prototype.mediaCopy = function (params
) {
4618 * Set or reset resource-values used by xterm to decide whether
4619 * to construct escape sequences holding information about the
4620 * modifiers pressed with a given key. The first parameter iden-
4621 * tifies the resource to set/reset. The second parameter is the
4622 * value to assign to the resource. If the second parameter is
4623 * omitted, the resource is reset to its initial value.
4624 * Ps = 1 -> modifyCursorKeys.
4625 * Ps = 2 -> modifyFunctionKeys.
4626 * Ps = 4 -> modifyOtherKeys.
4627 * If no parameters are given, all resources are reset to their
4630 Terminal
.prototype.setResources = function (params
) {
4635 * Disable modifiers which may be enabled via the CSI > Ps; Ps m
4636 * sequence. This corresponds to a resource value of "-1", which
4637 * cannot be set with the other sequence. The parameter identi-
4638 * fies the resource to be disabled:
4639 * Ps = 1 -> modifyCursorKeys.
4640 * Ps = 2 -> modifyFunctionKeys.
4641 * Ps = 4 -> modifyOtherKeys.
4642 * If the parameter is omitted, modifyFunctionKeys is disabled.
4643 * When modifyFunctionKeys is disabled, xterm uses the modifier
4644 * keys to make an extended sequence of functions rather than
4645 * adding a parameter to each function key to denote the modi-
4648 Terminal
.prototype.disableModifiers = function (params
) {
4653 * Set resource value pointerMode. This is used by xterm to
4654 * decide whether to hide the pointer cursor as the user types.
4655 * Valid values for the parameter:
4656 * Ps = 0 -> never hide the pointer.
4657 * Ps = 1 -> hide if the mouse tracking mode is not enabled.
4658 * Ps = 2 -> always hide the pointer. If no parameter is
4659 * given, xterm uses the default, which is 1 .
4661 Terminal
.prototype.setPointerMode = function (params
) {
4665 * CSI ! p Soft terminal reset (DECSTR).
4666 * http://vt100.net/docs/vt220-rm/table4-10.html
4668 Terminal
.prototype.softReset = function (params
) {
4669 this.cursorHidden
= false;
4670 this.insertMode
= false;
4671 this.originMode
= false;
4672 this.wraparoundMode
= false; // autowrap
4673 this.applicationKeypad
= false; // ?
4674 this.viewport
.syncScrollArea();
4675 this.applicationCursor
= false;
4677 this.scrollBottom
= this.rows
- 1;
4678 this.curAttr
= this.defAttr
;
4679 this.x
= this.y
= 0; // ?
4680 this.charset
= null;
4681 this.glevel
= 0; // ??
4682 this.charsets
= [null]; // ??
4686 * Request ANSI mode (DECRQM). For VT300 and up, reply is
4688 * where Ps is the mode number as in RM, and Pm is the mode
4690 * 0 - not recognized
4693 * 3 - permanently set
4694 * 4 - permanently reset
4696 Terminal
.prototype.requestAnsiMode = function (params
) {
4701 * Request DEC private mode (DECRQM). For VT300 and up, reply is
4703 * where Ps is the mode number as in DECSET, Pm is the mode value
4704 * as in the ANSI DECRQM.
4706 Terminal
.prototype.requestPrivateMode = function (params
) {
4711 * Set conformance level (DECSCL). Valid values for the first
4713 * Ps = 6 1 -> VT100.
4714 * Ps = 6 2 -> VT200.
4715 * Ps = 6 3 -> VT300.
4716 * Valid values for the second parameter:
4717 * Ps = 0 -> 8-bit controls.
4718 * Ps = 1 -> 7-bit controls (always set for VT100).
4719 * Ps = 2 -> 8-bit controls.
4721 Terminal
.prototype.setConformanceLevel = function (params
) {
4725 * CSI Ps q Load LEDs (DECLL).
4726 * Ps = 0 -> Clear all LEDS (default).
4727 * Ps = 1 -> Light Num Lock.
4728 * Ps = 2 -> Light Caps Lock.
4729 * Ps = 3 -> Light Scroll Lock.
4730 * Ps = 2 1 -> Extinguish Num Lock.
4731 * Ps = 2 2 -> Extinguish Caps Lock.
4732 * Ps = 2 3 -> Extinguish Scroll Lock.
4734 Terminal
.prototype.loadLEDs = function (params
) {
4739 * Set cursor style (DECSCUSR, VT520).
4740 * Ps = 0 -> blinking block.
4741 * Ps = 1 -> blinking block (default).
4742 * Ps = 2 -> steady block.
4743 * Ps = 3 -> blinking underline.
4744 * Ps = 4 -> steady underline.
4746 Terminal
.prototype.setCursorStyle = function (params
) {
4751 * Select character protection attribute (DECSCA). Valid values
4752 * for the parameter:
4753 * Ps = 0 -> DECSED and DECSEL can erase (default).
4754 * Ps = 1 -> DECSED and DECSEL cannot erase.
4755 * Ps = 2 -> DECSED and DECSEL can erase.
4757 Terminal
.prototype.setCharProtectionAttr = function (params
) {
4762 * Restore DEC Private Mode Values. The value of Ps previously
4763 * saved is restored. Ps values are the same as for DECSET.
4765 Terminal
.prototype.restorePrivateValues = function (params
) {
4769 * CSI Pt; Pl; Pb; Pr; Ps$ r
4770 * Change Attributes in Rectangular Area (DECCARA), VT400 and up.
4771 * Pt; Pl; Pb; Pr denotes the rectangle.
4772 * Ps denotes the SGR attributes to change: 0, 1, 4, 5, 7.
4773 * NOTE: xterm doesn't enable this code by default.
4775 Terminal
.prototype.setAttrInRectangle = function (params
) {
4776 var t
= params
[0], l
= params
[1], b
= params
[2], r
= params
[3], attr
= params
[4];
4778 for (; t
< b
+ 1; t
++) {
4779 line
= this.lines
[this.ybase
+ t
];
4780 for (i
= l
; i
< r
; i
++) {
4781 line
[i
] = [attr
, line
[i
][1]];
4785 this.updateRange(params
[0]);
4786 this.updateRange(params
[2]);
4789 * CSI Pc; Pt; Pl; Pb; Pr$ x
4790 * Fill Rectangular Area (DECFRA), VT420 and up.
4791 * Pc is the character to use.
4792 * Pt; Pl; Pb; Pr denotes the rectangle.
4793 * NOTE: xterm doesn't enable this code by default.
4795 Terminal
.prototype.fillRectangle = function (params
) {
4796 var ch
= params
[0], t
= params
[1], l
= params
[2], b
= params
[3], r
= params
[4];
4798 for (; t
< b
+ 1; t
++) {
4799 line
= this.lines
[this.ybase
+ t
];
4800 for (i
= l
; i
< r
; i
++) {
4801 line
[i
] = [line
[i
][0], String
.fromCharCode(ch
)];
4805 this.updateRange(params
[1]);
4806 this.updateRange(params
[3]);
4810 * Enable Locator Reporting (DECELR).
4811 * Valid values for the first parameter:
4812 * Ps = 0 -> Locator disabled (default).
4813 * Ps = 1 -> Locator enabled.
4814 * Ps = 2 -> Locator enabled for one report, then disabled.
4815 * The second parameter specifies the coordinate unit for locator
4817 * Valid values for the second parameter:
4818 * Pu = 0 <- or omitted -> default to character cells.
4819 * Pu = 1 <- device physical pixels.
4820 * Pu = 2 <- character cells.
4822 Terminal
.prototype.enableLocatorReporting = function (params
) {
4823 var val
= params
[0] > 0;
4824 //this.mouseEvents = val;
4825 //this.decLocator = val;
4828 * CSI Pt; Pl; Pb; Pr$ z
4829 * Erase Rectangular Area (DECERA), VT400 and up.
4830 * Pt; Pl; Pb; Pr denotes the rectangle.
4831 * NOTE: xterm doesn't enable this code by default.
4833 Terminal
.prototype.eraseRectangle = function (params
) {
4834 var t
= params
[0], l
= params
[1], b
= params
[2], r
= params
[3];
4836 ch
= [this.eraseAttr(), ' ', 1]; // xterm?
4837 for (; t
< b
+ 1; t
++) {
4838 line
= this.lines
[this.ybase
+ t
];
4839 for (i
= l
; i
< r
; i
++) {
4844 this.updateRange(params
[0]);
4845 this.updateRange(params
[2]);
4849 * Insert P s Column(s) (default = 1) (DECIC), VT420 and up.
4850 * NOTE: xterm doesn't enable this code by default.
4852 Terminal
.prototype.insertColumns = function () {
4853 var param
= params
[0], l
= this.ybase
+ this.rows
, ch
= [this.eraseAttr(), ' ', 1] // xterm?
4856 for (i
= this.ybase
; i
< l
; i
++) {
4857 this.lines
[i
].splice(this.x
+ 1, 0, ch
);
4858 this.lines
[i
].pop();
4865 * Delete P s Column(s) (default = 1) (DECDC), VT420 and up
4866 * NOTE: xterm doesn't enable this code by default.
4868 Terminal
.prototype.deleteColumns = function () {
4869 var param
= params
[0], l
= this.ybase
+ this.rows
, ch
= [this.eraseAttr(), ' ', 1] // xterm?
4872 for (i
= this.ybase
; i
< l
; i
++) {
4873 this.lines
[i
].splice(this.x
, 1);
4874 this.lines
[i
].push(ch
);
4882 Terminal
.charsets
= {};
4883 // DEC Special Character and Line Drawing Set.
4884 // http://vt100.net/docs/vt102-ug/table5-13.html
4885 // A lot of curses apps use this if they see TERM=xterm.
4886 // testing: echo -e '\e(0a\e(B'
4887 // The xterm output sometimes seems to conflict with the
4888 // reference above. xterm seems in line with the reference
4889 // when running vttest however.
4890 // The table below now uses xterm's output from vttest.
4891 Terminal
.charsets
.SCLD
= {
4922 '~': '\u00b7' // '·'
4924 Terminal
.charsets
.UK
= null; // (A
4925 Terminal
.charsets
.US
= null; // (B (USASCII)
4926 Terminal
.charsets
.Dutch
= null; // (4
4927 Terminal
.charsets
.Finnish
= null; // (C or (5
4928 Terminal
.charsets
.French
= null; // (R
4929 Terminal
.charsets
.FrenchCanadian
= null; // (Q
4930 Terminal
.charsets
.German
= null; // (K
4931 Terminal
.charsets
.Italian
= null; // (Y
4932 Terminal
.charsets
.NorwegianDanish
= null; // (E or (6
4933 Terminal
.charsets
.Spanish
= null; // (Z
4934 Terminal
.charsets
.Swedish
= null; // (H or (7
4935 Terminal
.charsets
.Swiss
= null; // (=
4936 Terminal
.charsets
.ISOLatin
= null; // /A
4940 function on(el
, type
, handler
, capture
) {
4941 if (!Array
.isArray(el
)) {
4944 el
.forEach(function (element
) {
4945 element
.addEventListener(type
, handler
, capture
|| false);
4948 function off(el
, type
, handler
, capture
) {
4949 el
.removeEventListener(type
, handler
, capture
|| false);
4951 function cancel(ev
, force
) {
4952 if (!this.cancelEvents
&& !force
) {
4955 ev
.preventDefault();
4956 ev
.stopPropagation();
4959 function inherits(child
, parent
) {
4961 this.constructor = child
;
4963 f
.prototype = parent
.prototype;
4964 child
.prototype = new f
;
4966 // if bold is broken, we can't
4967 // use it in the terminal.
4968 function isBoldBroken(document
) {
4969 var body
= document
.getElementsByTagName('body')[0];
4970 var el
= document
.createElement('span');
4971 el
.innerHTML
= 'hello world';
4972 body
.appendChild(el
);
4973 var w1
= el
.scrollWidth
;
4974 el
.style
.fontWeight
= 'bold';
4975 var w2
= el
.scrollWidth
;
4976 body
.removeChild(el
);
4979 function indexOf(obj
, el
) {
4987 function isThirdLevelShift(term
, ev
) {
4988 var thirdLevelKey
= (term
.browser
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) ||
4989 (term
.browser
.isMSWindows
&& ev
.altKey
&& ev
.ctrlKey
&& !ev
.metaKey
);
4990 if (ev
.type
== 'keypress') {
4991 return thirdLevelKey
;
4993 // Don't invoke for arrows, pageDown, home, backspace, etc. (on non-keypress events)
4994 return thirdLevelKey
&& (!ev
.keyCode
|| ev
.keyCode
> 47);
4996 function matchColor(r1
, g1
, b1
) {
4997 var hash
= (r1
<< 16) | (g1
<< 8) | b1
;
4998 if (matchColor
._cache
[hash
] != null) {
4999 return matchColor
._cache
[hash
];
5001 var ldiff
= Infinity
, li
= -1, i
= 0, c
, r2
, g2
, b2
, diff
;
5002 for (; i
< Terminal
.vcolors
.length
; i
++) {
5003 c
= Terminal
.vcolors
[i
];
5007 diff
= matchColor
.distance(r1
, g1
, b1
, r2
, g2
, b2
);
5017 return matchColor
._cache
[hash
] = li
;
5019 matchColor
._cache
= {};
5020 // http://stackoverflow.com/questions/1633828
5021 matchColor
.distance = function (r1
, g1
, b1
, r2
, g2
, b2
) {
5022 return Math
.pow(30 * (r1
- r2
), 2)
5023 + Math
.pow(59 * (g1
- g2
), 2)
5024 + Math
.pow(11 * (b1
- b2
), 2);
5026 function each(obj
, iter
, con
) {
5028 return obj
.forEach(iter
, con
);
5029 for (var i
= 0; i
< obj
.length
; i
++) {
5030 iter
.call(con
, obj
[i
], i
, obj
);
5033 function keys(obj
) {
5035 return Object
.keys(obj
);
5038 if (Object
.prototype.hasOwnProperty
.call(obj
, key
)) {
5044 var wcwidth
= (function (opts
) {
5045 // extracted from https://www.cl.cam.ac.uk/%7Emgk25/ucs/wcwidth.c
5046 // combining characters
5048 [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
5049 [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
5050 [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
5051 [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670],
5052 [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED],
5053 [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A],
5054 [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902],
5055 [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D],
5056 [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981],
5057 [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD],
5058 [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C],
5059 [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D],
5060 [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC],
5061 [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD],
5062 [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C],
5063 [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D],
5064 [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0],
5065 [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48],
5066 [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC],
5067 [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD],
5068 [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D],
5069 [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6],
5070 [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E],
5071 [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC],
5072 [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35],
5073 [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E],
5074 [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97],
5075 [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030],
5076 [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039],
5077 [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F],
5078 [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753],
5079 [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD],
5080 [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD],
5081 [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922],
5082 [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B],
5083 [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34],
5084 [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42],
5085 [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF],
5086 [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063],
5087 [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F],
5088 [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B],
5089 [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F],
5090 [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB],
5091 [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F],
5092 [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169],
5093 [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD],
5094 [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F],
5098 function bisearch(ucs
) {
5100 var max
= COMBINING
.length
- 1;
5102 if (ucs
< COMBINING
[0][0] || ucs
> COMBINING
[max
][1])
5104 while (max
>= min
) {
5105 mid
= Math
.floor((min
+ max
) / 2);
5106 if (ucs
> COMBINING
[mid
][1])
5108 else if (ucs
< COMBINING
[mid
][0])
5115 function wcwidth(ucs
) {
5116 // test for 8-bit control characters
5119 if (ucs
< 32 || (ucs
>= 0x7f && ucs
< 0xa0))
5120 return opts
.control
;
5121 // binary search in table of non-spacing characters
5124 // if we arrive here, ucs is not a combining or C0/C1 control character
5130 (ucs
>= 0x2e80 && ucs
<= 0xa4cf && ucs
!= 0x303f) ||
5131 (ucs
>= 0xac00 && ucs
<= 0xd7a3) ||
5132 (ucs
>= 0xf900 && ucs
<= 0xfaff) ||
5133 (ucs
>= 0xfe10 && ucs
<= 0xfe19) ||
5134 (ucs
>= 0xfe30 && ucs
<= 0xfe6f) ||
5135 (ucs
>= 0xff00 && ucs
<= 0xff60) ||
5136 (ucs
>= 0xffe0 && ucs
<= 0xffe6) ||
5137 (ucs
>= 0x20000 && ucs
<= 0x2fffd) ||
5138 (ucs
>= 0x30000 && ucs
<= 0x3fffd)));
5141 })({ nul
: 0, control
: 0 }); // configurable options
5145 Terminal
.EventEmitter
= EventEmitter_js_1
.EventEmitter
;
5146 Terminal
.inherits
= inherits
;
5148 * Adds an event listener to the terminal.
5150 * @param {string} event The name of the event. TODO: Document all event types
5151 * @param {function} callback The function to call when the event is triggered.
5155 Terminal
.cancel
= cancel
;
5156 module
.exports
= Terminal
;
5158 },{"./CompositionHelper.js":1,"./EventEmitter.js":2,"./Viewport.js":3,"./handlers/Clipboard.js":4,"./utils/Browser":5}]},{},[7])(7)
5160 //# sourceMappingURL=xterm.js.map