Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(822)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/terminal/xterm.js/build/xterm.js

Issue 2372303003: DevTools: introduce external service client (behind experiment). (Closed)
Patch Set: external linter Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.e xports=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,func tion(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].expor ts}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) 2016, SourceLair Limited <www.sourcelair.com> (MIT License)
10 */
11
12 /**
13 * Encapsulates the logic for handling compositionstart, compositionupdate and c ompositionend
14 * events, displaying the in-progress composition to the UI and forwarding the f inal 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 c omposition in.
18 * @param {Terminal} terminal The Terminal to forward the finished composition t o.
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 disp layed 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 fals e 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 CompositionHel per 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 exe cuted.
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 acti ve.
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 whe n a composition
102 * is ending.
103 * @param {boolean} waitForPropogation Whether to wait for events to propogate b efore sending
104 * the input. This should be false if a non-composition keystroke is entered b efore the
105 * compositionend event is triggered, such as enter, so that the composition i s 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 immediate ly.
115 this.isSendingComposition = false;
116 var input = this.textarea.value.substring(this.compositionPosition.start, th is.compositionPosition.end);
117 this.terminal.handler(input);
118 } else {
119 // Make a deep copy of the composition position here as a new compositionsta rt 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 tex tarea on most
127 // browsers, use a setTimeout with 0ms time to allow the native compositione nd 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 Chr omium
131 // - The last compositionupdate event's data property does not always accura tely describe
132 // the character, a counter example being Korean where an ending consonsan t 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 sta rted.
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 allow ed to complete.
158 * This should be called when not currently composing but a keydown event with t he "composition
159 * character" (229) is triggered, in order to allow non-composition text to be e ntered 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 bel ow 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 * EventEmitter
217 */
218
219 function EventEmitter() {
220 this._events = this._events || {};
221 }
222
223 EventEmitter.prototype.addListener = function (type, listener) {
224 this._events[type] = this._events[type] || [];
225 this._events[type].push(listener);
226 };
227
228 EventEmitter.prototype.on = EventEmitter.prototype.addListener;
229
230 EventEmitter.prototype.removeListener = function (type, listener) {
231 if (!this._events[type]) return;
232
233 var obj = this._events[type],
234 i = obj.length;
235
236 while (i--) {
237 if (obj[i] === listener || obj[i].listener === listener) {
238 obj.splice(i, 1);
239 return;
240 }
241 }
242 };
243
244 EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
245
246 EventEmitter.prototype.removeAllListeners = function (type) {
247 if (this._events[type]) delete this._events[type];
248 };
249
250 EventEmitter.prototype.once = function (type, listener) {
251 var self = this;
252 function on() {
253 var args = Array.prototype.slice.call(arguments);
254 this.removeListener(type, on);
255 return listener.apply(this, args);
256 }
257 on.listener = listener;
258 return this.on(type, on);
259 };
260
261 EventEmitter.prototype.emit = function (type) {
262 if (!this._events[type]) return;
263
264 var args = Array.prototype.slice.call(arguments, 1),
265 obj = this._events[type],
266 l = obj.length,
267 i = 0;
268
269 for (; i < l; i++) {
270 obj[i].apply(this, args);
271 }
272 };
273
274 EventEmitter.prototype.listeners = function (type) {
275 return this._events[type] = this._events[type] || [];
276 };
277
278 exports.EventEmitter = EventEmitter;
279
280 },{}],3:[function(_dereq_,module,exports){
281 'use strict';
282
283 Object.defineProperty(exports, "__esModule", {
284 value: true
285 });
286 /**
287 * xterm.js: xterm, in the browser
288 * Copyright (c) 2016, SourceLair Limited <www.sourcelair.com> (MIT License)
289 */
290
291 /**
292 * Represents the viewport of a terminal, the visible area within the larger buf fer of output.
293 * Logic for the virtual scroll bar is included in this object.
294 * @param {Terminal} terminal The Terminal object.
295 * @param {HTMLElement} viewportElement The DOM element acting as the viewport
296 * @param {HTMLElement} charMeasureElement A DOM element used to measure the cha racter size of
297 * the terminal.
298 */
299 function Viewport(terminal, viewportElement, scrollArea, charMeasureElement) {
300 this.terminal = terminal;
301 this.viewportElement = viewportElement;
302 this.scrollArea = scrollArea;
303 this.charMeasureElement = charMeasureElement;
304 this.currentRowHeight = 0;
305 this.lastRecordedBufferLength = 0;
306 this.lastRecordedViewportHeight = 0;
307
308 this.terminal.on('scroll', this.syncScrollArea.bind(this));
309 this.terminal.on('resize', this.syncScrollArea.bind(this));
310 this.viewportElement.addEventListener('scroll', this.onScroll.bind(this));
311
312 this.syncScrollArea();
313 }
314
315 /**
316 * Refreshes row height, setting line-height, viewport height and scroll area he ight if
317 * necessary.
318 * @param {number|undefined} charSize A character size measurement bounding rect object, if it
319 * doesn't exist it will be created.
320 */
321 Viewport.prototype.refresh = function (charSize) {
322 var size = charSize || this.charMeasureElement.getBoundingClientRect();
323 if (size.height > 0) {
324 var rowHeightChanged = size.height !== this.currentRowHeight;
325 if (rowHeightChanged) {
326 this.currentRowHeight = size.height;
327 this.viewportElement.style.lineHeight = size.height + 'px';
328 this.terminal.rowContainer.style.lineHeight = size.height + 'px';
329 }
330 var viewportHeightChanged = this.lastRecordedViewportHeight !== this.termina l.rows;
331 if (rowHeightChanged || viewportHeightChanged) {
332 this.lastRecordedViewportHeight = this.terminal.rows;
333 this.viewportElement.style.height = size.height * this.terminal.rows + 'px ';
334 }
335 this.scrollArea.style.height = size.height * this.lastRecordedBufferLength + 'px';
336 }
337 };
338
339 /**
340 * Updates dimensions and synchronizes the scroll area if necessary.
341 */
342 Viewport.prototype.syncScrollArea = function () {
343 if (this.lastRecordedBufferLength !== this.terminal.lines.length) {
344 // If buffer height changed
345 this.lastRecordedBufferLength = this.terminal.lines.length;
346 this.refresh();
347 } else if (this.lastRecordedViewportHeight !== this.terminal.rows) {
348 // If viewport height changed
349 this.refresh();
350 } else {
351 // If size has changed, refresh viewport
352 var size = this.charMeasureElement.getBoundingClientRect();
353 if (size.height !== this.currentRowHeight) {
354 this.refresh(size);
355 }
356 }
357
358 // Sync scrollTop
359 var scrollTop = this.terminal.ydisp * this.currentRowHeight;
360 if (this.viewportElement.scrollTop !== scrollTop) {
361 this.viewportElement.scrollTop = scrollTop;
362 }
363 };
364
365 /**
366 * Handles scroll events on the viewport, calculating the new viewport and reque sting the
367 * terminal to scroll to it.
368 * @param {Event} ev The scroll event.
369 */
370 Viewport.prototype.onScroll = function (ev) {
371 var newRow = Math.round(this.viewportElement.scrollTop / this.currentRowHeight );
372 var diff = newRow - this.terminal.ydisp;
373 this.terminal.scrollDisp(diff, true);
374 };
375
376 /**
377 * Handles mouse wheel events by adjusting the viewport's scrollTop and delegati ng the actual
378 * scrolling to `onScroll`, this event needs to be attached manually by the cons umer of
379 * `Viewport`.
380 * @param {WheelEvent} ev The mouse wheel event.
381 */
382 Viewport.prototype.onWheel = function (ev) {
383 if (ev.deltaY === 0) {
384 // Do nothing if it's not a vertical scroll event
385 return;
386 }
387 // Fallback to WheelEvent.DOM_DELTA_PIXEL
388 var multiplier = 1;
389 if (ev.deltaMode === WheelEvent.DOM_DELTA_LINE) {
390 multiplier = this.currentRowHeight;
391 } else if (ev.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
392 multiplier = this.currentRowHeight * this.terminal.rows;
393 }
394 this.viewportElement.scrollTop += ev.deltaY * multiplier;
395 // Prevent the page from scrolling when the terminal scrolls
396 ev.preventDefault();
397 };
398
399 exports.Viewport = Viewport;
400
401 },{}],4:[function(_dereq_,module,exports){
402 (function (__dirname){
403 'use strict';var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="s ymbol"?function(obj){return typeof obj;}:function(obj){return obj&&typeof Symbol ==="function"&&obj.constructor===Symbol?"symbol":typeof obj;};/**
404 * xterm.js: xterm, in the browser
405 * Copyright (c) 2014, SourceLair Limited <www.sourcelair.com> (MIT License)
406 * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
407 * https://github.com/chjj/term.js
408 *
409 * Permission is hereby granted, free of charge, to any person obtaining a copy
410 * of this software and associated documentation files (the "Software"), to deal
411 * in the Software without restriction, including without limitation the rights
412 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
413 * copies of the Software, and to permit persons to whom the Software is
414 * furnished to do so, subject to the following conditions:
415 *
416 * The above copyright notice and this permission notice shall be included in
417 * all copies or substantial portions of the Software.
418 *
419 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
420 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
421 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
422 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
423 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
424 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
425 * THE SOFTWARE.
426 *
427 * Originally forked from (with the author's permission):
428 * Fabrice Bellard's javascript vt100 for jslinux:
429 * http://bellard.org/jslinux/
430 * Copyright (c) 2011 Fabrice Bellard
431 * The original design remains. The terminal itself
432 * has been extended to include xterm CSI codes, among
433 * other features.
434 */var _CompositionHelper=_dereq_('./CompositionHelper.js');var _EventEmitter=_d ereq_('./EventEmitter.js');var _Viewport=_dereq_('./Viewport.js');/**
435 * Terminal Emulation References:
436 * http://vt100.net/
437 * http://invisible-island.net/xterm/ctlseqs/ctlseqs.txt
438 * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
439 * http://invisible-island.net/vttest/
440 * http://www.inwap.com/pdp10/ansicode.txt
441 * http://linux.die.net/man/4/console_codes
442 * http://linux.die.net/man/7/urxvt
443 */// Let it work inside Node.js for automated testing purposes.
444 var document=typeof window!='undefined'?window.document:null;/**
445 * States
446 */var normal=0,escaped=1,csi=2,osc=3,charset=4,dcs=5,ignore=6;/**
447 * Terminal
448 *//**
449 * Creates a new `Terminal` object.
450 *
451 * @param {object} options An object containing a set of options, the available options are:
452 * - cursorBlink (boolean): Whether the terminal cursor blinks
453 *
454 * @public
455 * @class Xterm Xterm
456 * @alias module:xterm/src/xterm
457 */function Terminal(options){var self=this;if(!(this instanceof Terminal)){retu rn new Terminal(arguments[0],arguments[1],arguments[2]);}self.cancel=Terminal.ca ncel;_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){opt ions[key]=Terminal.options[key];if(Terminal[key]!==Terminal.defaults[key]){optio ns[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(opti ons.colors.length===18){options.colors=options.colors.concat(Terminal._colors.sl ice(16,-2),options.colors.slice(-2));}this.colors=options.colors;this.options=op tions;// this.context = options.context || window;
458 // this.document = options.document || document;
459 this.parent=options.body||options.parent||(document?document.getElementsByTagNam e('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);} /**
460 * The scroll position of the y cursor, ie. ybase + y = the y position within the entire
461 * buffer
462 */this.ybase=0;/**
463 * The scroll position of the viewport
464 */this.ydisp=0;/**
465 * The cursor's x position after ybase
466 */this.x=0;/**
467 * The cursor's y position after ybase
468 */this.y=0;/**
469 * Used to debounce the refresh function
470 */this.isRefreshing=false;/**
471 * Whether there is a full terminal refresh queued
472 */this.cursorState=0;this.cursorHidden=false;this.convertEol;this.state=0;thi s.queue='';this.scrollTop=0;this.scrollBottom=this.rows-1;this.customKeydownHand ler=null;// modes
473 this.applicationKeypad=false;this.applicationCursor=false;this.originMode=false; this.insertMode=false;this.wraparoundMode=true;// defaults: xterm - true, vt100 - false
474 this.normal=null;// charset
475 this.charset=null;this.gcharset=null;this.glevel=0;this.charsets=[null];// mouse properties
476 this.decLocator;this.x10Mouse;this.vt200Mouse;this.vt300Mouse;this.normalMouse;t his.mouseEvents;this.sendFocus;this.utfMouse;this.sgrMouse;this.urxvtMouse;// mi sc
477 this.element;this.children;this.refreshStart;this.refreshEnd;this.savedX;this.sa vedY;this.savedCols;// stream
478 this.readable=true;this.writable=true;this.defAttr=0<<18|257<<9|256<<0;this.curA ttr=this.defAttr;this.params=[];this.currentParam=0;this.prefix='';this.postfix= '';// leftover surrogate high from previous write invocation
479 this.surrogate_high='';/**
480 * An array of all lines in the entire buffer, including the prompt. The lines are array of
481 * characters which are 2-length arrays where [0] is an attribute and [1] is t he character.
482 */this.lines=[];var i=this.rows;while(i--){this.lines.push(this.blankLine()); }this.tabs;this.setupStops();}inherits(Terminal,_EventEmitter.EventEmitter);/**
483 * back_color_erase feature for xterm.
484 */Terminal.prototype.eraseAttr=function(){// if (this.is('screen')) return this .defAttr;
485 return this.defAttr&~0x1ff|this.curAttr&0x1ff;};/**
486 * Colors
487 */// Colors 0-15
488 Terminal.tangoColors=[// dark:
489 '#2e3436','#cc0000','#4e9a06','#c4a000','#3465a4','#75507b','#06989a','#d3d7cf', // bright:
490 '#555753','#ef2929','#8ae234','#fce94f','#729fcf','#ad7fa8','#34e2e2','#eeeeec'] ;// Colors 0-15 + 16-255
491 // Much thanks to TooTallNate for writing this.
492 Terminal.colors=function(){var colors=Terminal.tangoColors.slice(),r=[0x00,0x5f, 0x87,0xaf,0xd7,0xff],i;// 16-231
493 i=0;for(;i<216;i++){out(r[i/36%6|0],r[i/6%6|0],r[i%6]);}// 232-255 (grey)
494 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;}r eturn colors;}();Terminal._colors=Terminal.colors.slice();Terminal.vcolors=funct ion(){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;}();/**
495 * Options
496 */Terminal.defaults={colors:Terminal.colors,theme:'default',convertEol:false,te rmName:'xterm',geometry:[80,24],cursorBlink:false,visualBell:false,popOnBell:fal se,scrollback:1000,screenKeys:false,debug:false,cancelEvents:false// programFeat ures: false,
497 // focusKeys: false,
498 };Terminal.options={};Terminal.focus=null;each(keys(Terminal.defaults),function( key){Terminal[key]=Terminal.defaults[key];Terminal.options[key]=Terminal.default s[key];});/**
499 * Focus the terminal. Delegates focus handling to the terminal's DOM element.
500 */Terminal.prototype.focus=function(){return this.textarea.focus();};/**
501 * Retrieves an option's value from the terminal.
502 * @param {string} key The option key.
503 */Terminal.prototype.getOption=function(key,value){if(!(key in Terminal.default s)){throw new Error('No option with key "'+key+'"');}if(typeof this.options[key] !=='undefined'){return this.options[key];}return this[key];};/**
504 * Sets an option on the terminal.
505 * @param {string} key The option key.
506 * @param {string} value The option value.
507 */Terminal.prototype.setOption=function(key,value){if(!(key in Terminal.default s)){throw new Error('No option with key "'+key+'"');}this[key]=value;this.option s[key]=value;};/**
508 * Binds the desired focus behavior on a given terminal object.
509 *
510 * @static
511 */Terminal.bindFocus=function(term){on(term.textarea,'focus',function(ev){if(te rm.sendFocus){term.send('\x1b[I');}term.element.classList.add('focus');term.show Cursor();Terminal.focus=term;term.emit('focus',{terminal:term});});};/**
512 * Blur the terminal. Delegates blur handling to the terminal's DOM element.
513 */Terminal.prototype.blur=function(){return this.textarea.blur();};/**
514 * Binds the desired blur behavior on a given terminal object.
515 *
516 * @static
517 */Terminal.bindBlur=function(term){on(term.textarea,'blur',function(ev){term.re fresh(term.y,term.y);if(term.sendFocus){term.send('\x1b[O');}term.element.classL ist.remove('focus');Terminal.focus=null;term.emit('blur',{terminal:term});});};/ **
518 * Initialize default behavior
519 */Terminal.prototype.initGlobal=function(){Terminal.bindPaste(this);Terminal.bi ndKeys(this);Terminal.bindCopy(this);Terminal.bindFocus(this);Terminal.bindBlur( this);};/**
520 * Bind to paste event and allow both keyboard and right-click pasting, without having the
521 * contentEditable value set to true.
522 */Terminal.bindPaste=function(term){on([term.textarea,term.element],'paste',fun ction(ev){ev.stopPropagation();if(ev.clipboardData){var text=ev.clipboardData.ge tData('text/plain');term.handler(text);term.textarea.value='';return term.cancel (ev);}});};/**
523 * Prepares text copied from terminal selection, to be saved in the clipboard by :
524 * 1. stripping all trailing white spaces
525 * 2. converting all non-breaking spaces to regular spaces
526 * @param {string} text The copied text that needs processing for storing in cli pboard
527 * @returns {string}
528 * @static
529 */Terminal.prepareCopiedTextForClipboard=function(text){var space=String.fromCh arCode(32),nonBreakingSpace=String.fromCharCode(160),allNonBreakingSpaces=new Re gExp(nonBreakingSpace,'g'),processedText=text.split('\n').map(function(line){/**
530 * Strip all trailing white spaces and convert all non-breaking spaces t o regular
531 * spaces.
532 */var processedLine=line.replace(/\s+$/g,'').replace(allNonBreakingSpac es,space);return processedLine;}).join('\n');return processedText;};/**
533 * Apply key handling to the terminal
534 */Terminal.bindKeys=function(term){on(term.element,'keydown',function(ev){if(do cument.activeElement!=this){return;}term.keyDown(ev);},true);on(term.element,'ke ypress',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
535 this.value='';},true);on(term.textarea,'compositionstart',term.compositionHelper .compositionstart.bind(term.compositionHelper));on(term.textarea,'compositionupd ate',term.compositionHelper.compositionupdate.bind(term.compositionHelper));on(t erm.textarea,'compositionend',term.compositionHelper.compositionend.bind(term.co mpositionHelper));term.on('refresh',term.compositionHelper.updateCompositionElem ents.bind(term.compositionHelper));};/**
536 * Binds copy functionality to the given terminal.
537 * @static
538 */Terminal.bindCopy=function(term){on(term.element,'copy',function(ev){return;/ / temporary
539 });};/**
540 * Insert the given row to the terminal or produce a new one
541 * if no row argument is passed. Return the inserted row.
542 * @param {HTMLElement} row (optional) The row to append to the terminal.
543 */Terminal.prototype.insertRow=function(row){if((typeof row==='undefined'?'unde fined':_typeof(row))!='object'){row=document.createElement('div');}this.rowConta iner.appendChild(row);this.children.push(row);return row;};/**
544 * Opens the terminal within an element.
545 *
546 * @param {HTMLElement} parent The element to create the terminal within.
547 */Terminal.prototype.open=function(parent){var self=this,i=0,div;this.parent=pa rent||this.parent;if(!this.parent){throw new Error('Terminal requires a parent e lement.');}// Grab global elements
548 this.context=this.parent.ownerDocument.defaultView;this.document=this.parent.own erDocument;this.body=this.document.getElementsByTagName('body')[0];// Parse User -Agent
549 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
550 // and ISO third level shifts.
551 // http://stackoverflow.com/q/19877924/577598
552 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.navi gator.platform==='iPhone';this.isMSWindows=contains(this.context.navigator.platf orm,['Windows','Win16','Win32','WinCE']);}//Create main element container
553 this.element=this.document.createElement('div');this.element.classList.add('term inal');this.element.classList.add('xterm');this.element.classList.add('xterm-the me-'+this.theme);this.element.style.height;this.element.setAttribute('tabindex', 0);this.viewportElement=document.createElement('div');this.viewportElement.class List.add('xterm-viewport');this.element.appendChild(this.viewportElement);this.v iewportScrollArea=document.createElement('div');this.viewportScrollArea.classLis t.add('xterm-scroll-area');this.viewportElement.appendChild(this.viewportScrollA rea);// Create the container that will hold the lines of the terminal and then
554 // produce the lines the lines.
555 this.rowContainer=document.createElement('div');this.rowContainer.classList.add( 'xterm-rows');this.element.appendChild(this.rowContainer);this.children=[];// Cr eate the container that will hold helpers like the textarea for
556 // capturing DOM Events. Then produce the helpers.
557 this.helperContainer=document.createElement('div');this.helperContainer.classLis t.add('xterm-helpers');// TODO: This should probably be inserted once it's fille d to prevent an additional layout
558 this.element.appendChild(this.helperContainer);this.textarea=document.createElem ent('textarea');this.textarea.classList.add('xterm-helper-textarea');this.textar ea.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',{ter minal:self});});this.helperContainer.appendChild(this.textarea);this.composition View=document.createElement('div');this.compositionView.classList.add('compositi on-view');this.compositionHelper=new _CompositionHelper.CompositionHelper(this.t extarea,this.compositionView,this);this.helperContainer.appendChild(this.composi tionView);this.charMeasureElement=document.createElement('div');this.charMeasure Element.classList.add('xterm-char-measure-element');this.charMeasureElement.inne rHTML='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.ch arMeasureElement);// Draw the screen.
559 this.refresh(0,this.rows-1);// Initialize global actions that
560 // need to be taken on the document.
561 this.initGlobal();// Ensure there is a Terminal.focus.
562 this.focus();on(this.element,'click',function(){var selection=document.getSelect ion(),collapsed=selection.isCollapsed,isRange=typeof collapsed=='boolean'?!colla psed:selection.type=='Range';if(!isRange){self.focus();}});// Listen for mouse e vents and translate
563 // them into terminal mouse protocols.
564 this.bindMouse();// Figure out whether boldness affects
565 // the character width of monospace fonts.
566 if(Terminal.brokenBold==null){Terminal.brokenBold=isBoldBroken(this.document);}t his.emit('open');};/**
567 * Attempts to load an add-on using CommonJS or RequireJS (whichever is availabl e).
568 * @param {string} addon The name of the addon to load
569 * @static
570 */Terminal.loadAddon=function(addon,callback){if((typeof exports==='undefined'? 'undefined':_typeof(exports))==='object'&&(typeof module==='undefined'?'undefine d':_typeof(module))==='object'){// CommonJS
571 return _dereq_(__dirname+'/../addons/'+addon);}else if(typeof define=='function' ){// RequireJS
572 return _dereq_(['../addons/'+addon+'/'+addon],callback);}else{console.error('Can not load a module without a CommonJS or RequireJS environment.');return false;}} ;/**
573 * XTerm mouse events
574 * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking
575 * To better understand these
576 * the xterm code is very helpful:
577 * Relevant files:
578 * button.c, charproc.c, misc.c
579 * Relevant functions in xterm/button.c:
580 * BtnCode, EmitButtonCode, EditorButton, SendMousePosition
581 */Terminal.prototype.bindMouse=function(){var el=this.element,self=this,pressed =32;// mouseup, mousedown, wheel
582 // left click: ^[[M 3<^[[M#3<
583 // wheel up: ^[[M`3>
584 function sendButton(ev){var button,pos;// get the xterm-style button
585 button=getButton(ev);// get mouse coordinates
586 pos=getCoords(ev);if(!pos)return;sendEvent(button,pos);switch(ev.overrideType||e v.type){case'mousedown':pressed=button;break;case'mouseup':// keep it at the lef t
587 // button, just in case.
588 pressed=32;break;case'wheel':// nothing. don't
589 // interfere with
590 // `pressed`.
591 break;}}// motion example of a left click:
592 // ^[[M 3<^[[M@4<^[[M@5<^[[M@6<^[[M@7<^[[M#7<
593 function sendMove(ev){var button=pressed,pos;pos=getCoords(ev);if(!pos)return;// buttons marked as motions
594 // are incremented by 32
595 button+=32;sendEvent(button,pos);}// encode button and
596 // position to characters
597 function encode(data,ch){if(!self.utfMouse){if(ch===255)return data.push(0);if(c h>127)ch=127;data.push(ch);}else{if(ch===2047)return data.push(0);if(ch<127){dat a.push(ch);}else{if(ch>2047)ch=2047;data.push(0xC0|ch>>6);data.push(0x80|ch&0x3F );}}}// send a mouse event:
598 // regular/utf8: ^[[M Cb Cx Cy
599 // urxvt: ^[[ Cb ; Cx ; Cy M
600 // sgr: ^[[ Cb ; Cx ; Cy M/m
601 // vt300: ^[[ 24(1/3/5)~ [ Cx , Cy ] \r
602 // locator: CSI P e ; P b ; P r ; P c ; P p & w
603 function sendEvent(button,pos){// self.emit('mouse', {
604 // x: pos.x - 32,
605 // y: pos.x - 32,
606 // button: button
607 // });
608 if(self.vt300Mouse){// NOTE: Unstable.
609 // http://www.vt100.net/docs/vt3xx-gp/chapter15.html
610 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;els e data+='0';data+='~['+pos.x+','+pos.y+']\r';self.send(data);return;}if(self.dec Locator){// NOTE: Unstable.
611 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['+butto n+';'+(button===3?4:0)+';'+pos.y+';'+pos.x+';'+(pos.page||0)+'&w');return;}if(se lf.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('\x 1b[<'+((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 getButt on(ev){var button,shift,meta,ctrl,mod;// two low bits:
612 // 0 = left
613 // 1 = middle
614 // 2 = right
615 // 3 = release
616 // wheel up/down:
617 // 1, and 2 - with 64 added
618 switch(ev.overrideType||ev.type){case'mousedown':button=ev.button!=null?+ev.butt on: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.det ail<0?64:65;break;case'wheel':button=ev.wheelDeltaY>0?64:65;break;}// next three bits are the modifiers:
619 // 4 = shift, 8 = meta, 16 = control
620 shift=ev.shiftKey?4:0;meta=ev.metaKey?8:0;ctrl=ev.ctrlKey?16:0;mod=shift|meta|ct rl;// no mods
621 if(self.vt200Mouse){// ctrl only
622 mod&=ctrl;}else if(!self.normalMouse){mod=0;}// increment to SP
623 button=32+(mod<<2)+button;return button;}// mouse coordinates measured in cols/r ows
624 function getCoords(ev){var x,y,w,h,el;// ignore browsers without pageX for now
625 if(ev.pageX==null)return;x=ev.pageX;y=ev.pageY;el=self.element;// should probabl y check offsetParent
626 // but this is more portable
627 while(el&&el!==self.document.documentElement){x-=el.offsetLeft;y-=el.offsetTop;e l='offsetParent'in el?el.offsetParent:el.parentNode;}// convert to cols/rows
628 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
629 // bad positions to the program
630 if(x<0)x=0;if(x>self.cols)x=self.cols;if(y<0)y=0;if(y>self.rows)y=self.rows;// x term sends raw bytes and
631 // starts at 32 (SP) for each.
632 x+=32;y+=32;return{x:x,y:y,type:'wheel'};}on(el,'mousedown',function(ev){if(!sel f.mouseEvents)return;// send the button
633 sendButton(ev);// ensure focus
634 self.focus();// fix for odd bug
635 //if (self.vt200Mouse && !self.normalMouse) {
636 if(self.vt200Mouse){ev.overrideType='mouseup';sendButton(ev);return self.cancel( ev);}// bind events
637 if(self.normalMouse)on(self.document,'mousemove',sendMove);// x10 compatibility mode can't send button releases
638 if(!self.x10Mouse){on(self.document,'mouseup',function up(ev){sendButton(ev);if( self.normalMouse)off(self.document,'mousemove',sendMove);off(self.document,'mous eup',up);return self.cancel(ev);});}return self.cancel(ev);});//if (self.normalM ouse) {
639 // on(self.document, 'mousemove', sendMove);
640 //}
641 on(el,'wheel',function(ev){if(!self.mouseEvents)return;if(self.x10Mouse||self.vt 300Mouse||self.decLocator)return;sendButton(ev);return self.cancel(ev);});// all ow wheel scrolling in
642 // the shell for example
643 on(el,'wheel',function(ev){if(self.mouseEvents)return;self.viewport.onWheel(ev); return self.cancel(ev);});};/**
644 * Destroys the terminal.
645 */Terminal.prototype.destroy=function(){this.readable=false;this.writable=false ;this._events={};this.handler=function(){};this.write=function(){};if(this.eleme nt.parentNode){this.element.parentNode.removeChild(this.element);}//this.emit('c lose');
646 };/**
647 * Flags used to render terminal text properly
648 */Terminal.flags={BOLD:1,UNDERLINE:2,BLINK:4,INVERSE:8,INVISIBLE:16};/**
649 * Refreshes (re-renders) terminal content within two rows (inclusive)
650 *
651 * Rendering Engine:
652 *
653 * In the screen buffer, each character is stored as a an array with a character
654 * and a 32-bit integer:
655 * - First value: a utf-16 character.
656 * - Second value:
657 * - Next 9 bits: background color (0-511).
658 * - Next 9 bits: foreground color (0-511).
659 * - Next 14 bits: a mask for misc. flags:
660 * - 1=bold
661 * - 2=underline
662 * - 4=blink
663 * - 8=inverse
664 * - 16=invisible
665 *
666 * @param {number} start The row to start from (between 0 and terminal's height terminal - 1)
667 * @param {number} end The row to end at (between fromRow and terminal's height terminal - 1)
668 * @param {boolean} queue Whether the refresh should ran right now or be queued
669 */Terminal.prototype.refresh=function(start,end,queue){var self=this;// queue d efaults to true
670 queue=typeof queue=='undefined'?true:queue;/**
671 * The refresh queue allows refresh to execute only approximately 30 times a s econd. For
672 * commands that pass a significant amount of output to the write function, th is prevents the
673 * terminal from maxing out the CPU and making the UI unresponsive. While comm ands can still
674 * run beyond what they do on the terminal, it is far better with a debounce i n place as
675 * every single terminal manipulation does not need to be constructed in the D OM.
676 *
677 * A side-effect of this is that it makes ^C to interrupt a process seem more responsive.
678 */if(queue){// If refresh should be queued, order the refresh and return.
679 if(this._refreshIsQueued){// If a refresh has already been queued, just order a full refresh next
680 this._fullRefreshNext=true;}else{setTimeout(function(){self.refresh(start,end,fa lse);},34);this._refreshIsQueued=true;}return;}// If refresh should be run right now (not be queued), release the lock
681 this._refreshIsQueued=false;// If multiple refreshes were requested, make a full refresh.
682 if(this._fullRefreshNext){start=0;end=this.rows-1;this._fullRefreshNext=false;// reset lock
683 }var x,y,i,line,out,ch,ch_width,width,data,attr,bg,fg,flags,row,parent,focused=d ocument.activeElement;// If this is a big refresh, remove the terminal rows from the DOM for faster calculations
684 if(end-start>=this.rows/2){parent=this.element.parentNode;if(parent){this.elemen t.removeChild(this.rowContainer);}}width=this.cols;y=start;if(end>=this.rows.len gth){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_wid th=line[i][2];if(!ch_width)continue;if(i===x)data=-1;if(data!==attr){if(attr!==t his.defAttr){out+='</span>';}if(data!==this.defAttr){if(data===-1){out+='<span c lass="reverse-video terminal-cursor';if(this.cursorBlink){out+=' blinking';}out+ ='">';}else{var classNames=[];bg=data&0x1ff;fg=data>>9&0x1ff;flags=data>>18;if(f lags&Terminal.flags.BOLD){if(!Terminal.brokenBold){classNames.push('xterm-bold') ;}// See: XTerm*boldColors
685 if(fg<8)fg+=8;}if(flags&Terminal.flags.UNDERLINE){classNames.push('xterm-underli ne');}if(flags&Terminal.flags.BLINK){classNames.push('xterm-blink');}// If inver se flag is on, then swap the foreground and background variables.
686 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 befor e the
687 // above boldColors effect instead?
688 if(flags&1&&fg<8)fg+=8;}if(flags&Terminal.flags.INVISIBLE){classNames.push('xter m-hidden');}/**
689 * Weird situation: Invert flag used black foreground and white back ground results
690 * in invalid background color, positioned at the 256 index of the 2 56 terminal
691 * color map. Pin the colors manually in such a case.
692 *
693 * Source: https://github.com/sourcelair/xterm.js/issues/57
694 */if(flags&Terminal.flags.INVERSE){if(bg==257){bg=15;}if(fg==256){f g=0;}}if(bg<256){classNames.push('xterm-bg-color-'+bg);}if(fg<256){classNames.pu sh('xterm-color-'+fg);}out+='<span';if(classNames.length){out+=' class="'+classN ames.join(' ')+'"';}out+='>';}}}switch(ch){case'&':out+='&amp;';break;case'<':ou t+='&lt;';break;case'>':out+='&gt;';break;default:if(ch<=' '){out+='&nbsp;';}els e{out+=ch;}break;}attr=data;}if(attr!==this.defAttr){out+='</span>';}this.childr en[y].innerHTML=out;}if(parent){this.element.appendChild(this.rowContainer);}thi s.emit('refresh',{element:this.element,start:start,end:end});};/**
695 * Display the cursor element
696 */Terminal.prototype.showCursor=function(){if(!this.cursorState){this.cursorSta te=1;this.refresh(this.y,this.y);}};/**
697 * Scroll the terminal
698 */Terminal.prototype.scroll=function(){var row;if(++this.ybase===this.scrollbac k){this.ybase=this.ybase/2|0;this.lines=this.lines.slice(-(this.ybase+this.rows) +1);}this.ydisp=this.ybase;// last line
699 row=this.ybase+this.rows-1;// subtract the bottom scroll region
700 row-=this.rows-1-this.scrollBottom;if(row===this.lines.length){// potential opti mization:
701 // pushing is faster than splicing
702 // when they amount to the same
703 // behavior.
704 this.lines.push(this.blankLine());}else{// add our new line
705 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.scrol lTop,1);}// this.maxRange();
706 this.updateRange(this.scrollTop);this.updateRange(this.scrollBottom);this.emit(' scroll',this.ydisp);};/**
707 * Scroll the display of the terminal
708 * @param {number} disp The number of lines to scroll down (negatives scroll up) .
709 * @param {boolean} suppressScrollEvent Don't emit the scroll event as scrollDis p. This is used
710 * to avoid unwanted events being handled by the veiwport when the event was tri ggered from the
711 * viewport originally.
712 */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);};/**
713 * Writes text to the terminal.
714 * @param {string} text The text to write to the terminal.
715 */Terminal.prototype.write=function(data){var l=data.length,i=0,j,cs,ch,code,lo w,ch_width,row;this.refreshStart=this.y;this.refreshEnd=this.y;if(this.ybase!==t his.ydisp){this.ydisp=this.ybase;this.emit('scroll',this.ydisp);this.maxRange(); }// apply leftover surrogate high from last write
716 if(this.surrogate_high){data=this.surrogate_high+data;this.surrogate_high='';}fo r(;i<l;i++){ch=data[i];// FIXME: higher chars than 0xa0 are not allowed in escap e sequences
717 // --> maybe move to default
718 code=data.charCodeAt(i);if(0xD800<=code&&code<=0xDBFF){// we got a surrogate hig h
719 // get surrogate low (next 2 bytes)
720 low=data.charCodeAt(i+1);if(isNaN(low)){// end of data stream, save surrogate hi gh
721 this.surrogate_high=ch;continue;}code=(code-0xD800)*0x400+(low-0xDC00)+0x10000;c h+=data.charAt(i+1);}// surrogate low - already handled above
722 if(0xDC00<=code&&code<=0xDFFF)continue;switch(this.state){case normal:switch(ch) {case'\x07':this.bell();break;// '\n', '\v', '\f'
723 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'
724 case'\r':this.x=0;break;// '\b'
725 case'\x08':if(this.x>0){this.x--;}break;// '\t'
726 case'\t':this.x=this.nextStop();break;// shift out
727 case'\x0e':this.setgLevel(1);break;// shift in
728 case'\x0f':this.setgLevel(0);break;// '\e'
729 case'\x1b':this.state=escaped;break;default:// ' '
730 // calculate print space
731 // expensive call, therefore we save width in line buffer
732 ch_width=wcwidth(code);if(ch>=' '){if(this.charset&&this.charset[ch]){ch=this.ch arset[ch];}row=this.y+this.ybase;// insert combining char in last cell
733 // FIXME: needs handling after cursor jumps
734 if(!ch_width&&this.x){// dont overflow left
735 if(this.lines[row][this.x-1]){if(!this.lines[row][this.x-1][2]){// found empty c ell after fullwidth, need to go 2 cells back
736 if(this.lines[row][this.x-2])this.lines[row][this.x-2][1]+=ch;}else{this.lines[r ow][this.x-1][1]+=ch;}this.updateRange(this.y);}break;}// goto next line if ch w ould overflow
737 // TODO: needs a global min terminal width of 2
738 if(this.x+ch_width-1>=this.cols){// autowrap - DECAWM
739 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 xter m behavior
740 continue;}}row=this.y+this.ybase;// insert mode: move characters to right
741 if(this.insertMode){// do this twice for a fullwidth char
742 for(var moves=0;moves<ch_width;++moves){// remove last cell, if it's width is 0
743 // we have to adjust the second last cell as well
744 var removed=this.lines[this.y+this.ybase].pop();if(removed[2]===0&&this.lines[ro w][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
745 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
746 if(ch_width===2){this.lines[row][this.x]=[this.curAttr,'',0];this.x++;}}break;}b reak;case escaped:switch(ch){// ESC [ Control Sequence Introducer ( CSI is 0x9b) .
747 case'[':this.params=[];this.currentParam=0;this.state=csi;break;// ESC ] Operati ng System Command ( OSC is 0x9d).
748 case']':this.params=[];this.currentParam=0;this.state=osc;break;// ESC P Device Control String ( DCS is 0x90).
749 case'P':this.params=[];this.currentParam=0;this.state=dcs;break;// ESC _ Applica tion Program Command ( APC is 0x9f).
750 case'_':this.state=ignore;break;// ESC ^ Privacy Message ( PM is 0x9e).
751 case'^':this.state=ignore;break;// ESC c Full Reset (RIS).
752 case'c':this.reset();break;// ESC E Next Line ( NEL is 0x85).
753 // ESC D Index ( IND is 0x84).
754 case'E':this.x=0;;case'D':this.index();break;// ESC M Reverse Index ( RI is 0x8d ).
755 case'M':this.reverseIndex();break;// ESC % Select default/utf-8 character set.
756 // @ = default, G = utf-8
757 case'%'://this.charset = null;
758 this.setgLevel(0);this.setgCharset(0,Terminal.charsets.US);this.state=normal;i++ ;break;// ESC (,),*,+,-,. Designate G0-G2 Character Set.
759 case'(':// <-- this seems to get all the attention
760 case')':case'*':case'+':case'-':case'.':switch(ch){case'(':this.gcharset=0;break ;case')':this.gcharset=1;break;case'*':this.gcharset=2;break;case'+':this.gchars et=3;break;case'-':this.gcharset=1;break;case'.':this.gcharset=2;break;}this.sta te=charset;break;// Designate G3 Character Set (VT300).
761 // A = ISO Latin-1 Supplemental.
762 // Not implemented.
763 case'/':this.gcharset=3;this.state=charset;i--;break;// ESC N
764 // Single Shift Select of G2 Character Set
765 // ( SS2 is 0x8e). This affects next character only.
766 case'N':break;// ESC O
767 // Single Shift Select of G3 Character Set
768 // ( SS3 is 0x8f). This affects next character only.
769 case'O':break;// ESC n
770 // Invoke the G2 Character Set as GL (LS2).
771 case'n':this.setgLevel(2);break;// ESC o
772 // Invoke the G3 Character Set as GL (LS3).
773 case'o':this.setgLevel(3);break;// ESC |
774 // Invoke the G3 Character Set as GR (LS3R).
775 case'|':this.setgLevel(3);break;// ESC }
776 // Invoke the G2 Character Set as GR (LS2R).
777 case'}':this.setgLevel(2);break;// ESC ~
778 // Invoke the G1 Character Set as GR (LS1R).
779 case'~':this.setgLevel(1);break;// ESC 7 Save Cursor (DECSC).
780 case'7':this.saveCursor();this.state=normal;break;// ESC 8 Restore Cursor (DECRC ).
781 case'8':this.restoreCursor();this.state=normal;break;// ESC # 3 DEC line height/ width
782 case'#':this.state=normal;i++;break;// ESC H Tab Set (HTS is 0x88).
783 case'H':this.tabSet();break;// ESC = Application Keypad (DECKPAM).
784 case'=':this.log('Serial port requested application keypad.');this.applicationKe ypad=true;this.viewport.syncScrollArea();this.state=normal;break;// ESC > Normal Keypad (DECKPNM).
785 case'>':this.log('Switching back to normal keypad.');this.applicationKeypad=fals e;this.viewport.syncScrollArea();this.state=normal;break;default:this.state=norm al;this.error('Unknown ESC control: %s.',ch);break;}break;case charset:switch(ch ){case'0':// DEC Special Character and Line Drawing Set.
786 cs=Terminal.charsets.SCLD;break;case'A':// UK
787 cs=Terminal.charsets.UK;break;case'B':// United States (USASCII).
788 cs=Terminal.charsets.US;break;case'4':// Dutch
789 cs=Terminal.charsets.Dutch;break;case'C':// Finnish
790 case'5':cs=Terminal.charsets.Finnish;break;case'R':// French
791 cs=Terminal.charsets.French;break;case'Q':// FrenchCanadian
792 cs=Terminal.charsets.FrenchCanadian;break;case'K':// German
793 cs=Terminal.charsets.German;break;case'Y':// Italian
794 cs=Terminal.charsets.Italian;break;case'E':// NorwegianDanish
795 case'6':cs=Terminal.charsets.NorwegianDanish;break;case'Z':// Spanish
796 cs=Terminal.charsets.Spanish;break;case'H':// Swedish
797 case'7':cs=Terminal.charsets.Swedish;break;case'=':// Swiss
798 cs=Terminal.charsets.Swiss;break;case'/':// ISOLatin (actually /A)
799 cs=Terminal.charsets.ISOLatin;i++;break;default:// Default
800 cs=Terminal.charsets.US;break;}this.setgCharset(this.gcharset,cs);this.gcharset= null;this.state=normal;break;case osc:// OSC Ps ; Pt ST
801 // OSC Ps ; Pt BEL
802 // Set Text Parameters.
803 if(ch==='\x1b'||ch==='\x07'){if(ch==='\x1b')i++;this.params.push(this.currentPar am);switch(this.params[0]){case 0:case 1:case 2:if(this.params[1]){this.title=th is.params[1];this.handleTitle(this.title);}break;case 3:// set X property
804 break;case 4:case 5:// change dynamic colors
805 break;case 10:case 11:case 12:case 13:case 14:case 15:case 16:case 17:case 18:ca se 19:// change dynamic ui colors
806 break;case 46:// change log file
807 break;case 50:// dynamic font
808 break;case 51:// emacs shell
809 break;case 52:// manipulate selection data
810 break;case 104:case 105:case 110:case 111:case 112:case 113:case 114:case 115:ca se 116:case 117:case 118:// reset colors
811 break;}this.params=[];this.currentParam=0;this.state=normal;}else{if(!this.param s.length){if(ch>='0'&&ch<='9'){this.currentParam=this.currentParam*10+ch.charCod eAt(0)-48;}else if(ch===';'){this.params.push(this.currentParam);this.currentPar am='';}}else{this.currentParam+=ch;}}break;case csi:// '?', '>', '!'
812 if(ch==='?'||ch==='>'||ch==='!'){this.prefix=ch;break;}// 0 - 9
813 if(ch>='0'&&ch<='9'){this.currentParam=this.currentParam*10+ch.charCodeAt(0)-48; break;}// '$', '"', ' ', '\''
814 if(ch==='$'||ch==='"'||ch===' '||ch==='\''){this.postfix=ch;break;}this.params.p ush(this.currentParam);this.currentParam=0;// ';'
815 if(ch===';')break;this.state=normal;switch(ch){// CSI Ps A
816 // Cursor Up Ps Times (default = 1) (CUU).
817 case'A':this.cursorUp(this.params);break;// CSI Ps B
818 // Cursor Down Ps Times (default = 1) (CUD).
819 case'B':this.cursorDown(this.params);break;// CSI Ps C
820 // Cursor Forward Ps Times (default = 1) (CUF).
821 case'C':this.cursorForward(this.params);break;// CSI Ps D
822 // Cursor Backward Ps Times (default = 1) (CUB).
823 case'D':this.cursorBackward(this.params);break;// CSI Ps ; Ps H
824 // Cursor Position [row;column] (default = [1,1]) (CUP).
825 case'H':this.cursorPos(this.params);break;// CSI Ps J Erase in Display (ED).
826 case'J':this.eraseInDisplay(this.params);break;// CSI Ps K Erase in Line (EL).
827 case'K':this.eraseInLine(this.params);break;// CSI Pm m Character Attributes (S GR).
828 case'm':if(!this.prefix){this.charAttributes(this.params);}break;// CSI Ps n De vice Status Report (DSR).
829 case'n':if(!this.prefix){this.deviceStatus(this.params);}break;/**
830 * Additions
831 */// CSI Ps @
832 // Insert Ps (Blank) Character(s) (default = 1) (ICH).
833 case'@':this.insertChars(this.params);break;// CSI Ps E
834 // Cursor Next Line Ps Times (default = 1) (CNL).
835 case'E':this.cursorNextLine(this.params);break;// CSI Ps F
836 // Cursor Preceding Line Ps Times (default = 1) (CNL).
837 case'F':this.cursorPrecedingLine(this.params);break;// CSI Ps G
838 // Cursor Character Absolute [column] (default = [row,1]) (CHA).
839 case'G':this.cursorCharAbsolute(this.params);break;// CSI Ps L
840 // Insert Ps Line(s) (default = 1) (IL).
841 case'L':this.insertLines(this.params);break;// CSI Ps M
842 // Delete Ps Line(s) (default = 1) (DL).
843 case'M':this.deleteLines(this.params);break;// CSI Ps P
844 // Delete Ps Character(s) (default = 1) (DCH).
845 case'P':this.deleteChars(this.params);break;// CSI Ps X
846 // Erase Ps Character(s) (default = 1) (ECH).
847 case'X':this.eraseChars(this.params);break;// CSI Pm ` Character Position Absol ute
848 // [column] (default = [row,1]) (HPA).
849 case'`':this.charPosAbsolute(this.params);break;// 141 61 a * HPR -
850 // Horizontal Position Relative
851 case'a':this.HPositionRelative(this.params);break;// CSI P s c
852 // Send Device Attributes (Primary DA).
853 // CSI > P s c
854 // Send Device Attributes (Secondary DA)
855 case'c':this.sendDeviceAttributes(this.params);break;// CSI Pm d
856 // Line Position Absolute [row] (default = [1,column]) (VPA).
857 case'd':this.linePosAbsolute(this.params);break;// 145 65 e * VPR - Vertical Pos ition Relative
858 case'e':this.VPositionRelative(this.params);break;// CSI Ps ; Ps f
859 // Horizontal and Vertical Position [row;column] (default =
860 // [1,1]) (HVP).
861 case'f':this.HVPosition(this.params);break;// CSI Pm h Set Mode (SM).
862 // CSI ? Pm h - mouse escape codes, cursor escape codes
863 case'h':this.setMode(this.params);break;// CSI Pm l Reset Mode (RM).
864 // CSI ? Pm l
865 case'l':this.resetMode(this.params);break;// CSI Ps ; Ps r
866 // Set Scrolling Region [top;bottom] (default = full size of win-
867 // dow) (DECSTBM).
868 // CSI ? Pm r
869 case'r':this.setScrollRegion(this.params);break;// CSI s
870 // Save cursor (ANSI.SYS).
871 case's':this.saveCursor(this.params);break;// CSI u
872 // Restore cursor (ANSI.SYS).
873 case'u':this.restoreCursor(this.params);break;/**
874 * Lesser Used
875 */// CSI Ps I
876 // Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
877 case'I':this.cursorForwardTab(this.params);break;// CSI Ps S Scroll up Ps lines (default = 1) (SU).
878 case'S':this.scrollUp(this.params);break;// CSI Ps T Scroll down Ps lines (defa ult = 1) (SD).
879 // CSI Ps ; Ps ; Ps ; Ps ; Ps T
880 // CSI > Ps; Ps T
881 case'T':// if (this.prefix === '>') {
882 // this.resetTitleModes(this.params);
883 // break;
884 // }
885 // if (this.params.length > 2) {
886 // this.initMouseTracking(this.params);
887 // break;
888 // }
889 if(this.params.length<2&&!this.prefix){this.scrollDown(this.params);}break;// CS I Ps Z
890 // Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
891 case'Z':this.cursorBackwardTab(this.params);break;// CSI Ps b Repeat the preced ing graphic character Ps times (REP).
892 case'b':this.repeatPrecedingCharacter(this.params);break;// CSI Ps g Tab Clear (TBC).
893 case'g':this.tabClear(this.params);break;// CSI Pm i Media Copy (MC).
894 // CSI ? Pm i
895 // case 'i':
896 // this.mediaCopy(this.params);
897 // break;
898 // CSI Pm m Character Attributes (SGR).
899 // CSI > Ps; Ps m
900 // case 'm': // duplicate
901 // if (this.prefix === '>') {
902 // this.setResources(this.params);
903 // } else {
904 // this.charAttributes(this.params);
905 // }
906 // break;
907 // CSI Ps n Device Status Report (DSR).
908 // CSI > Ps n
909 // case 'n': // duplicate
910 // if (this.prefix === '>') {
911 // this.disableModifiers(this.params);
912 // } else {
913 // this.deviceStatus(this.params);
914 // }
915 // break;
916 // CSI > Ps p Set pointer mode.
917 // CSI ! p Soft terminal reset (DECSTR).
918 // CSI Ps$ p
919 // Request ANSI mode (DECRQM).
920 // CSI ? Ps$ p
921 // Request DEC private mode (DECRQM).
922 // CSI Ps ; Ps " p
923 case'p':switch(this.prefix){// case '>':
924 // this.setPointerMode(this.params);
925 // break;
926 case'!':this.softReset(this.params);break;// case '?':
927 // if (this.postfix === '$') {
928 // this.requestPrivateMode(this.params);
929 // }
930 // break;
931 // default:
932 // if (this.postfix === '"') {
933 // this.setConformanceLevel(this.params);
934 // } else if (this.postfix === '$') {
935 // this.requestAnsiMode(this.params);
936 // }
937 // break;
938 }break;// CSI Ps q Load LEDs (DECLL).
939 // CSI Ps SP q
940 // CSI Ps " q
941 // case 'q':
942 // if (this.postfix === ' ') {
943 // this.setCursorStyle(this.params);
944 // break;
945 // }
946 // if (this.postfix === '"') {
947 // this.setCharProtectionAttr(this.params);
948 // break;
949 // }
950 // this.loadLEDs(this.params);
951 // break;
952 // CSI Ps ; Ps r
953 // Set Scrolling Region [top;bottom] (default = full size of win-
954 // dow) (DECSTBM).
955 // CSI ? Pm r
956 // CSI Pt; Pl; Pb; Pr; Ps$ r
957 // case 'r': // duplicate
958 // if (this.prefix === '?') {
959 // this.restorePrivateValues(this.params);
960 // } else if (this.postfix === '$') {
961 // this.setAttrInRectangle(this.params);
962 // } else {
963 // this.setScrollRegion(this.params);
964 // }
965 // break;
966 // CSI s Save cursor (ANSI.SYS).
967 // CSI ? Pm s
968 // case 's': // duplicate
969 // if (this.prefix === '?') {
970 // this.savePrivateValues(this.params);
971 // } else {
972 // this.saveCursor(this.params);
973 // }
974 // break;
975 // CSI Ps ; Ps ; Ps t
976 // CSI Pt; Pl; Pb; Pr; Ps$ t
977 // CSI > Ps; Ps t
978 // CSI Ps SP t
979 // case 't':
980 // if (this.postfix === '$') {
981 // this.reverseAttrInRectangle(this.params);
982 // } else if (this.postfix === ' ') {
983 // this.setWarningBellVolume(this.params);
984 // } else {
985 // if (this.prefix === '>') {
986 // this.setTitleModeFeature(this.params);
987 // } else {
988 // this.manipulateWindow(this.params);
989 // }
990 // }
991 // break;
992 // CSI u Restore cursor (ANSI.SYS).
993 // CSI Ps SP u
994 // case 'u': // duplicate
995 // if (this.postfix === ' ') {
996 // this.setMarginBellVolume(this.params);
997 // } else {
998 // this.restoreCursor(this.params);
999 // }
1000 // break;
1001 // CSI Pt; Pl; Pb; Pr; Pp; Pt; Pl; Pp$ v
1002 // case 'v':
1003 // if (this.postfix === '$') {
1004 // this.copyRectagle(this.params);
1005 // }
1006 // break;
1007 // CSI Pt ; Pl ; Pb ; Pr ' w
1008 // case 'w':
1009 // if (this.postfix === '\'') {
1010 // this.enableFilterRectangle(this.params);
1011 // }
1012 // break;
1013 // CSI Ps x Request Terminal Parameters (DECREQTPARM).
1014 // CSI Ps x Select Attribute Change Extent (DECSACE).
1015 // CSI Pc; Pt; Pl; Pb; Pr$ x
1016 // case 'x':
1017 // if (this.postfix === '$') {
1018 // this.fillRectangle(this.params);
1019 // } else {
1020 // this.requestParameters(this.params);
1021 // //this.__(this.params);
1022 // }
1023 // break;
1024 // CSI Ps ; Pu ' z
1025 // CSI Pt; Pl; Pb; Pr$ z
1026 // case 'z':
1027 // if (this.postfix === '\'') {
1028 // this.enableLocatorReporting(this.params);
1029 // } else if (this.postfix === '$') {
1030 // this.eraseRectangle(this.params);
1031 // }
1032 // break;
1033 // CSI Pm ' {
1034 // CSI Pt; Pl; Pb; Pr$ {
1035 // case '{':
1036 // if (this.postfix === '\'') {
1037 // this.setLocatorEvents(this.params);
1038 // } else if (this.postfix === '$') {
1039 // this.selectiveEraseRectangle(this.params);
1040 // }
1041 // break;
1042 // CSI Ps ' |
1043 // case '|':
1044 // if (this.postfix === '\'') {
1045 // this.requestLocatorPosition(this.params);
1046 // }
1047 // break;
1048 // CSI P m SP }
1049 // Insert P s Column(s) (default = 1) (DECIC), VT420 and up.
1050 // case '}':
1051 // if (this.postfix === ' ') {
1052 // this.insertColumns(this.params);
1053 // }
1054 // break;
1055 // CSI P m SP ~
1056 // Delete P s Column(s) (default = 1) (DECDC), VT420 and up
1057 // case '~':
1058 // if (this.postfix === ' ') {
1059 // this.deleteColumns(this.params);
1060 // }
1061 // break;
1062 default:this.error('Unknown CSI code: %s.',ch);break;}this.prefix='';this.postfi x='';break;case dcs:if(ch==='\x1b'||ch==='\x07'){if(ch==='\x1b')i++;switch(this. prefix){// User-Defined Keys (DECUDK).
1063 case'':break;// Request Status String (DECRQSS).
1064 // test: echo -e '\eP$q"p\e\\'
1065 case'$q':var pt=this.currentParam,valid=false;switch(pt){// DECSCA
1066 case'"q':pt='0"q';break;// DECSCL
1067 case'"p':pt='61"p';break;// DECSTBM
1068 case'r':pt=''+(this.scrollTop+1)+';'+(this.scrollBottom+1)+'r';break;// SGR
1069 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).
1070 case'+p':break;// Request Termcap/Terminfo String (xterm, experimental)
1071 // Regular xterm does not even respond to this sequence.
1072 // This can cause a small glitch in vim.
1073 // test: echo -ne '\eP+q6b64\e\\'
1074 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.currentPara m){if(!this.prefix&&ch!=='$'&&ch!=='+'){this.currentParam=ch;}else if(this.prefi x.length===2){this.currentParam=ch;}else{this.prefix+=ch;}}else{this.currentPara m+=ch;}break;case ignore:// For PM and APC.
1075 if(ch==='\x1b'||ch==='\x07'){if(ch==='\x1b')i++;this.state=normal;}break;}}this. updateRange(this.y);this.refresh(this.refreshStart,this.refreshEnd);};/**
1076 * Writes text to the terminal, followed by a break line character (\n).
1077 * @param {string} text The text to write to the terminal.
1078 */Terminal.prototype.writeln=function(data){this.write(data+'\r\n');};/**
1079 * Attaches a custom keydown handler which is run before keys are processed, giv ing consumers of
1080 * xterm.js ultimate control as to what keys should be processed by the terminal and what keys
1081 * should not.
1082 * @param {function} customKeydownHandler The custom KeyboardEvent handler to at tach. This is a
1083 * function that takes a KeyboardEvent, allowing consumers to stop propogation and/or prevent
1084 * the default action. The function returns whether the event should be proces sed by xterm.js.
1085 */Terminal.prototype.attachCustomKeydownHandler=function(customKeydownHandler){ this.customKeydownHandler=customKeydownHandler;};/**
1086 * Handle a keydown event
1087 * Key Resources:
1088 * - https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
1089 * @param {KeyboardEvent} ev The keydown event to be handled.
1090 */Terminal.prototype.keyDown=function(ev){if(this.customKeydownHandler&&this.cu stomKeydownHandler(ev)===false){return false;}if(!this.compositionHelper.keydown .bind(this.compositionHelper)(ev)){return false;}var self=this;var result=this.e valuateKeyEscapeSequence(ev);if(result.scrollDisp){this.scrollDisp(result.scroll Disp);return this.cancel(ev,true);}if(isThirdLevelShift(this,ev)){return true;}i f(result.cancel){// The event is canceled at the end already, is this necessary?
1091 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);};/**
1092 * Returns an object that determines how a KeyboardEvent should be handled. The key of the
1093 * returned value is the new key code to pass to the PTY.
1094 *
1095 * Reference: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
1096 * @param {KeyboardEvent} ev The keyboard event to be translated to key escape s equence.
1097 */Terminal.prototype.evaluateKeyEscapeSequence=function(ev){var result={// Whet her to cancel event propogation (NOTE: this may not be needed since the event is
1098 // canceled at the end of keyDown
1099 cancel:false,// The new key even to emit
1100 key:undefined,// The number of characters to scroll, if this is defined it will cancel the event
1101 scrollDisp:undefined};var modifiers=ev.shiftKey<<0|ev.altKey<<1|ev.ctrlKey<<2|ev .metaKey<<3;switch(ev.keyCode){case 8:// backspace
1102 if(ev.shiftKey){result.key='\x08';// ^H
1103 break;}result.key='\x7f';// ^?
1104 break;case 9:// tab
1105 if(ev.shiftKey){result.key='\x1b[Z';break;}result.key='\t';result.cancel=true;br eak;case 13:// return/enter
1106 result.key='\r';result.cancel=true;break;case 27:// escape
1107 result.key='\x1b';result.cancel=true;break;case 37:// left-arrow
1108 if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'D';// HACK: Make Alt + left-ar row behave like Ctrl + left-arrow: move one word backwards
1109 // http://unix.stackexchange.com/a/108106
1110 if(result.key=='\x1b[1;3D'){result.key='\x1b[1;5D';}}else if(this.applicationCur sor){result.key='\x1bOD';}else{result.key='\x1b[D';}break;case 39:// right-arrow
1111 if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'C';// HACK: Make Alt + right-a rrow behave like Ctrl + right-arrow: move one word forward
1112 // http://unix.stackexchange.com/a/108106
1113 if(result.key=='\x1b[1;3C'){result.key='\x1b[1;5C';}}else if(this.applicationCur sor){result.key='\x1bOC';}else{result.key='\x1b[C';}break;case 38:// up-arrow
1114 if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'A';// HACK: Make Alt + up-arro w behave like Ctrl + up-arrow
1115 // http://unix.stackexchange.com/a/108106
1116 if(result.key=='\x1b[1;3A'){result.key='\x1b[1;5A';}}else if(this.applicationCur sor){result.key='\x1bOA';}else{result.key='\x1b[A';}break;case 40:// down-arrow
1117 if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'B';// HACK: Make Alt + down-ar row behave like Ctrl + down-arrow
1118 // http://unix.stackexchange.com/a/108106
1119 if(result.key=='\x1b[1;3B'){result.key='\x1b[1;5B';}}else if(this.applicationCur sor){result.key='\x1bOB';}else{result.key='\x1b[B';}break;case 45:// insert
1120 if(!ev.shiftKey&&!ev.ctrlKey){// <Ctrl> or <Shift> + <Insert> are used to
1121 // copy-paste on some systems.
1122 result.key='\x1b[2~';}break;case 46:// delete
1123 if(modifiers){result.key='\x1b[3;'+(modifiers+1)+'~';}else{result.key='\x1b[3~'; }break;case 36:// home
1124 if(modifiers)result.key='\x1b[1;'+(modifiers+1)+'H';else if(this.applicationCurs or)result.key='\x1bOH';else result.key='\x1b[H';break;case 35:// end
1125 if(modifiers)result.key='\x1b[1;'+(modifiers+1)+'F';else if(this.applicationCurs or)result.key='\x1bOF';else result.key='\x1b[F';break;case 33:// page up
1126 if(ev.shiftKey){result.scrollDisp=-(this.rows-1);}else{result.key='\x1b[5~';}bre ak;case 34:// page down
1127 if(ev.shiftKey){result.scrollDisp=this.rows-1;}else{result.key='\x1b[6~';}break; case 112:// F1-F12
1128 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{resu lt.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='\x 1b[20;'+(modifiers+1)+'~';}else{result.key='\x1b[20~';}break;case 121:if(modifie rs){result.key='\x1b[21;'+(modifiers+1)+'~';}else{result.key='\x1b[21~';}break;c ase 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
1129 if(ev.ctrlKey&&!ev.shiftKey&&!ev.altKey&&!ev.metaKey){if(ev.keyCode>=65&&ev.keyC ode<=90){result.key=String.fromCharCode(ev.keyCode-64);}else if(ev.keyCode===32) {// NUL
1130 result.key=String.fromCharCode(0);}else if(ev.keyCode>=51&&ev.keyCode<=55){// es cape, file sep, group sep, record sep, unit sep
1131 result.key=String.fromCharCode(ev.keyCode-51+27);}else if(ev.keyCode===56){// de lete
1132 result.key=String.fromCharCode(127);}else if(ev.keyCode===219){// ^[ - escape
1133 result.key=String.fromCharCode(27);}else if(ev.keyCode===221){// ^] - group sep
1134 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.
1135 if(ev.keyCode>=65&&ev.keyCode<=90){result.key='\x1b'+String.fromCharCode(ev.keyC ode+32);}else if(ev.keyCode===192){result.key='\x1b`';}else if(ev.keyCode>=48&&e v.keyCode<=57){result.key='\x1b'+(ev.keyCode-48);}}break;}return result;};/**
1136 * Set the G level of the terminal
1137 * @param g
1138 */Terminal.prototype.setgLevel=function(g){this.glevel=g;this.charset=this.char sets[g];};/**
1139 * Set the charset for the given G level of the terminal
1140 * @param g
1141 * @param charset
1142 */Terminal.prototype.setgCharset=function(g,charset){this.charsets[g]=charset;i f(this.glevel===g){this.charset=charset;}};/**
1143 * Handle a keypress event.
1144 * Key Resources:
1145 * - https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
1146 * @param {KeyboardEvent} ev The keypress event to be handled.
1147 */Terminal.prototype.keyPress=function(ev){var key;this.cancel(ev);if(ev.charCo de){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.ctr lKey||ev.metaKey)&&!isThirdLevelShift(this,ev)){return false;}key=String.fromCha rCode(key);this.emit('keypress',key,ev);this.emit('key',key,ev);this.showCursor( );this.handler(key);return false;};/**
1148 * Send data for handling to the terminal
1149 * @param {string} data
1150 */Terminal.prototype.send=function(data){var self=this;if(!this.queue){setTimeo ut(function(){self.handler(self.queue);self.queue='';},1);}this.queue+=data;};/* *
1151 * Ring the bell.
1152 * Note: We could do sweet things with webaudio here
1153 */Terminal.prototype.bell=function(){if(!this.visualBell)return;var self=this;t his.element.style.borderColor='white';setTimeout(function(){self.element.style.b orderColor='';},10);if(this.popOnBell)this.focus();};/**
1154 * Log the current state to the console.
1155 */Terminal.prototype.log=function(){if(!this.debug)return;if(!this.context.cons ole||!this.context.console.log)return;var args=Array.prototype.slice.call(argume nts);this.context.console.log.apply(this.context.console,args);};/**
1156 * Log the current state as error to the console.
1157 */Terminal.prototype.error=function(){if(!this.debug)return;if(!this.context.co nsole||!this.context.console.error)return;var args=Array.prototype.slice.call(ar guments);this.context.console.error.apply(this.context.console,args);};/**
1158 * Resizes the terminal.
1159 *
1160 * @param {number} x The number of columns to resize to.
1161 * @param {number} y The number of rows to resize to.
1162 */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
1163 j=this.cols;if(j<x){ch=[this.defAttr,' ',1];// does xterm use the default attr?
1164 i=this.lines.length;while(i--){while(this.lines[i].length<x){this.lines[i].push( ch);}}}else{// (j > x)
1165 i=this.lines.length;while(i--){while(this.lines[i].length>x){this.lines[i].pop() ;}}}this.setupStops(j);this.cols=x;// resize rows
1166 j=this.rows;addToY=0;if(j<y){el=this.element;while(j++<y){// y is rows, not this .y
1167 if(this.lines.length<y+this.ybase){if(this.ybase>0&&this.lines.length<=this.ybas e+this.y+addToY+1){// There is room above the buffer and there are no empty elem ents below the line,
1168 // scroll up
1169 this.ybase--;addToY++;if(this.ydisp>0){// Viewport is at the top of the buffer, must increase downwards
1170 this.ydisp--;}}else{// Add a blank line if there is no buffer left at the top to scroll to, or if there
1171 // are blank lines after the cursor
1172 this.lines.push(this.blankLine());}}if(this.children.length<y){this.insertRow(); }}}else{// (j > y)
1173 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
1174 this.lines.pop();}else{// The line is the cursor, scroll down
1175 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 t he cursor stays on screen
1176 if(this.y>=y){this.y=y-1;}if(addToY){this.y+=addToY;}if(this.x>=x){this.x=x-1;}t his.scrollTop=0;this.scrollBottom=y-1;this.refresh(0,this.rows-1);this.normal=nu ll;this.emit('resize',{terminal:this,cols:x,rows:y});};/**
1177 * Updates the range of rows to refresh
1178 * @param {number} y The number of rows to refresh next.
1179 */Terminal.prototype.updateRange=function(y){if(y<this.refreshStart)this.refres hStart=y;if(y>this.refreshEnd)this.refreshEnd=y;// if (y > this.refreshEnd) {
1180 // this.refreshEnd = y;
1181 // if (y > this.rows - 1) {
1182 // this.refreshEnd = this.rows - 1;
1183 // }
1184 // }
1185 };/**
1186 * Set the range of refreshing to the maximyum value
1187 */Terminal.prototype.maxRange=function(){this.refreshStart=0;this.refreshEnd=th is.rows-1;};/**
1188 * Setup the tab stops.
1189 * @param {number} i
1190 */Terminal.prototype.setupStops=function(i){if(i!=null){if(!this.tabs[i]){i=thi s.prevStop(i);}}else{this.tabs={};i=0;}for(;i<this.cols;i+=8){this.tabs[i]=true; }};/**
1191 * Move the cursor to the previous tab stop from the given position (default is current).
1192 * @param {number} x The position to move the cursor to the previous tab stop.
1193 */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;};/**
1194 * Move the cursor one tab stop forward from the given position (default is curr ent).
1195 * @param {number} x The position to move the cursor one tab stop forward.
1196 */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;};/**
1197 * Erase in the identified line everything from "x" to the end of the line (righ t).
1198 * @param {number} x The column from which to start erasing to the end of the li ne.
1199 * @param {number} y The line in which to operate.
1200 */Terminal.prototype.eraseRight=function(x,y){var line=this.lines[this.ybase+y] ,ch=[this.eraseAttr(),' ',1];// xterm
1201 for(;x<this.cols;x++){line[x]=ch;}this.updateRange(y);};/**
1202 * Erase in the identified line everything from "x" to the start of the line (le ft).
1203 * @param {number} x The column from which to start erasing to the start of the line.
1204 * @param {number} y The line in which to operate.
1205 */Terminal.prototype.eraseLeft=function(x,y){var line=this.lines[this.ybase+y], ch=[this.eraseAttr(),' ',1];// xterm
1206 x++;while(x--){line[x]=ch;}this.updateRange(y);};/**
1207 * Clears the entire buffer, making the prompt line the new first line.
1208 */Terminal.prototype.clear=function(){if(this.ybase===0&&this.y===0){// Don't c lear if it's already clear
1209 return;}this.lines=[this.lines[this.ybase+this.y]];this.ydisp=0;this.ybase=0;thi s.y=0;for(var i=1;i<this.rows;i++){this.lines.push(this.blankLine());}this.refre sh(0,this.rows-1);this.emit('scroll',this.ydisp);};/**
1210 * Erase all content in the given line
1211 * @param {number} y The line to erase all of its contents.
1212 */Terminal.prototype.eraseLine=function(y){this.eraseRight(0,y);};/**
1213 * Return the data array of a blank line/
1214 * @param {number} cur First bunch of data for each "blank" character.
1215 */Terminal.prototype.blankLine=function(cur){var attr=cur?this.eraseAttr():this .defAttr;var ch=[attr,' ',1]// width defaults to 1 halfwidth character
1216 ,line=[],i=0;for(;i<this.cols;i++){line[i]=ch;}return line;};/**
1217 * If cur return the back color xterm feature attribute. Else return defAttr.
1218 * @param {object} cur
1219 */Terminal.prototype.ch=function(cur){return cur?[this.eraseAttr(),' ',1]:[this .defAttr,' ',1];};/**
1220 * Evaluate if the current erminal is the given argument.
1221 * @param {object} term The terminal to evaluate
1222 */Terminal.prototype.is=function(term){var name=this.termName;return(name+'').i ndexOf(term)===0;};/**
1223 * Emit the 'data' event and populate the given data.
1224 * @param {string} data The data to populate in the event.
1225 */Terminal.prototype.handler=function(data){this.emit('data',data);};/**
1226 * Emit the 'title' event and populate the given title.
1227 * @param {string} title The title to populate in the event.
1228 */Terminal.prototype.handleTitle=function(title){this.emit('title',title);};/**
1229 * ESC
1230 *//**
1231 * ESC D Index (IND is 0x84).
1232 */Terminal.prototype.index=function(){this.y++;if(this.y>this.scrollBottom){thi s.y--;this.scroll();}this.state=normal;};/**
1233 * ESC M Reverse Index (RI is 0x8d).
1234 */Terminal.prototype.reverseIndex=function(){var j;this.y--;if(this.y<this.scro llTop){this.y++;// possibly move the code below to term.reverseScroll();
1235 // test: echo -ne '\e[1;1H\e[44m\eM\e[0m'
1236 // blankLine(true) is xterm/linux behavior
1237 this.lines.splice(this.y+this.ybase,0,this.blankLine(true));j=this.rows-1-this.s crollBottom;this.lines.splice(this.rows-1+this.ybase-j+1,1);// this.maxRange();
1238 this.updateRange(this.scrollTop);this.updateRange(this.scrollBottom);}this.state =normal;};/**
1239 * ESC c Full Reset (RIS).
1240 */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();};/**
1241 * ESC H Tab Set (HTS is 0x88).
1242 */Terminal.prototype.tabSet=function(){this.tabs[this.x]=true;this.state=normal ;};/**
1243 * CSI
1244 *//**
1245 * CSI Ps A
1246 * Cursor Up Ps Times (default = 1) (CUU).
1247 */Terminal.prototype.cursorUp=function(params){var param=params[0];if(param<1)p aram=1;this.y-=param;if(this.y<0)this.y=0;};/**
1248 * CSI Ps B
1249 * Cursor Down Ps Times (default = 1) (CUD).
1250 */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;}};/**
1251 * CSI Ps C
1252 * Cursor Forward Ps Times (default = 1) (CUF).
1253 */Terminal.prototype.cursorForward=function(params){var param=params[0];if(para m<1)param=1;this.x+=param;if(this.x>=this.cols){this.x=this.cols-1;}};/**
1254 * CSI Ps D
1255 * Cursor Backward Ps Times (default = 1) (CUB).
1256 */Terminal.prototype.cursorBackward=function(params){var param=params[0];if(par am<1)param=1;this.x-=param;if(this.x<0)this.x=0;};/**
1257 * CSI Ps ; Ps H
1258 * Cursor Position [row;column] (default = [1,1]) (CUP).
1259 */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>=thi s.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;};/**
1260 * CSI Ps J Erase in Display (ED).
1261 * Ps = 0 -> Erase Below (default).
1262 * Ps = 1 -> Erase Above.
1263 * Ps = 2 -> Erase All.
1264 * Ps = 3 -> Erase Saved Lines (xterm).
1265 * CSI ? Ps J
1266 * Erase in Display (DECSED).
1267 * Ps = 0 -> Selective Erase Below (default).
1268 * Ps = 1 -> Selective Erase Above.
1269 * Ps = 2 -> Selective Erase All.
1270 */Terminal.prototype.eraseInDisplay=function(params){var j;switch(params[0]){ca se 0:this.eraseRight(this.x,this.y);j=this.y+1;for(;j<this.rows;j++){this.eraseL ine(j);}break;case 1:this.eraseLeft(this.x,this.y);j=this.y;while(j--){this.eras eLine(j);}break;case 2:j=this.rows;while(j--){this.eraseLine(j);}break;case 3:;/ / no saved lines
1271 break;}};/**
1272 * CSI Ps K Erase in Line (EL).
1273 * Ps = 0 -> Erase to Right (default).
1274 * Ps = 1 -> Erase to Left.
1275 * Ps = 2 -> Erase All.
1276 * CSI ? Ps K
1277 * Erase in Line (DECSEL).
1278 * Ps = 0 -> Selective Erase to Right (default).
1279 * Ps = 1 -> Selective Erase to Left.
1280 * Ps = 2 -> Selective Erase All.
1281 */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;}};/**
1282 * CSI Pm m Character Attributes (SGR).
1283 * Ps = 0 -> Normal (default).
1284 * Ps = 1 -> Bold.
1285 * Ps = 4 -> Underlined.
1286 * Ps = 5 -> Blink (appears as Bold).
1287 * Ps = 7 -> Inverse.
1288 * Ps = 8 -> Invisible, i.e., hidden (VT300).
1289 * Ps = 2 2 -> Normal (neither bold nor faint).
1290 * Ps = 2 4 -> Not underlined.
1291 * Ps = 2 5 -> Steady (not blinking).
1292 * Ps = 2 7 -> Positive (not inverse).
1293 * Ps = 2 8 -> Visible, i.e., not hidden (VT300).
1294 * Ps = 3 0 -> Set foreground color to Black.
1295 * Ps = 3 1 -> Set foreground color to Red.
1296 * Ps = 3 2 -> Set foreground color to Green.
1297 * Ps = 3 3 -> Set foreground color to Yellow.
1298 * Ps = 3 4 -> Set foreground color to Blue.
1299 * Ps = 3 5 -> Set foreground color to Magenta.
1300 * Ps = 3 6 -> Set foreground color to Cyan.
1301 * Ps = 3 7 -> Set foreground color to White.
1302 * Ps = 3 9 -> Set foreground color to default (original).
1303 * Ps = 4 0 -> Set background color to Black.
1304 * Ps = 4 1 -> Set background color to Red.
1305 * Ps = 4 2 -> Set background color to Green.
1306 * Ps = 4 3 -> Set background color to Yellow.
1307 * Ps = 4 4 -> Set background color to Blue.
1308 * Ps = 4 5 -> Set background color to Magenta.
1309 * Ps = 4 6 -> Set background color to Cyan.
1310 * Ps = 4 7 -> Set background color to White.
1311 * Ps = 4 9 -> Set background color to default (original).
1312 *
1313 * If 16-color support is compiled, the following apply. Assume
1314 * that xterm's resources are set so that the ISO color codes are
1315 * the first 8 of a set of 16. Then the aixterm colors are the
1316 * bright versions of the ISO colors:
1317 * Ps = 9 0 -> Set foreground color to Black.
1318 * Ps = 9 1 -> Set foreground color to Red.
1319 * Ps = 9 2 -> Set foreground color to Green.
1320 * Ps = 9 3 -> Set foreground color to Yellow.
1321 * Ps = 9 4 -> Set foreground color to Blue.
1322 * Ps = 9 5 -> Set foreground color to Magenta.
1323 * Ps = 9 6 -> Set foreground color to Cyan.
1324 * Ps = 9 7 -> Set foreground color to White.
1325 * Ps = 1 0 0 -> Set background color to Black.
1326 * Ps = 1 0 1 -> Set background color to Red.
1327 * Ps = 1 0 2 -> Set background color to Green.
1328 * Ps = 1 0 3 -> Set background color to Yellow.
1329 * Ps = 1 0 4 -> Set background color to Blue.
1330 * Ps = 1 0 5 -> Set background color to Magenta.
1331 * Ps = 1 0 6 -> Set background color to Cyan.
1332 * Ps = 1 0 7 -> Set background color to White.
1333 *
1334 * If xterm is compiled with the 16-color support disabled, it
1335 * supports the following, from rxvt:
1336 * Ps = 1 0 0 -> Set foreground and background color to
1337 * default.
1338 *
1339 * If 88- or 256-color support is compiled, the following apply.
1340 * Ps = 3 8 ; 5 ; Ps -> Set foreground color to the second
1341 * Ps.
1342 * Ps = 4 8 ; 5 ; Ps -> Set background color to the second
1343 * Ps.
1344 */Terminal.prototype.charAttributes=function(params){// Optimize a single SGR0.
1345 if(params.length===1&&params[0]===0){this.curAttr=this.defAttr;return;}var l=par ams.length,i=0,flags=this.curAttr>>18,fg=this.curAttr>>9&0x1ff,bg=this.curAttr&0 x1ff,p;for(;i<l;i++){p=params[i];if(p>=30&&p<=37){// fg color 8
1346 fg=p-30;}else if(p>=40&&p<=47){// bg color 8
1347 bg=p-40;}else if(p>=90&&p<=97){// fg color 16
1348 p+=8;fg=p-90;}else if(p>=100&&p<=107){// bg color 16
1349 p+=8;bg=p-100;}else if(p===0){// default
1350 flags=this.defAttr>>18;fg=this.defAttr>>9&0x1ff;bg=this.defAttr&0x1ff;// flags = 0;
1351 // fg = 0x1ff;
1352 // bg = 0x1ff;
1353 }else if(p===1){// bold text
1354 flags|=1;}else if(p===4){// underlined text
1355 flags|=2;}else if(p===5){// blink
1356 flags|=4;}else if(p===7){// inverse and positive
1357 // test with: echo -e '\e[31m\e[42mhello\e[7mworld\e[27mhi\e[m'
1358 flags|=8;}else if(p===8){// invisible
1359 flags|=16;}else if(p===22){// not bold
1360 flags&=~1;}else if(p===24){// not underlined
1361 flags&=~2;}else if(p===25){// not blink
1362 flags&=~4;}else if(p===27){// not inverse
1363 flags&=~8;}else if(p===28){// not invisible
1364 flags&=~16;}else if(p===39){// reset fg
1365 fg=this.defAttr>>9&0x1ff;}else if(p===49){// reset bg
1366 bg=this.defAttr&0x1ff;}else if(p===38){// fg color 256
1367 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]&0xf f;fg=p;}}else if(p===48){// bg color 256
1368 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]&0xf f;bg=p;}}else if(p===100){// reset fg/bg
1369 fg=this.defAttr>>9&0x1ff;bg=this.defAttr&0x1ff;}else{this.error('Unknown SGR att ribute: %d.',p);}}this.curAttr=flags<<18|fg<<9|bg;};/**
1370 * CSI Ps n Device Status Report (DSR).
1371 * Ps = 5 -> Status Report. Result (``OK'') is
1372 * CSI 0 n
1373 * Ps = 6 -> Report Cursor Position (CPR) [row;column].
1374 * Result is
1375 * CSI r ; c R
1376 * CSI ? Ps n
1377 * Device Status Report (DSR, DEC-specific).
1378 * Ps = 6 -> Report Cursor Position (CPR) [row;column] as CSI
1379 * ? r ; c R (assumes page is zero).
1380 * Ps = 1 5 -> Report Printer status as CSI ? 1 0 n (ready).
1381 * or CSI ? 1 1 n (not ready).
1382 * Ps = 2 5 -> Report UDK status as CSI ? 2 0 n (unlocked)
1383 * or CSI ? 2 1 n (locked).
1384 * Ps = 2 6 -> Report Keyboard status as
1385 * CSI ? 2 7 ; 1 ; 0 ; 0 n (North American).
1386 * The last two parameters apply to VT400 & up, and denote key-
1387 * board ready and LK01 respectively.
1388 * Ps = 5 3 -> Report Locator status as
1389 * CSI ? 5 3 n Locator available, if compiled-in, or
1390 * CSI ? 5 0 n No Locator, if not.
1391 */Terminal.prototype.deviceStatus=function(params){if(!this.prefix){switch(para ms[0]){case 5:// status report
1392 this.send('\x1b[0n');break;case 6:// cursor position
1393 this.send('\x1b['+(this.y+1)+';'+(this.x+1)+'R');break;}}else if(this.prefix===' ?'){// modern xterm doesnt seem to
1394 // respond to any of these except ?6, 6, and 5
1395 switch(params[0]){case 6:// cursor position
1396 this.send('\x1b[?'+(this.y+1)+';'+(this.x+1)+'R');break;case 15:// no printer
1397 // this.send('\x1b[?11n');
1398 break;case 25:// dont support user defined keys
1399 // this.send('\x1b[?21n');
1400 break;case 26:// north american keyboard
1401 // this.send('\x1b[?27;1;0;0n');
1402 break;case 53:// no dec locator/mouse
1403 // this.send('\x1b[?50n');
1404 break;}}};/**
1405 * Additions
1406 *//**
1407 * CSI Ps @
1408 * Insert Ps (Blank) Character(s) (default = 1) (ICH).
1409 */Terminal.prototype.insertChars=function(params){var param,row,j,ch;param=para ms[0];if(param<1)param=1;row=this.y+this.ybase;j=this.x;ch=[this.eraseAttr(),' ' ,1];// xterm
1410 while(param--&&j<this.cols){this.lines[row].splice(j++,0,ch);this.lines[row].pop ();}};/**
1411 * CSI Ps E
1412 * Cursor Next Line Ps Times (default = 1) (CNL).
1413 * same as CSI Ps B ?
1414 */Terminal.prototype.cursorNextLine=function(params){var param=params[0];if(par am<1)param=1;this.y+=param;if(this.y>=this.rows){this.y=this.rows-1;}this.x=0;}; /**
1415 * CSI Ps F
1416 * Cursor Preceding Line Ps Times (default = 1) (CNL).
1417 * reuse CSI Ps A ?
1418 */Terminal.prototype.cursorPrecedingLine=function(params){var param=params[0];i f(param<1)param=1;this.y-=param;if(this.y<0)this.y=0;this.x=0;};/**
1419 * CSI Ps G
1420 * Cursor Character Absolute [column] (default = [row,1]) (CHA).
1421 */Terminal.prototype.cursorCharAbsolute=function(params){var param=params[0];if (param<1)param=1;this.x=param-1;};/**
1422 * CSI Ps L
1423 * Insert Ps Line(s) (default = 1) (IL).
1424 */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=th is.rows-1+this.ybase-j+1;while(param--){// test: echo -e '\e[44m\e[1L\e[0m'
1425 // blankLine(true) - xterm/linux behavior
1426 this.lines.splice(row,0,this.blankLine(true));this.lines.splice(j,1);}// this.ma xRange();
1427 this.updateRange(this.y);this.updateRange(this.scrollBottom);};/**
1428 * CSI Ps M
1429 * Delete Ps Line(s) (default = 1) (DL).
1430 */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=th is.rows-1+this.ybase-j;while(param--){// test: echo -e '\e[44m\e[1M\e[0m'
1431 // blankLine(true) - xterm/linux behavior
1432 this.lines.splice(j+1,0,this.blankLine(true));this.lines.splice(row,1);}// this. maxRange();
1433 this.updateRange(this.y);this.updateRange(this.scrollBottom);};/**
1434 * CSI Ps P
1435 * Delete Ps Character(s) (default = 1) (DCH).
1436 */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];// xter m
1437 while(param--){this.lines[row].splice(this.x,1);this.lines[row].push(ch);}};/**
1438 * CSI Ps X
1439 * Erase Ps Character(s) (default = 1) (ECH).
1440 */Terminal.prototype.eraseChars=function(params){var param,row,j,ch;param=param s[0];if(param<1)param=1;row=this.y+this.ybase;j=this.x;ch=[this.eraseAttr(),' ', 1];// xterm
1441 while(param--&&j<this.cols){this.lines[row][j++]=ch;}};/**
1442 * CSI Pm ` Character Position Absolute
1443 * [column] (default = [row,1]) (HPA).
1444 */Terminal.prototype.charPosAbsolute=function(params){var param=params[0];if(pa ram<1)param=1;this.x=param-1;if(this.x>=this.cols){this.x=this.cols-1;}};/**
1445 * 141 61 a * HPR -
1446 * Horizontal Position Relative
1447 * reuse CSI Ps C ?
1448 */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;}};/**
1449 * CSI Ps c Send Device Attributes (Primary DA).
1450 * Ps = 0 or omitted -> request attributes from terminal. The
1451 * response depends on the decTerminalID resource setting.
1452 * -> CSI ? 1 ; 2 c (``VT100 with Advanced Video Option'')
1453 * -> CSI ? 1 ; 0 c (``VT101 with No Options'')
1454 * -> CSI ? 6 c (``VT102'')
1455 * -> CSI ? 6 0 ; 1 ; 2 ; 6 ; 8 ; 9 ; 1 5 ; c (``VT220'')
1456 * The VT100-style response parameters do not mean anything by
1457 * themselves. VT220 parameters do, telling the host what fea-
1458 * tures the terminal supports:
1459 * Ps = 1 -> 132-columns.
1460 * Ps = 2 -> Printer.
1461 * Ps = 6 -> Selective erase.
1462 * Ps = 8 -> User-defined keys.
1463 * Ps = 9 -> National replacement character sets.
1464 * Ps = 1 5 -> Technical characters.
1465 * Ps = 2 2 -> ANSI color, e.g., VT525.
1466 * Ps = 2 9 -> ANSI text locator (i.e., DEC Locator mode).
1467 * CSI > Ps c
1468 * Send Device Attributes (Secondary DA).
1469 * Ps = 0 or omitted -> request the terminal's identification
1470 * code. The response depends on the decTerminalID resource set-
1471 * ting. It should apply only to VT220 and up, but xterm extends
1472 * this to VT100.
1473 * -> CSI > Pp ; Pv ; Pc c
1474 * where Pp denotes the terminal type
1475 * Pp = 0 -> ``VT100''.
1476 * Pp = 1 -> ``VT220''.
1477 * and Pv is the firmware version (for xterm, this was originally
1478 * the XFree86 patch number, starting with 95). In a DEC termi-
1479 * nal, Pc indicates the ROM cartridge registration number and is
1480 * always zero.
1481 * More information:
1482 * xterm/charproc.c - line 2012, for more information.
1483 * vim responds with ^[[?0c or ^[[?1c after the terminal's response (?)
1484 */Terminal.prototype.sendDeviceAttributes=function(params){if(params[0]>0)retur n;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');}}e lse if(this.prefix==='>'){// xterm and urxvt
1485 // seem to spit this
1486 // out around ~370 times (?).
1487 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 li nux console.
1488 // linux console echoes parameters.
1489 this.send(params[0]+'c');}else if(this.is('screen')){this.send('\x1b[>83;40003;0 c');}}};/**
1490 * CSI Pm d
1491 * Line Position Absolute [row] (default = [1,column]) (VPA).
1492 */Terminal.prototype.linePosAbsolute=function(params){var param=params[0];if(pa ram<1)param=1;this.y=param-1;if(this.y>=this.rows){this.y=this.rows-1;}};/**
1493 * 145 65 e * VPR - Vertical Position Relative
1494 * reuse CSI Ps B ?
1495 */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;}};/**
1496 * CSI Ps ; Ps f
1497 * Horizontal and Vertical Position [row;column] (default =
1498 * [1,1]) (HVP).
1499 */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.row s-1;}this.x=params[1]-1;if(this.x>=this.cols){this.x=this.cols-1;}};/**
1500 * CSI Pm h Set Mode (SM).
1501 * Ps = 2 -> Keyboard Action Mode (AM).
1502 * Ps = 4 -> Insert Mode (IRM).
1503 * Ps = 1 2 -> Send/receive (SRM).
1504 * Ps = 2 0 -> Automatic Newline (LNM).
1505 * CSI ? Pm h
1506 * DEC Private Mode Set (DECSET).
1507 * Ps = 1 -> Application Cursor Keys (DECCKM).
1508 * Ps = 2 -> Designate USASCII for character sets G0-G3
1509 * (DECANM), and set VT100 mode.
1510 * Ps = 3 -> 132 Column Mode (DECCOLM).
1511 * Ps = 4 -> Smooth (Slow) Scroll (DECSCLM).
1512 * Ps = 5 -> Reverse Video (DECSCNM).
1513 * Ps = 6 -> Origin Mode (DECOM).
1514 * Ps = 7 -> Wraparound Mode (DECAWM).
1515 * Ps = 8 -> Auto-repeat Keys (DECARM).
1516 * Ps = 9 -> Send Mouse X & Y on button press. See the sec-
1517 * tion Mouse Tracking.
1518 * Ps = 1 0 -> Show toolbar (rxvt).
1519 * Ps = 1 2 -> Start Blinking Cursor (att610).
1520 * Ps = 1 8 -> Print form feed (DECPFF).
1521 * Ps = 1 9 -> Set print extent to full screen (DECPEX).
1522 * Ps = 2 5 -> Show Cursor (DECTCEM).
1523 * Ps = 3 0 -> Show scrollbar (rxvt).
1524 * Ps = 3 5 -> Enable font-shifting functions (rxvt).
1525 * Ps = 3 8 -> Enter Tektronix Mode (DECTEK).
1526 * Ps = 4 0 -> Allow 80 -> 132 Mode.
1527 * Ps = 4 1 -> more(1) fix (see curses resource).
1528 * Ps = 4 2 -> Enable Nation Replacement Character sets (DECN-
1529 * RCM).
1530 * Ps = 4 4 -> Turn On Margin Bell.
1531 * Ps = 4 5 -> Reverse-wraparound Mode.
1532 * Ps = 4 6 -> Start Logging. This is normally disabled by a
1533 * compile-time option.
1534 * Ps = 4 7 -> Use Alternate Screen Buffer. (This may be dis-
1535 * abled by the titeInhibit resource).
1536 * Ps = 6 6 -> Application keypad (DECNKM).
1537 * Ps = 6 7 -> Backarrow key sends backspace (DECBKM).
1538 * Ps = 1 0 0 0 -> Send Mouse X & Y on button press and
1539 * release. See the section Mouse Tracking.
1540 * Ps = 1 0 0 1 -> Use Hilite Mouse Tracking.
1541 * Ps = 1 0 0 2 -> Use Cell Motion Mouse Tracking.
1542 * Ps = 1 0 0 3 -> Use All Motion Mouse Tracking.
1543 * Ps = 1 0 0 4 -> Send FocusIn/FocusOut events.
1544 * Ps = 1 0 0 5 -> Enable Extended Mouse Mode.
1545 * Ps = 1 0 1 0 -> Scroll to bottom on tty output (rxvt).
1546 * Ps = 1 0 1 1 -> Scroll to bottom on key press (rxvt).
1547 * Ps = 1 0 3 4 -> Interpret "meta" key, sets eighth bit.
1548 * (enables the eightBitInput resource).
1549 * Ps = 1 0 3 5 -> Enable special modifiers for Alt and Num-
1550 * Lock keys. (This enables the numLock resource).
1551 * Ps = 1 0 3 6 -> Send ESC when Meta modifies a key. (This
1552 * enables the metaSendsEscape resource).
1553 * Ps = 1 0 3 7 -> Send DEL from the editing-keypad Delete
1554 * key.
1555 * Ps = 1 0 3 9 -> Send ESC when Alt modifies a key. (This
1556 * enables the altSendsEscape resource).
1557 * Ps = 1 0 4 0 -> Keep selection even if not highlighted.
1558 * (This enables the keepSelection resource).
1559 * Ps = 1 0 4 1 -> Use the CLIPBOARD selection. (This enables
1560 * the selectToClipboard resource).
1561 * Ps = 1 0 4 2 -> Enable Urgency window manager hint when
1562 * Control-G is received. (This enables the bellIsUrgent
1563 * resource).
1564 * Ps = 1 0 4 3 -> Enable raising of the window when Control-G
1565 * is received. (enables the popOnBell resource).
1566 * Ps = 1 0 4 7 -> Use Alternate Screen Buffer. (This may be
1567 * disabled by the titeInhibit resource).
1568 * Ps = 1 0 4 8 -> Save cursor as in DECSC. (This may be dis-
1569 * abled by the titeInhibit resource).
1570 * Ps = 1 0 4 9 -> Save cursor as in DECSC and use Alternate
1571 * Screen Buffer, clearing it first. (This may be disabled by
1572 * the titeInhibit resource). This combines the effects of the 1
1573 * 0 4 7 and 1 0 4 8 modes. Use this with terminfo-based
1574 * applications rather than the 4 7 mode.
1575 * Ps = 1 0 5 0 -> Set terminfo/termcap function-key mode.
1576 * Ps = 1 0 5 1 -> Set Sun function-key mode.
1577 * Ps = 1 0 5 2 -> Set HP function-key mode.
1578 * Ps = 1 0 5 3 -> Set SCO function-key mode.
1579 * Ps = 1 0 6 0 -> Set legacy keyboard emulation (X11R6).
1580 * Ps = 1 0 6 1 -> Set VT220 keyboard emulation.
1581 * Ps = 2 0 0 4 -> Set bracketed paste mode.
1582 * Modes:
1583 * http: *vt100.net/docs/vt220-rm/chapter4.html
1584 */Terminal.prototype.setMode=function(params){if((typeof params==='undefined'?' undefined':_typeof(params))==='object'){var l=params.length,i=0;for(;i<l;i++){th is.setMode(params[i]);}return;}if(!this.prefix){switch(params){case 4:this.inser tMode=true;break;case 20://this.convertEol = true;
1585 break;}}else if(this.prefix==='?'){switch(params){case 1:this.applicationCursor= true;break;case 2:this.setgCharset(0,Terminal.charsets.US);this.setgCharset(1,Te rminal.charsets.US);this.setgCharset(2,Terminal.charsets.US);this.setgCharset(3, Terminal.charsets.US);// set VT100 mode here
1586 break;case 3:// 132 col mode
1587 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;
1588 break;case 66:this.log('Serial port requested application keypad.');this.applica tionKeypad=true;this.viewport.syncScrollArea();break;case 9:// X10 Mouse
1589 // no release, no motion, no wheel, no modifiers.
1590 case 1000:// vt200 mouse
1591 // no motion.
1592 // no modifiers, except control on the wheel.
1593 case 1002:// button event mouse
1594 case 1003:// any event mouse
1595 // any event - sends motion events,
1596 // even if there is no button held down.
1597 this.x10Mouse=params===9;this.vt200Mouse=params===1000;this.normalMouse=params>1 000;this.mouseEvents=true;this.element.style.cursor='default';this.log('Binding to mouse events.');break;case 1004:// send focusin/focusout events
1598 // focusin: ^[[I
1599 // focusout: ^[[O
1600 this.sendFocus=true;break;case 1005:// utf8 ext mode mouse
1601 this.utfMouse=true;// for wide terminals
1602 // simply encodes large values as utf8 characters
1603 break;case 1006:// sgr ext mode mouse
1604 this.sgrMouse=true;// for wide terminals
1605 // does not add 32 to fields
1606 // press: ^[[<b;x;yM
1607 // release: ^[[<b;x;ym
1608 break;case 1015:// urxvt ext mode mouse
1609 this.urxvtMouse=true;// for wide terminals
1610 // numbers for fields
1611 // press: ^[[b;x;yM
1612 // motion: ^[[b;x;yT
1613 break;case 25:// show cursor
1614 this.cursorHidden=false;break;case 1049:// alt screen buffer cursor
1615 //this.saveCursor();
1616 ;// FALL-THROUGH
1617 case 47:// alt screen buffer
1618 case 1047:// alt screen buffer
1619 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:t his.tabs// XXX save charset(s) here?
1620 // charset: this.charset,
1621 // glevel: this.glevel,
1622 // charsets: this.charsets
1623 };this.reset();this.normal=normal;this.showCursor();}break;}}};/**
1624 * CSI Pm l Reset Mode (RM).
1625 * Ps = 2 -> Keyboard Action Mode (AM).
1626 * Ps = 4 -> Replace Mode (IRM).
1627 * Ps = 1 2 -> Send/receive (SRM).
1628 * Ps = 2 0 -> Normal Linefeed (LNM).
1629 * CSI ? Pm l
1630 * DEC Private Mode Reset (DECRST).
1631 * Ps = 1 -> Normal Cursor Keys (DECCKM).
1632 * Ps = 2 -> Designate VT52 mode (DECANM).
1633 * Ps = 3 -> 80 Column Mode (DECCOLM).
1634 * Ps = 4 -> Jump (Fast) Scroll (DECSCLM).
1635 * Ps = 5 -> Normal Video (DECSCNM).
1636 * Ps = 6 -> Normal Cursor Mode (DECOM).
1637 * Ps = 7 -> No Wraparound Mode (DECAWM).
1638 * Ps = 8 -> No Auto-repeat Keys (DECARM).
1639 * Ps = 9 -> Don't send Mouse X & Y on button press.
1640 * Ps = 1 0 -> Hide toolbar (rxvt).
1641 * Ps = 1 2 -> Stop Blinking Cursor (att610).
1642 * Ps = 1 8 -> Don't print form feed (DECPFF).
1643 * Ps = 1 9 -> Limit print to scrolling region (DECPEX).
1644 * Ps = 2 5 -> Hide Cursor (DECTCEM).
1645 * Ps = 3 0 -> Don't show scrollbar (rxvt).
1646 * Ps = 3 5 -> Disable font-shifting functions (rxvt).
1647 * Ps = 4 0 -> Disallow 80 -> 132 Mode.
1648 * Ps = 4 1 -> No more(1) fix (see curses resource).
1649 * Ps = 4 2 -> Disable Nation Replacement Character sets (DEC-
1650 * NRCM).
1651 * Ps = 4 4 -> Turn Off Margin Bell.
1652 * Ps = 4 5 -> No Reverse-wraparound Mode.
1653 * Ps = 4 6 -> Stop Logging. (This is normally disabled by a
1654 * compile-time option).
1655 * Ps = 4 7 -> Use Normal Screen Buffer.
1656 * Ps = 6 6 -> Numeric keypad (DECNKM).
1657 * Ps = 6 7 -> Backarrow key sends delete (DECBKM).
1658 * Ps = 1 0 0 0 -> Don't send Mouse X & Y on button press and
1659 * release. See the section Mouse Tracking.
1660 * Ps = 1 0 0 1 -> Don't use Hilite Mouse Tracking.
1661 * Ps = 1 0 0 2 -> Don't use Cell Motion Mouse Tracking.
1662 * Ps = 1 0 0 3 -> Don't use All Motion Mouse Tracking.
1663 * Ps = 1 0 0 4 -> Don't send FocusIn/FocusOut events.
1664 * Ps = 1 0 0 5 -> Disable Extended Mouse Mode.
1665 * Ps = 1 0 1 0 -> Don't scroll to bottom on tty output
1666 * (rxvt).
1667 * Ps = 1 0 1 1 -> Don't scroll to bottom on key press (rxvt).
1668 * Ps = 1 0 3 4 -> Don't interpret "meta" key. (This disables
1669 * the eightBitInput resource).
1670 * Ps = 1 0 3 5 -> Disable special modifiers for Alt and Num-
1671 * Lock keys. (This disables the numLock resource).
1672 * Ps = 1 0 3 6 -> Don't send ESC when Meta modifies a key.
1673 * (This disables the metaSendsEscape resource).
1674 * Ps = 1 0 3 7 -> Send VT220 Remove from the editing-keypad
1675 * Delete key.
1676 * Ps = 1 0 3 9 -> Don't send ESC when Alt modifies a key.
1677 * (This disables the altSendsEscape resource).
1678 * Ps = 1 0 4 0 -> Do not keep selection when not highlighted.
1679 * (This disables the keepSelection resource).
1680 * Ps = 1 0 4 1 -> Use the PRIMARY selection. (This disables
1681 * the selectToClipboard resource).
1682 * Ps = 1 0 4 2 -> Disable Urgency window manager hint when
1683 * Control-G is received. (This disables the bellIsUrgent
1684 * resource).
1685 * Ps = 1 0 4 3 -> Disable raising of the window when Control-
1686 * G is received. (This disables the popOnBell resource).
1687 * Ps = 1 0 4 7 -> Use Normal Screen Buffer, clearing screen
1688 * first if in the Alternate Screen. (This may be disabled by
1689 * the titeInhibit resource).
1690 * Ps = 1 0 4 8 -> Restore cursor as in DECRC. (This may be
1691 * disabled by the titeInhibit resource).
1692 * Ps = 1 0 4 9 -> Use Normal Screen Buffer and restore cursor
1693 * as in DECRC. (This may be disabled by the titeInhibit
1694 * resource). This combines the effects of the 1 0 4 7 and 1 0
1695 * 4 8 modes. Use this with terminfo-based applications rather
1696 * than the 4 7 mode.
1697 * Ps = 1 0 5 0 -> Reset terminfo/termcap function-key mode.
1698 * Ps = 1 0 5 1 -> Reset Sun function-key mode.
1699 * Ps = 1 0 5 2 -> Reset HP function-key mode.
1700 * Ps = 1 0 5 3 -> Reset SCO function-key mode.
1701 * Ps = 1 0 6 0 -> Reset legacy keyboard emulation (X11R6).
1702 * Ps = 1 0 6 1 -> Reset keyboard emulation to Sun/PC style.
1703 * Ps = 2 0 0 4 -> Reset bracketed paste mode.
1704 */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.i nsertMode=false;break;case 20://this.convertEol = false;
1705 break;}}else if(this.prefix==='?'){switch(params){case 1:this.applicationCursor= false;break;case 3:if(this.cols===132&&this.savedCols){this.resize(this.savedCol s,this.rows);}delete this.savedCols;break;case 6:this.originMode=false;break;cas e 7:this.wraparoundMode=false;break;case 12:// this.cursorBlink = false;
1706 break;case 66:this.log('Switching back to normal keypad.');this.applicationKeypa d=false;this.viewport.syncScrollArea();break;case 9:// X10 Mouse
1707 case 1000:// vt200 mouse
1708 case 1002:// button event mouse
1709 case 1003:// any event mouse
1710 this.x10Mouse=false;this.vt200Mouse=false;this.normalMouse=false;this.mouseEvent s=false;this.element.style.cursor='';break;case 1004:// send focusin/focusout ev ents
1711 this.sendFocus=false;break;case 1005:// utf8 ext mode mouse
1712 this.utfMouse=false;break;case 1006:// sgr ext mode mouse
1713 this.sgrMouse=false;break;case 1015:// urxvt ext mode mouse
1714 this.urxvtMouse=false;break;case 25:// hide cursor
1715 this.cursorHidden=true;break;case 1049:// alt screen buffer cursor
1716 ;// FALL-THROUGH
1717 case 47:// normal screen buffer
1718 case 1047:// normal screen buffer - clearing it first
1719 if(this.normal){this.lines=this.normal.lines;this.ybase=this.normal.ybase;this.y disp=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) {
1720 // this.x = this.savedX;
1721 // this.y = this.savedY;
1722 // }
1723 this.refresh(0,this.rows-1);this.showCursor();}break;}}};/**
1724 * CSI Ps ; Ps r
1725 * Set Scrolling Region [top;bottom] (default = full size of win-
1726 * dow) (DECSTBM).
1727 * CSI ? Pm r
1728 */Terminal.prototype.setScrollRegion=function(params){if(this.prefix)return;thi s.scrollTop=(params[0]||1)-1;this.scrollBottom=(params[1]||this.rows)-1;this.x=0 ;this.y=0;};/**
1729 * CSI s
1730 * Save cursor (ANSI.SYS).
1731 */Terminal.prototype.saveCursor=function(params){this.savedX=this.x;this.savedY =this.y;};/**
1732 * CSI u
1733 * Restore cursor (ANSI.SYS).
1734 */Terminal.prototype.restoreCursor=function(params){this.x=this.savedX||0;this. y=this.savedY||0;};/**
1735 * Lesser Used
1736 *//**
1737 * CSI Ps I
1738 * Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
1739 */Terminal.prototype.cursorForwardTab=function(params){var param=params[0]||1;w hile(param--){this.x=this.nextStop();}};/**
1740 * CSI Ps S Scroll up Ps lines (default = 1) (SU).
1741 */Terminal.prototype.scrollUp=function(params){var param=params[0]||1;while(par am--){this.lines.splice(this.ybase+this.scrollTop,1);this.lines.splice(this.ybas e+this.scrollBottom,0,this.blankLine());}// this.maxRange();
1742 this.updateRange(this.scrollTop);this.updateRange(this.scrollBottom);};/**
1743 * CSI Ps T Scroll down Ps lines (default = 1) (SD).
1744 */Terminal.prototype.scrollDown=function(params){var param=params[0]||1;whi le(param--){this.lines.splice(this.ybase+this.scrollBottom,1);this.lines.splice( this.ybase+this.scrollTop,0,this.blankLine());}// this.maxRange();
1745 this.updateRange(this.scrollTop);this.updateRange(this.scrollBottom);};/**
1746 * CSI Ps ; Ps ; Ps ; Ps ; Ps T
1747 * Initiate highlight mouse tracking. Parameters are
1748 * [func;startx;starty;firstrow;lastrow]. See the section Mouse
1749 * Tracking.
1750 */Terminal.prototype.initMouseTracking=function(params){// Relevant: DECSET 100 1
1751 };/**
1752 * CSI > Ps; Ps T
1753 * Reset one or more features of the title modes to the default
1754 * value. Normally, "reset" disables the feature. It is possi-
1755 * ble to disable the ability to reset features by compiling a
1756 * different default for the title modes into xterm.
1757 * Ps = 0 -> Do not set window/icon labels using hexadecimal.
1758 * Ps = 1 -> Do not query window/icon labels using hexadeci-
1759 * mal.
1760 * Ps = 2 -> Do not set window/icon labels using UTF-8.
1761 * Ps = 3 -> Do not query window/icon labels using UTF-8.
1762 * (See discussion of "Title Modes").
1763 */Terminal.prototype.resetTitleModes=function(params){;};/**
1764 * CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
1765 */Terminal.prototype.cursorBackwardTab=function(params){var param=params[0]||1; while(param--){this.x=this.prevStop();}};/**
1766 * CSI Ps b Repeat the preceding graphic character Ps times (REP).
1767 */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;}};/**
1768 * CSI Ps g Tab Clear (TBC).
1769 * Ps = 0 -> Clear Current Column (default).
1770 * Ps = 3 -> Clear All.
1771 * Potentially:
1772 * Ps = 2 -> Clear Stops on Line.
1773 * http://vt100.net/annarbor/aaa-ug/section6.html
1774 */Terminal.prototype.tabClear=function(params){var param=params[0];if(param<=0) {delete this.tabs[this.x];}else if(param===3){this.tabs={};}};/**
1775 * CSI Pm i Media Copy (MC).
1776 * Ps = 0 -> Print screen (default).
1777 * Ps = 4 -> Turn off printer controller mode.
1778 * Ps = 5 -> Turn on printer controller mode.
1779 * CSI ? Pm i
1780 * Media Copy (MC, DEC-specific).
1781 * Ps = 1 -> Print line containing cursor.
1782 * Ps = 4 -> Turn off autoprint mode.
1783 * Ps = 5 -> Turn on autoprint mode.
1784 * Ps = 1 0 -> Print composed display, ignores DECPEX.
1785 * Ps = 1 1 -> Print all pages.
1786 */Terminal.prototype.mediaCopy=function(params){;};/**
1787 * CSI > Ps; Ps m
1788 * Set or reset resource-values used by xterm to decide whether
1789 * to construct escape sequences holding information about the
1790 * modifiers pressed with a given key. The first parameter iden-
1791 * tifies the resource to set/reset. The second parameter is the
1792 * value to assign to the resource. If the second parameter is
1793 * omitted, the resource is reset to its initial value.
1794 * Ps = 1 -> modifyCursorKeys.
1795 * Ps = 2 -> modifyFunctionKeys.
1796 * Ps = 4 -> modifyOtherKeys.
1797 * If no parameters are given, all resources are reset to their
1798 * initial values.
1799 */Terminal.prototype.setResources=function(params){;};/**
1800 * CSI > Ps n
1801 * Disable modifiers which may be enabled via the CSI > Ps; Ps m
1802 * sequence. This corresponds to a resource value of "-1", which
1803 * cannot be set with the other sequence. The parameter identi-
1804 * fies the resource to be disabled:
1805 * Ps = 1 -> modifyCursorKeys.
1806 * Ps = 2 -> modifyFunctionKeys.
1807 * Ps = 4 -> modifyOtherKeys.
1808 * If the parameter is omitted, modifyFunctionKeys is disabled.
1809 * When modifyFunctionKeys is disabled, xterm uses the modifier
1810 * keys to make an extended sequence of functions rather than
1811 * adding a parameter to each function key to denote the modi-
1812 * fiers.
1813 */Terminal.prototype.disableModifiers=function(params){;};/**
1814 * CSI > Ps p
1815 * Set resource value pointerMode. This is used by xterm to
1816 * decide whether to hide the pointer cursor as the user types.
1817 * Valid values for the parameter:
1818 * Ps = 0 -> never hide the pointer.
1819 * Ps = 1 -> hide if the mouse tracking mode is not enabled.
1820 * Ps = 2 -> always hide the pointer. If no parameter is
1821 * given, xterm uses the default, which is 1 .
1822 */Terminal.prototype.setPointerMode=function(params){;};/**
1823 * CSI ! p Soft terminal reset (DECSTR).
1824 * http://vt100.net/docs/vt220-rm/table4-10.html
1825 */Terminal.prototype.softReset=function(params){this.cursorHidden=false;this.in sertMode=false;this.originMode=false;this.wraparoundMode=false;// autowrap
1826 this.applicationKeypad=false;// ?
1827 this.viewport.syncScrollArea();this.applicationCursor=false;this.scrollTop=0;thi s.scrollBottom=this.rows-1;this.curAttr=this.defAttr;this.x=this.y=0;// ?
1828 this.charset=null;this.glevel=0;// ??
1829 this.charsets=[null];// ??
1830 };/**
1831 * CSI Ps$ p
1832 * Request ANSI mode (DECRQM). For VT300 and up, reply is
1833 * CSI Ps; Pm$ y
1834 * where Ps is the mode number as in RM, and Pm is the mode
1835 * value:
1836 * 0 - not recognized
1837 * 1 - set
1838 * 2 - reset
1839 * 3 - permanently set
1840 * 4 - permanently reset
1841 */Terminal.prototype.requestAnsiMode=function(params){;};/**
1842 * CSI ? Ps$ p
1843 * Request DEC private mode (DECRQM). For VT300 and up, reply is
1844 * CSI ? Ps; Pm$ p
1845 * where Ps is the mode number as in DECSET, Pm is the mode value
1846 * as in the ANSI DECRQM.
1847 */Terminal.prototype.requestPrivateMode=function(params){;};/**
1848 * CSI Ps ; Ps " p
1849 * Set conformance level (DECSCL). Valid values for the first
1850 * parameter:
1851 * Ps = 6 1 -> VT100.
1852 * Ps = 6 2 -> VT200.
1853 * Ps = 6 3 -> VT300.
1854 * Valid values for the second parameter:
1855 * Ps = 0 -> 8-bit controls.
1856 * Ps = 1 -> 7-bit controls (always set for VT100).
1857 * Ps = 2 -> 8-bit controls.
1858 */Terminal.prototype.setConformanceLevel=function(params){;};/**
1859 * CSI Ps q Load LEDs (DECLL).
1860 * Ps = 0 -> Clear all LEDS (default).
1861 * Ps = 1 -> Light Num Lock.
1862 * Ps = 2 -> Light Caps Lock.
1863 * Ps = 3 -> Light Scroll Lock.
1864 * Ps = 2 1 -> Extinguish Num Lock.
1865 * Ps = 2 2 -> Extinguish Caps Lock.
1866 * Ps = 2 3 -> Extinguish Scroll Lock.
1867 */Terminal.prototype.loadLEDs=function(params){;};/**
1868 * CSI Ps SP q
1869 * Set cursor style (DECSCUSR, VT520).
1870 * Ps = 0 -> blinking block.
1871 * Ps = 1 -> blinking block (default).
1872 * Ps = 2 -> steady block.
1873 * Ps = 3 -> blinking underline.
1874 * Ps = 4 -> steady underline.
1875 */Terminal.prototype.setCursorStyle=function(params){;};/**
1876 * CSI Ps " q
1877 * Select character protection attribute (DECSCA). Valid values
1878 * for the parameter:
1879 * Ps = 0 -> DECSED and DECSEL can erase (default).
1880 * Ps = 1 -> DECSED and DECSEL cannot erase.
1881 * Ps = 2 -> DECSED and DECSEL can erase.
1882 */Terminal.prototype.setCharProtectionAttr=function(params){;};/**
1883 * CSI ? Pm r
1884 * Restore DEC Private Mode Values. The value of Ps previously
1885 * saved is restored. Ps values are the same as for DECSET.
1886 */Terminal.prototype.restorePrivateValues=function(params){;};/**
1887 * CSI Pt; Pl; Pb; Pr; Ps$ r
1888 * Change Attributes in Rectangular Area (DECCARA), VT400 and up.
1889 * Pt; Pl; Pb; Pr denotes the rectangle.
1890 * Ps denotes the SGR attributes to change: 0, 1, 4, 5, 7.
1891 * NOTE: xterm doesn't enable this code by default.
1892 */Terminal.prototype.setAttrInRectangle=function(params){var t=params[0],l=para ms[1],b=params[2],r=params[3],attr=params[4];var line,i;for(;t<b+1;t++){line=thi s.lines[this.ybase+t];for(i=l;i<r;i++){line[i]=[attr,line[i][1]];}}// this.maxRa nge();
1893 this.updateRange(params[0]);this.updateRange(params[2]);};/**
1894 * CSI Pc; Pt; Pl; Pb; Pr$ x
1895 * Fill Rectangular Area (DECFRA), VT420 and up.
1896 * Pc is the character to use.
1897 * Pt; Pl; Pb; Pr denotes the rectangle.
1898 * NOTE: xterm doesn't enable this code by default.
1899 */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();
1900 this.updateRange(params[1]);this.updateRange(params[3]);};/**
1901 * CSI Ps ; Pu ' z
1902 * Enable Locator Reporting (DECELR).
1903 * Valid values for the first parameter:
1904 * Ps = 0 -> Locator disabled (default).
1905 * Ps = 1 -> Locator enabled.
1906 * Ps = 2 -> Locator enabled for one report, then disabled.
1907 * The second parameter specifies the coordinate unit for locator
1908 * reports.
1909 * Valid values for the second parameter:
1910 * Pu = 0 <- or omitted -> default to character cells.
1911 * Pu = 1 <- device physical pixels.
1912 * Pu = 2 <- character cells.
1913 */Terminal.prototype.enableLocatorReporting=function(params){var val=params[0]> 0;//this.mouseEvents = val;
1914 //this.decLocator = val;
1915 };/**
1916 * CSI Pt; Pl; Pb; Pr$ z
1917 * Erase Rectangular Area (DECERA), VT400 and up.
1918 * Pt; Pl; Pb; Pr denotes the rectangle.
1919 * NOTE: xterm doesn't enable this code by default.
1920 */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?
1921 for(;t<b+1;t++){line=this.lines[this.ybase+t];for(i=l;i<r;i++){line[i]=ch;}}// t his.maxRange();
1922 this.updateRange(params[0]);this.updateRange(params[2]);};/**
1923 * CSI P m SP }
1924 * Insert P s Column(s) (default = 1) (DECIC), VT420 and up.
1925 * NOTE: xterm doesn't enable this code by default.
1926 */Terminal.prototype.insertColumns=function(){var param=params[0],l=this.ybase+ this.rows,ch=[this.eraseAttr(),' ',1]// xterm?
1927 ,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();};/**
1928 * CSI P m SP ~
1929 * Delete P s Column(s) (default = 1) (DECDC), VT420 and up
1930 * NOTE: xterm doesn't enable this code by default.
1931 */Terminal.prototype.deleteColumns=function(){var param=params[0],l=this.ybase+ this.rows,ch=[this.eraseAttr(),' ',1]// xterm?
1932 ,i;while(param--){for(i=this.ybase;i<l;i++){this.lines[i].splice(this.x,1);this. lines[i].push(ch);}}this.maxRange();};/**
1933 * Character Sets
1934 */Terminal.charsets={};// DEC Special Character and Line Drawing Set.
1935 // http://vt100.net/docs/vt102-ug/table5-13.html
1936 // A lot of curses apps use this if they see TERM=xterm.
1937 // testing: echo -e '\e(0a\e(B'
1938 // The xterm output sometimes seems to conflict with the
1939 // reference above. xterm seems in line with the reference
1940 // when running vttest however.
1941 // The table below now uses xterm's output from vttest.
1942 Terminal.charsets.SCLD={// (0
1943 '`':'◆',// '◆'
1944 'a':'▒',// '▒'
1945 'b':'\t',// '\t'
1946 'c':'\f',// '\f'
1947 'd':'\r',// '\r'
1948 'e':'\n',// '\n'
1949 'f':'°',// '°'
1950 'g':'±',// '±'
1951 'h':'␤',// '\u2424' (NL)
1952 'i':'\u000b',// '\v'
1953 'j':'┘',// '┘'
1954 'k':'┐',// '┐'
1955 'l':'┌',// '┌'
1956 'm':'└',// '└'
1957 'n':'┼',// '┼'
1958 'o':'⎺',// '⎺'
1959 'p':'⎻',// '⎻'
1960 'q':'─',// '─'
1961 'r':'⎼',// '⎼'
1962 's':'⎽',// '⎽'
1963 't':'├',// '├'
1964 'u':'┤',// '┤'
1965 'v':'┴',// '┴'
1966 'w':'┬',// '┬'
1967 'x':'│',// '│'
1968 'y':'≤',// '≤'
1969 'z':'≥',// '≥'
1970 '{':'π',// 'π'
1971 '|':'≠',// '≠'
1972 '}':'£',// '£'
1973 '~':'·'// '·'
1974 };Terminal.charsets.UK=null;// (A
1975 Terminal.charsets.US=null;// (B (USASCII)
1976 Terminal.charsets.Dutch=null;// (4
1977 Terminal.charsets.Finnish=null;// (C or (5
1978 Terminal.charsets.French=null;// (R
1979 Terminal.charsets.FrenchCanadian=null;// (Q
1980 Terminal.charsets.German=null;// (K
1981 Terminal.charsets.Italian=null;// (Y
1982 Terminal.charsets.NorwegianDanish=null;// (E or (6
1983 Terminal.charsets.Spanish=null;// (Z
1984 Terminal.charsets.Swedish=null;// (H or (7
1985 Terminal.charsets.Swiss=null;// (=
1986 Terminal.charsets.ISOLatin=null;// /A
1987 /**
1988 * Helpers
1989 */function contains(el,arr){for(var i=0;i<arr.length;i+=1){if(el===arr[i]){retu rn true;}}return false;}function on(el,type,handler,capture){if(!Array.isArray(e l)){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.p rototype;child.prototype=new f();}// if bold is broken, we can't
1990 // use it in the terminal.
1991 function isBoldBroken(document){var body=document.getElementsByTagName('body')[0 ];var el=document.createElement('span');el.innerHTML='hello world';body.appendCh ild(el);var w1=el.scrollWidth;el.style.fontWeight='bold';var w2=el.scrollWidth;b ody.removeChild(el);return w1!==w2;}function indexOf(obj,el){var i=obj.length;wh ile(i--){if(obj[i]===el)return i;}return-1;}function isThirdLevelShift(term,ev){ var thirdLevelKey=term.isMac&&ev.altKey&&!ev.ctrlKey&&!ev.metaKey||term.isMSWind ows&&ev.altKey&&ev.ctrlKey&&!ev.metaKey;if(ev.type=='keypress'){return thirdLeve lKey;}// Don't invoke for arrows, pageDown, home, backspace, etc. (on non-keypre ss events)
1992 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.vcolor s.length;i++){c=Terminal.vcolors[i];r2=c[0];g2=c[1];b2=c[2];diff=matchColor.dist ance(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://stackoverflo w.com/questions/1633828
1993 matchColor.distance=function(r1,g1,b1,r2,g2,b2){return Math.pow(30*(r1-r2),2)+Ma th.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(co n,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)){ke ys.push(key);}}return keys;}var wcwidth=function(opts){// extracted from https:/ /www.cl.cam.ac.uk/%7Emgk25/ucs/wcwidth.c
1994 // combining characters
1995 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]];// bin ary search
1996 function bisearch(ucs){var min=0;var max=COMBINING.length-1;var mid;if(ucs<COMBI NING[0][0]||ucs>COMBINING[max][1])return false;while(max>=min){mid=Math.floor((m in+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 co ntrol characters
1997 if(ucs===0)return opts.nul;if(ucs<32||ucs>=0x7f&&ucs<0xa0)return opts.control;// binary search in table of non-spacing characters
1998 if(bisearch(ucs))return 0;// if we arrive here, ucs is not a combining or C0/C1 control character
1999 return 1+(ucs>=0x1100&&(ucs<=0x115f||// Hangul Jamo init. consonants
2000 ucs==0x2329||ucs==0x232a||ucs>=0x2e80&&ucs<=0xa4cf&&ucs!=0x303f||// CJK..Yi
2001 ucs>=0xac00&&ucs<=0xd7a3||// Hangul Syllables
2002 ucs>=0xf900&&ucs<=0xfaff||// CJK Compat Ideographs
2003 ucs>=0xfe10&&ucs<=0xfe19||// Vertical forms
2004 ucs>=0xfe30&&ucs<=0xfe6f||// CJK Compat Forms
2005 ucs>=0xff00&&ucs<=0xff60||// Fullwidth Forms
2006 ucs>=0xffe0&&ucs<=0xffe6||ucs>=0x20000&&ucs<=0x2fffd||ucs>=0x30000&&ucs<=0x3fffd ));}return wcwidth;}({nul:0,control:0});// configurable options
2007 /**
2008 * Expose
2009 */Terminal.EventEmitter=_EventEmitter.EventEmitter;Terminal.CompositionHelper=_ CompositionHelper.CompositionHelper;Terminal.Viewport=_Viewport.Viewport;Termina l.inherits=inherits;/**
2010 * Adds an event listener to the terminal.
2011 *
2012 * @param {string} event The name of the event. TODO: Document all event types
2013 * @param {function} callback The function to call when the event is triggered.
2014 */Terminal.on=on;Terminal.off=off;Terminal.cancel=cancel;module.exports=Termina l;
2015
2016 }).call(this,"/src")
2017
2018 },{"./CompositionHelper.js":1,"./EventEmitter.js":2,"./Viewport.js":3}]},{},[4]) (4)
2019 });
2020 //# sourceMappingURL=xterm.js.map
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698