]> git.proxmox.com Git - mirror_xterm.js.git/blob - dist/xterm.js
Merge remote-tracking branch 'upstream/master' into typescript_build_2
[mirror_xterm.js.git] / dist / xterm.js
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(_dereq_,module,exports){
2 'use strict';
3
4 Object.defineProperty(exports, "__esModule", {
5 value: true
6 });
7 /**
8 * xterm.js: xterm, in the browser
9 * Copyright (c) 2014-2016, SourceLair Private Company (www.sourcelair.com (MIT License)
10 */
11
12 /**
13 * Encapsulates the logic for handling compositionstart, compositionupdate and compositionend
14 * events, displaying the in-progress composition to the UI and forwarding the final composition
15 * to the handler.
16 * @param {HTMLTextAreaElement} textarea The textarea that xterm uses for input.
17 * @param {HTMLElement} compositionView The element to display the in-progress composition in.
18 * @param {Terminal} terminal The Terminal to forward the finished composition to.
19 */
20 function CompositionHelper(textarea, compositionView, terminal) {
21 this.textarea = textarea;
22 this.compositionView = compositionView;
23 this.terminal = terminal;
24
25 // Whether input composition is currently happening, eg. via a mobile keyboard, speech input
26 // or IME. This variable determines whether the compositionText should be displayed on the UI.
27 this.isComposing = false;
28
29 // The input currently being composed, eg. via a mobile keyboard, speech input or IME.
30 this.compositionText = null;
31
32 // The position within the input textarea's value of the current composition.
33 this.compositionPosition = { start: null, end: null };
34
35 // Whether a composition is in the process of being sent, setting this to false will cancel
36 // any in-progress composition.
37 this.isSendingComposition = false;
38 }
39
40 /**
41 * Handles the compositionstart event, activating the composition view.
42 */
43 CompositionHelper.prototype.compositionstart = function () {
44 this.isComposing = true;
45 this.compositionPosition.start = this.textarea.value.length;
46 this.compositionView.textContent = '';
47 this.compositionView.classList.add('active');
48 };
49
50 /**
51 * Handles the compositionupdate event, updating the composition view.
52 * @param {CompositionEvent} ev The event.
53 */
54 CompositionHelper.prototype.compositionupdate = function (ev) {
55 this.compositionView.textContent = ev.data;
56 this.updateCompositionElements();
57 var self = this;
58 setTimeout(function () {
59 self.compositionPosition.end = self.textarea.value.length;
60 }, 0);
61 };
62
63 /**
64 * Handles the compositionend event, hiding the composition view and sending the composition to
65 * the handler.
66 */
67 CompositionHelper.prototype.compositionend = function () {
68 this.finalizeComposition(true);
69 };
70
71 /**
72 * Handles the keydown event, routing any necessary events to the CompositionHelper functions.
73 * @return Whether the Terminal should continue processing the keydown event.
74 */
75 CompositionHelper.prototype.keydown = function (ev) {
76 if (this.isComposing || this.isSendingComposition) {
77 if (ev.keyCode === 229) {
78 // Continue composing if the keyCode is the "composition character"
79 return false;
80 } else if (ev.keyCode === 16 || ev.keyCode === 17 || ev.keyCode === 18) {
81 // Continue composing if the keyCode is a modifier key
82 return false;
83 } else {
84 // Finish composition immediately. This is mainly here for the case where enter is
85 // pressed and the handler needs to be triggered before the command is executed.
86 this.finalizeComposition(false);
87 }
88 }
89
90 if (ev.keyCode === 229) {
91 // If the "composition character" is used but gets to this point it means a non-composition
92 // character (eg. numbers and punctuation) was pressed when the IME was active.
93 this.handleAnyTextareaChanges();
94 return false;
95 }
96
97 return true;
98 };
99
100 /**
101 * Finalizes the composition, resuming regular input actions. This is called when a composition
102 * is ending.
103 * @param {boolean} waitForPropogation Whether to wait for events to propogate before sending
104 * the input. This should be false if a non-composition keystroke is entered before the
105 * compositionend event is triggered, such as enter, so that the composition is send before
106 * the command is executed.
107 */
108 CompositionHelper.prototype.finalizeComposition = function (waitForPropogation) {
109 this.compositionView.classList.remove('active');
110 this.isComposing = false;
111 this.clearTextareaPosition();
112
113 if (!waitForPropogation) {
114 // Cancel any delayed composition send requests and send the input immediately.
115 this.isSendingComposition = false;
116 var input = this.textarea.value.substring(this.compositionPosition.start, this.compositionPosition.end);
117 this.terminal.handler(input);
118 } else {
119 // Make a deep copy of the composition position here as a new compositionstart event may
120 // fire before the setTimeout executes.
121 var currentCompositionPosition = {
122 start: this.compositionPosition.start,
123 end: this.compositionPosition.end
124 };
125
126 // Since composition* events happen before the changes take place in the textarea on most
127 // browsers, use a setTimeout with 0ms time to allow the native compositionend event to
128 // complete. This ensures the correct character is retrieved, this solution was used
129 // because:
130 // - The compositionend event's data property is unreliable, at least on Chromium
131 // - The last compositionupdate event's data property does not always accurately describe
132 // the character, a counter example being Korean where an ending consonsant can move to
133 // the following character if the following input is a vowel.
134 var self = this;
135 this.isSendingComposition = true;
136 setTimeout(function () {
137 // Ensure that the input has not already been sent
138 if (self.isSendingComposition) {
139 self.isSendingComposition = false;
140 var input;
141 if (self.isComposing) {
142 // Use the end position to get the string if a new composition has started.
143 input = self.textarea.value.substring(currentCompositionPosition.start, currentCompositionPosition.end);
144 } else {
145 // Don't use the end position here in order to pick up any characters after the
146 // composition has finished, for example when typing a non-composition character
147 // (eg. 2) after a composition character.
148 input = self.textarea.value.substring(currentCompositionPosition.start);
149 }
150 self.terminal.handler(input);
151 }
152 }, 0);
153 }
154 };
155
156 /**
157 * Apply any changes made to the textarea after the current event chain is allowed to complete.
158 * This should be called when not currently composing but a keydown event with the "composition
159 * character" (229) is triggered, in order to allow non-composition text to be entered when an
160 * IME is active.
161 */
162 CompositionHelper.prototype.handleAnyTextareaChanges = function () {
163 var oldValue = this.textarea.value;
164 var self = this;
165 setTimeout(function () {
166 // Ignore if a composition has started since the timeout
167 if (!self.isComposing) {
168 var newValue = self.textarea.value;
169 var diff = newValue.replace(oldValue, '');
170 if (diff.length > 0) {
171 self.terminal.handler(diff);
172 }
173 }
174 }, 0);
175 };
176
177 /**
178 * Positions the composition view on top of the cursor and the textarea just below it (so the
179 * IME helper dialog is positioned correctly).
180 */
181 CompositionHelper.prototype.updateCompositionElements = function (dontRecurse) {
182 if (!this.isComposing) {
183 return;
184 }
185 var cursor = this.terminal.element.querySelector('.terminal-cursor');
186 if (cursor) {
187 this.compositionView.style.left = cursor.offsetLeft + 'px';
188 this.compositionView.style.top = cursor.offsetTop + 'px';
189 var compositionViewBounds = this.compositionView.getBoundingClientRect();
190 this.textarea.style.left = cursor.offsetLeft + compositionViewBounds.width + 'px';
191 this.textarea.style.top = cursor.offsetTop + cursor.offsetHeight + 'px';
192 }
193 if (!dontRecurse) {
194 setTimeout(this.updateCompositionElements.bind(this, true), 0);
195 }
196 };
197
198 /**
199 * Clears the textarea's position so that the cursor does not blink on IE.
200 * @private
201 */
202 CompositionHelper.prototype.clearTextareaPosition = function () {
203 this.textarea.style.left = '';
204 this.textarea.style.top = '';
205 };
206
207 exports.CompositionHelper = CompositionHelper;
208
209 },{}],2:[function(_dereq_,module,exports){
210 "use strict";
211
212 Object.defineProperty(exports, "__esModule", {
213 value: true
214 });
215 /**
216 * xterm.js: xterm, in the browser
217 * Copyright (c) 2014-2016, SourceLair Private Company (www.sourcelair.com (MIT License)
218 */
219
220 function EventEmitter() {
221 this._events = this._events || {};
222 }
223
224 EventEmitter.prototype.addListener = function (type, listener) {
225 this._events[type] = this._events[type] || [];
226 this._events[type].push(listener);
227 };
228
229 EventEmitter.prototype.on = EventEmitter.prototype.addListener;
230
231 EventEmitter.prototype.removeListener = function (type, listener) {
232 if (!this._events[type]) return;
233
234 var obj = this._events[type],
235 i = obj.length;
236
237 while (i--) {
238 if (obj[i] === listener || obj[i].listener === listener) {
239 obj.splice(i, 1);
240 return;
241 }
242 }
243 };
244
245 EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
246
247 EventEmitter.prototype.removeAllListeners = function (type) {
248 if (this._events[type]) delete this._events[type];
249 };
250
251 EventEmitter.prototype.once = function (type, listener) {
252 var self = this;
253 function on() {
254 var args = Array.prototype.slice.call(arguments);
255 this.removeListener(type, on);
256 return listener.apply(this, args);
257 }
258 on.listener = listener;
259 return this.on(type, on);
260 };
261
262 EventEmitter.prototype.emit = function (type) {
263 if (!this._events[type]) return;
264
265 var args = Array.prototype.slice.call(arguments, 1),
266 obj = this._events[type],
267 l = obj.length,
268 i = 0;
269
270 for (; i < l; i++) {
271 obj[i].apply(this, args);
272 }
273 };
274
275 EventEmitter.prototype.listeners = function (type) {
276 return this._events[type] = this._events[type] || [];
277 };
278
279 exports.EventEmitter = EventEmitter;
280
281 },{}],3:[function(_dereq_,module,exports){
282 'use strict';
283
284 Object.defineProperty(exports, "__esModule", {
285 value: true
286 });
287 /**
288 * xterm.js: xterm, in the browser
289 * Copyright (c) 2014-2016, SourceLair Private Company (www.sourcelair.com (MIT License)
290 */
291
292 /**
293 * Represents the viewport of a terminal, the visible area within the larger buffer of output.
294 * Logic for the virtual scroll bar is included in this object.
295 * @param {Terminal} terminal The Terminal object.
296 * @param {HTMLElement} viewportElement The DOM element acting as the viewport
297 * @param {HTMLElement} charMeasureElement A DOM element used to measure the character size of
298 * the terminal.
299 */
300 function Viewport(terminal, viewportElement, scrollArea, charMeasureElement) {
301 this.terminal = terminal;
302 this.viewportElement = viewportElement;
303 this.scrollArea = scrollArea;
304 this.charMeasureElement = charMeasureElement;
305 this.currentRowHeight = 0;
306 this.lastRecordedBufferLength = 0;
307 this.lastRecordedViewportHeight = 0;
308
309 this.terminal.on('scroll', this.syncScrollArea.bind(this));
310 this.terminal.on('resize', this.syncScrollArea.bind(this));
311 this.viewportElement.addEventListener('scroll', this.onScroll.bind(this));
312
313 this.syncScrollArea();
314 }
315
316 /**
317 * Refreshes row height, setting line-height, viewport height and scroll area height if
318 * necessary.
319 * @param {number|undefined} charSize A character size measurement bounding rect object, if it
320 * doesn't exist it will be created.
321 */
322 Viewport.prototype.refresh = function (charSize) {
323 var size = charSize || this.charMeasureElement.getBoundingClientRect();
324 if (size.height > 0) {
325 var rowHeightChanged = size.height !== this.currentRowHeight;
326 if (rowHeightChanged) {
327 this.currentRowHeight = size.height;
328 this.viewportElement.style.lineHeight = size.height + 'px';
329 this.terminal.rowContainer.style.lineHeight = size.height + 'px';
330 }
331 var viewportHeightChanged = this.lastRecordedViewportHeight !== this.terminal.rows;
332 if (rowHeightChanged || viewportHeightChanged) {
333 this.lastRecordedViewportHeight = this.terminal.rows;
334 this.viewportElement.style.height = size.height * this.terminal.rows + 'px';
335 }
336 this.scrollArea.style.height = size.height * this.lastRecordedBufferLength + 'px';
337 }
338 };
339
340 /**
341 * Updates dimensions and synchronizes the scroll area if necessary.
342 */
343 Viewport.prototype.syncScrollArea = function () {
344 if (this.lastRecordedBufferLength !== this.terminal.lines.length) {
345 // If buffer height changed
346 this.lastRecordedBufferLength = this.terminal.lines.length;
347 this.refresh();
348 } else if (this.lastRecordedViewportHeight !== this.terminal.rows) {
349 // If viewport height changed
350 this.refresh();
351 } else {
352 // If size has changed, refresh viewport
353 var size = this.charMeasureElement.getBoundingClientRect();
354 if (size.height !== this.currentRowHeight) {
355 this.refresh(size);
356 }
357 }
358
359 // Sync scrollTop
360 var scrollTop = this.terminal.ydisp * this.currentRowHeight;
361 if (this.viewportElement.scrollTop !== scrollTop) {
362 this.viewportElement.scrollTop = scrollTop;
363 }
364 };
365
366 /**
367 * Handles scroll events on the viewport, calculating the new viewport and requesting the
368 * terminal to scroll to it.
369 * @param {Event} ev The scroll event.
370 */
371 Viewport.prototype.onScroll = function (ev) {
372 var newRow = Math.round(this.viewportElement.scrollTop / this.currentRowHeight);
373 var diff = newRow - this.terminal.ydisp;
374 this.terminal.scrollDisp(diff, true);
375 };
376
377 /**
378 * Handles mouse wheel events by adjusting the viewport's scrollTop and delegating the actual
379 * scrolling to `onScroll`, this event needs to be attached manually by the consumer of
380 * `Viewport`.
381 * @param {WheelEvent} ev The mouse wheel event.
382 */
383 Viewport.prototype.onWheel = function (ev) {
384 if (ev.deltaY === 0) {
385 // Do nothing if it's not a vertical scroll event
386 return;
387 }
388 // Fallback to WheelEvent.DOM_DELTA_PIXEL
389 var multiplier = 1;
390 if (ev.deltaMode === WheelEvent.DOM_DELTA_LINE) {
391 multiplier = this.currentRowHeight;
392 } else if (ev.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
393 multiplier = this.currentRowHeight * this.terminal.rows;
394 }
395 this.viewportElement.scrollTop += ev.deltaY * multiplier;
396 // Prevent the page from scrolling when the terminal scrolls
397 ev.preventDefault();
398 };
399
400 exports.Viewport = Viewport;
401
402 },{}],4:[function(_dereq_,module,exports){
403 'use strict';
404
405 Object.defineProperty(exports, "__esModule", {
406 value: true
407 });
408 /**
409 * xterm.js: xterm, in the browser
410 * Copyright (c) 2016, SourceLair Private Company <www.sourcelair.com> (MIT License)
411 */
412
413 /**
414 * Clipboard handler module. This module contains methods for handling all
415 * clipboard-related events appropriately in the terminal.
416 * @module xterm/handlers/Clipboard
417 */
418
419 /**
420 * Prepares text copied from terminal selection, to be saved in the clipboard by:
421 * 1. stripping all trailing white spaces
422 * 2. converting all non-breaking spaces to regular spaces
423 * @param {string} text The copied text that needs processing for storing in clipboard
424 * @returns {string}
425 */
426 function prepareTextForClipboard(text) {
427 var space = String.fromCharCode(32),
428 nonBreakingSpace = String.fromCharCode(160),
429 allNonBreakingSpaces = new RegExp(nonBreakingSpace, 'g'),
430 processedText = text.split('\n').map(function (line) {
431 // Strip all trailing white spaces and convert all non-breaking spaces
432 // to regular spaces.
433 var processedLine = line.replace(/\s+$/g, '').replace(allNonBreakingSpaces, space);
434
435 return processedLine;
436 }).join('\n');
437
438 return processedText;
439 }
440
441 /**
442 * Binds copy functionality to the given terminal.
443 * @param {ClipboardEvent} ev The original copy event to be handled
444 */
445 function copyHandler(ev) {
446 var copiedText = window.getSelection().toString(),
447 text = prepareTextForClipboard(copiedText);
448
449 ev.clipboardData.setData('text/plain', text);
450 ev.preventDefault(); // Prevent or the original text will be copied.
451 }
452
453 /**
454 * Redirect the clipboard's data to the terminal's input handler.
455 * @param {ClipboardEvent} ev The original paste event to be handled
456 * @param {Terminal} term The terminal on which to apply the handled paste event
457 */
458 function pasteHandler(ev, term) {
459 ev.stopPropagation();
460 if (ev.clipboardData) {
461 var text = ev.clipboardData.getData('text/plain');
462 term.handler(text);
463 term.textarea.value = '';
464 return term.cancel(ev);
465 }
466 }
467
468 /**
469 * Bind to right-click event and allow right-click copy and paste.
470 *
471 * **Logic**
472 * If text is selected and right-click happens on selected text, then
473 * do nothing to allow seamless copying.
474 * If no text is selected or right-click is outside of the selection
475 * area, then bring the terminal's input below the cursor, in order to
476 * trigger the event on the textarea and allow-right click paste, without
477 * caring about disappearing selection.
478 * @param {ClipboardEvent} ev The original paste event to be handled
479 * @param {Terminal} term The terminal on which to apply the handled paste event
480 */
481 function rightClickHandler(ev, term) {
482 var s = document.getSelection(),
483 sText = prepareTextForClipboard(s.toString()),
484 r = s.getRangeAt(0);
485
486 var x = ev.clientX,
487 y = ev.clientY;
488
489 var cr = r.getClientRects(),
490 clickIsOnSelection = false,
491 i,
492 rect;
493
494 for (i = 0; i < cr.length; i++) {
495 rect = cr[i];
496 clickIsOnSelection = x > rect.left && x < rect.right && y > rect.top && y < rect.bottom;
497 // If we clicked on selection and selection is not a single space,
498 // then mark the right click as copy-only. We check for the single
499 // space selection, as this can happen when clicking on an &nbsp;
500 // and there is not much pointing in copying a single space.
501 // Single space is char
502 if (clickIsOnSelection && sText !== ' ') {
503 break;
504 }
505 }
506
507 // Bring textarea at the cursor position
508 if (!clickIsOnSelection) {
509 term.textarea.style.position = 'fixed';
510 term.textarea.style.width = '10px';
511 term.textarea.style.height = '10px';
512 term.textarea.style.left = x + 'px';
513 term.textarea.style.top = y + 'px';
514 term.textarea.style.zIndex = 1000;
515 term.textarea.focus();
516
517 // Reset the terminal textarea's styling
518 setTimeout(function () {
519 term.textarea.style.position = null;
520 term.textarea.style.width = null;
521 term.textarea.style.height = null;
522 term.textarea.style.left = null;
523 term.textarea.style.top = null;
524 term.textarea.style.zIndex = null;
525 }, 1);
526 }
527 }
528
529 exports.prepareTextForClipboard = prepareTextForClipboard;
530 exports.copyHandler = copyHandler;
531 exports.pasteHandler = pasteHandler;
532 exports.rightClickHandler = rightClickHandler;
533
534 },{}],5:[function(_dereq_,module,exports){
535 (function (__dirname){
536 'use strict';var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj;}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};/**
537 * xterm.js: xterm, in the browser
538 * Copyright (c) 2014-2014, SourceLair Private Company <www.sourcelair.com> (MIT License)
539 * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
540 * https://github.com/chjj/term.js
541 *
542 * Permission is hereby granted, free of charge, to any person obtaining a copy
543 * of this software and associated documentation files (the "Software"), to deal
544 * in the Software without restriction, including without limitation the rights
545 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
546 * copies of the Software, and to permit persons to whom the Software is
547 * furnished to do so, subject to the following conditions:
548 *
549 * The above copyright notice and this permission notice shall be included in
550 * all copies or substantial portions of the Software.
551 *
552 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
553 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
554 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
555 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
556 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
557 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
558 * THE SOFTWARE.
559 *
560 * Originally forked from (with the author's permission):
561 * Fabrice Bellard's javascript vt100 for jslinux:
562 * http://bellard.org/jslinux/
563 * Copyright (c) 2011 Fabrice Bellard
564 * The original design remains. The terminal itself
565 * has been extended to include xterm CSI codes, among
566 * other features.
567 */var _CompositionHelper=_dereq_('./CompositionHelper.js');var _EventEmitter=_dereq_('./EventEmitter.js');var _Viewport=_dereq_('./Viewport.js');var _Clipboard=_dereq_('./handlers/Clipboard.js');/**
568 * Terminal Emulation References:
569 * http://vt100.net/
570 * http://invisible-island.net/xterm/ctlseqs/ctlseqs.txt
571 * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
572 * http://invisible-island.net/vttest/
573 * http://www.inwap.com/pdp10/ansicode.txt
574 * http://linux.die.net/man/4/console_codes
575 * http://linux.die.net/man/7/urxvt
576 */// Let it work inside Node.js for automated testing purposes.
577 var document=typeof window!='undefined'?window.document:null;/**
578 * States
579 */var normal=0,escaped=1,csi=2,osc=3,charset=4,dcs=5,ignore=6;/**
580 * Terminal
581 *//**
582 * Creates a new `Terminal` object.
583 *
584 * @param {object} options An object containing a set of options, the available options are:
585 * - cursorBlink (boolean): Whether the terminal cursor blinks
586 *
587 * @public
588 * @class Xterm Xterm
589 * @alias module:xterm/src/xterm
590 */function Terminal(options){var self=this;if(!(this instanceof Terminal)){return new Terminal(arguments[0],arguments[1],arguments[2]);}self.cancel=Terminal.cancel;_EventEmitter.EventEmitter.call(this);if(typeof options==='number'){options={cols:arguments[0],rows:arguments[1],handler:arguments[2]};}options=options||{};Object.keys(Terminal.defaults).forEach(function(key){if(options[key]==null){options[key]=Terminal.options[key];if(Terminal[key]!==Terminal.defaults[key]){options[key]=Terminal[key];}}self[key]=options[key];});if(options.colors.length===8){options.colors=options.colors.concat(Terminal._colors.slice(8));}else if(options.colors.length===16){options.colors=options.colors.concat(Terminal._colors.slice(16));}else if(options.colors.length===10){options.colors=options.colors.slice(0,-2).concat(Terminal._colors.slice(8,-2),options.colors.slice(-2));}else if(options.colors.length===18){options.colors=options.colors.concat(Terminal._colors.slice(16,-2),options.colors.slice(-2));}this.colors=options.colors;this.options=options;// this.context = options.context || window;
591 // this.document = options.document || document;
592 this.parent=options.body||options.parent||(document?document.getElementsByTagName('body')[0]:null);this.cols=options.cols||options.geometry[0];this.rows=options.rows||options.geometry[1];if(options.handler){this.on('data',options.handler);}/**
593 * The scroll position of the y cursor, ie. ybase + y = the y position within the entire
594 * buffer
595 */this.ybase=0;/**
596 * The scroll position of the viewport
597 */this.ydisp=0;/**
598 * The cursor's x position after ybase
599 */this.x=0;/**
600 * The cursor's y position after ybase
601 */this.y=0;/**
602 * Used to debounce the refresh function
603 */this.isRefreshing=false;/**
604 * Whether there is a full terminal refresh queued
605 */this.cursorState=0;this.cursorHidden=false;this.convertEol;this.state=0;this.queue='';this.scrollTop=0;this.scrollBottom=this.rows-1;this.customKeydownHandler=null;// modes
606 this.applicationKeypad=false;this.applicationCursor=false;this.originMode=false;this.insertMode=false;this.wraparoundMode=true;// defaults: xterm - true, vt100 - false
607 this.normal=null;// charset
608 this.charset=null;this.gcharset=null;this.glevel=0;this.charsets=[null];// mouse properties
609 this.decLocator;this.x10Mouse;this.vt200Mouse;this.vt300Mouse;this.normalMouse;this.mouseEvents;this.sendFocus;this.utfMouse;this.sgrMouse;this.urxvtMouse;// misc
610 this.element;this.children;this.refreshStart;this.refreshEnd;this.savedX;this.savedY;this.savedCols;// stream
611 this.readable=true;this.writable=true;this.defAttr=0<<18|257<<9|256<<0;this.curAttr=this.defAttr;this.params=[];this.currentParam=0;this.prefix='';this.postfix='';// leftover surrogate high from previous write invocation
612 this.surrogate_high='';/**
613 * An array of all lines in the entire buffer, including the prompt. The lines are array of
614 * characters which are 2-length arrays where [0] is an attribute and [1] is the character.
615 */this.lines=[];var i=this.rows;while(i--){this.lines.push(this.blankLine());}this.tabs;this.setupStops();}inherits(Terminal,_EventEmitter.EventEmitter);/**
616 * back_color_erase feature for xterm.
617 */Terminal.prototype.eraseAttr=function(){// if (this.is('screen')) return this.defAttr;
618 return this.defAttr&~0x1ff|this.curAttr&0x1ff;};/**
619 * Colors
620 */// Colors 0-15
621 Terminal.tangoColors=[// dark:
622 '#2e3436','#cc0000','#4e9a06','#c4a000','#3465a4','#75507b','#06989a','#d3d7cf',// bright:
623 '#555753','#ef2929','#8ae234','#fce94f','#729fcf','#ad7fa8','#34e2e2','#eeeeec'];// Colors 0-15 + 16-255
624 // Much thanks to TooTallNate for writing this.
625 Terminal.colors=function(){var colors=Terminal.tangoColors.slice(),r=[0x00,0x5f,0x87,0xaf,0xd7,0xff],i;// 16-231
626 i=0;for(;i<216;i++){out(r[i/36%6|0],r[i/6%6|0],r[i%6]);}// 232-255 (grey)
627 i=0;for(;i<24;i++){r=8+i*10;out(r,r,r);}function out(r,g,b){colors.push('#'+hex(r)+hex(g)+hex(b));}function hex(c){c=c.toString(16);return c.length<2?'0'+c:c;}return colors;}();Terminal._colors=Terminal.colors.slice();Terminal.vcolors=function(){var out=[],colors=Terminal.colors,i=0,color;for(;i<256;i++){color=parseInt(colors[i].substring(1),16);out.push([color>>16&0xff,color>>8&0xff,color&0xff]);}return out;}();/**
628 * Options
629 */Terminal.defaults={colors:Terminal.colors,theme:'default',convertEol:false,termName:'xterm',geometry:[80,24],cursorBlink:false,visualBell:false,popOnBell:false,scrollback:1000,screenKeys:false,debug:false,cancelEvents:false// programFeatures: false,
630 // focusKeys: false,
631 };Terminal.options={};Terminal.focus=null;each(keys(Terminal.defaults),function(key){Terminal[key]=Terminal.defaults[key];Terminal.options[key]=Terminal.defaults[key];});/**
632 * Focus the terminal. Delegates focus handling to the terminal's DOM element.
633 */Terminal.prototype.focus=function(){return this.textarea.focus();};/**
634 * Retrieves an option's value from the terminal.
635 * @param {string} key The option key.
636 */Terminal.prototype.getOption=function(key,value){if(!(key in Terminal.defaults)){throw new Error('No option with key "'+key+'"');}if(typeof this.options[key]!=='undefined'){return this.options[key];}return this[key];};/**
637 * Sets an option on the terminal.
638 * @param {string} key The option key.
639 * @param {string} value The option value.
640 */Terminal.prototype.setOption=function(key,value){if(!(key in Terminal.defaults)){throw new Error('No option with key "'+key+'"');}this[key]=value;this.options[key]=value;};/**
641 * Binds the desired focus behavior on a given terminal object.
642 *
643 * @static
644 */Terminal.bindFocus=function(term){on(term.textarea,'focus',function(ev){if(term.sendFocus){term.send('\x1b[I');}term.element.classList.add('focus');term.showCursor();Terminal.focus=term;term.emit('focus',{terminal:term});});};/**
645 * Blur the terminal. Delegates blur handling to the terminal's DOM element.
646 */Terminal.prototype.blur=function(){return this.textarea.blur();};/**
647 * Binds the desired blur behavior on a given terminal object.
648 *
649 * @static
650 */Terminal.bindBlur=function(term){on(term.textarea,'blur',function(ev){term.refresh(term.y,term.y);if(term.sendFocus){term.send('\x1b[O');}term.element.classList.remove('focus');Terminal.focus=null;term.emit('blur',{terminal:term});});};/**
651 * Initialize default behavior
652 */Terminal.prototype.initGlobal=function(){var term=this;Terminal.bindKeys(this);Terminal.bindFocus(this);Terminal.bindBlur(this);// Bind clipboard functionality
653 on(this.element,'copy',_Clipboard.copyHandler);on(this.textarea,'paste',function(ev){_Clipboard.pasteHandler.call(this,ev,term);});on(this.element,'contextmenu',function(ev){_Clipboard.rightClickHandler.call(this,ev,term);});};/**
654 * Apply key handling to the terminal
655 */Terminal.bindKeys=function(term){on(term.element,'keydown',function(ev){if(document.activeElement!=this){return;}term.keyDown(ev);},true);on(term.element,'keypress',function(ev){if(document.activeElement!=this){return;}term.keyPress(ev);},true);on(term.element,'keyup',term.focus.bind(term));on(term.textarea,'keydown',function(ev){term.keyDown(ev);},true);on(term.textarea,'keypress',function(ev){term.keyPress(ev);// Truncate the textarea's value, since it is not needed
656 this.value='';},true);on(term.textarea,'compositionstart',term.compositionHelper.compositionstart.bind(term.compositionHelper));on(term.textarea,'compositionupdate',term.compositionHelper.compositionupdate.bind(term.compositionHelper));on(term.textarea,'compositionend',term.compositionHelper.compositionend.bind(term.compositionHelper));term.on('refresh',term.compositionHelper.updateCompositionElements.bind(term.compositionHelper));};/**
657 * Insert the given row to the terminal or produce a new one
658 * if no row argument is passed. Return the inserted row.
659 * @param {HTMLElement} row (optional) The row to append to the terminal.
660 */Terminal.prototype.insertRow=function(row){if((typeof row==='undefined'?'undefined':_typeof(row))!='object'){row=document.createElement('div');}this.rowContainer.appendChild(row);this.children.push(row);return row;};/**
661 * Opens the terminal within an element.
662 *
663 * @param {HTMLElement} parent The element to create the terminal within.
664 */Terminal.prototype.open=function(parent){var self=this,i=0,div;this.parent=parent||this.parent;if(!this.parent){throw new Error('Terminal requires a parent element.');}// Grab global elements
665 this.context=this.parent.ownerDocument.defaultView;this.document=this.parent.ownerDocument;this.body=this.document.getElementsByTagName('body')[0];// Parse User-Agent
666 if(this.context.navigator&&this.context.navigator.userAgent){this.isMSIE=!!~this.context.navigator.userAgent.indexOf('MSIE');}// Find the users platform. We use this to interpret the meta key
667 // and ISO third level shifts.
668 // http://stackoverflow.com/q/19877924/577598
669 if(this.context.navigator&&this.context.navigator.platform){this.isMac=contains(this.context.navigator.platform,['Macintosh','MacIntel','MacPPC','Mac68K']);this.isIpad=this.context.navigator.platform==='iPad';this.isIphone=this.context.navigator.platform==='iPhone';this.isMSWindows=contains(this.context.navigator.platform,['Windows','Win16','Win32','WinCE']);}//Create main element container
670 this.element=this.document.createElement('div');this.element.classList.add('terminal');this.element.classList.add('xterm');this.element.classList.add('xterm-theme-'+this.theme);this.element.style.height;this.element.setAttribute('tabindex',0);this.viewportElement=document.createElement('div');this.viewportElement.classList.add('xterm-viewport');this.element.appendChild(this.viewportElement);this.viewportScrollArea=document.createElement('div');this.viewportScrollArea.classList.add('xterm-scroll-area');this.viewportElement.appendChild(this.viewportScrollArea);// Create the container that will hold the lines of the terminal and then
671 // produce the lines the lines.
672 this.rowContainer=document.createElement('div');this.rowContainer.classList.add('xterm-rows');this.element.appendChild(this.rowContainer);this.children=[];// Create the container that will hold helpers like the textarea for
673 // capturing DOM Events. Then produce the helpers.
674 this.helperContainer=document.createElement('div');this.helperContainer.classList.add('xterm-helpers');// TODO: This should probably be inserted once it's filled to prevent an additional layout
675 this.element.appendChild(this.helperContainer);this.textarea=document.createElement('textarea');this.textarea.classList.add('xterm-helper-textarea');this.textarea.setAttribute('autocorrect','off');this.textarea.setAttribute('autocapitalize','off');this.textarea.setAttribute('spellcheck','false');this.textarea.tabIndex=0;this.textarea.addEventListener('focus',function(){self.emit('focus',{terminal:self});});this.textarea.addEventListener('blur',function(){self.emit('blur',{terminal:self});});this.helperContainer.appendChild(this.textarea);this.compositionView=document.createElement('div');this.compositionView.classList.add('composition-view');this.compositionHelper=new _CompositionHelper.CompositionHelper(this.textarea,this.compositionView,this);this.helperContainer.appendChild(this.compositionView);this.charMeasureElement=document.createElement('div');this.charMeasureElement.classList.add('xterm-char-measure-element');this.charMeasureElement.innerHTML='W';this.helperContainer.appendChild(this.charMeasureElement);for(;i<this.rows;i++){this.insertRow();}this.parent.appendChild(this.element);this.viewport=new _Viewport.Viewport(this,this.viewportElement,this.viewportScrollArea,this.charMeasureElement);// Draw the screen.
676 this.refresh(0,this.rows-1);// Initialize global actions that
677 // need to be taken on the document.
678 this.initGlobal();// Ensure there is a Terminal.focus.
679 this.focus();on(this.element,'click',function(){var selection=document.getSelection(),collapsed=selection.isCollapsed,isRange=typeof collapsed=='boolean'?!collapsed:selection.type=='Range';if(!isRange){self.focus();}});// Listen for mouse events and translate
680 // them into terminal mouse protocols.
681 this.bindMouse();// Figure out whether boldness affects
682 // the character width of monospace fonts.
683 if(Terminal.brokenBold==null){Terminal.brokenBold=isBoldBroken(this.document);}this.emit('open');};/**
684 * Attempts to load an add-on using CommonJS or RequireJS (whichever is available).
685 * @param {string} addon The name of the addon to load
686 * @static
687 */Terminal.loadAddon=function(addon,callback){if((typeof exports==='undefined'?'undefined':_typeof(exports))==='object'&&(typeof module==='undefined'?'undefined':_typeof(module))==='object'){// CommonJS
688 return _dereq_(__dirname+'/../addons/'+addon);}else if(typeof define=='function'){// RequireJS
689 return _dereq_(['../addons/'+addon+'/'+addon],callback);}else{console.error('Cannot load a module without a CommonJS or RequireJS environment.');return false;}};/**
690 * XTerm mouse events
691 * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking
692 * To better understand these
693 * the xterm code is very helpful:
694 * Relevant files:
695 * button.c, charproc.c, misc.c
696 * Relevant functions in xterm/button.c:
697 * BtnCode, EmitButtonCode, EditorButton, SendMousePosition
698 */Terminal.prototype.bindMouse=function(){var el=this.element,self=this,pressed=32;// mouseup, mousedown, wheel
699 // left click: ^[[M 3<^[[M#3<
700 // wheel up: ^[[M`3>
701 function sendButton(ev){var button,pos;// get the xterm-style button
702 button=getButton(ev);// get mouse coordinates
703 pos=getCoords(ev);if(!pos)return;sendEvent(button,pos);switch(ev.overrideType||ev.type){case'mousedown':pressed=button;break;case'mouseup':// keep it at the left
704 // button, just in case.
705 pressed=32;break;case'wheel':// nothing. don't
706 // interfere with
707 // `pressed`.
708 break;}}// motion example of a left click:
709 // ^[[M 3<^[[M@4<^[[M@5<^[[M@6<^[[M@7<^[[M#7<
710 function sendMove(ev){var button=pressed,pos;pos=getCoords(ev);if(!pos)return;// buttons marked as motions
711 // are incremented by 32
712 button+=32;sendEvent(button,pos);}// encode button and
713 // position to characters
714 function encode(data,ch){if(!self.utfMouse){if(ch===255)return data.push(0);if(ch>127)ch=127;data.push(ch);}else{if(ch===2047)return data.push(0);if(ch<127){data.push(ch);}else{if(ch>2047)ch=2047;data.push(0xC0|ch>>6);data.push(0x80|ch&0x3F);}}}// send a mouse event:
715 // regular/utf8: ^[[M Cb Cx Cy
716 // urxvt: ^[[ Cb ; Cx ; Cy M
717 // sgr: ^[[ Cb ; Cx ; Cy M/m
718 // vt300: ^[[ 24(1/3/5)~ [ Cx , Cy ] \r
719 // locator: CSI P e ; P b ; P r ; P c ; P p & w
720 function sendEvent(button,pos){// self.emit('mouse', {
721 // x: pos.x - 32,
722 // y: pos.x - 32,
723 // button: button
724 // });
725 if(self.vt300Mouse){// NOTE: Unstable.
726 // http://www.vt100.net/docs/vt3xx-gp/chapter15.html
727 button&=3;pos.x-=32;pos.y-=32;var data='\x1b[24';if(button===0)data+='1';else if(button===1)data+='3';else if(button===2)data+='5';else if(button===3)return;else data+='0';data+='~['+pos.x+','+pos.y+']\r';self.send(data);return;}if(self.decLocator){// NOTE: Unstable.
728 button&=3;pos.x-=32;pos.y-=32;if(button===0)button=2;else if(button===1)button=4;else if(button===2)button=6;else if(button===3)button=3;self.send('\x1b['+button+';'+(button===3?4:0)+';'+pos.y+';'+pos.x+';'+(pos.page||0)+'&w');return;}if(self.urxvtMouse){pos.x-=32;pos.y-=32;pos.x++;pos.y++;self.send('\x1b['+button+';'+pos.x+';'+pos.y+'M');return;}if(self.sgrMouse){pos.x-=32;pos.y-=32;self.send('\x1b[<'+((button&3)===3?button&~3:button)+';'+pos.x+';'+pos.y+((button&3)===3?'m':'M'));return;}var data=[];encode(data,button);encode(data,pos.x);encode(data,pos.y);self.send('\x1b[M'+String.fromCharCode.apply(String,data));}function getButton(ev){var button,shift,meta,ctrl,mod;// two low bits:
729 // 0 = left
730 // 1 = middle
731 // 2 = right
732 // 3 = release
733 // wheel up/down:
734 // 1, and 2 - with 64 added
735 switch(ev.overrideType||ev.type){case'mousedown':button=ev.button!=null?+ev.button:ev.which!=null?ev.which-1:null;if(self.isMSIE){button=button===1?0:button===4?1:button;}break;case'mouseup':button=3;break;case'DOMMouseScroll':button=ev.detail<0?64:65;break;case'wheel':button=ev.wheelDeltaY>0?64:65;break;}// next three bits are the modifiers:
736 // 4 = shift, 8 = meta, 16 = control
737 shift=ev.shiftKey?4:0;meta=ev.metaKey?8:0;ctrl=ev.ctrlKey?16:0;mod=shift|meta|ctrl;// no mods
738 if(self.vt200Mouse){// ctrl only
739 mod&=ctrl;}else if(!self.normalMouse){mod=0;}// increment to SP
740 button=32+(mod<<2)+button;return button;}// mouse coordinates measured in cols/rows
741 function getCoords(ev){var x,y,w,h,el;// ignore browsers without pageX for now
742 if(ev.pageX==null)return;x=ev.pageX;y=ev.pageY;el=self.element;// should probably check offsetParent
743 // but this is more portable
744 while(el&&el!==self.document.documentElement){x-=el.offsetLeft;y-=el.offsetTop;el='offsetParent'in el?el.offsetParent:el.parentNode;}// convert to cols/rows
745 w=self.element.clientWidth;h=self.element.clientHeight;x=Math.ceil(x/w*self.cols);y=Math.ceil(y/h*self.rows);// be sure to avoid sending
746 // bad positions to the program
747 if(x<0)x=0;if(x>self.cols)x=self.cols;if(y<0)y=0;if(y>self.rows)y=self.rows;// xterm sends raw bytes and
748 // starts at 32 (SP) for each.
749 x+=32;y+=32;return{x:x,y:y,type:'wheel'};}on(el,'mousedown',function(ev){if(!self.mouseEvents)return;// send the button
750 sendButton(ev);// ensure focus
751 self.focus();// fix for odd bug
752 //if (self.vt200Mouse && !self.normalMouse) {
753 if(self.vt200Mouse){ev.overrideType='mouseup';sendButton(ev);return self.cancel(ev);}// bind events
754 if(self.normalMouse)on(self.document,'mousemove',sendMove);// x10 compatibility mode can't send button releases
755 if(!self.x10Mouse){on(self.document,'mouseup',function up(ev){sendButton(ev);if(self.normalMouse)off(self.document,'mousemove',sendMove);off(self.document,'mouseup',up);return self.cancel(ev);});}return self.cancel(ev);});//if (self.normalMouse) {
756 // on(self.document, 'mousemove', sendMove);
757 //}
758 on(el,'wheel',function(ev){if(!self.mouseEvents)return;if(self.x10Mouse||self.vt300Mouse||self.decLocator)return;sendButton(ev);return self.cancel(ev);});// allow wheel scrolling in
759 // the shell for example
760 on(el,'wheel',function(ev){if(self.mouseEvents)return;self.viewport.onWheel(ev);return self.cancel(ev);});};/**
761 * Destroys the terminal.
762 */Terminal.prototype.destroy=function(){this.readable=false;this.writable=false;this._events={};this.handler=function(){};this.write=function(){};if(this.element.parentNode){this.element.parentNode.removeChild(this.element);}//this.emit('close');
763 };/**
764 * Flags used to render terminal text properly
765 */Terminal.flags={BOLD:1,UNDERLINE:2,BLINK:4,INVERSE:8,INVISIBLE:16};/**
766 * Refreshes (re-renders) terminal content within two rows (inclusive)
767 *
768 * Rendering Engine:
769 *
770 * In the screen buffer, each character is stored as a an array with a character
771 * and a 32-bit integer:
772 * - First value: a utf-16 character.
773 * - Second value:
774 * - Next 9 bits: background color (0-511).
775 * - Next 9 bits: foreground color (0-511).
776 * - Next 14 bits: a mask for misc. flags:
777 * - 1=bold
778 * - 2=underline
779 * - 4=blink
780 * - 8=inverse
781 * - 16=invisible
782 *
783 * @param {number} start The row to start from (between 0 and terminal's height terminal - 1)
784 * @param {number} end The row to end at (between fromRow and terminal's height terminal - 1)
785 * @param {boolean} queue Whether the refresh should ran right now or be queued
786 */Terminal.prototype.refresh=function(start,end,queue){var self=this;// queue defaults to true
787 queue=typeof queue=='undefined'?true:queue;/**
788 * The refresh queue allows refresh to execute only approximately 30 times a second. For
789 * commands that pass a significant amount of output to the write function, this prevents the
790 * terminal from maxing out the CPU and making the UI unresponsive. While commands can still
791 * run beyond what they do on the terminal, it is far better with a debounce in place as
792 * every single terminal manipulation does not need to be constructed in the DOM.
793 *
794 * A side-effect of this is that it makes ^C to interrupt a process seem more responsive.
795 */if(queue){// If refresh should be queued, order the refresh and return.
796 if(this._refreshIsQueued){// If a refresh has already been queued, just order a full refresh next
797 this._fullRefreshNext=true;}else{setTimeout(function(){self.refresh(start,end,false);},34);this._refreshIsQueued=true;}return;}// If refresh should be run right now (not be queued), release the lock
798 this._refreshIsQueued=false;// If multiple refreshes were requested, make a full refresh.
799 if(this._fullRefreshNext){start=0;end=this.rows-1;this._fullRefreshNext=false;// reset lock
800 }var x,y,i,line,out,ch,ch_width,width,data,attr,bg,fg,flags,row,parent,focused=document.activeElement;// If this is a big refresh, remove the terminal rows from the DOM for faster calculations
801 if(end-start>=this.rows/2){parent=this.element.parentNode;if(parent){this.element.removeChild(this.rowContainer);}}width=this.cols;y=start;if(end>=this.rows.length){this.log('`end` is too large. Most likely a bad CSR.');end=this.rows.length-1;}for(;y<=end;y++){row=y+this.ydisp;line=this.lines[row];out='';if(this.y===y-(this.ybase-this.ydisp)&&this.cursorState&&!this.cursorHidden){x=this.x;}else{x=-1;}attr=this.defAttr;i=0;for(;i<width;i++){data=line[i][0];ch=line[i][1];ch_width=line[i][2];if(!ch_width)continue;if(i===x)data=-1;if(data!==attr){if(attr!==this.defAttr){out+='</span>';}if(data!==this.defAttr){if(data===-1){out+='<span class="reverse-video terminal-cursor';if(this.cursorBlink){out+=' blinking';}out+='">';}else{var classNames=[];bg=data&0x1ff;fg=data>>9&0x1ff;flags=data>>18;if(flags&Terminal.flags.BOLD){if(!Terminal.brokenBold){classNames.push('xterm-bold');}// See: XTerm*boldColors
802 if(fg<8)fg+=8;}if(flags&Terminal.flags.UNDERLINE){classNames.push('xterm-underline');}if(flags&Terminal.flags.BLINK){classNames.push('xterm-blink');}// If inverse flag is on, then swap the foreground and background variables.
803 if(flags&Terminal.flags.INVERSE){/* One-line variable swap in JavaScript: http://stackoverflow.com/a/16201730 */bg=[fg,fg=bg][0];// Should inverse just be before the
804 // above boldColors effect instead?
805 if(flags&1&&fg<8)fg+=8;}if(flags&Terminal.flags.INVISIBLE){classNames.push('xterm-hidden');}/**
806 * Weird situation: Invert flag used black foreground and white background results
807 * in invalid background color, positioned at the 256 index of the 256 terminal
808 * color map. Pin the colors manually in such a case.
809 *
810 * Source: https://github.com/sourcelair/xterm.js/issues/57
811 */if(flags&Terminal.flags.INVERSE){if(bg==257){bg=15;}if(fg==256){fg=0;}}if(bg<256){classNames.push('xterm-bg-color-'+bg);}if(fg<256){classNames.push('xterm-color-'+fg);}out+='<span';if(classNames.length){out+=' class="'+classNames.join(' ')+'"';}out+='>';}}}switch(ch){case'&':out+='&amp;';break;case'<':out+='&lt;';break;case'>':out+='&gt;';break;default:if(ch<=' '){out+='&nbsp;';}else{out+=ch;}break;}attr=data;}if(attr!==this.defAttr){out+='</span>';}this.children[y].innerHTML=out;}if(parent){this.element.appendChild(this.rowContainer);}this.emit('refresh',{element:this.element,start:start,end:end});};/**
812 * Display the cursor element
813 */Terminal.prototype.showCursor=function(){if(!this.cursorState){this.cursorState=1;this.refresh(this.y,this.y);}};/**
814 * Scroll the terminal
815 */Terminal.prototype.scroll=function(){var row;if(++this.ybase===this.scrollback){this.ybase=this.ybase/2|0;this.lines=this.lines.slice(-(this.ybase+this.rows)+1);}this.ydisp=this.ybase;// last line
816 row=this.ybase+this.rows-1;// subtract the bottom scroll region
817 row-=this.rows-1-this.scrollBottom;if(row===this.lines.length){// potential optimization:
818 // pushing is faster than splicing
819 // when they amount to the same
820 // behavior.
821 this.lines.push(this.blankLine());}else{// add our new line
822 this.lines.splice(row,0,this.blankLine());}if(this.scrollTop!==0){if(this.ybase!==0){this.ybase--;this.ydisp=this.ybase;}this.lines.splice(this.ybase+this.scrollTop,1);}// this.maxRange();
823 this.updateRange(this.scrollTop);this.updateRange(this.scrollBottom);this.emit('scroll',this.ydisp);};/**
824 * Scroll the display of the terminal
825 * @param {number} disp The number of lines to scroll down (negatives scroll up).
826 * @param {boolean} suppressScrollEvent Don't emit the scroll event as scrollDisp. This is used
827 * to avoid unwanted events being handled by the veiwport when the event was triggered from the
828 * viewport originally.
829 */Terminal.prototype.scrollDisp=function(disp,suppressScrollEvent){this.ydisp+=disp;if(this.ydisp>this.ybase){this.ydisp=this.ybase;}else if(this.ydisp<0){this.ydisp=0;}if(!suppressScrollEvent){this.emit('scroll',this.ydisp);}this.refresh(0,this.rows-1);};/**
830 * Writes text to the terminal.
831 * @param {string} text The text to write to the terminal.
832 */Terminal.prototype.write=function(data){var l=data.length,i=0,j,cs,ch,code,low,ch_width,row;this.refreshStart=this.y;this.refreshEnd=this.y;if(this.ybase!==this.ydisp){this.ydisp=this.ybase;this.emit('scroll',this.ydisp);this.maxRange();}// apply leftover surrogate high from last write
833 if(this.surrogate_high){data=this.surrogate_high+data;this.surrogate_high='';}for(;i<l;i++){ch=data[i];// FIXME: higher chars than 0xa0 are not allowed in escape sequences
834 // --> maybe move to default
835 code=data.charCodeAt(i);if(0xD800<=code&&code<=0xDBFF){// we got a surrogate high
836 // get surrogate low (next 2 bytes)
837 low=data.charCodeAt(i+1);if(isNaN(low)){// end of data stream, save surrogate high
838 this.surrogate_high=ch;continue;}code=(code-0xD800)*0x400+(low-0xDC00)+0x10000;ch+=data.charAt(i+1);}// surrogate low - already handled above
839 if(0xDC00<=code&&code<=0xDFFF)continue;switch(this.state){case normal:switch(ch){case'\x07':this.bell();break;// '\n', '\v', '\f'
840 case'\n':case'\x0b':case'\x0c':if(this.convertEol){this.x=0;}this.y++;if(this.y>this.scrollBottom){this.y--;this.scroll();}break;// '\r'
841 case'\r':this.x=0;break;// '\b'
842 case'\x08':if(this.x>0){this.x--;}break;// '\t'
843 case'\t':this.x=this.nextStop();break;// shift out
844 case'\x0e':this.setgLevel(1);break;// shift in
845 case'\x0f':this.setgLevel(0);break;// '\e'
846 case'\x1b':this.state=escaped;break;default:// ' '
847 // calculate print space
848 // expensive call, therefore we save width in line buffer
849 ch_width=wcwidth(code);if(ch>=' '){if(this.charset&&this.charset[ch]){ch=this.charset[ch];}row=this.y+this.ybase;// insert combining char in last cell
850 // FIXME: needs handling after cursor jumps
851 if(!ch_width&&this.x){// dont overflow left
852 if(this.lines[row][this.x-1]){if(!this.lines[row][this.x-1][2]){// found empty cell after fullwidth, need to go 2 cells back
853 if(this.lines[row][this.x-2])this.lines[row][this.x-2][1]+=ch;}else{this.lines[row][this.x-1][1]+=ch;}this.updateRange(this.y);}break;}// goto next line if ch would overflow
854 // TODO: needs a global min terminal width of 2
855 if(this.x+ch_width-1>=this.cols){// autowrap - DECAWM
856 if(this.wraparoundMode){this.x=0;this.y++;if(this.y>this.scrollBottom){this.y--;this.scroll();}}else{this.x=this.cols-1;if(ch_width===2)// FIXME: check for xterm behavior
857 continue;}}row=this.y+this.ybase;// insert mode: move characters to right
858 if(this.insertMode){// do this twice for a fullwidth char
859 for(var moves=0;moves<ch_width;++moves){// remove last cell, if it's width is 0
860 // we have to adjust the second last cell as well
861 var removed=this.lines[this.y+this.ybase].pop();if(removed[2]===0&&this.lines[row][this.cols-2]&&this.lines[row][this.cols-2][2]===2)this.lines[row][this.cols-2]=[this.curAttr,' ',1];// insert empty cell at cursor
862 this.lines[row].splice(this.x,0,[this.curAttr,' ',1]);}}this.lines[row][this.x]=[this.curAttr,ch,ch_width];this.x++;this.updateRange(this.y);// fullwidth char - set next cell width to zero and advance cursor
863 if(ch_width===2){this.lines[row][this.x]=[this.curAttr,'',0];this.x++;}}break;}break;case escaped:switch(ch){// ESC [ Control Sequence Introducer ( CSI is 0x9b).
864 case'[':this.params=[];this.currentParam=0;this.state=csi;break;// ESC ] Operating System Command ( OSC is 0x9d).
865 case']':this.params=[];this.currentParam=0;this.state=osc;break;// ESC P Device Control String ( DCS is 0x90).
866 case'P':this.params=[];this.currentParam=0;this.state=dcs;break;// ESC _ Application Program Command ( APC is 0x9f).
867 case'_':this.state=ignore;break;// ESC ^ Privacy Message ( PM is 0x9e).
868 case'^':this.state=ignore;break;// ESC c Full Reset (RIS).
869 case'c':this.reset();break;// ESC E Next Line ( NEL is 0x85).
870 // ESC D Index ( IND is 0x84).
871 case'E':this.x=0;;case'D':this.index();break;// ESC M Reverse Index ( RI is 0x8d).
872 case'M':this.reverseIndex();break;// ESC % Select default/utf-8 character set.
873 // @ = default, G = utf-8
874 case'%'://this.charset = null;
875 this.setgLevel(0);this.setgCharset(0,Terminal.charsets.US);this.state=normal;i++;break;// ESC (,),*,+,-,. Designate G0-G2 Character Set.
876 case'(':// <-- this seems to get all the attention
877 case')':case'*':case'+':case'-':case'.':switch(ch){case'(':this.gcharset=0;break;case')':this.gcharset=1;break;case'*':this.gcharset=2;break;case'+':this.gcharset=3;break;case'-':this.gcharset=1;break;case'.':this.gcharset=2;break;}this.state=charset;break;// Designate G3 Character Set (VT300).
878 // A = ISO Latin-1 Supplemental.
879 // Not implemented.
880 case'/':this.gcharset=3;this.state=charset;i--;break;// ESC N
881 // Single Shift Select of G2 Character Set
882 // ( SS2 is 0x8e). This affects next character only.
883 case'N':break;// ESC O
884 // Single Shift Select of G3 Character Set
885 // ( SS3 is 0x8f). This affects next character only.
886 case'O':break;// ESC n
887 // Invoke the G2 Character Set as GL (LS2).
888 case'n':this.setgLevel(2);break;// ESC o
889 // Invoke the G3 Character Set as GL (LS3).
890 case'o':this.setgLevel(3);break;// ESC |
891 // Invoke the G3 Character Set as GR (LS3R).
892 case'|':this.setgLevel(3);break;// ESC }
893 // Invoke the G2 Character Set as GR (LS2R).
894 case'}':this.setgLevel(2);break;// ESC ~
895 // Invoke the G1 Character Set as GR (LS1R).
896 case'~':this.setgLevel(1);break;// ESC 7 Save Cursor (DECSC).
897 case'7':this.saveCursor();this.state=normal;break;// ESC 8 Restore Cursor (DECRC).
898 case'8':this.restoreCursor();this.state=normal;break;// ESC # 3 DEC line height/width
899 case'#':this.state=normal;i++;break;// ESC H Tab Set (HTS is 0x88).
900 case'H':this.tabSet();break;// ESC = Application Keypad (DECKPAM).
901 case'=':this.log('Serial port requested application keypad.');this.applicationKeypad=true;this.viewport.syncScrollArea();this.state=normal;break;// ESC > Normal Keypad (DECKPNM).
902 case'>':this.log('Switching back to normal keypad.');this.applicationKeypad=false;this.viewport.syncScrollArea();this.state=normal;break;default:this.state=normal;this.error('Unknown ESC control: %s.',ch);break;}break;case charset:switch(ch){case'0':// DEC Special Character and Line Drawing Set.
903 cs=Terminal.charsets.SCLD;break;case'A':// UK
904 cs=Terminal.charsets.UK;break;case'B':// United States (USASCII).
905 cs=Terminal.charsets.US;break;case'4':// Dutch
906 cs=Terminal.charsets.Dutch;break;case'C':// Finnish
907 case'5':cs=Terminal.charsets.Finnish;break;case'R':// French
908 cs=Terminal.charsets.French;break;case'Q':// FrenchCanadian
909 cs=Terminal.charsets.FrenchCanadian;break;case'K':// German
910 cs=Terminal.charsets.German;break;case'Y':// Italian
911 cs=Terminal.charsets.Italian;break;case'E':// NorwegianDanish
912 case'6':cs=Terminal.charsets.NorwegianDanish;break;case'Z':// Spanish
913 cs=Terminal.charsets.Spanish;break;case'H':// Swedish
914 case'7':cs=Terminal.charsets.Swedish;break;case'=':// Swiss
915 cs=Terminal.charsets.Swiss;break;case'/':// ISOLatin (actually /A)
916 cs=Terminal.charsets.ISOLatin;i++;break;default:// Default
917 cs=Terminal.charsets.US;break;}this.setgCharset(this.gcharset,cs);this.gcharset=null;this.state=normal;break;case osc:// OSC Ps ; Pt ST
918 // OSC Ps ; Pt BEL
919 // Set Text Parameters.
920 if(ch==='\x1b'||ch==='\x07'){if(ch==='\x1b')i++;this.params.push(this.currentParam);switch(this.params[0]){case 0:case 1:case 2:if(this.params[1]){this.title=this.params[1];this.handleTitle(this.title);}break;case 3:// set X property
921 break;case 4:case 5:// change dynamic colors
922 break;case 10:case 11:case 12:case 13:case 14:case 15:case 16:case 17:case 18:case 19:// change dynamic ui colors
923 break;case 46:// change log file
924 break;case 50:// dynamic font
925 break;case 51:// emacs shell
926 break;case 52:// manipulate selection data
927 break;case 104:case 105:case 110:case 111:case 112:case 113:case 114:case 115:case 116:case 117:case 118:// reset colors
928 break;}this.params=[];this.currentParam=0;this.state=normal;}else{if(!this.params.length){if(ch>='0'&&ch<='9'){this.currentParam=this.currentParam*10+ch.charCodeAt(0)-48;}else if(ch===';'){this.params.push(this.currentParam);this.currentParam='';}}else{this.currentParam+=ch;}}break;case csi:// '?', '>', '!'
929 if(ch==='?'||ch==='>'||ch==='!'){this.prefix=ch;break;}// 0 - 9
930 if(ch>='0'&&ch<='9'){this.currentParam=this.currentParam*10+ch.charCodeAt(0)-48;break;}// '$', '"', ' ', '\''
931 if(ch==='$'||ch==='"'||ch===' '||ch==='\''){this.postfix=ch;break;}this.params.push(this.currentParam);this.currentParam=0;// ';'
932 if(ch===';')break;this.state=normal;switch(ch){// CSI Ps A
933 // Cursor Up Ps Times (default = 1) (CUU).
934 case'A':this.cursorUp(this.params);break;// CSI Ps B
935 // Cursor Down Ps Times (default = 1) (CUD).
936 case'B':this.cursorDown(this.params);break;// CSI Ps C
937 // Cursor Forward Ps Times (default = 1) (CUF).
938 case'C':this.cursorForward(this.params);break;// CSI Ps D
939 // Cursor Backward Ps Times (default = 1) (CUB).
940 case'D':this.cursorBackward(this.params);break;// CSI Ps ; Ps H
941 // Cursor Position [row;column] (default = [1,1]) (CUP).
942 case'H':this.cursorPos(this.params);break;// CSI Ps J Erase in Display (ED).
943 case'J':this.eraseInDisplay(this.params);break;// CSI Ps K Erase in Line (EL).
944 case'K':this.eraseInLine(this.params);break;// CSI Pm m Character Attributes (SGR).
945 case'm':if(!this.prefix){this.charAttributes(this.params);}break;// CSI Ps n Device Status Report (DSR).
946 case'n':if(!this.prefix){this.deviceStatus(this.params);}break;/**
947 * Additions
948 */// CSI Ps @
949 // Insert Ps (Blank) Character(s) (default = 1) (ICH).
950 case'@':this.insertChars(this.params);break;// CSI Ps E
951 // Cursor Next Line Ps Times (default = 1) (CNL).
952 case'E':this.cursorNextLine(this.params);break;// CSI Ps F
953 // Cursor Preceding Line Ps Times (default = 1) (CNL).
954 case'F':this.cursorPrecedingLine(this.params);break;// CSI Ps G
955 // Cursor Character Absolute [column] (default = [row,1]) (CHA).
956 case'G':this.cursorCharAbsolute(this.params);break;// CSI Ps L
957 // Insert Ps Line(s) (default = 1) (IL).
958 case'L':this.insertLines(this.params);break;// CSI Ps M
959 // Delete Ps Line(s) (default = 1) (DL).
960 case'M':this.deleteLines(this.params);break;// CSI Ps P
961 // Delete Ps Character(s) (default = 1) (DCH).
962 case'P':this.deleteChars(this.params);break;// CSI Ps X
963 // Erase Ps Character(s) (default = 1) (ECH).
964 case'X':this.eraseChars(this.params);break;// CSI Pm ` Character Position Absolute
965 // [column] (default = [row,1]) (HPA).
966 case'`':this.charPosAbsolute(this.params);break;// 141 61 a * HPR -
967 // Horizontal Position Relative
968 case'a':this.HPositionRelative(this.params);break;// CSI P s c
969 // Send Device Attributes (Primary DA).
970 // CSI > P s c
971 // Send Device Attributes (Secondary DA)
972 case'c':this.sendDeviceAttributes(this.params);break;// CSI Pm d
973 // Line Position Absolute [row] (default = [1,column]) (VPA).
974 case'd':this.linePosAbsolute(this.params);break;// 145 65 e * VPR - Vertical Position Relative
975 case'e':this.VPositionRelative(this.params);break;// CSI Ps ; Ps f
976 // Horizontal and Vertical Position [row;column] (default =
977 // [1,1]) (HVP).
978 case'f':this.HVPosition(this.params);break;// CSI Pm h Set Mode (SM).
979 // CSI ? Pm h - mouse escape codes, cursor escape codes
980 case'h':this.setMode(this.params);break;// CSI Pm l Reset Mode (RM).
981 // CSI ? Pm l
982 case'l':this.resetMode(this.params);break;// CSI Ps ; Ps r
983 // Set Scrolling Region [top;bottom] (default = full size of win-
984 // dow) (DECSTBM).
985 // CSI ? Pm r
986 case'r':this.setScrollRegion(this.params);break;// CSI s
987 // Save cursor (ANSI.SYS).
988 case's':this.saveCursor(this.params);break;// CSI u
989 // Restore cursor (ANSI.SYS).
990 case'u':this.restoreCursor(this.params);break;/**
991 * Lesser Used
992 */// CSI Ps I
993 // Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
994 case'I':this.cursorForwardTab(this.params);break;// CSI Ps S Scroll up Ps lines (default = 1) (SU).
995 case'S':this.scrollUp(this.params);break;// CSI Ps T Scroll down Ps lines (default = 1) (SD).
996 // CSI Ps ; Ps ; Ps ; Ps ; Ps T
997 // CSI > Ps; Ps T
998 case'T':// if (this.prefix === '>') {
999 // this.resetTitleModes(this.params);
1000 // break;
1001 // }
1002 // if (this.params.length > 2) {
1003 // this.initMouseTracking(this.params);
1004 // break;
1005 // }
1006 if(this.params.length<2&&!this.prefix){this.scrollDown(this.params);}break;// CSI Ps Z
1007 // Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
1008 case'Z':this.cursorBackwardTab(this.params);break;// CSI Ps b Repeat the preceding graphic character Ps times (REP).
1009 case'b':this.repeatPrecedingCharacter(this.params);break;// CSI Ps g Tab Clear (TBC).
1010 case'g':this.tabClear(this.params);break;// CSI Pm i Media Copy (MC).
1011 // CSI ? Pm i
1012 // case 'i':
1013 // this.mediaCopy(this.params);
1014 // break;
1015 // CSI Pm m Character Attributes (SGR).
1016 // CSI > Ps; Ps m
1017 // case 'm': // duplicate
1018 // if (this.prefix === '>') {
1019 // this.setResources(this.params);
1020 // } else {
1021 // this.charAttributes(this.params);
1022 // }
1023 // break;
1024 // CSI Ps n Device Status Report (DSR).
1025 // CSI > Ps n
1026 // case 'n': // duplicate
1027 // if (this.prefix === '>') {
1028 // this.disableModifiers(this.params);
1029 // } else {
1030 // this.deviceStatus(this.params);
1031 // }
1032 // break;
1033 // CSI > Ps p Set pointer mode.
1034 // CSI ! p Soft terminal reset (DECSTR).
1035 // CSI Ps$ p
1036 // Request ANSI mode (DECRQM).
1037 // CSI ? Ps$ p
1038 // Request DEC private mode (DECRQM).
1039 // CSI Ps ; Ps " p
1040 case'p':switch(this.prefix){// case '>':
1041 // this.setPointerMode(this.params);
1042 // break;
1043 case'!':this.softReset(this.params);break;// case '?':
1044 // if (this.postfix === '$') {
1045 // this.requestPrivateMode(this.params);
1046 // }
1047 // break;
1048 // default:
1049 // if (this.postfix === '"') {
1050 // this.setConformanceLevel(this.params);
1051 // } else if (this.postfix === '$') {
1052 // this.requestAnsiMode(this.params);
1053 // }
1054 // break;
1055 }break;// CSI Ps q Load LEDs (DECLL).
1056 // CSI Ps SP q
1057 // CSI Ps " q
1058 // case 'q':
1059 // if (this.postfix === ' ') {
1060 // this.setCursorStyle(this.params);
1061 // break;
1062 // }
1063 // if (this.postfix === '"') {
1064 // this.setCharProtectionAttr(this.params);
1065 // break;
1066 // }
1067 // this.loadLEDs(this.params);
1068 // break;
1069 // CSI Ps ; Ps r
1070 // Set Scrolling Region [top;bottom] (default = full size of win-
1071 // dow) (DECSTBM).
1072 // CSI ? Pm r
1073 // CSI Pt; Pl; Pb; Pr; Ps$ r
1074 // case 'r': // duplicate
1075 // if (this.prefix === '?') {
1076 // this.restorePrivateValues(this.params);
1077 // } else if (this.postfix === '$') {
1078 // this.setAttrInRectangle(this.params);
1079 // } else {
1080 // this.setScrollRegion(this.params);
1081 // }
1082 // break;
1083 // CSI s Save cursor (ANSI.SYS).
1084 // CSI ? Pm s
1085 // case 's': // duplicate
1086 // if (this.prefix === '?') {
1087 // this.savePrivateValues(this.params);
1088 // } else {
1089 // this.saveCursor(this.params);
1090 // }
1091 // break;
1092 // CSI Ps ; Ps ; Ps t
1093 // CSI Pt; Pl; Pb; Pr; Ps$ t
1094 // CSI > Ps; Ps t
1095 // CSI Ps SP t
1096 // case 't':
1097 // if (this.postfix === '$') {
1098 // this.reverseAttrInRectangle(this.params);
1099 // } else if (this.postfix === ' ') {
1100 // this.setWarningBellVolume(this.params);
1101 // } else {
1102 // if (this.prefix === '>') {
1103 // this.setTitleModeFeature(this.params);
1104 // } else {
1105 // this.manipulateWindow(this.params);
1106 // }
1107 // }
1108 // break;
1109 // CSI u Restore cursor (ANSI.SYS).
1110 // CSI Ps SP u
1111 // case 'u': // duplicate
1112 // if (this.postfix === ' ') {
1113 // this.setMarginBellVolume(this.params);
1114 // } else {
1115 // this.restoreCursor(this.params);
1116 // }
1117 // break;
1118 // CSI Pt; Pl; Pb; Pr; Pp; Pt; Pl; Pp$ v
1119 // case 'v':
1120 // if (this.postfix === '$') {
1121 // this.copyRectagle(this.params);
1122 // }
1123 // break;
1124 // CSI Pt ; Pl ; Pb ; Pr ' w
1125 // case 'w':
1126 // if (this.postfix === '\'') {
1127 // this.enableFilterRectangle(this.params);
1128 // }
1129 // break;
1130 // CSI Ps x Request Terminal Parameters (DECREQTPARM).
1131 // CSI Ps x Select Attribute Change Extent (DECSACE).
1132 // CSI Pc; Pt; Pl; Pb; Pr$ x
1133 // case 'x':
1134 // if (this.postfix === '$') {
1135 // this.fillRectangle(this.params);
1136 // } else {
1137 // this.requestParameters(this.params);
1138 // //this.__(this.params);
1139 // }
1140 // break;
1141 // CSI Ps ; Pu ' z
1142 // CSI Pt; Pl; Pb; Pr$ z
1143 // case 'z':
1144 // if (this.postfix === '\'') {
1145 // this.enableLocatorReporting(this.params);
1146 // } else if (this.postfix === '$') {
1147 // this.eraseRectangle(this.params);
1148 // }
1149 // break;
1150 // CSI Pm ' {
1151 // CSI Pt; Pl; Pb; Pr$ {
1152 // case '{':
1153 // if (this.postfix === '\'') {
1154 // this.setLocatorEvents(this.params);
1155 // } else if (this.postfix === '$') {
1156 // this.selectiveEraseRectangle(this.params);
1157 // }
1158 // break;
1159 // CSI Ps ' |
1160 // case '|':
1161 // if (this.postfix === '\'') {
1162 // this.requestLocatorPosition(this.params);
1163 // }
1164 // break;
1165 // CSI P m SP }
1166 // Insert P s Column(s) (default = 1) (DECIC), VT420 and up.
1167 // case '}':
1168 // if (this.postfix === ' ') {
1169 // this.insertColumns(this.params);
1170 // }
1171 // break;
1172 // CSI P m SP ~
1173 // Delete P s Column(s) (default = 1) (DECDC), VT420 and up
1174 // case '~':
1175 // if (this.postfix === ' ') {
1176 // this.deleteColumns(this.params);
1177 // }
1178 // break;
1179 default:this.error('Unknown CSI code: %s.',ch);break;}this.prefix='';this.postfix='';break;case dcs:if(ch==='\x1b'||ch==='\x07'){if(ch==='\x1b')i++;switch(this.prefix){// User-Defined Keys (DECUDK).
1180 case'':break;// Request Status String (DECRQSS).
1181 // test: echo -e '\eP$q"p\e\\'
1182 case'$q':var pt=this.currentParam,valid=false;switch(pt){// DECSCA
1183 case'"q':pt='0"q';break;// DECSCL
1184 case'"p':pt='61"p';break;// DECSTBM
1185 case'r':pt=''+(this.scrollTop+1)+';'+(this.scrollBottom+1)+'r';break;// SGR
1186 case'm':pt='0m';break;default:this.error('Unknown DCS Pt: %s.',pt);pt='';break;}this.send('\x1bP'+ +valid+'$r'+pt+'\x1b\\');break;// Set Termcap/Terminfo Data (xterm, experimental).
1187 case'+p':break;// Request Termcap/Terminfo String (xterm, experimental)
1188 // Regular xterm does not even respond to this sequence.
1189 // This can cause a small glitch in vim.
1190 // test: echo -ne '\eP+q6b64\e\\'
1191 case'+q':var pt=this.currentParam,valid=false;this.send('\x1bP'+ +valid+'+r'+pt+'\x1b\\');break;default:this.error('Unknown DCS prefix: %s.',this.prefix);break;}this.currentParam=0;this.prefix='';this.state=normal;}else if(!this.currentParam){if(!this.prefix&&ch!=='$'&&ch!=='+'){this.currentParam=ch;}else if(this.prefix.length===2){this.currentParam=ch;}else{this.prefix+=ch;}}else{this.currentParam+=ch;}break;case ignore:// For PM and APC.
1192 if(ch==='\x1b'||ch==='\x07'){if(ch==='\x1b')i++;this.state=normal;}break;}}this.updateRange(this.y);this.refresh(this.refreshStart,this.refreshEnd);};/**
1193 * Writes text to the terminal, followed by a break line character (\n).
1194 * @param {string} text The text to write to the terminal.
1195 */Terminal.prototype.writeln=function(data){this.write(data+'\r\n');};/**
1196 * Attaches a custom keydown handler which is run before keys are processed, giving consumers of
1197 * xterm.js ultimate control as to what keys should be processed by the terminal and what keys
1198 * should not.
1199 * @param {function} customKeydownHandler The custom KeyboardEvent handler to attach. This is a
1200 * function that takes a KeyboardEvent, allowing consumers to stop propogation and/or prevent
1201 * the default action. The function returns whether the event should be processed by xterm.js.
1202 */Terminal.prototype.attachCustomKeydownHandler=function(customKeydownHandler){this.customKeydownHandler=customKeydownHandler;};/**
1203 * Handle a keydown event
1204 * Key Resources:
1205 * - https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
1206 * @param {KeyboardEvent} ev The keydown event to be handled.
1207 */Terminal.prototype.keyDown=function(ev){if(this.customKeydownHandler&&this.customKeydownHandler(ev)===false){return false;}if(!this.compositionHelper.keydown.bind(this.compositionHelper)(ev)){return false;}var self=this;var result=this.evaluateKeyEscapeSequence(ev);if(result.scrollDisp){this.scrollDisp(result.scrollDisp);return this.cancel(ev,true);}if(isThirdLevelShift(this,ev)){return true;}if(result.cancel){// The event is canceled at the end already, is this necessary?
1208 this.cancel(ev,true);}if(!result.key){return true;}this.emit('keydown',ev);this.emit('key',result.key,ev);this.showCursor();this.handler(result.key);return this.cancel(ev,true);};/**
1209 * Returns an object that determines how a KeyboardEvent should be handled. The key of the
1210 * returned value is the new key code to pass to the PTY.
1211 *
1212 * Reference: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
1213 * @param {KeyboardEvent} ev The keyboard event to be translated to key escape sequence.
1214 */Terminal.prototype.evaluateKeyEscapeSequence=function(ev){var result={// Whether to cancel event propogation (NOTE: this may not be needed since the event is
1215 // canceled at the end of keyDown
1216 cancel:false,// The new key even to emit
1217 key:undefined,// The number of characters to scroll, if this is defined it will cancel the event
1218 scrollDisp:undefined};var modifiers=ev.shiftKey<<0|ev.altKey<<1|ev.ctrlKey<<2|ev.metaKey<<3;switch(ev.keyCode){case 8:// backspace
1219 if(ev.shiftKey){result.key='\x08';// ^H
1220 break;}result.key='\x7f';// ^?
1221 break;case 9:// tab
1222 if(ev.shiftKey){result.key='\x1b[Z';break;}result.key='\t';result.cancel=true;break;case 13:// return/enter
1223 result.key='\r';result.cancel=true;break;case 27:// escape
1224 result.key='\x1b';result.cancel=true;break;case 37:// left-arrow
1225 if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'D';// HACK: Make Alt + left-arrow behave like Ctrl + left-arrow: move one word backwards
1226 // http://unix.stackexchange.com/a/108106
1227 if(result.key=='\x1b[1;3D'){result.key='\x1b[1;5D';}}else if(this.applicationCursor){result.key='\x1bOD';}else{result.key='\x1b[D';}break;case 39:// right-arrow
1228 if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'C';// HACK: Make Alt + right-arrow behave like Ctrl + right-arrow: move one word forward
1229 // http://unix.stackexchange.com/a/108106
1230 if(result.key=='\x1b[1;3C'){result.key='\x1b[1;5C';}}else if(this.applicationCursor){result.key='\x1bOC';}else{result.key='\x1b[C';}break;case 38:// up-arrow
1231 if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'A';// HACK: Make Alt + up-arrow behave like Ctrl + up-arrow
1232 // http://unix.stackexchange.com/a/108106
1233 if(result.key=='\x1b[1;3A'){result.key='\x1b[1;5A';}}else if(this.applicationCursor){result.key='\x1bOA';}else{result.key='\x1b[A';}break;case 40:// down-arrow
1234 if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'B';// HACK: Make Alt + down-arrow behave like Ctrl + down-arrow
1235 // http://unix.stackexchange.com/a/108106
1236 if(result.key=='\x1b[1;3B'){result.key='\x1b[1;5B';}}else if(this.applicationCursor){result.key='\x1bOB';}else{result.key='\x1b[B';}break;case 45:// insert
1237 if(!ev.shiftKey&&!ev.ctrlKey){// <Ctrl> or <Shift> + <Insert> are used to
1238 // copy-paste on some systems.
1239 result.key='\x1b[2~';}break;case 46:// delete
1240 if(modifiers){result.key='\x1b[3;'+(modifiers+1)+'~';}else{result.key='\x1b[3~';}break;case 36:// home
1241 if(modifiers)result.key='\x1b[1;'+(modifiers+1)+'H';else if(this.applicationCursor)result.key='\x1bOH';else result.key='\x1b[H';break;case 35:// end
1242 if(modifiers)result.key='\x1b[1;'+(modifiers+1)+'F';else if(this.applicationCursor)result.key='\x1bOF';else result.key='\x1b[F';break;case 33:// page up
1243 if(ev.shiftKey){result.scrollDisp=-(this.rows-1);}else{result.key='\x1b[5~';}break;case 34:// page down
1244 if(ev.shiftKey){result.scrollDisp=this.rows-1;}else{result.key='\x1b[6~';}break;case 112:// F1-F12
1245 if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'P';}else{result.key='\x1bOP';}break;case 113:if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'Q';}else{result.key='\x1bOQ';}break;case 114:if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'R';}else{result.key='\x1bOR';}break;case 115:if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'S';}else{result.key='\x1bOS';}break;case 116:if(modifiers){result.key='\x1b[15;'+(modifiers+1)+'~';}else{result.key='\x1b[15~';}break;case 117:if(modifiers){result.key='\x1b[17;'+(modifiers+1)+'~';}else{result.key='\x1b[17~';}break;case 118:if(modifiers){result.key='\x1b[18;'+(modifiers+1)+'~';}else{result.key='\x1b[18~';}break;case 119:if(modifiers){result.key='\x1b[19;'+(modifiers+1)+'~';}else{result.key='\x1b[19~';}break;case 120:if(modifiers){result.key='\x1b[20;'+(modifiers+1)+'~';}else{result.key='\x1b[20~';}break;case 121:if(modifiers){result.key='\x1b[21;'+(modifiers+1)+'~';}else{result.key='\x1b[21~';}break;case 122:if(modifiers){result.key='\x1b[23;'+(modifiers+1)+'~';}else{result.key='\x1b[23~';}break;case 123:if(modifiers){result.key='\x1b[24;'+(modifiers+1)+'~';}else{result.key='\x1b[24~';}break;default:// a-z and space
1246 if(ev.ctrlKey&&!ev.shiftKey&&!ev.altKey&&!ev.metaKey){if(ev.keyCode>=65&&ev.keyCode<=90){result.key=String.fromCharCode(ev.keyCode-64);}else if(ev.keyCode===32){// NUL
1247 result.key=String.fromCharCode(0);}else if(ev.keyCode>=51&&ev.keyCode<=55){// escape, file sep, group sep, record sep, unit sep
1248 result.key=String.fromCharCode(ev.keyCode-51+27);}else if(ev.keyCode===56){// delete
1249 result.key=String.fromCharCode(127);}else if(ev.keyCode===219){// ^[ - escape
1250 result.key=String.fromCharCode(27);}else if(ev.keyCode===221){// ^] - group sep
1251 result.key=String.fromCharCode(29);}}else if(!this.isMac&&ev.altKey&&!ev.ctrlKey&&!ev.metaKey){// On Mac this is a third level shift. Use <Esc> instead.
1252 if(ev.keyCode>=65&&ev.keyCode<=90){result.key='\x1b'+String.fromCharCode(ev.keyCode+32);}else if(ev.keyCode===192){result.key='\x1b`';}else if(ev.keyCode>=48&&ev.keyCode<=57){result.key='\x1b'+(ev.keyCode-48);}}break;}return result;};/**
1253 * Set the G level of the terminal
1254 * @param g
1255 */Terminal.prototype.setgLevel=function(g){this.glevel=g;this.charset=this.charsets[g];};/**
1256 * Set the charset for the given G level of the terminal
1257 * @param g
1258 * @param charset
1259 */Terminal.prototype.setgCharset=function(g,charset){this.charsets[g]=charset;if(this.glevel===g){this.charset=charset;}};/**
1260 * Handle a keypress event.
1261 * Key Resources:
1262 * - https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
1263 * @param {KeyboardEvent} ev The keypress event to be handled.
1264 */Terminal.prototype.keyPress=function(ev){var key;this.cancel(ev);if(ev.charCode){key=ev.charCode;}else if(ev.which==null){key=ev.keyCode;}else if(ev.which!==0&&ev.charCode!==0){key=ev.which;}else{return false;}if(!key||(ev.altKey||ev.ctrlKey||ev.metaKey)&&!isThirdLevelShift(this,ev)){return false;}key=String.fromCharCode(key);this.emit('keypress',key,ev);this.emit('key',key,ev);this.showCursor();this.handler(key);return false;};/**
1265 * Send data for handling to the terminal
1266 * @param {string} data
1267 */Terminal.prototype.send=function(data){var self=this;if(!this.queue){setTimeout(function(){self.handler(self.queue);self.queue='';},1);}this.queue+=data;};/**
1268 * Ring the bell.
1269 * Note: We could do sweet things with webaudio here
1270 */Terminal.prototype.bell=function(){if(!this.visualBell)return;var self=this;this.element.style.borderColor='white';setTimeout(function(){self.element.style.borderColor='';},10);if(this.popOnBell)this.focus();};/**
1271 * Log the current state to the console.
1272 */Terminal.prototype.log=function(){if(!this.debug)return;if(!this.context.console||!this.context.console.log)return;var args=Array.prototype.slice.call(arguments);this.context.console.log.apply(this.context.console,args);};/**
1273 * Log the current state as error to the console.
1274 */Terminal.prototype.error=function(){if(!this.debug)return;if(!this.context.console||!this.context.console.error)return;var args=Array.prototype.slice.call(arguments);this.context.console.error.apply(this.context.console,args);};/**
1275 * Resizes the terminal.
1276 *
1277 * @param {number} x The number of columns to resize to.
1278 * @param {number} y The number of rows to resize to.
1279 */Terminal.prototype.resize=function(x,y){var line,el,i,j,ch,addToY;if(x===this.cols&&y===this.rows){return;}if(x<1)x=1;if(y<1)y=1;// resize cols
1280 j=this.cols;if(j<x){ch=[this.defAttr,' ',1];// does xterm use the default attr?
1281 i=this.lines.length;while(i--){while(this.lines[i].length<x){this.lines[i].push(ch);}}}else{// (j > x)
1282 i=this.lines.length;while(i--){while(this.lines[i].length>x){this.lines[i].pop();}}}this.setupStops(j);this.cols=x;// resize rows
1283 j=this.rows;addToY=0;if(j<y){el=this.element;while(j++<y){// y is rows, not this.y
1284 if(this.lines.length<y+this.ybase){if(this.ybase>0&&this.lines.length<=this.ybase+this.y+addToY+1){// There is room above the buffer and there are no empty elements below the line,
1285 // scroll up
1286 this.ybase--;addToY++;if(this.ydisp>0){// Viewport is at the top of the buffer, must increase downwards
1287 this.ydisp--;}}else{// Add a blank line if there is no buffer left at the top to scroll to, or if there
1288 // are blank lines after the cursor
1289 this.lines.push(this.blankLine());}}if(this.children.length<y){this.insertRow();}}}else{// (j > y)
1290 while(j-->y){if(this.lines.length>y+this.ybase){if(this.lines.length>this.ybase+this.y+1){// The line is a blank line below the cursor, remove it
1291 this.lines.pop();}else{// The line is the cursor, scroll down
1292 this.ybase++;this.ydisp++;}}if(this.children.length>y){el=this.children.shift();if(!el)continue;el.parentNode.removeChild(el);}}}this.rows=y;// Make sure that the cursor stays on screen
1293 if(this.y>=y){this.y=y-1;}if(addToY){this.y+=addToY;}if(this.x>=x){this.x=x-1;}this.scrollTop=0;this.scrollBottom=y-1;this.refresh(0,this.rows-1);this.normal=null;this.emit('resize',{terminal:this,cols:x,rows:y});};/**
1294 * Updates the range of rows to refresh
1295 * @param {number} y The number of rows to refresh next.
1296 */Terminal.prototype.updateRange=function(y){if(y<this.refreshStart)this.refreshStart=y;if(y>this.refreshEnd)this.refreshEnd=y;// if (y > this.refreshEnd) {
1297 // this.refreshEnd = y;
1298 // if (y > this.rows - 1) {
1299 // this.refreshEnd = this.rows - 1;
1300 // }
1301 // }
1302 };/**
1303 * Set the range of refreshing to the maximyum value
1304 */Terminal.prototype.maxRange=function(){this.refreshStart=0;this.refreshEnd=this.rows-1;};/**
1305 * Setup the tab stops.
1306 * @param {number} i
1307 */Terminal.prototype.setupStops=function(i){if(i!=null){if(!this.tabs[i]){i=this.prevStop(i);}}else{this.tabs={};i=0;}for(;i<this.cols;i+=8){this.tabs[i]=true;}};/**
1308 * Move the cursor to the previous tab stop from the given position (default is current).
1309 * @param {number} x The position to move the cursor to the previous tab stop.
1310 */Terminal.prototype.prevStop=function(x){if(x==null)x=this.x;while(!this.tabs[--x]&&x>0){}return x>=this.cols?this.cols-1:x<0?0:x;};/**
1311 * Move the cursor one tab stop forward from the given position (default is current).
1312 * @param {number} x The position to move the cursor one tab stop forward.
1313 */Terminal.prototype.nextStop=function(x){if(x==null)x=this.x;while(!this.tabs[++x]&&x<this.cols){}return x>=this.cols?this.cols-1:x<0?0:x;};/**
1314 * Erase in the identified line everything from "x" to the end of the line (right).
1315 * @param {number} x The column from which to start erasing to the end of the line.
1316 * @param {number} y The line in which to operate.
1317 */Terminal.prototype.eraseRight=function(x,y){var line=this.lines[this.ybase+y],ch=[this.eraseAttr(),' ',1];// xterm
1318 for(;x<this.cols;x++){line[x]=ch;}this.updateRange(y);};/**
1319 * Erase in the identified line everything from "x" to the start of the line (left).
1320 * @param {number} x The column from which to start erasing to the start of the line.
1321 * @param {number} y The line in which to operate.
1322 */Terminal.prototype.eraseLeft=function(x,y){var line=this.lines[this.ybase+y],ch=[this.eraseAttr(),' ',1];// xterm
1323 x++;while(x--){line[x]=ch;}this.updateRange(y);};/**
1324 * Clears the entire buffer, making the prompt line the new first line.
1325 */Terminal.prototype.clear=function(){if(this.ybase===0&&this.y===0){// Don't clear if it's already clear
1326 return;}this.lines=[this.lines[this.ybase+this.y]];this.ydisp=0;this.ybase=0;this.y=0;for(var i=1;i<this.rows;i++){this.lines.push(this.blankLine());}this.refresh(0,this.rows-1);this.emit('scroll',this.ydisp);};/**
1327 * Erase all content in the given line
1328 * @param {number} y The line to erase all of its contents.
1329 */Terminal.prototype.eraseLine=function(y){this.eraseRight(0,y);};/**
1330 * Return the data array of a blank line/
1331 * @param {number} cur First bunch of data for each "blank" character.
1332 */Terminal.prototype.blankLine=function(cur){var attr=cur?this.eraseAttr():this.defAttr;var ch=[attr,' ',1]// width defaults to 1 halfwidth character
1333 ,line=[],i=0;for(;i<this.cols;i++){line[i]=ch;}return line;};/**
1334 * If cur return the back color xterm feature attribute. Else return defAttr.
1335 * @param {object} cur
1336 */Terminal.prototype.ch=function(cur){return cur?[this.eraseAttr(),' ',1]:[this.defAttr,' ',1];};/**
1337 * Evaluate if the current erminal is the given argument.
1338 * @param {object} term The terminal to evaluate
1339 */Terminal.prototype.is=function(term){var name=this.termName;return(name+'').indexOf(term)===0;};/**
1340 * Emit the 'data' event and populate the given data.
1341 * @param {string} data The data to populate in the event.
1342 */Terminal.prototype.handler=function(data){this.emit('data',data);};/**
1343 * Emit the 'title' event and populate the given title.
1344 * @param {string} title The title to populate in the event.
1345 */Terminal.prototype.handleTitle=function(title){this.emit('title',title);};/**
1346 * ESC
1347 *//**
1348 * ESC D Index (IND is 0x84).
1349 */Terminal.prototype.index=function(){this.y++;if(this.y>this.scrollBottom){this.y--;this.scroll();}this.state=normal;};/**
1350 * ESC M Reverse Index (RI is 0x8d).
1351 */Terminal.prototype.reverseIndex=function(){var j;this.y--;if(this.y<this.scrollTop){this.y++;// possibly move the code below to term.reverseScroll();
1352 // test: echo -ne '\e[1;1H\e[44m\eM\e[0m'
1353 // blankLine(true) is xterm/linux behavior
1354 this.lines.splice(this.y+this.ybase,0,this.blankLine(true));j=this.rows-1-this.scrollBottom;this.lines.splice(this.rows-1+this.ybase-j+1,1);// this.maxRange();
1355 this.updateRange(this.scrollTop);this.updateRange(this.scrollBottom);}this.state=normal;};/**
1356 * ESC c Full Reset (RIS).
1357 */Terminal.prototype.reset=function(){this.options.rows=this.rows;this.options.cols=this.cols;var customKeydownHandler=this.customKeydownHandler;Terminal.call(this,this.options);this.customKeydownHandler=customKeydownHandler;this.refresh(0,this.rows-1);this.viewport.syncScrollArea();};/**
1358 * ESC H Tab Set (HTS is 0x88).
1359 */Terminal.prototype.tabSet=function(){this.tabs[this.x]=true;this.state=normal;};/**
1360 * CSI
1361 *//**
1362 * CSI Ps A
1363 * Cursor Up Ps Times (default = 1) (CUU).
1364 */Terminal.prototype.cursorUp=function(params){var param=params[0];if(param<1)param=1;this.y-=param;if(this.y<0)this.y=0;};/**
1365 * CSI Ps B
1366 * Cursor Down Ps Times (default = 1) (CUD).
1367 */Terminal.prototype.cursorDown=function(params){var param=params[0];if(param<1)param=1;this.y+=param;if(this.y>=this.rows){this.y=this.rows-1;}};/**
1368 * CSI Ps C
1369 * Cursor Forward Ps Times (default = 1) (CUF).
1370 */Terminal.prototype.cursorForward=function(params){var param=params[0];if(param<1)param=1;this.x+=param;if(this.x>=this.cols){this.x=this.cols-1;}};/**
1371 * CSI Ps D
1372 * Cursor Backward Ps Times (default = 1) (CUB).
1373 */Terminal.prototype.cursorBackward=function(params){var param=params[0];if(param<1)param=1;this.x-=param;if(this.x<0)this.x=0;};/**
1374 * CSI Ps ; Ps H
1375 * Cursor Position [row;column] (default = [1,1]) (CUP).
1376 */Terminal.prototype.cursorPos=function(params){var row,col;row=params[0]-1;if(params.length>=2){col=params[1]-1;}else{col=0;}if(row<0){row=0;}else if(row>=this.rows){row=this.rows-1;}if(col<0){col=0;}else if(col>=this.cols){col=this.cols-1;}this.x=col;this.y=row;};/**
1377 * CSI Ps J Erase in Display (ED).
1378 * Ps = 0 -> Erase Below (default).
1379 * Ps = 1 -> Erase Above.
1380 * Ps = 2 -> Erase All.
1381 * Ps = 3 -> Erase Saved Lines (xterm).
1382 * CSI ? Ps J
1383 * Erase in Display (DECSED).
1384 * Ps = 0 -> Selective Erase Below (default).
1385 * Ps = 1 -> Selective Erase Above.
1386 * Ps = 2 -> Selective Erase All.
1387 */Terminal.prototype.eraseInDisplay=function(params){var j;switch(params[0]){case 0:this.eraseRight(this.x,this.y);j=this.y+1;for(;j<this.rows;j++){this.eraseLine(j);}break;case 1:this.eraseLeft(this.x,this.y);j=this.y;while(j--){this.eraseLine(j);}break;case 2:j=this.rows;while(j--){this.eraseLine(j);}break;case 3:;// no saved lines
1388 break;}};/**
1389 * CSI Ps K Erase in Line (EL).
1390 * Ps = 0 -> Erase to Right (default).
1391 * Ps = 1 -> Erase to Left.
1392 * Ps = 2 -> Erase All.
1393 * CSI ? Ps K
1394 * Erase in Line (DECSEL).
1395 * Ps = 0 -> Selective Erase to Right (default).
1396 * Ps = 1 -> Selective Erase to Left.
1397 * Ps = 2 -> Selective Erase All.
1398 */Terminal.prototype.eraseInLine=function(params){switch(params[0]){case 0:this.eraseRight(this.x,this.y);break;case 1:this.eraseLeft(this.x,this.y);break;case 2:this.eraseLine(this.y);break;}};/**
1399 * CSI Pm m Character Attributes (SGR).
1400 * Ps = 0 -> Normal (default).
1401 * Ps = 1 -> Bold.
1402 * Ps = 4 -> Underlined.
1403 * Ps = 5 -> Blink (appears as Bold).
1404 * Ps = 7 -> Inverse.
1405 * Ps = 8 -> Invisible, i.e., hidden (VT300).
1406 * Ps = 2 2 -> Normal (neither bold nor faint).
1407 * Ps = 2 4 -> Not underlined.
1408 * Ps = 2 5 -> Steady (not blinking).
1409 * Ps = 2 7 -> Positive (not inverse).
1410 * Ps = 2 8 -> Visible, i.e., not hidden (VT300).
1411 * Ps = 3 0 -> Set foreground color to Black.
1412 * Ps = 3 1 -> Set foreground color to Red.
1413 * Ps = 3 2 -> Set foreground color to Green.
1414 * Ps = 3 3 -> Set foreground color to Yellow.
1415 * Ps = 3 4 -> Set foreground color to Blue.
1416 * Ps = 3 5 -> Set foreground color to Magenta.
1417 * Ps = 3 6 -> Set foreground color to Cyan.
1418 * Ps = 3 7 -> Set foreground color to White.
1419 * Ps = 3 9 -> Set foreground color to default (original).
1420 * Ps = 4 0 -> Set background color to Black.
1421 * Ps = 4 1 -> Set background color to Red.
1422 * Ps = 4 2 -> Set background color to Green.
1423 * Ps = 4 3 -> Set background color to Yellow.
1424 * Ps = 4 4 -> Set background color to Blue.
1425 * Ps = 4 5 -> Set background color to Magenta.
1426 * Ps = 4 6 -> Set background color to Cyan.
1427 * Ps = 4 7 -> Set background color to White.
1428 * Ps = 4 9 -> Set background color to default (original).
1429 *
1430 * If 16-color support is compiled, the following apply. Assume
1431 * that xterm's resources are set so that the ISO color codes are
1432 * the first 8 of a set of 16. Then the aixterm colors are the
1433 * bright versions of the ISO colors:
1434 * Ps = 9 0 -> Set foreground color to Black.
1435 * Ps = 9 1 -> Set foreground color to Red.
1436 * Ps = 9 2 -> Set foreground color to Green.
1437 * Ps = 9 3 -> Set foreground color to Yellow.
1438 * Ps = 9 4 -> Set foreground color to Blue.
1439 * Ps = 9 5 -> Set foreground color to Magenta.
1440 * Ps = 9 6 -> Set foreground color to Cyan.
1441 * Ps = 9 7 -> Set foreground color to White.
1442 * Ps = 1 0 0 -> Set background color to Black.
1443 * Ps = 1 0 1 -> Set background color to Red.
1444 * Ps = 1 0 2 -> Set background color to Green.
1445 * Ps = 1 0 3 -> Set background color to Yellow.
1446 * Ps = 1 0 4 -> Set background color to Blue.
1447 * Ps = 1 0 5 -> Set background color to Magenta.
1448 * Ps = 1 0 6 -> Set background color to Cyan.
1449 * Ps = 1 0 7 -> Set background color to White.
1450 *
1451 * If xterm is compiled with the 16-color support disabled, it
1452 * supports the following, from rxvt:
1453 * Ps = 1 0 0 -> Set foreground and background color to
1454 * default.
1455 *
1456 * If 88- or 256-color support is compiled, the following apply.
1457 * Ps = 3 8 ; 5 ; Ps -> Set foreground color to the second
1458 * Ps.
1459 * Ps = 4 8 ; 5 ; Ps -> Set background color to the second
1460 * Ps.
1461 */Terminal.prototype.charAttributes=function(params){// Optimize a single SGR0.
1462 if(params.length===1&&params[0]===0){this.curAttr=this.defAttr;return;}var l=params.length,i=0,flags=this.curAttr>>18,fg=this.curAttr>>9&0x1ff,bg=this.curAttr&0x1ff,p;for(;i<l;i++){p=params[i];if(p>=30&&p<=37){// fg color 8
1463 fg=p-30;}else if(p>=40&&p<=47){// bg color 8
1464 bg=p-40;}else if(p>=90&&p<=97){// fg color 16
1465 p+=8;fg=p-90;}else if(p>=100&&p<=107){// bg color 16
1466 p+=8;bg=p-100;}else if(p===0){// default
1467 flags=this.defAttr>>18;fg=this.defAttr>>9&0x1ff;bg=this.defAttr&0x1ff;// flags = 0;
1468 // fg = 0x1ff;
1469 // bg = 0x1ff;
1470 }else if(p===1){// bold text
1471 flags|=1;}else if(p===4){// underlined text
1472 flags|=2;}else if(p===5){// blink
1473 flags|=4;}else if(p===7){// inverse and positive
1474 // test with: echo -e '\e[31m\e[42mhello\e[7mworld\e[27mhi\e[m'
1475 flags|=8;}else if(p===8){// invisible
1476 flags|=16;}else if(p===22){// not bold
1477 flags&=~1;}else if(p===24){// not underlined
1478 flags&=~2;}else if(p===25){// not blink
1479 flags&=~4;}else if(p===27){// not inverse
1480 flags&=~8;}else if(p===28){// not invisible
1481 flags&=~16;}else if(p===39){// reset fg
1482 fg=this.defAttr>>9&0x1ff;}else if(p===49){// reset bg
1483 bg=this.defAttr&0x1ff;}else if(p===38){// fg color 256
1484 if(params[i+1]===2){i+=2;fg=matchColor(params[i]&0xff,params[i+1]&0xff,params[i+2]&0xff);if(fg===-1)fg=0x1ff;i+=2;}else if(params[i+1]===5){i+=2;p=params[i]&0xff;fg=p;}}else if(p===48){// bg color 256
1485 if(params[i+1]===2){i+=2;bg=matchColor(params[i]&0xff,params[i+1]&0xff,params[i+2]&0xff);if(bg===-1)bg=0x1ff;i+=2;}else if(params[i+1]===5){i+=2;p=params[i]&0xff;bg=p;}}else if(p===100){// reset fg/bg
1486 fg=this.defAttr>>9&0x1ff;bg=this.defAttr&0x1ff;}else{this.error('Unknown SGR attribute: %d.',p);}}this.curAttr=flags<<18|fg<<9|bg;};/**
1487 * CSI Ps n Device Status Report (DSR).
1488 * Ps = 5 -> Status Report. Result (``OK'') is
1489 * CSI 0 n
1490 * Ps = 6 -> Report Cursor Position (CPR) [row;column].
1491 * Result is
1492 * CSI r ; c R
1493 * CSI ? Ps n
1494 * Device Status Report (DSR, DEC-specific).
1495 * Ps = 6 -> Report Cursor Position (CPR) [row;column] as CSI
1496 * ? r ; c R (assumes page is zero).
1497 * Ps = 1 5 -> Report Printer status as CSI ? 1 0 n (ready).
1498 * or CSI ? 1 1 n (not ready).
1499 * Ps = 2 5 -> Report UDK status as CSI ? 2 0 n (unlocked)
1500 * or CSI ? 2 1 n (locked).
1501 * Ps = 2 6 -> Report Keyboard status as
1502 * CSI ? 2 7 ; 1 ; 0 ; 0 n (North American).
1503 * The last two parameters apply to VT400 & up, and denote key-
1504 * board ready and LK01 respectively.
1505 * Ps = 5 3 -> Report Locator status as
1506 * CSI ? 5 3 n Locator available, if compiled-in, or
1507 * CSI ? 5 0 n No Locator, if not.
1508 */Terminal.prototype.deviceStatus=function(params){if(!this.prefix){switch(params[0]){case 5:// status report
1509 this.send('\x1b[0n');break;case 6:// cursor position
1510 this.send('\x1b['+(this.y+1)+';'+(this.x+1)+'R');break;}}else if(this.prefix==='?'){// modern xterm doesnt seem to
1511 // respond to any of these except ?6, 6, and 5
1512 switch(params[0]){case 6:// cursor position
1513 this.send('\x1b[?'+(this.y+1)+';'+(this.x+1)+'R');break;case 15:// no printer
1514 // this.send('\x1b[?11n');
1515 break;case 25:// dont support user defined keys
1516 // this.send('\x1b[?21n');
1517 break;case 26:// north american keyboard
1518 // this.send('\x1b[?27;1;0;0n');
1519 break;case 53:// no dec locator/mouse
1520 // this.send('\x1b[?50n');
1521 break;}}};/**
1522 * Additions
1523 *//**
1524 * CSI Ps @
1525 * Insert Ps (Blank) Character(s) (default = 1) (ICH).
1526 */Terminal.prototype.insertChars=function(params){var param,row,j,ch;param=params[0];if(param<1)param=1;row=this.y+this.ybase;j=this.x;ch=[this.eraseAttr(),' ',1];// xterm
1527 while(param--&&j<this.cols){this.lines[row].splice(j++,0,ch);this.lines[row].pop();}};/**
1528 * CSI Ps E
1529 * Cursor Next Line Ps Times (default = 1) (CNL).
1530 * same as CSI Ps B ?
1531 */Terminal.prototype.cursorNextLine=function(params){var param=params[0];if(param<1)param=1;this.y+=param;if(this.y>=this.rows){this.y=this.rows-1;}this.x=0;};/**
1532 * CSI Ps F
1533 * Cursor Preceding Line Ps Times (default = 1) (CNL).
1534 * reuse CSI Ps A ?
1535 */Terminal.prototype.cursorPrecedingLine=function(params){var param=params[0];if(param<1)param=1;this.y-=param;if(this.y<0)this.y=0;this.x=0;};/**
1536 * CSI Ps G
1537 * Cursor Character Absolute [column] (default = [row,1]) (CHA).
1538 */Terminal.prototype.cursorCharAbsolute=function(params){var param=params[0];if(param<1)param=1;this.x=param-1;};/**
1539 * CSI Ps L
1540 * Insert Ps Line(s) (default = 1) (IL).
1541 */Terminal.prototype.insertLines=function(params){var param,row,j;param=params[0];if(param<1)param=1;row=this.y+this.ybase;j=this.rows-1-this.scrollBottom;j=this.rows-1+this.ybase-j+1;while(param--){// test: echo -e '\e[44m\e[1L\e[0m'
1542 // blankLine(true) - xterm/linux behavior
1543 this.lines.splice(row,0,this.blankLine(true));this.lines.splice(j,1);}// this.maxRange();
1544 this.updateRange(this.y);this.updateRange(this.scrollBottom);};/**
1545 * CSI Ps M
1546 * Delete Ps Line(s) (default = 1) (DL).
1547 */Terminal.prototype.deleteLines=function(params){var param,row,j;param=params[0];if(param<1)param=1;row=this.y+this.ybase;j=this.rows-1-this.scrollBottom;j=this.rows-1+this.ybase-j;while(param--){// test: echo -e '\e[44m\e[1M\e[0m'
1548 // blankLine(true) - xterm/linux behavior
1549 this.lines.splice(j+1,0,this.blankLine(true));this.lines.splice(row,1);}// this.maxRange();
1550 this.updateRange(this.y);this.updateRange(this.scrollBottom);};/**
1551 * CSI Ps P
1552 * Delete Ps Character(s) (default = 1) (DCH).
1553 */Terminal.prototype.deleteChars=function(params){var param,row,ch;param=params[0];if(param<1)param=1;row=this.y+this.ybase;ch=[this.eraseAttr(),' ',1];// xterm
1554 while(param--){this.lines[row].splice(this.x,1);this.lines[row].push(ch);}};/**
1555 * CSI Ps X
1556 * Erase Ps Character(s) (default = 1) (ECH).
1557 */Terminal.prototype.eraseChars=function(params){var param,row,j,ch;param=params[0];if(param<1)param=1;row=this.y+this.ybase;j=this.x;ch=[this.eraseAttr(),' ',1];// xterm
1558 while(param--&&j<this.cols){this.lines[row][j++]=ch;}};/**
1559 * CSI Pm ` Character Position Absolute
1560 * [column] (default = [row,1]) (HPA).
1561 */Terminal.prototype.charPosAbsolute=function(params){var param=params[0];if(param<1)param=1;this.x=param-1;if(this.x>=this.cols){this.x=this.cols-1;}};/**
1562 * 141 61 a * HPR -
1563 * Horizontal Position Relative
1564 * reuse CSI Ps C ?
1565 */Terminal.prototype.HPositionRelative=function(params){var param=params[0];if(param<1)param=1;this.x+=param;if(this.x>=this.cols){this.x=this.cols-1;}};/**
1566 * CSI Ps c Send Device Attributes (Primary DA).
1567 * Ps = 0 or omitted -> request attributes from terminal. The
1568 * response depends on the decTerminalID resource setting.
1569 * -> CSI ? 1 ; 2 c (``VT100 with Advanced Video Option'')
1570 * -> CSI ? 1 ; 0 c (``VT101 with No Options'')
1571 * -> CSI ? 6 c (``VT102'')
1572 * -> CSI ? 6 0 ; 1 ; 2 ; 6 ; 8 ; 9 ; 1 5 ; c (``VT220'')
1573 * The VT100-style response parameters do not mean anything by
1574 * themselves. VT220 parameters do, telling the host what fea-
1575 * tures the terminal supports:
1576 * Ps = 1 -> 132-columns.
1577 * Ps = 2 -> Printer.
1578 * Ps = 6 -> Selective erase.
1579 * Ps = 8 -> User-defined keys.
1580 * Ps = 9 -> National replacement character sets.
1581 * Ps = 1 5 -> Technical characters.
1582 * Ps = 2 2 -> ANSI color, e.g., VT525.
1583 * Ps = 2 9 -> ANSI text locator (i.e., DEC Locator mode).
1584 * CSI > Ps c
1585 * Send Device Attributes (Secondary DA).
1586 * Ps = 0 or omitted -> request the terminal's identification
1587 * code. The response depends on the decTerminalID resource set-
1588 * ting. It should apply only to VT220 and up, but xterm extends
1589 * this to VT100.
1590 * -> CSI > Pp ; Pv ; Pc c
1591 * where Pp denotes the terminal type
1592 * Pp = 0 -> ``VT100''.
1593 * Pp = 1 -> ``VT220''.
1594 * and Pv is the firmware version (for xterm, this was originally
1595 * the XFree86 patch number, starting with 95). In a DEC termi-
1596 * nal, Pc indicates the ROM cartridge registration number and is
1597 * always zero.
1598 * More information:
1599 * xterm/charproc.c - line 2012, for more information.
1600 * vim responds with ^[[?0c or ^[[?1c after the terminal's response (?)
1601 */Terminal.prototype.sendDeviceAttributes=function(params){if(params[0]>0)return;if(!this.prefix){if(this.is('xterm')||this.is('rxvt-unicode')||this.is('screen')){this.send('\x1b[?1;2c');}else if(this.is('linux')){this.send('\x1b[?6c');}}else if(this.prefix==='>'){// xterm and urxvt
1602 // seem to spit this
1603 // out around ~370 times (?).
1604 if(this.is('xterm')){this.send('\x1b[>0;276;0c');}else if(this.is('rxvt-unicode')){this.send('\x1b[>85;95;0c');}else if(this.is('linux')){// not supported by linux console.
1605 // linux console echoes parameters.
1606 this.send(params[0]+'c');}else if(this.is('screen')){this.send('\x1b[>83;40003;0c');}}};/**
1607 * CSI Pm d
1608 * Line Position Absolute [row] (default = [1,column]) (VPA).
1609 */Terminal.prototype.linePosAbsolute=function(params){var param=params[0];if(param<1)param=1;this.y=param-1;if(this.y>=this.rows){this.y=this.rows-1;}};/**
1610 * 145 65 e * VPR - Vertical Position Relative
1611 * reuse CSI Ps B ?
1612 */Terminal.prototype.VPositionRelative=function(params){var param=params[0];if(param<1)param=1;this.y+=param;if(this.y>=this.rows){this.y=this.rows-1;}};/**
1613 * CSI Ps ; Ps f
1614 * Horizontal and Vertical Position [row;column] (default =
1615 * [1,1]) (HVP).
1616 */Terminal.prototype.HVPosition=function(params){if(params[0]<1)params[0]=1;if(params[1]<1)params[1]=1;this.y=params[0]-1;if(this.y>=this.rows){this.y=this.rows-1;}this.x=params[1]-1;if(this.x>=this.cols){this.x=this.cols-1;}};/**
1617 * CSI Pm h Set Mode (SM).
1618 * Ps = 2 -> Keyboard Action Mode (AM).
1619 * Ps = 4 -> Insert Mode (IRM).
1620 * Ps = 1 2 -> Send/receive (SRM).
1621 * Ps = 2 0 -> Automatic Newline (LNM).
1622 * CSI ? Pm h
1623 * DEC Private Mode Set (DECSET).
1624 * Ps = 1 -> Application Cursor Keys (DECCKM).
1625 * Ps = 2 -> Designate USASCII for character sets G0-G3
1626 * (DECANM), and set VT100 mode.
1627 * Ps = 3 -> 132 Column Mode (DECCOLM).
1628 * Ps = 4 -> Smooth (Slow) Scroll (DECSCLM).
1629 * Ps = 5 -> Reverse Video (DECSCNM).
1630 * Ps = 6 -> Origin Mode (DECOM).
1631 * Ps = 7 -> Wraparound Mode (DECAWM).
1632 * Ps = 8 -> Auto-repeat Keys (DECARM).
1633 * Ps = 9 -> Send Mouse X & Y on button press. See the sec-
1634 * tion Mouse Tracking.
1635 * Ps = 1 0 -> Show toolbar (rxvt).
1636 * Ps = 1 2 -> Start Blinking Cursor (att610).
1637 * Ps = 1 8 -> Print form feed (DECPFF).
1638 * Ps = 1 9 -> Set print extent to full screen (DECPEX).
1639 * Ps = 2 5 -> Show Cursor (DECTCEM).
1640 * Ps = 3 0 -> Show scrollbar (rxvt).
1641 * Ps = 3 5 -> Enable font-shifting functions (rxvt).
1642 * Ps = 3 8 -> Enter Tektronix Mode (DECTEK).
1643 * Ps = 4 0 -> Allow 80 -> 132 Mode.
1644 * Ps = 4 1 -> more(1) fix (see curses resource).
1645 * Ps = 4 2 -> Enable Nation Replacement Character sets (DECN-
1646 * RCM).
1647 * Ps = 4 4 -> Turn On Margin Bell.
1648 * Ps = 4 5 -> Reverse-wraparound Mode.
1649 * Ps = 4 6 -> Start Logging. This is normally disabled by a
1650 * compile-time option.
1651 * Ps = 4 7 -> Use Alternate Screen Buffer. (This may be dis-
1652 * abled by the titeInhibit resource).
1653 * Ps = 6 6 -> Application keypad (DECNKM).
1654 * Ps = 6 7 -> Backarrow key sends backspace (DECBKM).
1655 * Ps = 1 0 0 0 -> Send Mouse X & Y on button press and
1656 * release. See the section Mouse Tracking.
1657 * Ps = 1 0 0 1 -> Use Hilite Mouse Tracking.
1658 * Ps = 1 0 0 2 -> Use Cell Motion Mouse Tracking.
1659 * Ps = 1 0 0 3 -> Use All Motion Mouse Tracking.
1660 * Ps = 1 0 0 4 -> Send FocusIn/FocusOut events.
1661 * Ps = 1 0 0 5 -> Enable Extended Mouse Mode.
1662 * Ps = 1 0 1 0 -> Scroll to bottom on tty output (rxvt).
1663 * Ps = 1 0 1 1 -> Scroll to bottom on key press (rxvt).
1664 * Ps = 1 0 3 4 -> Interpret "meta" key, sets eighth bit.
1665 * (enables the eightBitInput resource).
1666 * Ps = 1 0 3 5 -> Enable special modifiers for Alt and Num-
1667 * Lock keys. (This enables the numLock resource).
1668 * Ps = 1 0 3 6 -> Send ESC when Meta modifies a key. (This
1669 * enables the metaSendsEscape resource).
1670 * Ps = 1 0 3 7 -> Send DEL from the editing-keypad Delete
1671 * key.
1672 * Ps = 1 0 3 9 -> Send ESC when Alt modifies a key. (This
1673 * enables the altSendsEscape resource).
1674 * Ps = 1 0 4 0 -> Keep selection even if not highlighted.
1675 * (This enables the keepSelection resource).
1676 * Ps = 1 0 4 1 -> Use the CLIPBOARD selection. (This enables
1677 * the selectToClipboard resource).
1678 * Ps = 1 0 4 2 -> Enable Urgency window manager hint when
1679 * Control-G is received. (This enables the bellIsUrgent
1680 * resource).
1681 * Ps = 1 0 4 3 -> Enable raising of the window when Control-G
1682 * is received. (enables the popOnBell resource).
1683 * Ps = 1 0 4 7 -> Use Alternate Screen Buffer. (This may be
1684 * disabled by the titeInhibit resource).
1685 * Ps = 1 0 4 8 -> Save cursor as in DECSC. (This may be dis-
1686 * abled by the titeInhibit resource).
1687 * Ps = 1 0 4 9 -> Save cursor as in DECSC and use Alternate
1688 * Screen Buffer, clearing it first. (This may be disabled by
1689 * the titeInhibit resource). This combines the effects of the 1
1690 * 0 4 7 and 1 0 4 8 modes. Use this with terminfo-based
1691 * applications rather than the 4 7 mode.
1692 * Ps = 1 0 5 0 -> Set terminfo/termcap function-key mode.
1693 * Ps = 1 0 5 1 -> Set Sun function-key mode.
1694 * Ps = 1 0 5 2 -> Set HP function-key mode.
1695 * Ps = 1 0 5 3 -> Set SCO function-key mode.
1696 * Ps = 1 0 6 0 -> Set legacy keyboard emulation (X11R6).
1697 * Ps = 1 0 6 1 -> Set VT220 keyboard emulation.
1698 * Ps = 2 0 0 4 -> Set bracketed paste mode.
1699 * Modes:
1700 * http: *vt100.net/docs/vt220-rm/chapter4.html
1701 */Terminal.prototype.setMode=function(params){if((typeof params==='undefined'?'undefined':_typeof(params))==='object'){var l=params.length,i=0;for(;i<l;i++){this.setMode(params[i]);}return;}if(!this.prefix){switch(params){case 4:this.insertMode=true;break;case 20://this.convertEol = true;
1702 break;}}else if(this.prefix==='?'){switch(params){case 1:this.applicationCursor=true;break;case 2:this.setgCharset(0,Terminal.charsets.US);this.setgCharset(1,Terminal.charsets.US);this.setgCharset(2,Terminal.charsets.US);this.setgCharset(3,Terminal.charsets.US);// set VT100 mode here
1703 break;case 3:// 132 col mode
1704 this.savedCols=this.cols;this.resize(132,this.rows);break;case 6:this.originMode=true;break;case 7:this.wraparoundMode=true;break;case 12:// this.cursorBlink = true;
1705 break;case 66:this.log('Serial port requested application keypad.');this.applicationKeypad=true;this.viewport.syncScrollArea();break;case 9:// X10 Mouse
1706 // no release, no motion, no wheel, no modifiers.
1707 case 1000:// vt200 mouse
1708 // no motion.
1709 // no modifiers, except control on the wheel.
1710 case 1002:// button event mouse
1711 case 1003:// any event mouse
1712 // any event - sends motion events,
1713 // even if there is no button held down.
1714 this.x10Mouse=params===9;this.vt200Mouse=params===1000;this.normalMouse=params>1000;this.mouseEvents=true;this.element.style.cursor='default';this.log('Binding to mouse events.');break;case 1004:// send focusin/focusout events
1715 // focusin: ^[[I
1716 // focusout: ^[[O
1717 this.sendFocus=true;break;case 1005:// utf8 ext mode mouse
1718 this.utfMouse=true;// for wide terminals
1719 // simply encodes large values as utf8 characters
1720 break;case 1006:// sgr ext mode mouse
1721 this.sgrMouse=true;// for wide terminals
1722 // does not add 32 to fields
1723 // press: ^[[<b;x;yM
1724 // release: ^[[<b;x;ym
1725 break;case 1015:// urxvt ext mode mouse
1726 this.urxvtMouse=true;// for wide terminals
1727 // numbers for fields
1728 // press: ^[[b;x;yM
1729 // motion: ^[[b;x;yT
1730 break;case 25:// show cursor
1731 this.cursorHidden=false;break;case 1049:// alt screen buffer cursor
1732 //this.saveCursor();
1733 ;// FALL-THROUGH
1734 case 47:// alt screen buffer
1735 case 1047:// alt screen buffer
1736 if(!this.normal){var normal={lines:this.lines,ybase:this.ybase,ydisp:this.ydisp,x:this.x,y:this.y,scrollTop:this.scrollTop,scrollBottom:this.scrollBottom,tabs:this.tabs// XXX save charset(s) here?
1737 // charset: this.charset,
1738 // glevel: this.glevel,
1739 // charsets: this.charsets
1740 };this.reset();this.normal=normal;this.showCursor();}break;}}};/**
1741 * CSI Pm l Reset Mode (RM).
1742 * Ps = 2 -> Keyboard Action Mode (AM).
1743 * Ps = 4 -> Replace Mode (IRM).
1744 * Ps = 1 2 -> Send/receive (SRM).
1745 * Ps = 2 0 -> Normal Linefeed (LNM).
1746 * CSI ? Pm l
1747 * DEC Private Mode Reset (DECRST).
1748 * Ps = 1 -> Normal Cursor Keys (DECCKM).
1749 * Ps = 2 -> Designate VT52 mode (DECANM).
1750 * Ps = 3 -> 80 Column Mode (DECCOLM).
1751 * Ps = 4 -> Jump (Fast) Scroll (DECSCLM).
1752 * Ps = 5 -> Normal Video (DECSCNM).
1753 * Ps = 6 -> Normal Cursor Mode (DECOM).
1754 * Ps = 7 -> No Wraparound Mode (DECAWM).
1755 * Ps = 8 -> No Auto-repeat Keys (DECARM).
1756 * Ps = 9 -> Don't send Mouse X & Y on button press.
1757 * Ps = 1 0 -> Hide toolbar (rxvt).
1758 * Ps = 1 2 -> Stop Blinking Cursor (att610).
1759 * Ps = 1 8 -> Don't print form feed (DECPFF).
1760 * Ps = 1 9 -> Limit print to scrolling region (DECPEX).
1761 * Ps = 2 5 -> Hide Cursor (DECTCEM).
1762 * Ps = 3 0 -> Don't show scrollbar (rxvt).
1763 * Ps = 3 5 -> Disable font-shifting functions (rxvt).
1764 * Ps = 4 0 -> Disallow 80 -> 132 Mode.
1765 * Ps = 4 1 -> No more(1) fix (see curses resource).
1766 * Ps = 4 2 -> Disable Nation Replacement Character sets (DEC-
1767 * NRCM).
1768 * Ps = 4 4 -> Turn Off Margin Bell.
1769 * Ps = 4 5 -> No Reverse-wraparound Mode.
1770 * Ps = 4 6 -> Stop Logging. (This is normally disabled by a
1771 * compile-time option).
1772 * Ps = 4 7 -> Use Normal Screen Buffer.
1773 * Ps = 6 6 -> Numeric keypad (DECNKM).
1774 * Ps = 6 7 -> Backarrow key sends delete (DECBKM).
1775 * Ps = 1 0 0 0 -> Don't send Mouse X & Y on button press and
1776 * release. See the section Mouse Tracking.
1777 * Ps = 1 0 0 1 -> Don't use Hilite Mouse Tracking.
1778 * Ps = 1 0 0 2 -> Don't use Cell Motion Mouse Tracking.
1779 * Ps = 1 0 0 3 -> Don't use All Motion Mouse Tracking.
1780 * Ps = 1 0 0 4 -> Don't send FocusIn/FocusOut events.
1781 * Ps = 1 0 0 5 -> Disable Extended Mouse Mode.
1782 * Ps = 1 0 1 0 -> Don't scroll to bottom on tty output
1783 * (rxvt).
1784 * Ps = 1 0 1 1 -> Don't scroll to bottom on key press (rxvt).
1785 * Ps = 1 0 3 4 -> Don't interpret "meta" key. (This disables
1786 * the eightBitInput resource).
1787 * Ps = 1 0 3 5 -> Disable special modifiers for Alt and Num-
1788 * Lock keys. (This disables the numLock resource).
1789 * Ps = 1 0 3 6 -> Don't send ESC when Meta modifies a key.
1790 * (This disables the metaSendsEscape resource).
1791 * Ps = 1 0 3 7 -> Send VT220 Remove from the editing-keypad
1792 * Delete key.
1793 * Ps = 1 0 3 9 -> Don't send ESC when Alt modifies a key.
1794 * (This disables the altSendsEscape resource).
1795 * Ps = 1 0 4 0 -> Do not keep selection when not highlighted.
1796 * (This disables the keepSelection resource).
1797 * Ps = 1 0 4 1 -> Use the PRIMARY selection. (This disables
1798 * the selectToClipboard resource).
1799 * Ps = 1 0 4 2 -> Disable Urgency window manager hint when
1800 * Control-G is received. (This disables the bellIsUrgent
1801 * resource).
1802 * Ps = 1 0 4 3 -> Disable raising of the window when Control-
1803 * G is received. (This disables the popOnBell resource).
1804 * Ps = 1 0 4 7 -> Use Normal Screen Buffer, clearing screen
1805 * first if in the Alternate Screen. (This may be disabled by
1806 * the titeInhibit resource).
1807 * Ps = 1 0 4 8 -> Restore cursor as in DECRC. (This may be
1808 * disabled by the titeInhibit resource).
1809 * Ps = 1 0 4 9 -> Use Normal Screen Buffer and restore cursor
1810 * as in DECRC. (This may be disabled by the titeInhibit
1811 * resource). This combines the effects of the 1 0 4 7 and 1 0
1812 * 4 8 modes. Use this with terminfo-based applications rather
1813 * than the 4 7 mode.
1814 * Ps = 1 0 5 0 -> Reset terminfo/termcap function-key mode.
1815 * Ps = 1 0 5 1 -> Reset Sun function-key mode.
1816 * Ps = 1 0 5 2 -> Reset HP function-key mode.
1817 * Ps = 1 0 5 3 -> Reset SCO function-key mode.
1818 * Ps = 1 0 6 0 -> Reset legacy keyboard emulation (X11R6).
1819 * Ps = 1 0 6 1 -> Reset keyboard emulation to Sun/PC style.
1820 * Ps = 2 0 0 4 -> Reset bracketed paste mode.
1821 */Terminal.prototype.resetMode=function(params){if((typeof params==='undefined'?'undefined':_typeof(params))==='object'){var l=params.length,i=0;for(;i<l;i++){this.resetMode(params[i]);}return;}if(!this.prefix){switch(params){case 4:this.insertMode=false;break;case 20://this.convertEol = false;
1822 break;}}else if(this.prefix==='?'){switch(params){case 1:this.applicationCursor=false;break;case 3:if(this.cols===132&&this.savedCols){this.resize(this.savedCols,this.rows);}delete this.savedCols;break;case 6:this.originMode=false;break;case 7:this.wraparoundMode=false;break;case 12:// this.cursorBlink = false;
1823 break;case 66:this.log('Switching back to normal keypad.');this.applicationKeypad=false;this.viewport.syncScrollArea();break;case 9:// X10 Mouse
1824 case 1000:// vt200 mouse
1825 case 1002:// button event mouse
1826 case 1003:// any event mouse
1827 this.x10Mouse=false;this.vt200Mouse=false;this.normalMouse=false;this.mouseEvents=false;this.element.style.cursor='';break;case 1004:// send focusin/focusout events
1828 this.sendFocus=false;break;case 1005:// utf8 ext mode mouse
1829 this.utfMouse=false;break;case 1006:// sgr ext mode mouse
1830 this.sgrMouse=false;break;case 1015:// urxvt ext mode mouse
1831 this.urxvtMouse=false;break;case 25:// hide cursor
1832 this.cursorHidden=true;break;case 1049:// alt screen buffer cursor
1833 ;// FALL-THROUGH
1834 case 47:// normal screen buffer
1835 case 1047:// normal screen buffer - clearing it first
1836 if(this.normal){this.lines=this.normal.lines;this.ybase=this.normal.ybase;this.ydisp=this.normal.ydisp;this.x=this.normal.x;this.y=this.normal.y;this.scrollTop=this.normal.scrollTop;this.scrollBottom=this.normal.scrollBottom;this.tabs=this.normal.tabs;this.normal=null;// if (params === 1049) {
1837 // this.x = this.savedX;
1838 // this.y = this.savedY;
1839 // }
1840 this.refresh(0,this.rows-1);this.showCursor();}break;}}};/**
1841 * CSI Ps ; Ps r
1842 * Set Scrolling Region [top;bottom] (default = full size of win-
1843 * dow) (DECSTBM).
1844 * CSI ? Pm r
1845 */Terminal.prototype.setScrollRegion=function(params){if(this.prefix)return;this.scrollTop=(params[0]||1)-1;this.scrollBottom=(params[1]||this.rows)-1;this.x=0;this.y=0;};/**
1846 * CSI s
1847 * Save cursor (ANSI.SYS).
1848 */Terminal.prototype.saveCursor=function(params){this.savedX=this.x;this.savedY=this.y;};/**
1849 * CSI u
1850 * Restore cursor (ANSI.SYS).
1851 */Terminal.prototype.restoreCursor=function(params){this.x=this.savedX||0;this.y=this.savedY||0;};/**
1852 * Lesser Used
1853 *//**
1854 * CSI Ps I
1855 * Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
1856 */Terminal.prototype.cursorForwardTab=function(params){var param=params[0]||1;while(param--){this.x=this.nextStop();}};/**
1857 * CSI Ps S Scroll up Ps lines (default = 1) (SU).
1858 */Terminal.prototype.scrollUp=function(params){var param=params[0]||1;while(param--){this.lines.splice(this.ybase+this.scrollTop,1);this.lines.splice(this.ybase+this.scrollBottom,0,this.blankLine());}// this.maxRange();
1859 this.updateRange(this.scrollTop);this.updateRange(this.scrollBottom);};/**
1860 * CSI Ps T Scroll down Ps lines (default = 1) (SD).
1861 */Terminal.prototype.scrollDown=function(params){var param=params[0]||1;while(param--){this.lines.splice(this.ybase+this.scrollBottom,1);this.lines.splice(this.ybase+this.scrollTop,0,this.blankLine());}// this.maxRange();
1862 this.updateRange(this.scrollTop);this.updateRange(this.scrollBottom);};/**
1863 * CSI Ps ; Ps ; Ps ; Ps ; Ps T
1864 * Initiate highlight mouse tracking. Parameters are
1865 * [func;startx;starty;firstrow;lastrow]. See the section Mouse
1866 * Tracking.
1867 */Terminal.prototype.initMouseTracking=function(params){// Relevant: DECSET 1001
1868 };/**
1869 * CSI > Ps; Ps T
1870 * Reset one or more features of the title modes to the default
1871 * value. Normally, "reset" disables the feature. It is possi-
1872 * ble to disable the ability to reset features by compiling a
1873 * different default for the title modes into xterm.
1874 * Ps = 0 -> Do not set window/icon labels using hexadecimal.
1875 * Ps = 1 -> Do not query window/icon labels using hexadeci-
1876 * mal.
1877 * Ps = 2 -> Do not set window/icon labels using UTF-8.
1878 * Ps = 3 -> Do not query window/icon labels using UTF-8.
1879 * (See discussion of "Title Modes").
1880 */Terminal.prototype.resetTitleModes=function(params){;};/**
1881 * CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
1882 */Terminal.prototype.cursorBackwardTab=function(params){var param=params[0]||1;while(param--){this.x=this.prevStop();}};/**
1883 * CSI Ps b Repeat the preceding graphic character Ps times (REP).
1884 */Terminal.prototype.repeatPrecedingCharacter=function(params){var param=params[0]||1,line=this.lines[this.ybase+this.y],ch=line[this.x-1]||[this.defAttr,' ',1];while(param--){line[this.x++]=ch;}};/**
1885 * CSI Ps g Tab Clear (TBC).
1886 * Ps = 0 -> Clear Current Column (default).
1887 * Ps = 3 -> Clear All.
1888 * Potentially:
1889 * Ps = 2 -> Clear Stops on Line.
1890 * http://vt100.net/annarbor/aaa-ug/section6.html
1891 */Terminal.prototype.tabClear=function(params){var param=params[0];if(param<=0){delete this.tabs[this.x];}else if(param===3){this.tabs={};}};/**
1892 * CSI Pm i Media Copy (MC).
1893 * Ps = 0 -> Print screen (default).
1894 * Ps = 4 -> Turn off printer controller mode.
1895 * Ps = 5 -> Turn on printer controller mode.
1896 * CSI ? Pm i
1897 * Media Copy (MC, DEC-specific).
1898 * Ps = 1 -> Print line containing cursor.
1899 * Ps = 4 -> Turn off autoprint mode.
1900 * Ps = 5 -> Turn on autoprint mode.
1901 * Ps = 1 0 -> Print composed display, ignores DECPEX.
1902 * Ps = 1 1 -> Print all pages.
1903 */Terminal.prototype.mediaCopy=function(params){;};/**
1904 * CSI > Ps; Ps m
1905 * Set or reset resource-values used by xterm to decide whether
1906 * to construct escape sequences holding information about the
1907 * modifiers pressed with a given key. The first parameter iden-
1908 * tifies the resource to set/reset. The second parameter is the
1909 * value to assign to the resource. If the second parameter is
1910 * omitted, the resource is reset to its initial value.
1911 * Ps = 1 -> modifyCursorKeys.
1912 * Ps = 2 -> modifyFunctionKeys.
1913 * Ps = 4 -> modifyOtherKeys.
1914 * If no parameters are given, all resources are reset to their
1915 * initial values.
1916 */Terminal.prototype.setResources=function(params){;};/**
1917 * CSI > Ps n
1918 * Disable modifiers which may be enabled via the CSI > Ps; Ps m
1919 * sequence. This corresponds to a resource value of "-1", which
1920 * cannot be set with the other sequence. The parameter identi-
1921 * fies the resource to be disabled:
1922 * Ps = 1 -> modifyCursorKeys.
1923 * Ps = 2 -> modifyFunctionKeys.
1924 * Ps = 4 -> modifyOtherKeys.
1925 * If the parameter is omitted, modifyFunctionKeys is disabled.
1926 * When modifyFunctionKeys is disabled, xterm uses the modifier
1927 * keys to make an extended sequence of functions rather than
1928 * adding a parameter to each function key to denote the modi-
1929 * fiers.
1930 */Terminal.prototype.disableModifiers=function(params){;};/**
1931 * CSI > Ps p
1932 * Set resource value pointerMode. This is used by xterm to
1933 * decide whether to hide the pointer cursor as the user types.
1934 * Valid values for the parameter:
1935 * Ps = 0 -> never hide the pointer.
1936 * Ps = 1 -> hide if the mouse tracking mode is not enabled.
1937 * Ps = 2 -> always hide the pointer. If no parameter is
1938 * given, xterm uses the default, which is 1 .
1939 */Terminal.prototype.setPointerMode=function(params){;};/**
1940 * CSI ! p Soft terminal reset (DECSTR).
1941 * http://vt100.net/docs/vt220-rm/table4-10.html
1942 */Terminal.prototype.softReset=function(params){this.cursorHidden=false;this.insertMode=false;this.originMode=false;this.wraparoundMode=false;// autowrap
1943 this.applicationKeypad=false;// ?
1944 this.viewport.syncScrollArea();this.applicationCursor=false;this.scrollTop=0;this.scrollBottom=this.rows-1;this.curAttr=this.defAttr;this.x=this.y=0;// ?
1945 this.charset=null;this.glevel=0;// ??
1946 this.charsets=[null];// ??
1947 };/**
1948 * CSI Ps$ p
1949 * Request ANSI mode (DECRQM). For VT300 and up, reply is
1950 * CSI Ps; Pm$ y
1951 * where Ps is the mode number as in RM, and Pm is the mode
1952 * value:
1953 * 0 - not recognized
1954 * 1 - set
1955 * 2 - reset
1956 * 3 - permanently set
1957 * 4 - permanently reset
1958 */Terminal.prototype.requestAnsiMode=function(params){;};/**
1959 * CSI ? Ps$ p
1960 * Request DEC private mode (DECRQM). For VT300 and up, reply is
1961 * CSI ? Ps; Pm$ p
1962 * where Ps is the mode number as in DECSET, Pm is the mode value
1963 * as in the ANSI DECRQM.
1964 */Terminal.prototype.requestPrivateMode=function(params){;};/**
1965 * CSI Ps ; Ps " p
1966 * Set conformance level (DECSCL). Valid values for the first
1967 * parameter:
1968 * Ps = 6 1 -> VT100.
1969 * Ps = 6 2 -> VT200.
1970 * Ps = 6 3 -> VT300.
1971 * Valid values for the second parameter:
1972 * Ps = 0 -> 8-bit controls.
1973 * Ps = 1 -> 7-bit controls (always set for VT100).
1974 * Ps = 2 -> 8-bit controls.
1975 */Terminal.prototype.setConformanceLevel=function(params){;};/**
1976 * CSI Ps q Load LEDs (DECLL).
1977 * Ps = 0 -> Clear all LEDS (default).
1978 * Ps = 1 -> Light Num Lock.
1979 * Ps = 2 -> Light Caps Lock.
1980 * Ps = 3 -> Light Scroll Lock.
1981 * Ps = 2 1 -> Extinguish Num Lock.
1982 * Ps = 2 2 -> Extinguish Caps Lock.
1983 * Ps = 2 3 -> Extinguish Scroll Lock.
1984 */Terminal.prototype.loadLEDs=function(params){;};/**
1985 * CSI Ps SP q
1986 * Set cursor style (DECSCUSR, VT520).
1987 * Ps = 0 -> blinking block.
1988 * Ps = 1 -> blinking block (default).
1989 * Ps = 2 -> steady block.
1990 * Ps = 3 -> blinking underline.
1991 * Ps = 4 -> steady underline.
1992 */Terminal.prototype.setCursorStyle=function(params){;};/**
1993 * CSI Ps " q
1994 * Select character protection attribute (DECSCA). Valid values
1995 * for the parameter:
1996 * Ps = 0 -> DECSED and DECSEL can erase (default).
1997 * Ps = 1 -> DECSED and DECSEL cannot erase.
1998 * Ps = 2 -> DECSED and DECSEL can erase.
1999 */Terminal.prototype.setCharProtectionAttr=function(params){;};/**
2000 * CSI ? Pm r
2001 * Restore DEC Private Mode Values. The value of Ps previously
2002 * saved is restored. Ps values are the same as for DECSET.
2003 */Terminal.prototype.restorePrivateValues=function(params){;};/**
2004 * CSI Pt; Pl; Pb; Pr; Ps$ r
2005 * Change Attributes in Rectangular Area (DECCARA), VT400 and up.
2006 * Pt; Pl; Pb; Pr denotes the rectangle.
2007 * Ps denotes the SGR attributes to change: 0, 1, 4, 5, 7.
2008 * NOTE: xterm doesn't enable this code by default.
2009 */Terminal.prototype.setAttrInRectangle=function(params){var t=params[0],l=params[1],b=params[2],r=params[3],attr=params[4];var line,i;for(;t<b+1;t++){line=this.lines[this.ybase+t];for(i=l;i<r;i++){line[i]=[attr,line[i][1]];}}// this.maxRange();
2010 this.updateRange(params[0]);this.updateRange(params[2]);};/**
2011 * CSI Pc; Pt; Pl; Pb; Pr$ x
2012 * Fill Rectangular Area (DECFRA), VT420 and up.
2013 * Pc is the character to use.
2014 * Pt; Pl; Pb; Pr denotes the rectangle.
2015 * NOTE: xterm doesn't enable this code by default.
2016 */Terminal.prototype.fillRectangle=function(params){var ch=params[0],t=params[1],l=params[2],b=params[3],r=params[4];var line,i;for(;t<b+1;t++){line=this.lines[this.ybase+t];for(i=l;i<r;i++){line[i]=[line[i][0],String.fromCharCode(ch)];}}// this.maxRange();
2017 this.updateRange(params[1]);this.updateRange(params[3]);};/**
2018 * CSI Ps ; Pu ' z
2019 * Enable Locator Reporting (DECELR).
2020 * Valid values for the first parameter:
2021 * Ps = 0 -> Locator disabled (default).
2022 * Ps = 1 -> Locator enabled.
2023 * Ps = 2 -> Locator enabled for one report, then disabled.
2024 * The second parameter specifies the coordinate unit for locator
2025 * reports.
2026 * Valid values for the second parameter:
2027 * Pu = 0 <- or omitted -> default to character cells.
2028 * Pu = 1 <- device physical pixels.
2029 * Pu = 2 <- character cells.
2030 */Terminal.prototype.enableLocatorReporting=function(params){var val=params[0]>0;//this.mouseEvents = val;
2031 //this.decLocator = val;
2032 };/**
2033 * CSI Pt; Pl; Pb; Pr$ z
2034 * Erase Rectangular Area (DECERA), VT400 and up.
2035 * Pt; Pl; Pb; Pr denotes the rectangle.
2036 * NOTE: xterm doesn't enable this code by default.
2037 */Terminal.prototype.eraseRectangle=function(params){var t=params[0],l=params[1],b=params[2],r=params[3];var line,i,ch;ch=[this.eraseAttr(),' ',1];// xterm?
2038 for(;t<b+1;t++){line=this.lines[this.ybase+t];for(i=l;i<r;i++){line[i]=ch;}}// this.maxRange();
2039 this.updateRange(params[0]);this.updateRange(params[2]);};/**
2040 * CSI P m SP }
2041 * Insert P s Column(s) (default = 1) (DECIC), VT420 and up.
2042 * NOTE: xterm doesn't enable this code by default.
2043 */Terminal.prototype.insertColumns=function(){var param=params[0],l=this.ybase+this.rows,ch=[this.eraseAttr(),' ',1]// xterm?
2044 ,i;while(param--){for(i=this.ybase;i<l;i++){this.lines[i].splice(this.x+1,0,ch);this.lines[i].pop();}}this.maxRange();};/**
2045 * CSI P m SP ~
2046 * Delete P s Column(s) (default = 1) (DECDC), VT420 and up
2047 * NOTE: xterm doesn't enable this code by default.
2048 */Terminal.prototype.deleteColumns=function(){var param=params[0],l=this.ybase+this.rows,ch=[this.eraseAttr(),' ',1]// xterm?
2049 ,i;while(param--){for(i=this.ybase;i<l;i++){this.lines[i].splice(this.x,1);this.lines[i].push(ch);}}this.maxRange();};/**
2050 * Character Sets
2051 */Terminal.charsets={};// DEC Special Character and Line Drawing Set.
2052 // http://vt100.net/docs/vt102-ug/table5-13.html
2053 // A lot of curses apps use this if they see TERM=xterm.
2054 // testing: echo -e '\e(0a\e(B'
2055 // The xterm output sometimes seems to conflict with the
2056 // reference above. xterm seems in line with the reference
2057 // when running vttest however.
2058 // The table below now uses xterm's output from vttest.
2059 Terminal.charsets.SCLD={// (0
2060 '`':'\u25C6',// '◆'
2061 'a':'\u2592',// '▒'
2062 'b':'\t',// '\t'
2063 'c':'\f',// '\f'
2064 'd':'\r',// '\r'
2065 'e':'\n',// '\n'
2066 'f':'\xB0',// '°'
2067 'g':'\xB1',// '±'
2068 'h':'\u2424',// '\u2424' (NL)
2069 'i':'\x0B',// '\v'
2070 'j':'\u2518',// '┘'
2071 'k':'\u2510',// '┐'
2072 'l':'\u250C',// '┌'
2073 'm':'\u2514',// '└'
2074 'n':'\u253C',// '┼'
2075 'o':'\u23BA',// '⎺'
2076 'p':'\u23BB',// '⎻'
2077 'q':'\u2500',// '─'
2078 'r':'\u23BC',// '⎼'
2079 's':'\u23BD',// '⎽'
2080 't':'\u251C',// '├'
2081 'u':'\u2524',// '┤'
2082 'v':'\u2534',// '┴'
2083 'w':'\u252C',// '┬'
2084 'x':'\u2502',// '│'
2085 'y':'\u2264',// '≤'
2086 'z':'\u2265',// '≥'
2087 '{':'\u03C0',// 'π'
2088 '|':'\u2260',// '≠'
2089 '}':'\xA3',// '£'
2090 '~':'\xB7'// '·'
2091 };Terminal.charsets.UK=null;// (A
2092 Terminal.charsets.US=null;// (B (USASCII)
2093 Terminal.charsets.Dutch=null;// (4
2094 Terminal.charsets.Finnish=null;// (C or (5
2095 Terminal.charsets.French=null;// (R
2096 Terminal.charsets.FrenchCanadian=null;// (Q
2097 Terminal.charsets.German=null;// (K
2098 Terminal.charsets.Italian=null;// (Y
2099 Terminal.charsets.NorwegianDanish=null;// (E or (6
2100 Terminal.charsets.Spanish=null;// (Z
2101 Terminal.charsets.Swedish=null;// (H or (7
2102 Terminal.charsets.Swiss=null;// (=
2103 Terminal.charsets.ISOLatin=null;// /A
2104 /**
2105 * Helpers
2106 */function contains(el,arr){for(var i=0;i<arr.length;i+=1){if(el===arr[i]){return true;}}return false;}function on(el,type,handler,capture){if(!Array.isArray(el)){el=[el];}el.forEach(function(element){element.addEventListener(type,handler,capture||false);});}function off(el,type,handler,capture){el.removeEventListener(type,handler,capture||false);}function cancel(ev,force){if(!this.cancelEvents&&!force){return;}ev.preventDefault();ev.stopPropagation();return false;}function inherits(child,parent){function f(){this.constructor=child;}f.prototype=parent.prototype;child.prototype=new f();}// if bold is broken, we can't
2107 // use it in the terminal.
2108 function isBoldBroken(document){var body=document.getElementsByTagName('body')[0];var el=document.createElement('span');el.innerHTML='hello world';body.appendChild(el);var w1=el.scrollWidth;el.style.fontWeight='bold';var w2=el.scrollWidth;body.removeChild(el);return w1!==w2;}function indexOf(obj,el){var i=obj.length;while(i--){if(obj[i]===el)return i;}return-1;}function isThirdLevelShift(term,ev){var thirdLevelKey=term.isMac&&ev.altKey&&!ev.ctrlKey&&!ev.metaKey||term.isMSWindows&&ev.altKey&&ev.ctrlKey&&!ev.metaKey;if(ev.type=='keypress'){return thirdLevelKey;}// Don't invoke for arrows, pageDown, home, backspace, etc. (on non-keypress events)
2109 return thirdLevelKey&&(!ev.keyCode||ev.keyCode>47);}function matchColor(r1,g1,b1){var hash=r1<<16|g1<<8|b1;if(matchColor._cache[hash]!=null){return matchColor._cache[hash];}var ldiff=Infinity,li=-1,i=0,c,r2,g2,b2,diff;for(;i<Terminal.vcolors.length;i++){c=Terminal.vcolors[i];r2=c[0];g2=c[1];b2=c[2];diff=matchColor.distance(r1,g1,b1,r2,g2,b2);if(diff===0){li=i;break;}if(diff<ldiff){ldiff=diff;li=i;}}return matchColor._cache[hash]=li;}matchColor._cache={};// http://stackoverflow.com/questions/1633828
2110 matchColor.distance=function(r1,g1,b1,r2,g2,b2){return Math.pow(30*(r1-r2),2)+Math.pow(59*(g1-g2),2)+Math.pow(11*(b1-b2),2);};function each(obj,iter,con){if(obj.forEach)return obj.forEach(iter,con);for(var i=0;i<obj.length;i++){iter.call(con,obj[i],i,obj);}}function keys(obj){if(Object.keys)return Object.keys(obj);var key,keys=[];for(key in obj){if(Object.prototype.hasOwnProperty.call(obj,key)){keys.push(key);}}return keys;}var wcwidth=function(opts){// extracted from https://www.cl.cam.ac.uk/%7Emgk25/ucs/wcwidth.c
2111 // combining characters
2112 var COMBINING=[[0x0300,0x036F],[0x0483,0x0486],[0x0488,0x0489],[0x0591,0x05BD],[0x05BF,0x05BF],[0x05C1,0x05C2],[0x05C4,0x05C5],[0x05C7,0x05C7],[0x0600,0x0603],[0x0610,0x0615],[0x064B,0x065E],[0x0670,0x0670],[0x06D6,0x06E4],[0x06E7,0x06E8],[0x06EA,0x06ED],[0x070F,0x070F],[0x0711,0x0711],[0x0730,0x074A],[0x07A6,0x07B0],[0x07EB,0x07F3],[0x0901,0x0902],[0x093C,0x093C],[0x0941,0x0948],[0x094D,0x094D],[0x0951,0x0954],[0x0962,0x0963],[0x0981,0x0981],[0x09BC,0x09BC],[0x09C1,0x09C4],[0x09CD,0x09CD],[0x09E2,0x09E3],[0x0A01,0x0A02],[0x0A3C,0x0A3C],[0x0A41,0x0A42],[0x0A47,0x0A48],[0x0A4B,0x0A4D],[0x0A70,0x0A71],[0x0A81,0x0A82],[0x0ABC,0x0ABC],[0x0AC1,0x0AC5],[0x0AC7,0x0AC8],[0x0ACD,0x0ACD],[0x0AE2,0x0AE3],[0x0B01,0x0B01],[0x0B3C,0x0B3C],[0x0B3F,0x0B3F],[0x0B41,0x0B43],[0x0B4D,0x0B4D],[0x0B56,0x0B56],[0x0B82,0x0B82],[0x0BC0,0x0BC0],[0x0BCD,0x0BCD],[0x0C3E,0x0C40],[0x0C46,0x0C48],[0x0C4A,0x0C4D],[0x0C55,0x0C56],[0x0CBC,0x0CBC],[0x0CBF,0x0CBF],[0x0CC6,0x0CC6],[0x0CCC,0x0CCD],[0x0CE2,0x0CE3],[0x0D41,0x0D43],[0x0D4D,0x0D4D],[0x0DCA,0x0DCA],[0x0DD2,0x0DD4],[0x0DD6,0x0DD6],[0x0E31,0x0E31],[0x0E34,0x0E3A],[0x0E47,0x0E4E],[0x0EB1,0x0EB1],[0x0EB4,0x0EB9],[0x0EBB,0x0EBC],[0x0EC8,0x0ECD],[0x0F18,0x0F19],[0x0F35,0x0F35],[0x0F37,0x0F37],[0x0F39,0x0F39],[0x0F71,0x0F7E],[0x0F80,0x0F84],[0x0F86,0x0F87],[0x0F90,0x0F97],[0x0F99,0x0FBC],[0x0FC6,0x0FC6],[0x102D,0x1030],[0x1032,0x1032],[0x1036,0x1037],[0x1039,0x1039],[0x1058,0x1059],[0x1160,0x11FF],[0x135F,0x135F],[0x1712,0x1714],[0x1732,0x1734],[0x1752,0x1753],[0x1772,0x1773],[0x17B4,0x17B5],[0x17B7,0x17BD],[0x17C6,0x17C6],[0x17C9,0x17D3],[0x17DD,0x17DD],[0x180B,0x180D],[0x18A9,0x18A9],[0x1920,0x1922],[0x1927,0x1928],[0x1932,0x1932],[0x1939,0x193B],[0x1A17,0x1A18],[0x1B00,0x1B03],[0x1B34,0x1B34],[0x1B36,0x1B3A],[0x1B3C,0x1B3C],[0x1B42,0x1B42],[0x1B6B,0x1B73],[0x1DC0,0x1DCA],[0x1DFE,0x1DFF],[0x200B,0x200F],[0x202A,0x202E],[0x2060,0x2063],[0x206A,0x206F],[0x20D0,0x20EF],[0x302A,0x302F],[0x3099,0x309A],[0xA806,0xA806],[0xA80B,0xA80B],[0xA825,0xA826],[0xFB1E,0xFB1E],[0xFE00,0xFE0F],[0xFE20,0xFE23],[0xFEFF,0xFEFF],[0xFFF9,0xFFFB],[0x10A01,0x10A03],[0x10A05,0x10A06],[0x10A0C,0x10A0F],[0x10A38,0x10A3A],[0x10A3F,0x10A3F],[0x1D167,0x1D169],[0x1D173,0x1D182],[0x1D185,0x1D18B],[0x1D1AA,0x1D1AD],[0x1D242,0x1D244],[0xE0001,0xE0001],[0xE0020,0xE007F],[0xE0100,0xE01EF]];// binary search
2113 function bisearch(ucs){var min=0;var max=COMBINING.length-1;var mid;if(ucs<COMBINING[0][0]||ucs>COMBINING[max][1])return false;while(max>=min){mid=Math.floor((min+max)/2);if(ucs>COMBINING[mid][1])min=mid+1;else if(ucs<COMBINING[mid][0])max=mid-1;else return true;}return false;}function wcwidth(ucs){// test for 8-bit control characters
2114 if(ucs===0)return opts.nul;if(ucs<32||ucs>=0x7f&&ucs<0xa0)return opts.control;// binary search in table of non-spacing characters
2115 if(bisearch(ucs))return 0;// if we arrive here, ucs is not a combining or C0/C1 control character
2116 return 1+(ucs>=0x1100&&(ucs<=0x115f||// Hangul Jamo init. consonants
2117 ucs==0x2329||ucs==0x232a||ucs>=0x2e80&&ucs<=0xa4cf&&ucs!=0x303f||// CJK..Yi
2118 ucs>=0xac00&&ucs<=0xd7a3||// Hangul Syllables
2119 ucs>=0xf900&&ucs<=0xfaff||// CJK Compat Ideographs
2120 ucs>=0xfe10&&ucs<=0xfe19||// Vertical forms
2121 ucs>=0xfe30&&ucs<=0xfe6f||// CJK Compat Forms
2122 ucs>=0xff00&&ucs<=0xff60||// Fullwidth Forms
2123 ucs>=0xffe0&&ucs<=0xffe6||ucs>=0x20000&&ucs<=0x2fffd||ucs>=0x30000&&ucs<=0x3fffd));}return wcwidth;}({nul:0,control:0});// configurable options
2124 /**
2125 * Expose
2126 */Terminal.EventEmitter=_EventEmitter.EventEmitter;Terminal.CompositionHelper=_CompositionHelper.CompositionHelper;Terminal.Viewport=_Viewport.Viewport;Terminal.inherits=inherits;/**
2127 * Adds an event listener to the terminal.
2128 *
2129 * @param {string} event The name of the event. TODO: Document all event types
2130 * @param {function} callback The function to call when the event is triggered.
2131 */Terminal.on=on;Terminal.off=off;Terminal.cancel=cancel;module.exports=Terminal;
2132
2133 }).call(this,"/src")
2134
2135 },{"./CompositionHelper.js":1,"./EventEmitter.js":2,"./Viewport.js":3,"./handlers/Clipboard.js":4}]},{},[5])(5)
2136 });
2137 //# sourceMappingURL=xterm.js.map