]> git.proxmox.com Git - mirror_xterm.js.git/blame - dist/xterm.js
Merge remote-tracking branch 'origin/master' into 449_keep_span_pool
[mirror_xterm.js.git] / dist / xterm.js
CommitLineData
cd70d298 1(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Terminal = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
cd70d298 2"use strict";
d2f8f9dc 3Object.defineProperty(exports, "__esModule", { value: true });
8dd11f55
PK
4exports.CHARSETS = {};
5exports.DEFAULT_CHARSET = exports.CHARSETS['B'];
6exports.CHARSETS['0'] = {
7 '`': '\u25c6',
8 'a': '\u2592',
9 'b': '\u0009',
10 'c': '\u000c',
11 'd': '\u000d',
12 'e': '\u000a',
13 'f': '\u00b0',
14 'g': '\u00b1',
15 'h': '\u2424',
16 'i': '\u000b',
17 'j': '\u2518',
18 'k': '\u2510',
19 'l': '\u250c',
20 'm': '\u2514',
21 'n': '\u253c',
22 'o': '\u23ba',
23 'p': '\u23bb',
24 'q': '\u2500',
25 'r': '\u23bc',
26 's': '\u23bd',
27 't': '\u251c',
28 'u': '\u2524',
29 'v': '\u2534',
30 'w': '\u252c',
31 'x': '\u2502',
32 'y': '\u2264',
33 'z': '\u2265',
34 '{': '\u03c0',
35 '|': '\u2260',
36 '}': '\u00a3',
37 '~': '\u00b7'
38};
39exports.CHARSETS['A'] = {
40 '#': '£'
41};
42exports.CHARSETS['B'] = null;
43exports.CHARSETS['4'] = {
44 '#': '£',
45 '@': '¾',
46 '[': 'ij',
47 '\\': '½',
48 ']': '|',
49 '{': '¨',
50 '|': 'f',
51 '}': '¼',
52 '~': '´'
53};
54exports.CHARSETS['C'] =
55 exports.CHARSETS['5'] = {
56 '[': 'Ä',
57 '\\': 'Ö',
58 ']': 'Å',
59 '^': 'Ü',
60 '`': 'é',
61 '{': 'ä',
62 '|': 'ö',
63 '}': 'å',
64 '~': 'ü'
65 };
66exports.CHARSETS['R'] = {
67 '#': '£',
68 '@': 'à',
69 '[': '°',
70 '\\': 'ç',
71 ']': '§',
72 '{': 'é',
73 '|': 'ù',
74 '}': 'è',
75 '~': '¨'
76};
77exports.CHARSETS['Q'] = {
78 '@': 'à',
79 '[': 'â',
80 '\\': 'ç',
81 ']': 'ê',
82 '^': 'î',
83 '`': 'ô',
84 '{': 'é',
85 '|': 'ù',
86 '}': 'è',
87 '~': 'û'
88};
89exports.CHARSETS['K'] = {
90 '@': '§',
91 '[': 'Ä',
92 '\\': 'Ö',
93 ']': 'Ü',
94 '{': 'ä',
95 '|': 'ö',
96 '}': 'ü',
97 '~': 'ß'
98};
99exports.CHARSETS['Y'] = {
100 '#': '£',
101 '@': '§',
102 '[': '°',
103 '\\': 'ç',
104 ']': 'é',
105 '`': 'ù',
106 '{': 'à',
107 '|': 'ò',
108 '}': 'è',
109 '~': 'ì'
110};
111exports.CHARSETS['E'] =
112 exports.CHARSETS['6'] = {
113 '@': 'Ä',
114 '[': 'Æ',
115 '\\': 'Ø',
116 ']': 'Å',
117 '^': 'Ü',
118 '`': 'ä',
119 '{': 'æ',
120 '|': 'ø',
121 '}': 'å',
122 '~': 'ü'
123 };
124exports.CHARSETS['Z'] = {
125 '#': '£',
126 '@': '§',
127 '[': '¡',
128 '\\': 'Ñ',
129 ']': '¿',
130 '{': '°',
131 '|': 'ñ',
132 '}': 'ç'
133};
134exports.CHARSETS['H'] =
135 exports.CHARSETS['7'] = {
136 '@': 'É',
137 '[': 'Ä',
138 '\\': 'Ö',
139 ']': 'Å',
140 '^': 'Ü',
141 '`': 'é',
142 '{': 'ä',
143 '|': 'ö',
144 '}': 'å',
145 '~': 'ü'
146 };
147exports.CHARSETS['='] = {
148 '#': 'ù',
149 '@': 'à',
150 '[': 'é',
151 '\\': 'ç',
152 ']': 'ê',
153 '^': 'î',
154 '_': 'è',
155 '`': 'ô',
156 '{': 'ä',
157 '|': 'ö',
158 '}': 'ü',
159 '~': 'û'
160};
161
8fd44266
PK
162
163
8dd11f55
PK
164},{}],2:[function(require,module,exports){
165"use strict";
d2f8f9dc 166Object.defineProperty(exports, "__esModule", { value: true });
cd70d298 167var CompositionHelper = (function () {
cd70d298
PK
168 function CompositionHelper(textarea, compositionView, terminal) {
169 this.textarea = textarea;
170 this.compositionView = compositionView;
171 this.terminal = terminal;
172 this.isComposing = false;
173 this.isSendingComposition = false;
174 this.compositionPosition = { start: null, end: null };
175 }
cd70d298
PK
176 CompositionHelper.prototype.compositionstart = function () {
177 this.isComposing = true;
178 this.compositionPosition.start = this.textarea.value.length;
179 this.compositionView.textContent = '';
180 this.compositionView.classList.add('active');
5ce522a4 181 };
cd70d298 182 CompositionHelper.prototype.compositionupdate = function (ev) {
8dd11f55 183 var _this = this;
cd70d298
PK
184 this.compositionView.textContent = ev.data;
185 this.updateCompositionElements();
cd70d298 186 setTimeout(function () {
8dd11f55 187 _this.compositionPosition.end = _this.textarea.value.length;
cd70d298
PK
188 }, 0);
189 };
cd70d298
PK
190 CompositionHelper.prototype.compositionend = function () {
191 this.finalizeComposition(true);
192 };
cd70d298
PK
193 CompositionHelper.prototype.keydown = function (ev) {
194 if (this.isComposing || this.isSendingComposition) {
195 if (ev.keyCode === 229) {
cd70d298
PK
196 return false;
197 }
198 else if (ev.keyCode === 16 || ev.keyCode === 17 || ev.keyCode === 18) {
cd70d298
PK
199 return false;
200 }
201 else {
cd70d298
PK
202 this.finalizeComposition(false);
203 }
204 }
205 if (ev.keyCode === 229) {
cd70d298
PK
206 this.handleAnyTextareaChanges();
207 return false;
208 }
209 return true;
210 };
cd70d298 211 CompositionHelper.prototype.finalizeComposition = function (waitForPropogation) {
8dd11f55 212 var _this = this;
cd70d298
PK
213 this.compositionView.classList.remove('active');
214 this.isComposing = false;
215 this.clearTextareaPosition();
216 if (!waitForPropogation) {
cd70d298
PK
217 this.isSendingComposition = false;
218 var input = this.textarea.value.substring(this.compositionPosition.start, this.compositionPosition.end);
219 this.terminal.handler(input);
220 }
221 else {
8dd11f55 222 var currentCompositionPosition_1 = {
cd70d298
PK
223 start: this.compositionPosition.start,
224 end: this.compositionPosition.end,
225 };
cd70d298
PK
226 this.isSendingComposition = true;
227 setTimeout(function () {
8dd11f55
PK
228 if (_this.isSendingComposition) {
229 _this.isSendingComposition = false;
230 var input = void 0;
231 if (_this.isComposing) {
232 input = _this.textarea.value.substring(currentCompositionPosition_1.start, currentCompositionPosition_1.end);
cd70d298
PK
233 }
234 else {
8dd11f55 235 input = _this.textarea.value.substring(currentCompositionPosition_1.start);
cd70d298 236 }
8dd11f55 237 _this.terminal.handler(input);
cd70d298
PK
238 }
239 }, 0);
240 }
241 };
cd70d298 242 CompositionHelper.prototype.handleAnyTextareaChanges = function () {
8dd11f55 243 var _this = this;
cd70d298 244 var oldValue = this.textarea.value;
cd70d298 245 setTimeout(function () {
8dd11f55
PK
246 if (!_this.isComposing) {
247 var newValue = _this.textarea.value;
cd70d298
PK
248 var diff = newValue.replace(oldValue, '');
249 if (diff.length > 0) {
8dd11f55 250 _this.terminal.handler(diff);
cd70d298
PK
251 }
252 }
253 }, 0);
254 };
cd70d298 255 CompositionHelper.prototype.updateCompositionElements = function (dontRecurse) {
8dd11f55 256 var _this = this;
cd70d298
PK
257 if (!this.isComposing) {
258 return;
259 }
260 var cursor = this.terminal.element.querySelector('.terminal-cursor');
261 if (cursor) {
cd70d298
PK
262 var xtermRows = this.terminal.element.querySelector('.xterm-rows');
263 var cursorTop = xtermRows.offsetTop + cursor.offsetTop;
264 this.compositionView.style.left = cursor.offsetLeft + 'px';
265 this.compositionView.style.top = cursorTop + 'px';
266 this.compositionView.style.height = cursor.offsetHeight + 'px';
267 this.compositionView.style.lineHeight = cursor.offsetHeight + 'px';
cd70d298
PK
268 var compositionViewBounds = this.compositionView.getBoundingClientRect();
269 this.textarea.style.left = cursor.offsetLeft + 'px';
270 this.textarea.style.top = cursorTop + 'px';
271 this.textarea.style.width = compositionViewBounds.width + 'px';
272 this.textarea.style.height = compositionViewBounds.height + 'px';
273 this.textarea.style.lineHeight = compositionViewBounds.height + 'px';
274 }
275 if (!dontRecurse) {
8dd11f55 276 setTimeout(function () { return _this.updateCompositionElements(true); }, 0);
cd70d298
PK
277 }
278 };
279 ;
cd70d298
PK
280 CompositionHelper.prototype.clearTextareaPosition = function () {
281 this.textarea.style.left = '';
282 this.textarea.style.top = '';
283 };
284 ;
285 return CompositionHelper;
286}());
5ce522a4
PK
287exports.CompositionHelper = CompositionHelper;
288
8fd44266
PK
289
290
8dd11f55 291},{}],3:[function(require,module,exports){
cd70d298 292"use strict";
d2f8f9dc 293Object.defineProperty(exports, "__esModule", { value: true });
8dd11f55
PK
294var C0;
295(function (C0) {
296 C0.NUL = '\x00';
297 C0.SOH = '\x01';
298 C0.STX = '\x02';
299 C0.ETX = '\x03';
300 C0.EOT = '\x04';
301 C0.ENQ = '\x05';
302 C0.ACK = '\x06';
303 C0.BEL = '\x07';
304 C0.BS = '\x08';
305 C0.HT = '\x09';
306 C0.LF = '\x0a';
307 C0.VT = '\x0b';
308 C0.FF = '\x0c';
309 C0.CR = '\x0d';
310 C0.SO = '\x0e';
311 C0.SI = '\x0f';
312 C0.DLE = '\x10';
313 C0.DC1 = '\x11';
314 C0.DC2 = '\x12';
315 C0.DC3 = '\x13';
316 C0.DC4 = '\x14';
317 C0.NAK = '\x15';
318 C0.SYN = '\x16';
319 C0.ETB = '\x17';
320 C0.CAN = '\x18';
321 C0.EM = '\x19';
322 C0.SUB = '\x1a';
323 C0.ESC = '\x1b';
324 C0.FS = '\x1c';
325 C0.GS = '\x1d';
326 C0.RS = '\x1e';
327 C0.US = '\x1f';
328 C0.SP = '\x20';
329 C0.DEL = '\x7f';
330})(C0 = exports.C0 || (exports.C0 = {}));
331;
332
8fd44266
PK
333
334
8dd11f55
PK
335},{}],4:[function(require,module,exports){
336"use strict";
d2f8f9dc 337Object.defineProperty(exports, "__esModule", { value: true });
8dd11f55
PK
338;
339var EventEmitter = (function () {
340 function EventEmitter() {
341 this._events = this._events || {};
342 }
343 EventEmitter.prototype.on = function (type, listener) {
344 this._events[type] = this._events[type] || [];
345 this._events[type].push(listener);
346 };
347 EventEmitter.prototype.off = function (type, listener) {
348 if (!this._events[type]) {
cd70d298
PK
349 return;
350 }
8dd11f55
PK
351 var obj = this._events[type];
352 var i = obj.length;
353 while (i--) {
354 if (obj[i] === listener || obj[i].listener === listener) {
355 obj.splice(i, 1);
356 return;
357 }
358 }
359 };
360 EventEmitter.prototype.removeAllListeners = function (type) {
361 if (this._events[type]) {
362 delete this._events[type];
363 }
364 };
365 EventEmitter.prototype.once = function (type, listener) {
366 function on() {
367 var args = Array.prototype.slice.call(arguments);
368 this.off(type, on);
369 return listener.apply(this, args);
370 }
371 on.listener = listener;
372 return this.on(type, on);
373 };
374 EventEmitter.prototype.emit = function (type) {
375 if (!this._events[type]) {
376 return;
377 }
378 var args = Array.prototype.slice.call(arguments, 1);
379 var obj = this._events[type];
380 for (var i = 0; i < obj.length; i++) {
381 obj[i].apply(this, args);
382 }
383 };
384 EventEmitter.prototype.listeners = function (type) {
385 return this._events[type] || [];
386 };
387 return EventEmitter;
388}());
389exports.EventEmitter = EventEmitter;
5ce522a4 390
8fd44266
PK
391
392
8dd11f55 393},{}],5:[function(require,module,exports){
cd70d298 394"use strict";
d2f8f9dc 395Object.defineProperty(exports, "__esModule", { value: true });
8dd11f55
PK
396var EscapeSequences_1 = require("./EscapeSequences");
397var Charsets_1 = require("./Charsets");
398var InputHandler = (function () {
399 function InputHandler(_terminal) {
400 this._terminal = _terminal;
401 }
402 InputHandler.prototype.addChar = function (char, code) {
403 if (char >= ' ') {
404 var ch_width = wcwidth(code);
405 if (this._terminal.charset && this._terminal.charset[char]) {
406 char = this._terminal.charset[char];
407 }
408 var row = this._terminal.y + this._terminal.ybase;
409 if (!ch_width && this._terminal.x) {
410 if (this._terminal.lines.get(row)[this._terminal.x - 1]) {
411 if (!this._terminal.lines.get(row)[this._terminal.x - 1][2]) {
412 if (this._terminal.lines.get(row)[this._terminal.x - 2])
413 this._terminal.lines.get(row)[this._terminal.x - 2][1] += char;
414 }
415 else {
416 this._terminal.lines.get(row)[this._terminal.x - 1][1] += char;
417 }
418 this._terminal.updateRange(this._terminal.y);
419 }
420 return;
cd70d298 421 }
8dd11f55
PK
422 if (this._terminal.x + ch_width - 1 >= this._terminal.cols) {
423 if (this._terminal.wraparoundMode) {
424 this._terminal.x = 0;
425 this._terminal.y++;
426 if (this._terminal.y > this._terminal.scrollBottom) {
427 this._terminal.y--;
428 this._terminal.scroll();
429 }
430 }
431 else {
432 if (ch_width === 2)
433 return;
434 }
435 }
436 row = this._terminal.y + this._terminal.ybase;
437 if (this._terminal.insertMode) {
438 for (var moves = 0; moves < ch_width; ++moves) {
439 var removed = this._terminal.lines.get(this._terminal.y + this._terminal.ybase).pop();
440 if (removed[2] === 0
441 && this._terminal.lines.get(row)[this._terminal.cols - 2]
442 && this._terminal.lines.get(row)[this._terminal.cols - 2][2] === 2)
443 this._terminal.lines.get(row)[this._terminal.cols - 2] = [this._terminal.curAttr, ' ', 1];
444 this._terminal.lines.get(row).splice(this._terminal.x, 0, [this._terminal.curAttr, ' ', 1]);
445 }
446 }
447 this._terminal.lines.get(row)[this._terminal.x] = [this._terminal.curAttr, char, ch_width];
448 this._terminal.x++;
449 this._terminal.updateRange(this._terminal.y);
450 if (ch_width === 2) {
451 this._terminal.lines.get(row)[this._terminal.x] = [this._terminal.curAttr, '', 0];
452 this._terminal.x++;
cd70d298 453 }
cd70d298
PK
454 }
455 };
8dd11f55
PK
456 InputHandler.prototype.bell = function () {
457 var _this = this;
458 if (!this._terminal.visualBell) {
459 return;
cd70d298 460 }
8dd11f55
PK
461 this._terminal.element.style.borderColor = 'white';
462 setTimeout(function () { return _this._terminal.element.style.borderColor = ''; }, 10);
463 if (this._terminal.popOnBell) {
464 this._terminal.focus();
cd70d298 465 }
8dd11f55
PK
466 };
467 InputHandler.prototype.lineFeed = function () {
468 if (this._terminal.convertEol) {
469 this._terminal.x = 0;
cd70d298 470 }
8dd11f55
PK
471 this._terminal.y++;
472 if (this._terminal.y > this._terminal.scrollBottom) {
473 this._terminal.y--;
474 this._terminal.scroll();
475 }
476 if (this._terminal.x >= this._terminal.cols) {
477 this._terminal.x--;
cd70d298
PK
478 }
479 };
8dd11f55
PK
480 InputHandler.prototype.carriageReturn = function () {
481 this._terminal.x = 0;
cd70d298 482 };
8dd11f55
PK
483 InputHandler.prototype.backspace = function () {
484 if (this._terminal.x > 0) {
485 this._terminal.x--;
cd70d298 486 }
8dd11f55
PK
487 };
488 InputHandler.prototype.tab = function () {
489 this._terminal.x = this._terminal.nextStop();
490 };
491 InputHandler.prototype.shiftOut = function () {
492 this._terminal.setgLevel(1);
493 };
494 InputHandler.prototype.shiftIn = function () {
495 this._terminal.setgLevel(0);
496 };
497 InputHandler.prototype.insertChars = function (params) {
498 var param, row, j, ch;
499 param = params[0];
500 if (param < 1)
501 param = 1;
502 row = this._terminal.y + this._terminal.ybase;
503 j = this._terminal.x;
504 ch = [this._terminal.eraseAttr(), ' ', 1];
505 while (param-- && j < this._terminal.cols) {
506 this._terminal.lines.get(row).splice(j++, 0, ch);
507 this._terminal.lines.get(row).pop();
cd70d298 508 }
8dd11f55
PK
509 };
510 InputHandler.prototype.cursorUp = function (params) {
511 var param = params[0];
512 if (param < 1) {
513 param = 1;
514 }
515 this._terminal.y -= param;
516 if (this._terminal.y < 0) {
517 this._terminal.y = 0;
518 }
519 };
520 InputHandler.prototype.cursorDown = function (params) {
521 var param = params[0];
522 if (param < 1) {
523 param = 1;
524 }
525 this._terminal.y += param;
526 if (this._terminal.y >= this._terminal.rows) {
527 this._terminal.y = this._terminal.rows - 1;
528 }
529 if (this._terminal.x >= this._terminal.cols) {
530 this._terminal.x--;
cd70d298 531 }
8dd11f55
PK
532 };
533 InputHandler.prototype.cursorForward = function (params) {
534 var param = params[0];
535 if (param < 1) {
536 param = 1;
537 }
538 this._terminal.x += param;
539 if (this._terminal.x >= this._terminal.cols) {
540 this._terminal.x = this._terminal.cols - 1;
541 }
542 };
543 InputHandler.prototype.cursorBackward = function (params) {
544 var param = params[0];
545 if (param < 1) {
546 param = 1;
547 }
548 if (this._terminal.x >= this._terminal.cols) {
549 this._terminal.x--;
550 }
551 this._terminal.x -= param;
552 if (this._terminal.x < 0) {
553 this._terminal.x = 0;
554 }
555 };
556 InputHandler.prototype.cursorNextLine = function (params) {
557 var param = params[0];
558 if (param < 1) {
559 param = 1;
560 }
561 this._terminal.y += param;
562 if (this._terminal.y >= this._terminal.rows) {
563 this._terminal.y = this._terminal.rows - 1;
564 }
565 this._terminal.x = 0;
cd70d298
PK
566 };
567 ;
8dd11f55
PK
568 InputHandler.prototype.cursorPrecedingLine = function (params) {
569 var param = params[0];
570 if (param < 1) {
571 param = 1;
572 }
573 this._terminal.y -= param;
574 if (this._terminal.y < 0) {
575 this._terminal.y = 0;
576 }
577 this._terminal.x = 0;
cd70d298 578 };
8dd11f55
PK
579 ;
580 InputHandler.prototype.cursorCharAbsolute = function (params) {
581 var param = params[0];
582 if (param < 1) {
583 param = 1;
cd70d298 584 }
8dd11f55
PK
585 this._terminal.x = param - 1;
586 };
587 InputHandler.prototype.cursorPosition = function (params) {
588 var row, col;
589 row = params[0] - 1;
590 if (params.length >= 2) {
591 col = params[1] - 1;
cd70d298 592 }
8dd11f55
PK
593 else {
594 col = 0;
595 }
596 if (row < 0) {
597 row = 0;
598 }
599 else if (row >= this._terminal.rows) {
600 row = this._terminal.rows - 1;
601 }
602 if (col < 0) {
603 col = 0;
604 }
605 else if (col >= this._terminal.cols) {
606 col = this._terminal.cols - 1;
607 }
608 this._terminal.x = col;
609 this._terminal.y = row;
610 };
611 InputHandler.prototype.cursorForwardTab = function (params) {
612 var param = params[0] || 1;
613 while (param--) {
614 this._terminal.x = this._terminal.nextStop();
615 }
616 };
617 InputHandler.prototype.eraseInDisplay = function (params) {
618 var j;
619 switch (params[0]) {
620 case 0:
621 this._terminal.eraseRight(this._terminal.x, this._terminal.y);
622 j = this._terminal.y + 1;
623 for (; j < this._terminal.rows; j++) {
624 this._terminal.eraseLine(j);
625 }
626 break;
627 case 1:
628 this._terminal.eraseLeft(this._terminal.x, this._terminal.y);
629 j = this._terminal.y;
630 while (j--) {
631 this._terminal.eraseLine(j);
632 }
633 break;
634 case 2:
635 j = this._terminal.rows;
636 while (j--)
637 this._terminal.eraseLine(j);
638 break;
639 case 3:
d2f8f9dc
PK
640 var scrollBackSize = this._terminal.lines.length - this._terminal.rows;
641 if (scrollBackSize > 0) {
642 this._terminal.lines.trimStart(scrollBackSize);
643 this._terminal.ybase = Math.max(this._terminal.ybase - scrollBackSize, 0);
644 this._terminal.ydisp = Math.max(this._terminal.ydisp - scrollBackSize, 0);
645 }
cd70d298 646 break;
cd70d298 647 }
8dd11f55
PK
648 };
649 InputHandler.prototype.eraseInLine = function (params) {
650 switch (params[0]) {
651 case 0:
652 this._terminal.eraseRight(this._terminal.x, this._terminal.y);
653 break;
654 case 1:
655 this._terminal.eraseLeft(this._terminal.x, this._terminal.y);
656 break;
657 case 2:
658 this._terminal.eraseLine(this._terminal.y);
659 break;
cd70d298 660 }
8dd11f55
PK
661 };
662 InputHandler.prototype.insertLines = function (params) {
663 var param, row, j;
664 param = params[0];
665 if (param < 1) {
666 param = 1;
667 }
668 row = this._terminal.y + this._terminal.ybase;
669 j = this._terminal.rows - 1 - this._terminal.scrollBottom;
670 j = this._terminal.rows - 1 + this._terminal.ybase - j + 1;
671 while (param--) {
672 if (this._terminal.lines.length === this._terminal.lines.maxLength) {
673 this._terminal.lines.trimStart(1);
674 this._terminal.ybase--;
675 this._terminal.ydisp--;
676 row--;
677 j--;
678 }
679 this._terminal.lines.splice(row, 0, this._terminal.blankLine(true));
680 this._terminal.lines.splice(j, 1);
681 }
682 this._terminal.updateRange(this._terminal.y);
683 this._terminal.updateRange(this._terminal.scrollBottom);
684 };
685 InputHandler.prototype.deleteLines = function (params) {
686 var param, row, j;
687 param = params[0];
688 if (param < 1) {
689 param = 1;
690 }
691 row = this._terminal.y + this._terminal.ybase;
692 j = this._terminal.rows - 1 - this._terminal.scrollBottom;
693 j = this._terminal.rows - 1 + this._terminal.ybase - j;
694 while (param--) {
695 if (this._terminal.lines.length === this._terminal.lines.maxLength) {
696 this._terminal.lines.trimStart(1);
697 this._terminal.ybase -= 1;
698 this._terminal.ydisp -= 1;
699 }
700 this._terminal.lines.splice(j + 1, 0, this._terminal.blankLine(true));
701 this._terminal.lines.splice(row, 1);
702 }
703 this._terminal.updateRange(this._terminal.y);
704 this._terminal.updateRange(this._terminal.scrollBottom);
705 };
706 InputHandler.prototype.deleteChars = function (params) {
707 var param, row, ch;
708 param = params[0];
709 if (param < 1) {
710 param = 1;
711 }
712 row = this._terminal.y + this._terminal.ybase;
713 ch = [this._terminal.eraseAttr(), ' ', 1];
714 while (param--) {
715 this._terminal.lines.get(row).splice(this._terminal.x, 1);
716 this._terminal.lines.get(row).push(ch);
cd70d298 717 }
8dd11f55
PK
718 };
719 InputHandler.prototype.scrollUp = function (params) {
720 var param = params[0] || 1;
721 while (param--) {
722 this._terminal.lines.splice(this._terminal.ybase + this._terminal.scrollTop, 1);
723 this._terminal.lines.splice(this._terminal.ybase + this._terminal.scrollBottom, 0, this._terminal.blankLine());
724 }
725 this._terminal.updateRange(this._terminal.scrollTop);
726 this._terminal.updateRange(this._terminal.scrollBottom);
727 };
728 InputHandler.prototype.scrollDown = function (params) {
729 var param = params[0] || 1;
730 while (param--) {
731 this._terminal.lines.splice(this._terminal.ybase + this._terminal.scrollBottom, 1);
732 this._terminal.lines.splice(this._terminal.ybase + this._terminal.scrollTop, 0, this._terminal.blankLine());
733 }
734 this._terminal.updateRange(this._terminal.scrollTop);
735 this._terminal.updateRange(this._terminal.scrollBottom);
736 };
737 InputHandler.prototype.eraseChars = function (params) {
738 var param, row, j, ch;
739 param = params[0];
740 if (param < 1) {
741 param = 1;
742 }
743 row = this._terminal.y + this._terminal.ybase;
744 j = this._terminal.x;
745 ch = [this._terminal.eraseAttr(), ' ', 1];
746 while (param-- && j < this._terminal.cols) {
747 this._terminal.lines.get(row)[j++] = ch;
cd70d298 748 }
8dd11f55
PK
749 };
750 InputHandler.prototype.cursorBackwardTab = function (params) {
751 var param = params[0] || 1;
752 while (param--) {
753 this._terminal.x = this._terminal.prevStop();
cd70d298 754 }
8dd11f55
PK
755 };
756 InputHandler.prototype.charPosAbsolute = function (params) {
757 var param = params[0];
758 if (param < 1) {
759 param = 1;
cd70d298 760 }
8dd11f55
PK
761 this._terminal.x = param - 1;
762 if (this._terminal.x >= this._terminal.cols) {
763 this._terminal.x = this._terminal.cols - 1;
cd70d298 764 }
8dd11f55
PK
765 };
766 InputHandler.prototype.HPositionRelative = function (params) {
767 var param = params[0];
768 if (param < 1) {
769 param = 1;
cd70d298 770 }
8dd11f55
PK
771 this._terminal.x += param;
772 if (this._terminal.x >= this._terminal.cols) {
773 this._terminal.x = this._terminal.cols - 1;
774 }
775 };
776 InputHandler.prototype.repeatPrecedingCharacter = function (params) {
777 var param = params[0] || 1, line = this._terminal.lines.get(this._terminal.ybase + this._terminal.y), ch = line[this._terminal.x - 1] || [this._terminal.defAttr, ' ', 1];
778 while (param--) {
779 line[this._terminal.x++] = ch;
780 }
781 };
782 InputHandler.prototype.sendDeviceAttributes = function (params) {
783 if (params[0] > 0) {
784 return;
785 }
786 if (!this._terminal.prefix) {
787 if (this._terminal.is('xterm') || this._terminal.is('rxvt-unicode') || this._terminal.is('screen')) {
788 this._terminal.send(EscapeSequences_1.C0.ESC + '[?1;2c');
789 }
790 else if (this._terminal.is('linux')) {
791 this._terminal.send(EscapeSequences_1.C0.ESC + '[?6c');
792 }
793 }
794 else if (this._terminal.prefix === '>') {
795 if (this._terminal.is('xterm')) {
796 this._terminal.send(EscapeSequences_1.C0.ESC + '[>0;276;0c');
797 }
798 else if (this._terminal.is('rxvt-unicode')) {
799 this._terminal.send(EscapeSequences_1.C0.ESC + '[>85;95;0c');
800 }
801 else if (this._terminal.is('linux')) {
802 this._terminal.send(params[0] + 'c');
803 }
804 else if (this._terminal.is('screen')) {
805 this._terminal.send(EscapeSequences_1.C0.ESC + '[>83;40003;0c');
806 }
807 }
808 };
809 InputHandler.prototype.linePosAbsolute = function (params) {
810 var param = params[0];
811 if (param < 1) {
812 param = 1;
813 }
814 this._terminal.y = param - 1;
815 if (this._terminal.y >= this._terminal.rows) {
816 this._terminal.y = this._terminal.rows - 1;
817 }
818 };
819 InputHandler.prototype.VPositionRelative = function (params) {
820 var param = params[0];
821 if (param < 1) {
822 param = 1;
823 }
824 this._terminal.y += param;
825 if (this._terminal.y >= this._terminal.rows) {
826 this._terminal.y = this._terminal.rows - 1;
827 }
828 if (this._terminal.x >= this._terminal.cols) {
829 this._terminal.x--;
830 }
831 };
832 InputHandler.prototype.HVPosition = function (params) {
833 if (params[0] < 1)
834 params[0] = 1;
835 if (params[1] < 1)
836 params[1] = 1;
837 this._terminal.y = params[0] - 1;
838 if (this._terminal.y >= this._terminal.rows) {
839 this._terminal.y = this._terminal.rows - 1;
840 }
841 this._terminal.x = params[1] - 1;
842 if (this._terminal.x >= this._terminal.cols) {
843 this._terminal.x = this._terminal.cols - 1;
844 }
845 };
846 InputHandler.prototype.tabClear = function (params) {
847 var param = params[0];
848 if (param <= 0) {
849 delete this._terminal.tabs[this._terminal.x];
850 }
851 else if (param === 3) {
852 this._terminal.tabs = {};
853 }
854 };
855 InputHandler.prototype.setMode = function (params) {
856 if (params.length > 1) {
857 for (var i = 0; i < params.length; i++) {
858 this.setMode([params[i]]);
859 }
860 return;
861 }
862 if (!this._terminal.prefix) {
863 switch (params[0]) {
864 case 4:
865 this._terminal.insertMode = true;
866 break;
867 case 20:
868 break;
869 }
870 }
871 else if (this._terminal.prefix === '?') {
872 switch (params[0]) {
873 case 1:
874 this._terminal.applicationCursor = true;
875 break;
876 case 2:
877 this._terminal.setgCharset(0, Charsets_1.DEFAULT_CHARSET);
878 this._terminal.setgCharset(1, Charsets_1.DEFAULT_CHARSET);
879 this._terminal.setgCharset(2, Charsets_1.DEFAULT_CHARSET);
880 this._terminal.setgCharset(3, Charsets_1.DEFAULT_CHARSET);
881 break;
882 case 3:
883 this._terminal.savedCols = this._terminal.cols;
884 this._terminal.resize(132, this._terminal.rows);
885 break;
886 case 6:
887 this._terminal.originMode = true;
888 break;
889 case 7:
890 this._terminal.wraparoundMode = true;
891 break;
892 case 12:
893 break;
894 case 66:
895 this._terminal.log('Serial port requested application keypad.');
896 this._terminal.applicationKeypad = true;
897 this._terminal.viewport.syncScrollArea();
898 break;
899 case 9:
900 case 1000:
901 case 1002:
902 case 1003:
903 this._terminal.x10Mouse = params[0] === 9;
904 this._terminal.vt200Mouse = params[0] === 1000;
905 this._terminal.normalMouse = params[0] > 1000;
906 this._terminal.mouseEvents = true;
907 this._terminal.element.style.cursor = 'default';
908 this._terminal.log('Binding to mouse events.');
909 break;
910 case 1004:
911 this._terminal.sendFocus = true;
912 break;
913 case 1005:
914 this._terminal.utfMouse = true;
915 break;
916 case 1006:
917 this._terminal.sgrMouse = true;
918 break;
919 case 1015:
920 this._terminal.urxvtMouse = true;
921 break;
922 case 25:
923 this._terminal.cursorHidden = false;
924 break;
925 case 1049:
926 ;
927 case 47:
928 case 1047:
929 if (!this._terminal.normal) {
930 var normal = {
931 lines: this._terminal.lines,
932 ybase: this._terminal.ybase,
933 ydisp: this._terminal.ydisp,
934 x: this._terminal.x,
935 y: this._terminal.y,
936 scrollTop: this._terminal.scrollTop,
937 scrollBottom: this._terminal.scrollBottom,
938 tabs: this._terminal.tabs
939 };
940 this._terminal.reset();
941 this._terminal.viewport.syncScrollArea();
942 this._terminal.normal = normal;
943 this._terminal.showCursor();
cd70d298 944 }
8dd11f55 945 break;
cd70d298 946 }
8dd11f55
PK
947 }
948 };
949 InputHandler.prototype.resetMode = function (params) {
950 if (params.length > 1) {
951 for (var i = 0; i < params.length; i++) {
952 this.resetMode([params[i]]);
953 }
954 return;
955 }
956 if (!this._terminal.prefix) {
957 switch (params[0]) {
958 case 4:
959 this._terminal.insertMode = false;
cd70d298 960 break;
8dd11f55 961 case 20:
cd70d298 962 break;
8dd11f55
PK
963 }
964 }
965 else if (this._terminal.prefix === '?') {
966 switch (params[0]) {
967 case 1:
968 this._terminal.applicationCursor = false;
cd70d298 969 break;
8dd11f55
PK
970 case 3:
971 if (this._terminal.cols === 132 && this._terminal.savedCols) {
972 this._terminal.resize(this._terminal.savedCols, this._terminal.rows);
cd70d298 973 }
8dd11f55
PK
974 delete this._terminal.savedCols;
975 break;
976 case 6:
977 this._terminal.originMode = false;
978 break;
979 case 7:
980 this._terminal.wraparoundMode = false;
981 break;
982 case 12:
983 break;
984 case 66:
985 this._terminal.log('Switching back to normal keypad.');
986 this._terminal.applicationKeypad = false;
987 this._terminal.viewport.syncScrollArea();
988 break;
989 case 9:
990 case 1000:
991 case 1002:
992 case 1003:
993 this._terminal.x10Mouse = false;
994 this._terminal.vt200Mouse = false;
995 this._terminal.normalMouse = false;
996 this._terminal.mouseEvents = false;
997 this._terminal.element.style.cursor = '';
998 break;
999 case 1004:
1000 this._terminal.sendFocus = false;
1001 break;
1002 case 1005:
1003 this._terminal.utfMouse = false;
1004 break;
1005 case 1006:
1006 this._terminal.sgrMouse = false;
1007 break;
1008 case 1015:
1009 this._terminal.urxvtMouse = false;
1010 break;
1011 case 25:
1012 this._terminal.cursorHidden = true;
1013 break;
1014 case 1049:
1015 ;
1016 case 47:
1017 case 1047:
1018 if (this._terminal.normal) {
1019 this._terminal.lines = this._terminal.normal.lines;
1020 this._terminal.ybase = this._terminal.normal.ybase;
1021 this._terminal.ydisp = this._terminal.normal.ydisp;
1022 this._terminal.x = this._terminal.normal.x;
1023 this._terminal.y = this._terminal.normal.y;
1024 this._terminal.scrollTop = this._terminal.normal.scrollTop;
1025 this._terminal.scrollBottom = this._terminal.normal.scrollBottom;
1026 this._terminal.tabs = this._terminal.normal.tabs;
1027 this._terminal.normal = null;
1028 this._terminal.refresh(0, this._terminal.rows - 1);
1029 this._terminal.viewport.syncScrollArea();
1030 this._terminal.showCursor();
cd70d298
PK
1031 }
1032 break;
1033 }
cd70d298 1034 }
8dd11f55
PK
1035 };
1036 InputHandler.prototype.charAttributes = function (params) {
1037 if (params.length === 1 && params[0] === 0) {
1038 this._terminal.curAttr = this._terminal.defAttr;
1039 return;
cd70d298 1040 }
8dd11f55
PK
1041 var l = params.length, i = 0, flags = this._terminal.curAttr >> 18, fg = (this._terminal.curAttr >> 9) & 0x1ff, bg = this._terminal.curAttr & 0x1ff, p;
1042 for (; i < l; i++) {
1043 p = params[i];
1044 if (p >= 30 && p <= 37) {
1045 fg = p - 30;
1046 }
1047 else if (p >= 40 && p <= 47) {
1048 bg = p - 40;
1049 }
1050 else if (p >= 90 && p <= 97) {
1051 p += 8;
1052 fg = p - 90;
1053 }
1054 else if (p >= 100 && p <= 107) {
1055 p += 8;
1056 bg = p - 100;
1057 }
1058 else if (p === 0) {
1059 flags = this._terminal.defAttr >> 18;
1060 fg = (this._terminal.defAttr >> 9) & 0x1ff;
1061 bg = this._terminal.defAttr & 0x1ff;
1062 }
1063 else if (p === 1) {
1064 flags |= 1;
1065 }
1066 else if (p === 4) {
1067 flags |= 2;
1068 }
1069 else if (p === 5) {
1070 flags |= 4;
1071 }
1072 else if (p === 7) {
1073 flags |= 8;
1074 }
1075 else if (p === 8) {
1076 flags |= 16;
1077 }
1078 else if (p === 22) {
1079 flags &= ~1;
1080 }
1081 else if (p === 24) {
1082 flags &= ~2;
1083 }
1084 else if (p === 25) {
1085 flags &= ~4;
1086 }
1087 else if (p === 27) {
1088 flags &= ~8;
1089 }
1090 else if (p === 28) {
1091 flags &= ~16;
1092 }
1093 else if (p === 39) {
1094 fg = (this._terminal.defAttr >> 9) & 0x1ff;
1095 }
1096 else if (p === 49) {
1097 bg = this._terminal.defAttr & 0x1ff;
1098 }
1099 else if (p === 38) {
1100 if (params[i + 1] === 2) {
1101 i += 2;
1102 fg = this._terminal.matchColor(params[i] & 0xff, params[i + 1] & 0xff, params[i + 2] & 0xff);
1103 if (fg === -1)
1104 fg = 0x1ff;
1105 i += 2;
1106 }
1107 else if (params[i + 1] === 5) {
1108 i += 2;
1109 p = params[i] & 0xff;
1110 fg = p;
1111 }
1112 }
1113 else if (p === 48) {
1114 if (params[i + 1] === 2) {
1115 i += 2;
1116 bg = this._terminal.matchColor(params[i] & 0xff, params[i + 1] & 0xff, params[i + 2] & 0xff);
1117 if (bg === -1)
1118 bg = 0x1ff;
1119 i += 2;
1120 }
1121 else if (params[i + 1] === 5) {
1122 i += 2;
1123 p = params[i] & 0xff;
1124 bg = p;
1125 }
1126 }
1127 else if (p === 100) {
1128 fg = (this._terminal.defAttr >> 9) & 0x1ff;
1129 bg = this._terminal.defAttr & 0x1ff;
1130 }
1131 else {
1132 this._terminal.error('Unknown SGR attribute: %d.', p);
cd70d298
PK
1133 }
1134 }
8dd11f55
PK
1135 this._terminal.curAttr = (flags << 18) | (fg << 9) | bg;
1136 };
1137 InputHandler.prototype.deviceStatus = function (params) {
1138 if (!this._terminal.prefix) {
1139 switch (params[0]) {
1140 case 5:
1141 this._terminal.send(EscapeSequences_1.C0.ESC + '[0n');
1142 break;
1143 case 6:
1144 this._terminal.send(EscapeSequences_1.C0.ESC + '['
1145 + (this._terminal.y + 1)
1146 + ';'
1147 + (this._terminal.x + 1)
1148 + 'R');
1149 break;
1150 }
1151 }
1152 else if (this._terminal.prefix === '?') {
1153 switch (params[0]) {
1154 case 6:
1155 this._terminal.send(EscapeSequences_1.C0.ESC + '[?'
1156 + (this._terminal.y + 1)
1157 + ';'
1158 + (this._terminal.x + 1)
1159 + 'R');
1160 break;
1161 case 15:
1162 break;
1163 case 25:
1164 break;
1165 case 26:
1166 break;
1167 case 53:
1168 break;
1169 }
1170 }
1171 };
1172 InputHandler.prototype.softReset = function (params) {
1173 this._terminal.cursorHidden = false;
1174 this._terminal.insertMode = false;
1175 this._terminal.originMode = false;
b1619e42 1176 this._terminal.wraparoundMode = true;
8dd11f55
PK
1177 this._terminal.applicationKeypad = false;
1178 this._terminal.viewport.syncScrollArea();
1179 this._terminal.applicationCursor = false;
1180 this._terminal.scrollTop = 0;
1181 this._terminal.scrollBottom = this._terminal.rows - 1;
1182 this._terminal.curAttr = this._terminal.defAttr;
1183 this._terminal.x = this._terminal.y = 0;
1184 this._terminal.charset = null;
1185 this._terminal.glevel = 0;
1186 this._terminal.charsets = [null];
1187 };
1188 InputHandler.prototype.setCursorStyle = function (params) {
1189 var param = params[0] < 1 ? 1 : params[0];
1190 switch (param) {
1191 case 1:
1192 case 2:
1193 this._terminal.setOption('cursorStyle', 'block');
1194 break;
1195 case 3:
1196 case 4:
1197 this._terminal.setOption('cursorStyle', 'underline');
1198 break;
1199 case 5:
1200 case 6:
1201 this._terminal.setOption('cursorStyle', 'bar');
1202 break;
1203 }
1204 var isBlinking = param % 2 === 1;
1205 this._terminal.setOption('cursorBlink', isBlinking);
1206 };
1207 InputHandler.prototype.setScrollRegion = function (params) {
1208 if (this._terminal.prefix)
1209 return;
1210 this._terminal.scrollTop = (params[0] || 1) - 1;
1211 this._terminal.scrollBottom = (params[1] && params[1] <= this._terminal.rows ? params[1] : this._terminal.rows) - 1;
1212 this._terminal.x = 0;
1213 this._terminal.y = 0;
1214 };
1215 InputHandler.prototype.saveCursor = function (params) {
1216 this._terminal.savedX = this._terminal.x;
1217 this._terminal.savedY = this._terminal.y;
1218 };
1219 InputHandler.prototype.restoreCursor = function (params) {
1220 this._terminal.x = this._terminal.savedX || 0;
1221 this._terminal.y = this._terminal.savedY || 0;
1222 };
1223 return InputHandler;
1224}());
1225exports.InputHandler = InputHandler;
1226var wcwidth = (function (opts) {
1227 var COMBINING = [
1228 [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
1229 [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
1230 [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
1231 [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670],
1232 [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED],
1233 [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A],
1234 [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902],
1235 [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D],
1236 [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981],
1237 [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD],
1238 [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C],
1239 [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D],
1240 [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC],
1241 [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD],
1242 [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C],
1243 [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D],
1244 [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0],
1245 [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48],
1246 [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC],
1247 [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD],
1248 [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D],
1249 [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6],
1250 [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E],
1251 [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC],
1252 [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35],
1253 [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E],
1254 [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97],
1255 [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030],
1256 [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039],
1257 [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F],
1258 [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753],
1259 [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD],
1260 [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD],
1261 [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922],
1262 [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B],
1263 [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34],
1264 [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42],
1265 [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF],
1266 [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063],
1267 [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F],
1268 [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B],
1269 [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F],
1270 [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB],
1271 [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F],
1272 [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169],
1273 [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD],
1274 [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F],
1275 [0xE0100, 0xE01EF]
1276 ];
1277 function bisearch(ucs) {
1278 var min = 0;
1279 var max = COMBINING.length - 1;
1280 var mid;
1281 if (ucs < COMBINING[0][0] || ucs > COMBINING[max][1])
1282 return false;
1283 while (max >= min) {
1284 mid = Math.floor((min + max) / 2);
1285 if (ucs > COMBINING[mid][1])
1286 min = mid + 1;
1287 else if (ucs < COMBINING[mid][0])
1288 max = mid - 1;
1289 else
1290 return true;
1291 }
1292 return false;
cd70d298 1293 }
8dd11f55
PK
1294 function wcwidth(ucs) {
1295 if (ucs === 0)
1296 return opts.nul;
1297 if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0))
1298 return opts.control;
1299 if (bisearch(ucs))
1300 return 0;
1301 if (isWide(ucs)) {
1302 return 2;
1303 }
1304 return 1;
1305 }
1306 function isWide(ucs) {
1307 return (ucs >= 0x1100 && (ucs <= 0x115f ||
1308 ucs === 0x2329 ||
1309 ucs === 0x232a ||
1310 (ucs >= 0x2e80 && ucs <= 0xa4cf && ucs !== 0x303f) ||
1311 (ucs >= 0xac00 && ucs <= 0xd7a3) ||
1312 (ucs >= 0xf900 && ucs <= 0xfaff) ||
1313 (ucs >= 0xfe10 && ucs <= 0xfe19) ||
1314 (ucs >= 0xfe30 && ucs <= 0xfe6f) ||
1315 (ucs >= 0xff00 && ucs <= 0xff60) ||
1316 (ucs >= 0xffe0 && ucs <= 0xffe6) ||
1317 (ucs >= 0x20000 && ucs <= 0x2fffd) ||
1318 (ucs >= 0x30000 && ucs <= 0x3fffd)));
cd70d298 1319 }
8dd11f55
PK
1320 return wcwidth;
1321})({ nul: 0, control: 0 });
1322
8fd44266
PK
1323
1324
8dd11f55
PK
1325},{"./Charsets":1,"./EscapeSequences":3}],6:[function(require,module,exports){
1326"use strict";
d2f8f9dc 1327Object.defineProperty(exports, "__esModule", { value: true });
b1619e42
PK
1328var INVALID_LINK_CLASS = 'xterm-invalid-link';
1329var protocolClause = '(https?:\\/\\/)';
1330var domainCharacterSet = '[\\da-z\\.-]+';
1331var negatedDomainCharacterSet = '[^\\da-z\\.-]+';
1332var domainBodyClause = '(' + domainCharacterSet + ')';
1333var tldClause = '([a-z\\.]{2,6})';
1334var ipClause = '((\\d{1,3}\\.){3}\\d{1,3})';
1335var localHostClause = '(localhost)';
1336var portClause = '(:\\d{1,5})';
1337var hostClause = '((' + domainBodyClause + '\\.' + tldClause + ')|' + ipClause + '|' + localHostClause + ')' + portClause + '?';
d2f8f9dc
PK
1338var pathClause = '(\\/[\\/\\w\\.\\-%~]*)*';
1339var queryStringHashFragmentCharacterSet = '[0-9\\w\\[\\]\\(\\)\\/\\?\\!#@$%&\'*+,:;~\\=\\.\\-]*';
b1619e42
PK
1340var queryStringClause = '(\\?' + queryStringHashFragmentCharacterSet + ')?';
1341var hashFragmentClause = '(#' + queryStringHashFragmentCharacterSet + ')?';
1342var negatedPathCharacterSet = '[^\\/\\w\\.\\-%]+';
1343var bodyClause = hostClause + pathClause + queryStringClause + hashFragmentClause;
1344var start = '(?:^|' + negatedDomainCharacterSet + ')(';
1345var end = ')($|' + negatedPathCharacterSet + ')';
1346var strictUrlRegex = new RegExp(start + protocolClause + bodyClause + end);
1347var HYPERTEXT_LINK_MATCHER_ID = 0;
1348var Linkifier = (function () {
d2f8f9dc 1349 function Linkifier() {
b1619e42 1350 this._nextLinkMatcherId = HYPERTEXT_LINK_MATCHER_ID;
b1619e42
PK
1351 this._rowTimeoutIds = [];
1352 this._linkMatchers = [];
1353 this.registerLinkMatcher(strictUrlRegex, null, { matchIndex: 1 });
1354 }
d2f8f9dc
PK
1355 Linkifier.prototype.attachToDom = function (document, rows) {
1356 this._document = document;
1357 this._rows = rows;
1358 };
b1619e42 1359 Linkifier.prototype.linkifyRow = function (rowIndex) {
d2f8f9dc
PK
1360 if (!this._document) {
1361 return;
1362 }
b1619e42
PK
1363 var timeoutId = this._rowTimeoutIds[rowIndex];
1364 if (timeoutId) {
1365 clearTimeout(timeoutId);
1366 }
1367 this._rowTimeoutIds[rowIndex] = setTimeout(this._linkifyRow.bind(this, rowIndex), Linkifier.TIME_BEFORE_LINKIFY);
1368 };
d2f8f9dc 1369 Linkifier.prototype.setHypertextLinkHandler = function (handler) {
b1619e42
PK
1370 this._linkMatchers[HYPERTEXT_LINK_MATCHER_ID].handler = handler;
1371 };
d2f8f9dc
PK
1372 Linkifier.prototype.setHypertextValidationCallback = function (callback) {
1373 this._linkMatchers[HYPERTEXT_LINK_MATCHER_ID].validationCallback = callback;
1374 };
b1619e42
PK
1375 Linkifier.prototype.registerLinkMatcher = function (regex, handler, options) {
1376 if (options === void 0) { options = {}; }
1377 if (this._nextLinkMatcherId !== HYPERTEXT_LINK_MATCHER_ID && !handler) {
1378 throw new Error('handler must be defined');
1379 }
1380 var matcher = {
1381 id: this._nextLinkMatcherId++,
1382 regex: regex,
1383 handler: handler,
1384 matchIndex: options.matchIndex,
1385 validationCallback: options.validationCallback,
1386 priority: options.priority || 0
1387 };
1388 this._addLinkMatcherToList(matcher);
1389 return matcher.id;
1390 };
1391 Linkifier.prototype._addLinkMatcherToList = function (matcher) {
1392 if (this._linkMatchers.length === 0) {
1393 this._linkMatchers.push(matcher);
1394 return;
1395 }
1396 for (var i = this._linkMatchers.length - 1; i >= 0; i--) {
1397 if (matcher.priority <= this._linkMatchers[i].priority) {
1398 this._linkMatchers.splice(i + 1, 0, matcher);
1399 return;
1400 }
1401 }
1402 this._linkMatchers.splice(0, 0, matcher);
1403 };
1404 Linkifier.prototype.deregisterLinkMatcher = function (matcherId) {
1405 for (var i = 1; i < this._linkMatchers.length; i++) {
1406 if (this._linkMatchers[i].id === matcherId) {
1407 this._linkMatchers.splice(i, 1);
1408 return true;
1409 }
1410 }
1411 return false;
1412 };
1413 Linkifier.prototype._linkifyRow = function (rowIndex) {
1414 var row = this._rows[rowIndex];
1415 if (!row) {
1416 return;
1417 }
1418 var text = row.textContent;
d2f8f9dc
PK
1419 for (var i = 0; i < this._linkMatchers.length; i++) {
1420 var matcher = this._linkMatchers[i];
1421 var linkElements = this._doLinkifyRow(row, matcher);
1422 if (linkElements.length > 0) {
1423 if (matcher.validationCallback) {
1424 var _loop_1 = function (j) {
1425 var element = linkElements[j];
1426 matcher.validationCallback(element.textContent, element, function (isValid) {
1427 if (!isValid) {
1428 element.classList.add(INVALID_LINK_CLASS);
1429 }
1430 });
1431 };
1432 for (var j = 0; j < linkElements.length; j++) {
1433 _loop_1(j);
1434 }
b1619e42 1435 }
d2f8f9dc 1436 return;
b1619e42 1437 }
b1619e42
PK
1438 }
1439 };
d2f8f9dc
PK
1440 Linkifier.prototype._doLinkifyRow = function (row, matcher) {
1441 var result = [];
1442 var isHttpLinkMatcher = matcher.id === HYPERTEXT_LINK_MATCHER_ID;
1443 var nodes = row.childNodes;
1444 var match = row.textContent.match(matcher.regex);
1445 if (!match || match.length === 0) {
1446 return result;
1447 }
1448 var uri = match[typeof matcher.matchIndex !== 'number' ? 0 : matcher.matchIndex];
1449 var rowStartIndex = match.index + uri.length;
b1619e42
PK
1450 for (var i = 0; i < nodes.length; i++) {
1451 var node = nodes[i];
1452 var searchIndex = node.textContent.indexOf(uri);
1453 if (searchIndex >= 0) {
d2f8f9dc 1454 var linkElement = this._createAnchorElement(uri, matcher.handler, isHttpLinkMatcher);
b1619e42
PK
1455 if (node.textContent.length === uri.length) {
1456 if (node.nodeType === 3) {
1457 this._replaceNode(node, linkElement);
1458 }
1459 else {
1460 var element = node;
1461 if (element.nodeName === 'A') {
d2f8f9dc 1462 return result;
b1619e42
PK
1463 }
1464 element.innerHTML = '';
1465 element.appendChild(linkElement);
1466 }
1467 }
1468 else {
d2f8f9dc
PK
1469 var nodesAdded = this._replaceNodeSubstringWithNode(node, linkElement, uri, searchIndex);
1470 i += nodesAdded;
b1619e42 1471 }
d2f8f9dc
PK
1472 result.push(linkElement);
1473 match = row.textContent.substring(rowStartIndex).match(matcher.regex);
1474 if (!match || match.length === 0) {
1475 return result;
1476 }
1477 uri = match[typeof matcher.matchIndex !== 'number' ? 0 : matcher.matchIndex];
1478 rowStartIndex += match.index + uri.length;
b1619e42
PK
1479 }
1480 }
d2f8f9dc 1481 return result;
b1619e42
PK
1482 };
1483 Linkifier.prototype._createAnchorElement = function (uri, handler, isHypertextLinkHandler) {
1484 var element = this._document.createElement('a');
1485 element.textContent = uri;
d2f8f9dc 1486 element.draggable = false;
b1619e42
PK
1487 if (isHypertextLinkHandler) {
1488 element.href = uri;
1489 element.target = '_blank';
1490 element.addEventListener('click', function (event) {
1491 if (handler) {
1492 return handler(event, uri);
1493 }
1494 });
1495 }
1496 else {
1497 element.addEventListener('click', function (event) {
1498 if (element.classList.contains(INVALID_LINK_CLASS)) {
1499 return;
1500 }
1501 return handler(event, uri);
1502 });
1503 }
1504 return element;
1505 };
1506 Linkifier.prototype._replaceNode = function (oldNode) {
1507 var newNodes = [];
1508 for (var _i = 1; _i < arguments.length; _i++) {
1509 newNodes[_i - 1] = arguments[_i];
1510 }
1511 var parent = oldNode.parentNode;
1512 for (var i = 0; i < newNodes.length; i++) {
1513 parent.insertBefore(newNodes[i], oldNode);
1514 }
1515 parent.removeChild(oldNode);
1516 };
1517 Linkifier.prototype._replaceNodeSubstringWithNode = function (targetNode, newNode, substring, substringIndex) {
1518 var node = targetNode;
1519 if (node.nodeType !== 3) {
1520 node = node.childNodes[0];
1521 }
d2f8f9dc 1522 if (node.childNodes.length === 0 && node.nodeType !== 3) {
b1619e42
PK
1523 throw new Error('targetNode must be a text node or only contain a single text node');
1524 }
1525 var fullText = node.textContent;
1526 if (substringIndex === 0) {
d2f8f9dc
PK
1527 var rightText_1 = fullText.substring(substring.length);
1528 var rightTextNode_1 = this._document.createTextNode(rightText_1);
1529 this._replaceNode(node, newNode, rightTextNode_1);
1530 return 0;
b1619e42 1531 }
d2f8f9dc
PK
1532 if (substringIndex === targetNode.textContent.length - substring.length) {
1533 var leftText_1 = fullText.substring(0, substringIndex);
1534 var leftTextNode_1 = this._document.createTextNode(leftText_1);
1535 this._replaceNode(node, leftTextNode_1, newNode);
1536 return 0;
b1619e42 1537 }
d2f8f9dc
PK
1538 var leftText = fullText.substring(0, substringIndex);
1539 var leftTextNode = this._document.createTextNode(leftText);
1540 var rightText = fullText.substring(substringIndex + substring.length);
1541 var rightTextNode = this._document.createTextNode(rightText);
1542 this._replaceNode(node, leftTextNode, newNode, rightTextNode);
1543 return 1;
b1619e42
PK
1544 };
1545 return Linkifier;
1546}());
1547Linkifier.TIME_BEFORE_LINKIFY = 200;
1548exports.Linkifier = Linkifier;
1549
1550
1551
1552},{}],7:[function(require,module,exports){
1553"use strict";
d2f8f9dc 1554Object.defineProperty(exports, "__esModule", { value: true });
8dd11f55
PK
1555var EscapeSequences_1 = require("./EscapeSequences");
1556var Charsets_1 = require("./Charsets");
1557var normalStateHandler = {};
1558normalStateHandler[EscapeSequences_1.C0.BEL] = function (parser, handler) { return handler.bell(); };
1559normalStateHandler[EscapeSequences_1.C0.LF] = function (parser, handler) { return handler.lineFeed(); };
1560normalStateHandler[EscapeSequences_1.C0.VT] = normalStateHandler[EscapeSequences_1.C0.LF];
1561normalStateHandler[EscapeSequences_1.C0.FF] = normalStateHandler[EscapeSequences_1.C0.LF];
1562normalStateHandler[EscapeSequences_1.C0.CR] = function (parser, handler) { return handler.carriageReturn(); };
1563normalStateHandler[EscapeSequences_1.C0.BS] = function (parser, handler) { return handler.backspace(); };
1564normalStateHandler[EscapeSequences_1.C0.HT] = function (parser, handler) { return handler.tab(); };
1565normalStateHandler[EscapeSequences_1.C0.SO] = function (parser, handler) { return handler.shiftOut(); };
1566normalStateHandler[EscapeSequences_1.C0.SI] = function (parser, handler) { return handler.shiftIn(); };
1567normalStateHandler[EscapeSequences_1.C0.ESC] = function (parser, handler) { return parser.setState(ParserState.ESCAPED); };
1568var escapedStateHandler = {};
1569escapedStateHandler['['] = function (parser, terminal) {
1570 terminal.params = [];
1571 terminal.currentParam = 0;
1572 parser.setState(ParserState.CSI_PARAM);
1573};
1574escapedStateHandler[']'] = function (parser, terminal) {
1575 terminal.params = [];
1576 terminal.currentParam = 0;
1577 parser.setState(ParserState.OSC);
1578};
1579escapedStateHandler['P'] = function (parser, terminal) {
1580 terminal.params = [];
1581 terminal.currentParam = 0;
1582 parser.setState(ParserState.DCS);
1583};
1584escapedStateHandler['_'] = function (parser, terminal) {
1585 parser.setState(ParserState.IGNORE);
1586};
1587escapedStateHandler['^'] = function (parser, terminal) {
1588 parser.setState(ParserState.IGNORE);
1589};
1590escapedStateHandler['c'] = function (parser, terminal) {
1591 terminal.reset();
1592};
1593escapedStateHandler['E'] = function (parser, terminal) {
1594 terminal.x = 0;
1595 terminal.index();
1596 parser.setState(ParserState.NORMAL);
1597};
1598escapedStateHandler['D'] = function (parser, terminal) {
1599 terminal.index();
1600 parser.setState(ParserState.NORMAL);
1601};
1602escapedStateHandler['M'] = function (parser, terminal) {
1603 terminal.reverseIndex();
1604 parser.setState(ParserState.NORMAL);
1605};
1606escapedStateHandler['%'] = function (parser, terminal) {
1607 terminal.setgLevel(0);
1608 terminal.setgCharset(0, Charsets_1.DEFAULT_CHARSET);
1609 parser.setState(ParserState.NORMAL);
1610 parser.skipNextChar();
1611};
1612escapedStateHandler[EscapeSequences_1.C0.CAN] = function (parser) { return parser.setState(ParserState.NORMAL); };
1613var csiParamStateHandler = {};
1614csiParamStateHandler['?'] = function (parser) { return parser.setPrefix('?'); };
1615csiParamStateHandler['>'] = function (parser) { return parser.setPrefix('>'); };
1616csiParamStateHandler['!'] = function (parser) { return parser.setPrefix('!'); };
1617csiParamStateHandler['0'] = function (parser) { return parser.setParam(parser.getParam() * 10); };
1618csiParamStateHandler['1'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 1); };
1619csiParamStateHandler['2'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 2); };
1620csiParamStateHandler['3'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 3); };
1621csiParamStateHandler['4'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 4); };
1622csiParamStateHandler['5'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 5); };
1623csiParamStateHandler['6'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 6); };
1624csiParamStateHandler['7'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 7); };
1625csiParamStateHandler['8'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 8); };
1626csiParamStateHandler['9'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 9); };
1627csiParamStateHandler['$'] = function (parser) { return parser.setPostfix('$'); };
1628csiParamStateHandler['"'] = function (parser) { return parser.setPostfix('"'); };
1629csiParamStateHandler[' '] = function (parser) { return parser.setPostfix(' '); };
1630csiParamStateHandler['\''] = function (parser) { return parser.setPostfix('\''); };
1631csiParamStateHandler[';'] = function (parser) { return parser.finalizeParam(); };
1632csiParamStateHandler[EscapeSequences_1.C0.CAN] = function (parser) { return parser.setState(ParserState.NORMAL); };
1633var csiStateHandler = {};
1634csiStateHandler['@'] = function (handler, params, prefix) { return handler.insertChars(params); };
1635csiStateHandler['A'] = function (handler, params, prefix) { return handler.cursorUp(params); };
1636csiStateHandler['B'] = function (handler, params, prefix) { return handler.cursorDown(params); };
1637csiStateHandler['C'] = function (handler, params, prefix) { return handler.cursorForward(params); };
1638csiStateHandler['D'] = function (handler, params, prefix) { return handler.cursorBackward(params); };
1639csiStateHandler['E'] = function (handler, params, prefix) { return handler.cursorNextLine(params); };
1640csiStateHandler['F'] = function (handler, params, prefix) { return handler.cursorPrecedingLine(params); };
1641csiStateHandler['G'] = function (handler, params, prefix) { return handler.cursorCharAbsolute(params); };
1642csiStateHandler['H'] = function (handler, params, prefix) { return handler.cursorPosition(params); };
1643csiStateHandler['I'] = function (handler, params, prefix) { return handler.cursorForwardTab(params); };
1644csiStateHandler['J'] = function (handler, params, prefix) { return handler.eraseInDisplay(params); };
1645csiStateHandler['K'] = function (handler, params, prefix) { return handler.eraseInLine(params); };
1646csiStateHandler['L'] = function (handler, params, prefix) { return handler.insertLines(params); };
1647csiStateHandler['M'] = function (handler, params, prefix) { return handler.deleteLines(params); };
1648csiStateHandler['P'] = function (handler, params, prefix) { return handler.deleteChars(params); };
1649csiStateHandler['S'] = function (handler, params, prefix) { return handler.scrollUp(params); };
1650csiStateHandler['T'] = function (handler, params, prefix) {
1651 if (params.length < 2 && !prefix) {
1652 handler.scrollDown(params);
1653 }
1654};
1655csiStateHandler['X'] = function (handler, params, prefix) { return handler.eraseChars(params); };
1656csiStateHandler['Z'] = function (handler, params, prefix) { return handler.cursorBackwardTab(params); };
1657csiStateHandler['`'] = function (handler, params, prefix) { return handler.charPosAbsolute(params); };
1658csiStateHandler['a'] = function (handler, params, prefix) { return handler.HPositionRelative(params); };
1659csiStateHandler['b'] = function (handler, params, prefix) { return handler.repeatPrecedingCharacter(params); };
1660csiStateHandler['c'] = function (handler, params, prefix) { return handler.sendDeviceAttributes(params); };
1661csiStateHandler['d'] = function (handler, params, prefix) { return handler.linePosAbsolute(params); };
1662csiStateHandler['e'] = function (handler, params, prefix) { return handler.VPositionRelative(params); };
1663csiStateHandler['f'] = function (handler, params, prefix) { return handler.HVPosition(params); };
1664csiStateHandler['g'] = function (handler, params, prefix) { return handler.tabClear(params); };
1665csiStateHandler['h'] = function (handler, params, prefix) { return handler.setMode(params); };
1666csiStateHandler['l'] = function (handler, params, prefix) { return handler.resetMode(params); };
1667csiStateHandler['m'] = function (handler, params, prefix) { return handler.charAttributes(params); };
1668csiStateHandler['n'] = function (handler, params, prefix) { return handler.deviceStatus(params); };
1669csiStateHandler['p'] = function (handler, params, prefix) {
1670 switch (prefix) {
1671 case '!':
1672 handler.softReset(params);
1673 break;
cd70d298 1674 }
cd70d298 1675};
8dd11f55
PK
1676csiStateHandler['q'] = function (handler, params, prefix, postfix) {
1677 if (postfix === ' ') {
1678 handler.setCursorStyle(params);
1679 }
1680};
1681csiStateHandler['r'] = function (handler, params) { return handler.setScrollRegion(params); };
1682csiStateHandler['s'] = function (handler, params) { return handler.saveCursor(params); };
1683csiStateHandler['u'] = function (handler, params) { return handler.restoreCursor(params); };
1684csiStateHandler[EscapeSequences_1.C0.CAN] = function (handler, params, prefix, postfix, parser) { return parser.setState(ParserState.NORMAL); };
1685var ParserState;
1686(function (ParserState) {
1687 ParserState[ParserState["NORMAL"] = 0] = "NORMAL";
1688 ParserState[ParserState["ESCAPED"] = 1] = "ESCAPED";
1689 ParserState[ParserState["CSI_PARAM"] = 2] = "CSI_PARAM";
1690 ParserState[ParserState["CSI"] = 3] = "CSI";
1691 ParserState[ParserState["OSC"] = 4] = "OSC";
1692 ParserState[ParserState["CHARSET"] = 5] = "CHARSET";
1693 ParserState[ParserState["DCS"] = 6] = "DCS";
1694 ParserState[ParserState["IGNORE"] = 7] = "IGNORE";
1695})(ParserState || (ParserState = {}));
1696var Parser = (function () {
1697 function Parser(_inputHandler, _terminal) {
1698 this._inputHandler = _inputHandler;
1699 this._terminal = _terminal;
1700 this._state = ParserState.NORMAL;
1701 }
1702 Parser.prototype.parse = function (data) {
1703 var l = data.length, j, cs, ch, code, low;
1704 this._position = 0;
1705 if (this._terminal.surrogate_high) {
1706 data = this._terminal.surrogate_high + data;
1707 this._terminal.surrogate_high = '';
1708 }
1709 for (; this._position < l; this._position++) {
1710 ch = data[this._position];
1711 code = data.charCodeAt(this._position);
1712 if (0xD800 <= code && code <= 0xDBFF) {
1713 low = data.charCodeAt(this._position + 1);
1714 if (isNaN(low)) {
1715 this._terminal.surrogate_high = ch;
1716 continue;
cd70d298 1717 }
8dd11f55
PK
1718 code = ((code - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
1719 ch += data.charAt(this._position + 1);
1720 }
1721 if (0xDC00 <= code && code <= 0xDFFF)
1722 continue;
1723 switch (this._state) {
1724 case ParserState.NORMAL:
1725 if (ch in normalStateHandler) {
1726 normalStateHandler[ch](this, this._inputHandler);
1727 }
1728 else {
1729 this._inputHandler.addChar(ch, code);
1730 }
1731 break;
1732 case ParserState.ESCAPED:
1733 if (ch in escapedStateHandler) {
1734 escapedStateHandler[ch](this, this._terminal);
cd70d298 1735 break;
8dd11f55
PK
1736 }
1737 switch (ch) {
1738 case '(':
1739 case ')':
1740 case '*':
1741 case '+':
1742 case '-':
1743 case '.':
1744 switch (ch) {
1745 case '(':
1746 this._terminal.gcharset = 0;
1747 break;
1748 case ')':
1749 this._terminal.gcharset = 1;
1750 break;
1751 case '*':
1752 this._terminal.gcharset = 2;
1753 break;
1754 case '+':
1755 this._terminal.gcharset = 3;
1756 break;
1757 case '-':
1758 this._terminal.gcharset = 1;
1759 break;
1760 case '.':
1761 this._terminal.gcharset = 2;
1762 break;
cd70d298 1763 }
8dd11f55
PK
1764 this._state = ParserState.CHARSET;
1765 break;
1766 case '/':
1767 this._terminal.gcharset = 3;
1768 this._state = ParserState.CHARSET;
1769 this._position--;
1770 break;
1771 case 'N':
1772 break;
1773 case 'O':
1774 break;
1775 case 'n':
1776 this._terminal.setgLevel(2);
1777 break;
1778 case 'o':
1779 this._terminal.setgLevel(3);
1780 break;
1781 case '|':
1782 this._terminal.setgLevel(3);
1783 break;
1784 case '}':
1785 this._terminal.setgLevel(2);
cd70d298 1786 break;
8dd11f55
PK
1787 case '~':
1788 this._terminal.setgLevel(1);
cd70d298 1789 break;
8dd11f55
PK
1790 case '7':
1791 this._inputHandler.saveCursor();
1792 this._state = ParserState.NORMAL;
cd70d298 1793 break;
8dd11f55
PK
1794 case '8':
1795 this._inputHandler.restoreCursor();
1796 this._state = ParserState.NORMAL;
cd70d298 1797 break;
8dd11f55
PK
1798 case '#':
1799 this._state = ParserState.NORMAL;
1800 this._position++;
cd70d298 1801 break;
8dd11f55
PK
1802 case 'H':
1803 this._terminal.tabSet();
1804 this._state = ParserState.NORMAL;
cd70d298 1805 break;
8dd11f55
PK
1806 case '=':
1807 this._terminal.log('Serial port requested application keypad.');
1808 this._terminal.applicationKeypad = true;
1809 this._terminal.viewport.syncScrollArea();
1810 this._state = ParserState.NORMAL;
cd70d298 1811 break;
8dd11f55
PK
1812 case '>':
1813 this._terminal.log('Switching back to normal keypad.');
1814 this._terminal.applicationKeypad = false;
1815 this._terminal.viewport.syncScrollArea();
1816 this._state = ParserState.NORMAL;
cd70d298 1817 break;
8dd11f55
PK
1818 default:
1819 this._state = ParserState.NORMAL;
1820 this._terminal.error('Unknown ESC control: %s.', ch);
cd70d298
PK
1821 break;
1822 }
8dd11f55
PK
1823 break;
1824 case ParserState.CHARSET:
1825 if (ch in Charsets_1.CHARSETS) {
1826 cs = Charsets_1.CHARSETS[ch];
1827 if (ch === '/') {
1828 this.skipNextChar();
cd70d298
PK
1829 }
1830 }
1831 else {
8dd11f55 1832 cs = Charsets_1.DEFAULT_CHARSET;
cd70d298 1833 }
8dd11f55
PK
1834 this._terminal.setgCharset(this._terminal.gcharset, cs);
1835 this._terminal.gcharset = null;
1836 this._state = ParserState.NORMAL;
cd70d298 1837 break;
8dd11f55
PK
1838 case ParserState.OSC:
1839 if (ch === EscapeSequences_1.C0.ESC || ch === EscapeSequences_1.C0.BEL) {
1840 if (ch === EscapeSequences_1.C0.ESC)
1841 this._position++;
1842 this._terminal.params.push(this._terminal.currentParam);
1843 switch (this._terminal.params[0]) {
1844 case 0:
1845 case 1:
1846 case 2:
1847 if (this._terminal.params[1]) {
1848 this._terminal.title = this._terminal.params[1];
1849 this._terminal.handleTitle(this._terminal.title);
1850 }
1851 break;
1852 case 3:
1853 break;
1854 case 4:
1855 case 5:
1856 break;
1857 case 10:
1858 case 11:
1859 case 12:
1860 case 13:
1861 case 14:
1862 case 15:
1863 case 16:
1864 case 17:
1865 case 18:
1866 case 19:
1867 break;
1868 case 46:
1869 break;
1870 case 50:
1871 break;
1872 case 51:
1873 break;
1874 case 52:
1875 break;
1876 case 104:
1877 case 105:
1878 case 110:
1879 case 111:
1880 case 112:
1881 case 113:
1882 case 114:
1883 case 115:
1884 case 116:
1885 case 117:
1886 case 118:
1887 break;
cd70d298 1888 }
8dd11f55
PK
1889 this._terminal.params = [];
1890 this._terminal.currentParam = 0;
1891 this._state = ParserState.NORMAL;
1892 }
1893 else {
1894 if (!this._terminal.params.length) {
1895 if (ch >= '0' && ch <= '9') {
1896 this._terminal.currentParam =
1897 this._terminal.currentParam * 10 + ch.charCodeAt(0) - 48;
1898 }
1899 else if (ch === ';') {
1900 this._terminal.params.push(this._terminal.currentParam);
1901 this._terminal.currentParam = '';
1902 }
cd70d298 1903 }
8dd11f55
PK
1904 else {
1905 this._terminal.currentParam += ch;
cd70d298 1906 }
8dd11f55
PK
1907 }
1908 break;
1909 case ParserState.CSI_PARAM:
1910 if (ch in csiParamStateHandler) {
1911 csiParamStateHandler[ch](this);
cd70d298 1912 break;
8dd11f55
PK
1913 }
1914 this.finalizeParam();
1915 this._state = ParserState.CSI;
1916 case ParserState.CSI:
1917 if (ch in csiStateHandler) {
1918 csiStateHandler[ch](this._inputHandler, this._terminal.params, this._terminal.prefix, this._terminal.postfix, this);
1919 }
1920 else {
1921 this._terminal.error('Unknown CSI code: %s.', ch);
1922 }
1923 this._state = ParserState.NORMAL;
1924 this._terminal.prefix = '';
1925 this._terminal.postfix = '';
1926 break;
1927 case ParserState.DCS:
1928 if (ch === EscapeSequences_1.C0.ESC || ch === EscapeSequences_1.C0.BEL) {
1929 if (ch === EscapeSequences_1.C0.ESC)
1930 this._position++;
1931 switch (this._terminal.prefix) {
1932 case '':
1933 break;
1934 case '$q':
1935 var pt = this._terminal.currentParam, valid = false;
1936 switch (pt) {
1937 case '"q':
1938 pt = '0"q';
1939 break;
1940 case '"p':
1941 pt = '61"p';
1942 break;
1943 case 'r':
1944 pt = ''
1945 + (this._terminal.scrollTop + 1)
1946 + ';'
1947 + (this._terminal.scrollBottom + 1)
1948 + 'r';
1949 break;
1950 case 'm':
1951 pt = '0m';
1952 break;
1953 default:
1954 this._terminal.error('Unknown DCS Pt: %s.', pt);
1955 pt = '';
1956 break;
1957 }
1958 this._terminal.send(EscapeSequences_1.C0.ESC + 'P' + +valid + '$r' + pt + EscapeSequences_1.C0.ESC + '\\');
1959 break;
1960 case '+p':
1961 break;
1962 case '+q':
1963 pt = this._terminal.currentParam
1964 , valid = false;
1965 this._terminal.send(EscapeSequences_1.C0.ESC + 'P' + +valid + '+r' + pt + EscapeSequences_1.C0.ESC + '\\');
1966 break;
1967 default:
1968 this._terminal.error('Unknown DCS prefix: %s.', this._terminal.prefix);
cd70d298
PK
1969 break;
1970 }
8dd11f55
PK
1971 this._terminal.currentParam = 0;
1972 this._terminal.prefix = '';
1973 this._state = ParserState.NORMAL;
cd70d298 1974 }
8dd11f55
PK
1975 else if (!this._terminal.currentParam) {
1976 if (!this._terminal.prefix && ch !== '$' && ch !== '+') {
1977 this._terminal.currentParam = ch;
1978 }
1979 else if (this._terminal.prefix.length === 2) {
1980 this._terminal.currentParam = ch;
1981 }
1982 else {
1983 this._terminal.prefix += ch;
1984 }
cd70d298
PK
1985 }
1986 else {
8dd11f55 1987 this._terminal.currentParam += ch;
cd70d298 1988 }
8dd11f55
PK
1989 break;
1990 case ParserState.IGNORE:
1991 if (ch === EscapeSequences_1.C0.ESC || ch === EscapeSequences_1.C0.BEL) {
1992 if (ch === EscapeSequences_1.C0.ESC)
1993 this._position++;
1994 this._state = ParserState.NORMAL;
1995 }
1996 break;
1997 }
1998 }
1999 };
2000 Parser.prototype.setState = function (state) {
2001 this._state = state;
2002 };
2003 Parser.prototype.setPrefix = function (prefix) {
2004 this._terminal.prefix = prefix;
2005 };
2006 Parser.prototype.setPostfix = function (postfix) {
2007 this._terminal.postfix = postfix;
2008 };
2009 Parser.prototype.setParam = function (param) {
2010 this._terminal.currentParam = param;
2011 };
2012 Parser.prototype.getParam = function () {
2013 return this._terminal.currentParam;
2014 };
2015 Parser.prototype.finalizeParam = function () {
2016 this._terminal.params.push(this._terminal.currentParam);
2017 this._terminal.currentParam = 0;
2018 };
2019 Parser.prototype.skipNextChar = function () {
2020 this._position++;
2021 };
2022 return Parser;
2023}());
2024exports.Parser = Parser;
2025
8fd44266
PK
2026
2027
b1619e42 2028},{"./Charsets":1,"./EscapeSequences":3}],8:[function(require,module,exports){
8dd11f55 2029"use strict";
d2f8f9dc 2030Object.defineProperty(exports, "__esModule", { value: true });
8dd11f55
PK
2031var MAX_REFRESH_FRAME_SKIP = 5;
2032var FLAGS;
2033(function (FLAGS) {
2034 FLAGS[FLAGS["BOLD"] = 1] = "BOLD";
2035 FLAGS[FLAGS["UNDERLINE"] = 2] = "UNDERLINE";
2036 FLAGS[FLAGS["BLINK"] = 4] = "BLINK";
2037 FLAGS[FLAGS["INVERSE"] = 8] = "INVERSE";
2038 FLAGS[FLAGS["INVISIBLE"] = 16] = "INVISIBLE";
2039})(FLAGS || (FLAGS = {}));
2040;
2041var brokenBold = null;
2042var Renderer = (function () {
2043 function Renderer(_terminal) {
2044 this._terminal = _terminal;
2045 this._refreshRowsQueue = [];
2046 this._refreshFramesSkipped = 0;
2047 this._refreshAnimationFrame = null;
2048 if (brokenBold === null) {
d2f8f9dc 2049 brokenBold = checkBoldBroken(this._terminal.element);
8dd11f55
PK
2050 }
2051 }
2052 Renderer.prototype.queueRefresh = function (start, end) {
2053 this._refreshRowsQueue.push({ start: start, end: end });
2054 if (!this._refreshAnimationFrame) {
2055 this._refreshAnimationFrame = window.requestAnimationFrame(this._refreshLoop.bind(this));
2056 }
2057 };
2058 Renderer.prototype._refreshLoop = function () {
2059 var skipFrame = this._terminal.writeBuffer.length > 0 && this._refreshFramesSkipped++ <= MAX_REFRESH_FRAME_SKIP;
2060 if (skipFrame) {
2061 this._refreshAnimationFrame = window.requestAnimationFrame(this._refreshLoop.bind(this));
2062 return;
2063 }
2064 this._refreshFramesSkipped = 0;
2065 var start;
2066 var end;
2067 if (this._refreshRowsQueue.length > 4) {
2068 start = 0;
2069 end = this._terminal.rows - 1;
2070 }
2071 else {
2072 start = this._refreshRowsQueue[0].start;
2073 end = this._refreshRowsQueue[0].end;
2074 for (var i = 1; i < this._refreshRowsQueue.length; i++) {
2075 if (this._refreshRowsQueue[i].start < start) {
2076 start = this._refreshRowsQueue[i].start;
cd70d298 2077 }
8dd11f55
PK
2078 if (this._refreshRowsQueue[i].end > end) {
2079 end = this._refreshRowsQueue[i].end;
cd70d298 2080 }
8dd11f55 2081 }
cd70d298 2082 }
8dd11f55
PK
2083 this._refreshRowsQueue = [];
2084 this._refreshAnimationFrame = null;
2085 this._refresh(start, end);
cd70d298 2086 };
8dd11f55
PK
2087 Renderer.prototype._refresh = function (start, end) {
2088 var x, y, i, line, out, ch, ch_width, width, data, attr, bg, fg, flags, row, parent, focused = document.activeElement;
2089 if (end - start >= this._terminal.rows / 2) {
2090 parent = this._terminal.element.parentNode;
2091 if (parent) {
2092 this._terminal.element.removeChild(this._terminal.rowContainer);
2093 }
2094 }
2095 width = this._terminal.cols;
2096 y = start;
2097 if (end >= this._terminal.rows) {
2098 this._terminal.log('`end` is too large. Most likely a bad CSR.');
2099 end = this._terminal.rows - 1;
2100 }
2101 for (; y <= end; y++) {
2102 row = y + this._terminal.ydisp;
2103 line = this._terminal.lines.get(row);
2104 if (!line || !this._terminal.children[y]) {
2105 continue;
cd70d298 2106 }
8dd11f55
PK
2107 out = '';
2108 if (this._terminal.y === y - (this._terminal.ybase - this._terminal.ydisp)
2109 && this._terminal.cursorState
2110 && !this._terminal.cursorHidden) {
2111 x = this._terminal.x;
cd70d298
PK
2112 }
2113 else {
8dd11f55 2114 x = -1;
cd70d298 2115 }
8dd11f55
PK
2116 attr = this._terminal.defAttr;
2117 i = 0;
2118 for (; i < width; i++) {
2119 if (!line[i]) {
2120 continue;
cd70d298 2121 }
8dd11f55
PK
2122 data = line[i][0];
2123 ch = line[i][1];
2124 ch_width = line[i][2];
2125 if (!ch_width)
2126 continue;
2127 if (i === x)
2128 data = -1;
2129 if (data !== attr) {
2130 if (attr !== this._terminal.defAttr) {
2131 out += '</span>';
2132 }
2133 if (data !== this._terminal.defAttr) {
2134 if (data === -1) {
2135 out += '<span class="reverse-video terminal-cursor">';
2136 }
2137 else {
2138 var classNames = [];
2139 bg = data & 0x1ff;
2140 fg = (data >> 9) & 0x1ff;
2141 flags = data >> 18;
2142 if (flags & FLAGS.BOLD) {
2143 if (!brokenBold) {
2144 classNames.push('xterm-bold');
2145 }
2146 if (fg < 8)
2147 fg += 8;
2148 }
2149 if (flags & FLAGS.UNDERLINE) {
2150 classNames.push('xterm-underline');
2151 }
2152 if (flags & FLAGS.BLINK) {
2153 classNames.push('xterm-blink');
2154 }
2155 if (flags & FLAGS.INVERSE) {
2156 bg = [fg, fg = bg][0];
2157 if ((flags & 1) && fg < 8)
2158 fg += 8;
2159 }
2160 if (flags & FLAGS.INVISIBLE) {
2161 classNames.push('xterm-hidden');
2162 }
2163 if (flags & FLAGS.INVERSE) {
2164 if (bg === 257) {
2165 bg = 15;
2166 }
2167 if (fg === 256) {
2168 fg = 0;
2169 }
2170 }
2171 if (bg < 256) {
2172 classNames.push('xterm-bg-color-' + bg);
2173 }
2174 if (fg < 256) {
2175 classNames.push('xterm-color-' + fg);
2176 }
2177 out += '<span';
2178 if (classNames.length) {
2179 out += ' class="' + classNames.join(' ') + '"';
2180 }
2181 out += '>';
2182 }
2183 }
cd70d298 2184 }
8dd11f55
PK
2185 if (ch_width === 2) {
2186 out += '<span class="xterm-wide-char">';
cd70d298 2187 }
8dd11f55
PK
2188 switch (ch) {
2189 case '&':
2190 out += '&amp;';
2191 break;
2192 case '<':
2193 out += '&lt;';
2194 break;
2195 case '>':
2196 out += '&gt;';
2197 break;
2198 default:
2199 if (ch <= ' ') {
2200 out += '&nbsp;';
2201 }
2202 else {
2203 out += ch;
2204 }
2205 break;
2206 }
2207 if (ch_width === 2) {
2208 out += '</span>';
2209 }
2210 attr = data;
cd70d298 2211 }
8dd11f55
PK
2212 if (attr !== this._terminal.defAttr) {
2213 out += '</span>';
cd70d298 2214 }
8dd11f55
PK
2215 this._terminal.children[y].innerHTML = out;
2216 }
2217 if (parent) {
2218 this._terminal.element.appendChild(this._terminal.rowContainer);
2219 }
2220 this._terminal.emit('refresh', { element: this._terminal.element, start: start, end: end });
2221 };
2222 ;
2223 return Renderer;
2224}());
2225exports.Renderer = Renderer;
d2f8f9dc
PK
2226function checkBoldBroken(terminal) {
2227 var document = terminal.ownerDocument;
8dd11f55
PK
2228 var el = document.createElement('span');
2229 el.innerHTML = 'hello world';
d2f8f9dc
PK
2230 terminal.appendChild(el);
2231 var w1 = el.offsetWidth;
2232 var h1 = el.offsetHeight;
8dd11f55 2233 el.style.fontWeight = 'bold';
d2f8f9dc
PK
2234 var w2 = el.offsetWidth;
2235 var h2 = el.offsetHeight;
2236 terminal.removeChild(el);
2237 return w1 !== w2 || h1 !== h2;
8dd11f55
PK
2238}
2239
8fd44266
PK
2240
2241
b1619e42 2242},{}],9:[function(require,module,exports){
8dd11f55 2243"use strict";
d2f8f9dc 2244Object.defineProperty(exports, "__esModule", { value: true });
8dd11f55
PK
2245var Viewport = (function () {
2246 function Viewport(terminal, viewportElement, scrollArea, charMeasure) {
8fd44266 2247 var _this = this;
8dd11f55
PK
2248 this.terminal = terminal;
2249 this.viewportElement = viewportElement;
2250 this.scrollArea = scrollArea;
2251 this.charMeasure = charMeasure;
2252 this.currentRowHeight = 0;
2253 this.lastRecordedBufferLength = 0;
2254 this.lastRecordedViewportHeight = 0;
2255 this.terminal.on('scroll', this.syncScrollArea.bind(this));
2256 this.terminal.on('resize', this.syncScrollArea.bind(this));
2257 this.viewportElement.addEventListener('scroll', this.onScroll.bind(this));
8fd44266 2258 setTimeout(function () { return _this.syncScrollArea(); }, 0);
8dd11f55
PK
2259 }
2260 Viewport.prototype.refresh = function () {
2261 if (this.charMeasure.height > 0) {
2262 var rowHeightChanged = this.charMeasure.height !== this.currentRowHeight;
2263 if (rowHeightChanged) {
2264 this.currentRowHeight = this.charMeasure.height;
2265 this.viewportElement.style.lineHeight = this.charMeasure.height + 'px';
2266 this.terminal.rowContainer.style.lineHeight = this.charMeasure.height + 'px';
cd70d298 2267 }
8dd11f55
PK
2268 var viewportHeightChanged = this.lastRecordedViewportHeight !== this.terminal.rows;
2269 if (rowHeightChanged || viewportHeightChanged) {
2270 this.lastRecordedViewportHeight = this.terminal.rows;
2271 this.viewportElement.style.height = this.charMeasure.height * this.terminal.rows + 'px';
cd70d298 2272 }
8dd11f55
PK
2273 this.scrollArea.style.height = (this.charMeasure.height * this.lastRecordedBufferLength) + 'px';
2274 }
2275 };
2276 Viewport.prototype.syncScrollArea = function () {
2277 if (this.lastRecordedBufferLength !== this.terminal.lines.length) {
2278 this.lastRecordedBufferLength = this.terminal.lines.length;
2279 this.refresh();
2280 }
2281 else if (this.lastRecordedViewportHeight !== this.terminal.rows) {
2282 this.refresh();
2283 }
2284 else {
2285 if (this.charMeasure.height !== this.currentRowHeight) {
2286 this.refresh();
cd70d298 2287 }
8dd11f55
PK
2288 }
2289 var scrollTop = this.terminal.ydisp * this.currentRowHeight;
2290 if (this.viewportElement.scrollTop !== scrollTop) {
2291 this.viewportElement.scrollTop = scrollTop;
2292 }
2293 };
2294 Viewport.prototype.onScroll = function (ev) {
2295 var newRow = Math.round(this.viewportElement.scrollTop / this.currentRowHeight);
2296 var diff = newRow - this.terminal.ydisp;
2297 this.terminal.scrollDisp(diff, true);
2298 };
2299 Viewport.prototype.onWheel = function (ev) {
2300 if (ev.deltaY === 0) {
2301 return;
2302 }
2303 var multiplier = 1;
2304 if (ev.deltaMode === WheelEvent.DOM_DELTA_LINE) {
2305 multiplier = this.currentRowHeight;
2306 }
2307 else if (ev.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
2308 multiplier = this.currentRowHeight * this.terminal.rows;
2309 }
2310 this.viewportElement.scrollTop += ev.deltaY * multiplier;
2311 ev.preventDefault();
2312 };
2313 ;
2314 return Viewport;
2315}());
2316exports.Viewport = Viewport;
2317
8fd44266
PK
2318
2319
b1619e42 2320},{}],10:[function(require,module,exports){
8dd11f55 2321"use strict";
d2f8f9dc 2322Object.defineProperty(exports, "__esModule", { value: true });
8dd11f55
PK
2323function prepareTextForClipboard(text) {
2324 var space = String.fromCharCode(32), nonBreakingSpace = String.fromCharCode(160), allNonBreakingSpaces = new RegExp(nonBreakingSpace, 'g'), processedText = text.split('\n').map(function (line) {
2325 var processedLine = line.replace(/\s+$/g, '').replace(allNonBreakingSpaces, space);
2326 return processedLine;
2327 }).join('\n');
2328 return processedText;
2329}
2330exports.prepareTextForClipboard = prepareTextForClipboard;
2331function copyHandler(ev, term) {
2332 var copiedText = window.getSelection().toString(), text = prepareTextForClipboard(copiedText);
2333 if (term.browser.isMSIE) {
2334 window.clipboardData.setData('Text', text);
2335 }
2336 else {
2337 ev.clipboardData.setData('text/plain', text);
2338 }
2339 ev.preventDefault();
2340}
2341exports.copyHandler = copyHandler;
2342function pasteHandler(ev, term) {
2343 ev.stopPropagation();
2344 var text;
2345 var dispatchPaste = function (text) {
2346 term.handler(text);
2347 term.textarea.value = '';
2348 return term.cancel(ev);
2349 };
2350 if (term.browser.isMSIE) {
2351 if (window.clipboardData) {
2352 text = window.clipboardData.getData('Text');
2353 dispatchPaste(text);
2354 }
2355 }
2356 else {
2357 if (ev.clipboardData) {
2358 text = ev.clipboardData.getData('text/plain');
2359 dispatchPaste(text);
2360 }
2361 }
2362}
2363exports.pasteHandler = pasteHandler;
2364function rightClickHandler(ev, term) {
2365 var s = document.getSelection(), selectedText = prepareTextForClipboard(s.toString()), clickIsOnSelection = false, x = ev.clientX, y = ev.clientY;
2366 if (s.rangeCount) {
2367 var r = s.getRangeAt(0), cr = r.getClientRects();
2368 for (var i = 0; i < cr.length; i++) {
2369 var rect = cr[i];
2370 clickIsOnSelection = ((x > rect.left) && (x < rect.right) &&
2371 (y > rect.top) && (y < rect.bottom));
2372 if (clickIsOnSelection) {
2373 break;
cd70d298 2374 }
8dd11f55
PK
2375 }
2376 if (selectedText.match(/^\s$/) || !selectedText.length) {
2377 clickIsOnSelection = false;
2378 }
2379 }
2380 if (!clickIsOnSelection) {
2381 term.textarea.style.position = 'fixed';
2382 term.textarea.style.width = '20px';
2383 term.textarea.style.height = '20px';
2384 term.textarea.style.left = (x - 10) + 'px';
2385 term.textarea.style.top = (y - 10) + 'px';
2386 term.textarea.style.zIndex = '1000';
2387 term.textarea.focus();
2388 setTimeout(function () {
2389 term.textarea.style.position = null;
2390 term.textarea.style.width = null;
2391 term.textarea.style.height = null;
2392 term.textarea.style.left = null;
2393 term.textarea.style.top = null;
2394 term.textarea.style.zIndex = null;
2395 }, 4);
2396 }
2397}
2398exports.rightClickHandler = rightClickHandler;
2399
8fd44266
PK
2400
2401
b1619e42 2402},{}],11:[function(require,module,exports){
8dd11f55 2403"use strict";
d2f8f9dc 2404Object.defineProperty(exports, "__esModule", { value: true });
8dd11f55
PK
2405var Generic_1 = require("./Generic");
2406var isNode = (typeof navigator === 'undefined') ? true : false;
2407var userAgent = (isNode) ? 'node' : navigator.userAgent;
2408var platform = (isNode) ? 'node' : navigator.platform;
2409exports.isFirefox = !!~userAgent.indexOf('Firefox');
2410exports.isMSIE = !!~userAgent.indexOf('MSIE') || !!~userAgent.indexOf('Trident');
2411exports.isMac = Generic_1.contains(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], platform);
2412exports.isIpad = platform === 'iPad';
2413exports.isIphone = platform === 'iPhone';
2414exports.isMSWindows = Generic_1.contains(['Windows', 'Win16', 'Win32', 'WinCE'], platform);
2415
8fd44266
PK
2416
2417
b1619e42 2418},{"./Generic":14}],12:[function(require,module,exports){
8dd11f55 2419"use strict";
d2f8f9dc
PK
2420var __extends = (this && this.__extends) || (function () {
2421 var extendStatics = Object.setPrototypeOf ||
2422 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
2423 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
2424 return function (d, b) {
2425 extendStatics(d, b);
2426 function __() { this.constructor = d; }
2427 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
2428 };
2429})();
2430Object.defineProperty(exports, "__esModule", { value: true });
8dd11f55
PK
2431var EventEmitter_js_1 = require("../EventEmitter.js");
2432var CharMeasure = (function (_super) {
2433 __extends(CharMeasure, _super);
b1619e42 2434 function CharMeasure(document, parentElement) {
8dd11f55 2435 var _this = _super.call(this) || this;
b1619e42 2436 _this._document = document;
8dd11f55
PK
2437 _this._parentElement = parentElement;
2438 return _this;
2439 }
2440 Object.defineProperty(CharMeasure.prototype, "width", {
2441 get: function () {
2442 return this._width;
2443 },
2444 enumerable: true,
2445 configurable: true
2446 });
2447 Object.defineProperty(CharMeasure.prototype, "height", {
2448 get: function () {
2449 return this._height;
2450 },
2451 enumerable: true,
2452 configurable: true
2453 });
2454 CharMeasure.prototype.measure = function () {
2455 var _this = this;
2456 if (!this._measureElement) {
b1619e42 2457 this._measureElement = this._document.createElement('span');
8dd11f55
PK
2458 this._measureElement.style.position = 'absolute';
2459 this._measureElement.style.top = '0';
2460 this._measureElement.style.left = '-9999em';
2461 this._measureElement.textContent = 'W';
b1619e42 2462 this._measureElement.setAttribute('aria-hidden', 'true');
8dd11f55
PK
2463 this._parentElement.appendChild(this._measureElement);
2464 setTimeout(function () { return _this._doMeasure(); }, 0);
2465 }
2466 else {
2467 this._doMeasure();
2468 }
2469 };
2470 CharMeasure.prototype._doMeasure = function () {
2471 var geometry = this._measureElement.getBoundingClientRect();
2472 if (geometry.width === 0 || geometry.height === 0) {
2473 return;
2474 }
2475 if (this._width !== geometry.width || this._height !== geometry.height) {
2476 this._width = geometry.width;
2477 this._height = geometry.height;
2478 this.emit('charsizechanged');
2479 }
2480 };
2481 return CharMeasure;
2482}(EventEmitter_js_1.EventEmitter));
2483exports.CharMeasure = CharMeasure;
2484
8fd44266
PK
2485
2486
b1619e42 2487},{"../EventEmitter.js":4}],13:[function(require,module,exports){
8dd11f55 2488"use strict";
d2f8f9dc 2489Object.defineProperty(exports, "__esModule", { value: true });
8dd11f55
PK
2490var CircularList = (function () {
2491 function CircularList(maxLength) {
2492 this._array = new Array(maxLength);
2493 this._startIndex = 0;
2494 this._length = 0;
2495 }
2496 Object.defineProperty(CircularList.prototype, "maxLength", {
2497 get: function () {
2498 return this._array.length;
2499 },
2500 set: function (newMaxLength) {
2501 var newArray = new Array(newMaxLength);
2502 for (var i = 0; i < Math.min(newMaxLength, this.length); i++) {
2503 newArray[i] = this._array[this._getCyclicIndex(i)];
2504 }
2505 this._array = newArray;
2506 this._startIndex = 0;
2507 },
2508 enumerable: true,
2509 configurable: true
2510 });
2511 Object.defineProperty(CircularList.prototype, "length", {
2512 get: function () {
2513 return this._length;
2514 },
2515 set: function (newLength) {
2516 if (newLength > this._length) {
2517 for (var i = this._length; i < newLength; i++) {
2518 this._array[i] = undefined;
2519 }
cd70d298 2520 }
8dd11f55
PK
2521 this._length = newLength;
2522 },
2523 enumerable: true,
2524 configurable: true
2525 });
2526 Object.defineProperty(CircularList.prototype, "forEach", {
2527 get: function () {
2528 return this._array.forEach;
2529 },
2530 enumerable: true,
2531 configurable: true
2532 });
2533 CircularList.prototype.get = function (index) {
2534 return this._array[this._getCyclicIndex(index)];
2535 };
2536 CircularList.prototype.set = function (index, value) {
2537 this._array[this._getCyclicIndex(index)] = value;
2538 };
2539 CircularList.prototype.push = function (value) {
2540 this._array[this._getCyclicIndex(this._length)] = value;
2541 if (this._length === this.maxLength) {
2542 this._startIndex++;
2543 if (this._startIndex === this.maxLength) {
2544 this._startIndex = 0;
cd70d298 2545 }
8dd11f55
PK
2546 }
2547 else {
2548 this._length++;
2549 }
2550 };
2551 CircularList.prototype.pop = function () {
2552 return this._array[this._getCyclicIndex(this._length-- - 1)];
2553 };
2554 CircularList.prototype.splice = function (start, deleteCount) {
2555 var items = [];
2556 for (var _i = 2; _i < arguments.length; _i++) {
2557 items[_i - 2] = arguments[_i];
2558 }
2559 if (deleteCount) {
2560 for (var i = start; i < this._length - deleteCount; i++) {
2561 this._array[this._getCyclicIndex(i)] = this._array[this._getCyclicIndex(i + deleteCount)];
cd70d298 2562 }
8dd11f55
PK
2563 this._length -= deleteCount;
2564 }
2565 if (items && items.length) {
2566 for (var i = this._length - 1; i >= start; i--) {
2567 this._array[this._getCyclicIndex(i + items.length)] = this._array[this._getCyclicIndex(i)];
cd70d298 2568 }
8dd11f55
PK
2569 for (var i = 0; i < items.length; i++) {
2570 this._array[this._getCyclicIndex(start + i)] = items[i];
cd70d298 2571 }
8dd11f55
PK
2572 if (this._length + items.length > this.maxLength) {
2573 this._startIndex += (this._length + items.length) - this.maxLength;
2574 this._length = this.maxLength;
cd70d298
PK
2575 }
2576 else {
8dd11f55 2577 this._length += items.length;
cd70d298 2578 }
8dd11f55
PK
2579 }
2580 };
2581 CircularList.prototype.trimStart = function (count) {
2582 if (count > this._length) {
2583 count = this._length;
2584 }
2585 this._startIndex += count;
2586 this._length -= count;
2587 };
2588 CircularList.prototype.shiftElements = function (start, count, offset) {
2589 if (count <= 0) {
2590 return;
2591 }
2592 if (start < 0 || start >= this._length) {
2593 throw new Error('start argument out of range');
2594 }
2595 if (start + offset < 0) {
2596 throw new Error('Cannot shift elements in list beyond index 0');
2597 }
2598 if (offset > 0) {
2599 for (var i = count - 1; i >= 0; i--) {
2600 this.set(start + i + offset, this.get(start + i));
cd70d298 2601 }
8dd11f55
PK
2602 var expandListBy = (start + count + offset) - this._length;
2603 if (expandListBy > 0) {
2604 this._length += expandListBy;
2605 while (this._length > this.maxLength) {
2606 this._length--;
2607 this._startIndex++;
2608 }
cd70d298 2609 }
8dd11f55
PK
2610 }
2611 else {
2612 for (var i = 0; i < count; i++) {
2613 this.set(start + i + offset, this.get(start + i));
cd70d298 2614 }
8dd11f55
PK
2615 }
2616 };
2617 CircularList.prototype._getCyclicIndex = function (index) {
2618 return (this._startIndex + index) % this.maxLength;
2619 };
2620 return CircularList;
2621}());
2622exports.CircularList = CircularList;
2623
8fd44266
PK
2624
2625
b1619e42 2626},{}],14:[function(require,module,exports){
8dd11f55 2627"use strict";
d2f8f9dc 2628Object.defineProperty(exports, "__esModule", { value: true });
8dd11f55
PK
2629function contains(arr, el) {
2630 return arr.indexOf(el) >= 0;
2631}
2632exports.contains = contains;
2633;
2634
8fd44266
PK
2635
2636
b1619e42 2637},{}],15:[function(require,module,exports){
8dd11f55 2638"use strict";
d2f8f9dc 2639Object.defineProperty(exports, "__esModule", { value: true });
8dd11f55
PK
2640var CompositionHelper_1 = require("./CompositionHelper");
2641var EventEmitter_1 = require("./EventEmitter");
2642var Viewport_1 = require("./Viewport");
2643var Clipboard_1 = require("./handlers/Clipboard");
2644var CircularList_1 = require("./utils/CircularList");
2645var EscapeSequences_1 = require("./EscapeSequences");
2646var InputHandler_1 = require("./InputHandler");
2647var Parser_1 = require("./Parser");
2648var Renderer_1 = require("./Renderer");
b1619e42 2649var Linkifier_1 = require("./Linkifier");
8dd11f55
PK
2650var CharMeasure_1 = require("./utils/CharMeasure");
2651var Browser = require("./utils/Browser");
2652var document = (typeof window != 'undefined') ? window.document : null;
2653var WRITE_BUFFER_PAUSE_THRESHOLD = 5;
2654var WRITE_BATCH_SIZE = 300;
d2f8f9dc 2655var CURSOR_BLINK_INTERVAL = 600;
8dd11f55
PK
2656function Terminal(options) {
2657 var self = this;
2658 if (!(this instanceof Terminal)) {
2659 return new Terminal(arguments[0], arguments[1], arguments[2]);
2660 }
2661 self.browser = Browser;
2662 self.cancel = Terminal.cancel;
2663 EventEmitter_1.EventEmitter.call(this);
2664 if (typeof options === 'number') {
2665 options = {
2666 cols: arguments[0],
2667 rows: arguments[1],
2668 handler: arguments[2]
2669 };
2670 }
2671 options = options || {};
2672 Object.keys(Terminal.defaults).forEach(function (key) {
2673 if (options[key] == null) {
2674 options[key] = Terminal.options[key];
2675 if (Terminal[key] !== Terminal.defaults[key]) {
2676 options[key] = Terminal[key];
cd70d298 2677 }
8dd11f55
PK
2678 }
2679 self[key] = options[key];
2680 });
2681 if (options.colors.length === 8) {
2682 options.colors = options.colors.concat(Terminal._colors.slice(8));
2683 }
2684 else if (options.colors.length === 16) {
2685 options.colors = options.colors.concat(Terminal._colors.slice(16));
2686 }
2687 else if (options.colors.length === 10) {
2688 options.colors = options.colors.slice(0, -2).concat(Terminal._colors.slice(8, -2), options.colors.slice(-2));
2689 }
2690 else if (options.colors.length === 18) {
2691 options.colors = options.colors.concat(Terminal._colors.slice(16, -2), options.colors.slice(-2));
2692 }
2693 this.colors = options.colors;
2694 this.options = options;
2695 this.parent = options.body || options.parent || (document ? document.getElementsByTagName('body')[0] : null);
2696 this.cols = options.cols || options.geometry[0];
2697 this.rows = options.rows || options.geometry[1];
2698 this.geometry = [this.cols, this.rows];
2699 if (options.handler) {
2700 this.on('data', options.handler);
2701 }
2702 this.ybase = 0;
2703 this.ydisp = 0;
2704 this.x = 0;
2705 this.y = 0;
2706 this.cursorState = 0;
2707 this.cursorHidden = false;
2708 this.convertEol;
2709 this.queue = '';
2710 this.scrollTop = 0;
2711 this.scrollBottom = this.rows - 1;
2712 this.customKeydownHandler = null;
d2f8f9dc 2713 this.cursorBlinkInterval = null;
8dd11f55
PK
2714 this.applicationKeypad = false;
2715 this.applicationCursor = false;
2716 this.originMode = false;
2717 this.insertMode = false;
2718 this.wraparoundMode = true;
2719 this.normal = null;
2720 this.charset = null;
2721 this.gcharset = null;
2722 this.glevel = 0;
2723 this.charsets = [null];
2724 this.decLocator;
2725 this.x10Mouse;
2726 this.vt200Mouse;
2727 this.vt300Mouse;
2728 this.normalMouse;
2729 this.mouseEvents;
2730 this.sendFocus;
2731 this.utfMouse;
2732 this.sgrMouse;
2733 this.urxvtMouse;
2734 this.element;
2735 this.children;
2736 this.refreshStart;
2737 this.refreshEnd;
2738 this.savedX;
2739 this.savedY;
2740 this.savedCols;
2741 this.readable = true;
2742 this.writable = true;
2743 this.defAttr = (0 << 18) | (257 << 9) | (256 << 0);
2744 this.curAttr = this.defAttr;
2745 this.params = [];
2746 this.currentParam = 0;
2747 this.prefix = '';
2748 this.postfix = '';
2749 this.inputHandler = new InputHandler_1.InputHandler(this);
2750 this.parser = new Parser_1.Parser(this.inputHandler, this);
2751 this.renderer = this.renderer || null;
d2f8f9dc 2752 this.linkifier = this.linkifier || new Linkifier_1.Linkifier();
8dd11f55
PK
2753 this.writeBuffer = [];
2754 this.writeInProgress = false;
2755 this.xoffSentToCatchUp = false;
2756 this.writeStopped = false;
2757 this.surrogate_high = '';
2758 this.lines = new CircularList_1.CircularList(this.scrollback);
2759 var i = this.rows;
2760 while (i--) {
2761 this.lines.push(this.blankLine());
2762 }
2763 this.tabs;
2764 this.setupStops();
2765 this.userScrolling = false;
2766}
2767inherits(Terminal, EventEmitter_1.EventEmitter);
2768Terminal.prototype.eraseAttr = function () {
2769 return (this.defAttr & ~0x1ff) | (this.curAttr & 0x1ff);
2770};
2771Terminal.tangoColors = [
2772 '#2e3436',
2773 '#cc0000',
2774 '#4e9a06',
2775 '#c4a000',
2776 '#3465a4',
2777 '#75507b',
2778 '#06989a',
2779 '#d3d7cf',
2780 '#555753',
2781 '#ef2929',
2782 '#8ae234',
2783 '#fce94f',
2784 '#729fcf',
2785 '#ad7fa8',
2786 '#34e2e2',
2787 '#eeeeec'
2788];
2789Terminal.colors = (function () {
2790 var colors = Terminal.tangoColors.slice(), r = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff], i;
2791 i = 0;
2792 for (; i < 216; i++) {
2793 out(r[(i / 36) % 6 | 0], r[(i / 6) % 6 | 0], r[i % 6]);
2794 }
2795 i = 0;
2796 for (; i < 24; i++) {
2797 r = 8 + i * 10;
2798 out(r, r, r);
2799 }
2800 function out(r, g, b) {
2801 colors.push('#' + hex(r) + hex(g) + hex(b));
2802 }
2803 function hex(c) {
2804 c = c.toString(16);
2805 return c.length < 2 ? '0' + c : c;
2806 }
2807 return colors;
2808})();
2809Terminal._colors = Terminal.colors.slice();
2810Terminal.vcolors = (function () {
2811 var out = [], colors = Terminal.colors, i = 0, color;
2812 for (; i < 256; i++) {
2813 color = parseInt(colors[i].substring(1), 16);
2814 out.push([
2815 (color >> 16) & 0xff,
2816 (color >> 8) & 0xff,
2817 color & 0xff
2818 ]);
2819 }
2820 return out;
2821})();
2822Terminal.defaults = {
2823 colors: Terminal.colors,
2824 theme: 'default',
2825 convertEol: false,
2826 termName: 'xterm',
2827 geometry: [80, 24],
2828 cursorBlink: false,
2829 cursorStyle: 'block',
2830 visualBell: false,
2831 popOnBell: false,
2832 scrollback: 1000,
2833 screenKeys: false,
2834 debug: false,
2835 cancelEvents: false,
2836 disableStdin: false,
2837 useFlowControl: false,
2838 tabStopWidth: 8
2839};
2840Terminal.options = {};
2841Terminal.focus = null;
2842each(keys(Terminal.defaults), function (key) {
2843 Terminal[key] = Terminal.defaults[key];
2844 Terminal.options[key] = Terminal.defaults[key];
2845});
2846Terminal.prototype.focus = function () {
2847 return this.textarea.focus();
2848};
2849Terminal.prototype.getOption = function (key, value) {
2850 if (!(key in Terminal.defaults)) {
2851 throw new Error('No option with key "' + key + '"');
2852 }
2853 if (typeof this.options[key] !== 'undefined') {
2854 return this.options[key];
2855 }
2856 return this[key];
2857};
2858Terminal.prototype.setOption = function (key, value) {
2859 if (!(key in Terminal.defaults)) {
2860 throw new Error('No option with key "' + key + '"');
2861 }
2862 switch (key) {
2863 case 'scrollback':
2864 if (this.options[key] !== value) {
2865 if (this.lines.length > value) {
2866 var amountToTrim = this.lines.length - value;
2867 var needsRefresh = (this.ydisp - amountToTrim < 0);
2868 this.lines.trimStart(amountToTrim);
2869 this.ybase = Math.max(this.ybase - amountToTrim, 0);
2870 this.ydisp = Math.max(this.ydisp - amountToTrim, 0);
2871 if (needsRefresh) {
2872 this.refresh(0, this.rows - 1);
2873 }
2874 }
2875 this.lines.maxLength = value;
2876 this.viewport.syncScrollArea();
cd70d298
PK
2877 }
2878 break;
8dd11f55
PK
2879 }
2880 this[key] = value;
2881 this.options[key] = value;
2882 switch (key) {
2883 case 'cursorBlink':
d2f8f9dc 2884 this.setCursorBlinking(value);
cd70d298 2885 break;
8dd11f55
PK
2886 case 'cursorStyle':
2887 this.element.classList.toggle("xterm-cursor-style-underline", value === 'underline');
2888 this.element.classList.toggle("xterm-cursor-style-bar", value === 'bar');
cd70d298 2889 break;
8dd11f55
PK
2890 case 'tabStopWidth':
2891 this.setupStops();
cd70d298 2892 break;
8dd11f55
PK
2893 }
2894};
d2f8f9dc
PK
2895Terminal.prototype.restartCursorBlinking = function () {
2896 this.setCursorBlinking(this.options.cursorBlink);
2897};
2898Terminal.prototype.setCursorBlinking = function (enabled) {
2899 this.element.classList.toggle('xterm-cursor-blink', enabled);
2900 this.clearCursorBlinkingInterval();
2901 if (enabled) {
2902 var self = this;
2903 this.cursorBlinkInterval = setInterval(function () {
2904 self.element.classList.toggle('xterm-cursor-blink-on');
2905 }, CURSOR_BLINK_INTERVAL);
2906 }
2907};
2908Terminal.prototype.clearCursorBlinkingInterval = function () {
2909 this.element.classList.remove('xterm-cursor-blink-on');
2910 if (this.cursorBlinkInterval) {
2911 clearInterval(this.cursorBlinkInterval);
2912 this.cursorBlinkInterval = null;
2913 }
2914};
8dd11f55
PK
2915Terminal.bindFocus = function (term) {
2916 on(term.textarea, 'focus', function (ev) {
2917 if (term.sendFocus) {
2918 term.send(EscapeSequences_1.C0.ESC + '[I');
2919 }
2920 term.element.classList.add('focus');
2921 term.showCursor();
d2f8f9dc 2922 term.restartCursorBlinking.apply(term);
8dd11f55
PK
2923 Terminal.focus = term;
2924 term.emit('focus', { terminal: term });
2925 });
2926};
2927Terminal.prototype.blur = function () {
2928 return this.textarea.blur();
2929};
2930Terminal.bindBlur = function (term) {
2931 on(term.textarea, 'blur', function (ev) {
2932 term.refresh(term.y, term.y);
2933 if (term.sendFocus) {
2934 term.send(EscapeSequences_1.C0.ESC + '[O');
2935 }
2936 term.element.classList.remove('focus');
d2f8f9dc 2937 term.clearCursorBlinkingInterval.apply(term);
8dd11f55
PK
2938 Terminal.focus = null;
2939 term.emit('blur', { terminal: term });
2940 });
2941};
2942Terminal.prototype.initGlobal = function () {
2943 var term = this;
2944 Terminal.bindKeys(this);
2945 Terminal.bindFocus(this);
2946 Terminal.bindBlur(this);
2947 on(this.element, 'copy', function (ev) {
2948 Clipboard_1.copyHandler.call(this, ev, term);
2949 });
2950 on(this.textarea, 'paste', function (ev) {
2951 Clipboard_1.pasteHandler.call(this, ev, term);
2952 });
2953 on(this.element, 'paste', function (ev) {
2954 Clipboard_1.pasteHandler.call(this, ev, term);
2955 });
2956 function rightClickHandlerWrapper(ev) {
2957 Clipboard_1.rightClickHandler.call(this, ev, term);
2958 }
2959 if (term.browser.isFirefox) {
2960 on(this.element, 'mousedown', function (ev) {
2961 if (ev.button == 2) {
2962 rightClickHandlerWrapper(ev);
cd70d298 2963 }
8dd11f55
PK
2964 });
2965 }
2966 else {
2967 on(this.element, 'contextmenu', rightClickHandlerWrapper);
cd70d298 2968 }
cd70d298 2969};
8dd11f55
PK
2970Terminal.bindKeys = function (term) {
2971 on(term.element, 'keydown', function (ev) {
2972 if (document.activeElement != this) {
2973 return;
2974 }
2975 term.keyDown(ev);
2976 }, true);
2977 on(term.element, 'keypress', function (ev) {
2978 if (document.activeElement != this) {
2979 return;
2980 }
2981 term.keyPress(ev);
2982 }, true);
2983 on(term.element, 'keyup', function (ev) {
2984 if (!wasMondifierKeyOnlyEvent(ev)) {
2985 term.focus(term);
2986 }
2987 }, true);
2988 on(term.textarea, 'keydown', function (ev) {
2989 term.keyDown(ev);
2990 }, true);
2991 on(term.textarea, 'keypress', function (ev) {
2992 term.keyPress(ev);
2993 this.value = '';
2994 }, true);
2995 on(term.textarea, 'compositionstart', term.compositionHelper.compositionstart.bind(term.compositionHelper));
2996 on(term.textarea, 'compositionupdate', term.compositionHelper.compositionupdate.bind(term.compositionHelper));
2997 on(term.textarea, 'compositionend', term.compositionHelper.compositionend.bind(term.compositionHelper));
2998 term.on('refresh', term.compositionHelper.updateCompositionElements.bind(term.compositionHelper));
b1619e42
PK
2999 term.on('refresh', function (data) {
3000 term.queueLinkification(data.start, data.end);
3001 });
cd70d298 3002};
8dd11f55
PK
3003Terminal.prototype.insertRow = function (row) {
3004 if (typeof row != 'object') {
3005 row = document.createElement('div');
3006 }
3007 this.rowContainer.appendChild(row);
3008 this.children.push(row);
3009 return row;
3010};
3011Terminal.prototype.open = function (parent) {
3012 var self = this, i = 0, div;
3013 this.parent = parent || this.parent;
3014 if (!this.parent) {
3015 throw new Error('Terminal requires a parent element.');
3016 }
3017 this.context = this.parent.ownerDocument.defaultView;
3018 this.document = this.parent.ownerDocument;
3019 this.body = this.document.getElementsByTagName('body')[0];
3020 this.element = this.document.createElement('div');
3021 this.element.classList.add('terminal');
3022 this.element.classList.add('xterm');
3023 this.element.classList.add('xterm-theme-' + this.theme);
d2f8f9dc 3024 this.setCursorBlinking(this.options.cursorBlink);
8dd11f55
PK
3025 this.element.style.height;
3026 this.element.setAttribute('tabindex', 0);
3027 this.viewportElement = document.createElement('div');
3028 this.viewportElement.classList.add('xterm-viewport');
3029 this.element.appendChild(this.viewportElement);
3030 this.viewportScrollArea = document.createElement('div');
3031 this.viewportScrollArea.classList.add('xterm-scroll-area');
3032 this.viewportElement.appendChild(this.viewportScrollArea);
3033 this.rowContainer = document.createElement('div');
3034 this.rowContainer.classList.add('xterm-rows');
3035 this.element.appendChild(this.rowContainer);
3036 this.children = [];
d2f8f9dc 3037 this.linkifier.attachToDom(document, this.children);
8dd11f55
PK
3038 this.helperContainer = document.createElement('div');
3039 this.helperContainer.classList.add('xterm-helpers');
3040 this.element.appendChild(this.helperContainer);
3041 this.textarea = document.createElement('textarea');
3042 this.textarea.classList.add('xterm-helper-textarea');
3043 this.textarea.setAttribute('autocorrect', 'off');
3044 this.textarea.setAttribute('autocapitalize', 'off');
3045 this.textarea.setAttribute('spellcheck', 'false');
3046 this.textarea.tabIndex = 0;
3047 this.textarea.addEventListener('focus', function () {
3048 self.emit('focus', { terminal: self });
3049 });
3050 this.textarea.addEventListener('blur', function () {
3051 self.emit('blur', { terminal: self });
3052 });
3053 this.helperContainer.appendChild(this.textarea);
3054 this.compositionView = document.createElement('div');
3055 this.compositionView.classList.add('composition-view');
3056 this.compositionHelper = new CompositionHelper_1.CompositionHelper(this.textarea, this.compositionView, this);
3057 this.helperContainer.appendChild(this.compositionView);
3058 this.charSizeStyleElement = document.createElement('style');
3059 this.helperContainer.appendChild(this.charSizeStyleElement);
3060 for (; i < this.rows; i++) {
3061 this.insertRow();
cd70d298 3062 }
8dd11f55 3063 this.parent.appendChild(this.element);
b1619e42 3064 this.charMeasure = new CharMeasure_1.CharMeasure(document, this.helperContainer);
8dd11f55
PK
3065 this.charMeasure.on('charsizechanged', function () {
3066 self.updateCharSizeCSS();
3067 });
3068 this.charMeasure.measure();
3069 this.viewport = new Viewport_1.Viewport(this, this.viewportElement, this.viewportScrollArea, this.charMeasure);
3070 this.renderer = new Renderer_1.Renderer(this);
3071 this.refresh(0, this.rows - 1);
3072 this.initGlobal();
3073 this.focus();
3074 on(this.element, 'click', function () {
3075 var selection = document.getSelection(), collapsed = selection.isCollapsed, isRange = typeof collapsed == 'boolean' ? !collapsed : selection.type == 'Range';
3076 if (!isRange) {
3077 self.focus();
3078 }
3079 });
3080 this.bindMouse();
3081 this.emit('open');
cd70d298 3082};
8dd11f55
PK
3083Terminal.loadAddon = function (addon, callback) {
3084 if (typeof exports === 'object' && typeof module === 'object') {
3085 return require('./addons/' + addon + '/' + addon);
cd70d298 3086 }
8dd11f55
PK
3087 else if (typeof define == 'function') {
3088 return require(['./addons/' + addon + '/' + addon], callback);
cd70d298
PK
3089 }
3090 else {
8dd11f55 3091 console.error('Cannot load a module without a CommonJS or RequireJS environment.');
cd70d298
PK
3092 return false;
3093 }
cd70d298 3094};
8dd11f55
PK
3095Terminal.prototype.updateCharSizeCSS = function () {
3096 this.charSizeStyleElement.textContent = '.xterm-wide-char{width:' + (this.charMeasure.width * 2) + 'px;}';
cd70d298 3097};
8dd11f55
PK
3098Terminal.prototype.bindMouse = function () {
3099 var el = this.element, self = this, pressed = 32;
3100 function sendButton(ev) {
3101 var button, pos;
3102 button = getButton(ev);
3103 pos = getCoords(ev);
3104 if (!pos)
3105 return;
3106 sendEvent(button, pos);
3107 switch (ev.overrideType || ev.type) {
3108 case 'mousedown':
3109 pressed = button;
3110 break;
3111 case 'mouseup':
3112 pressed = 32;
3113 break;
3114 case 'wheel':
3115 break;
cd70d298
PK
3116 }
3117 }
8dd11f55
PK
3118 function sendMove(ev) {
3119 var button = pressed, pos;
3120 pos = getCoords(ev);
3121 if (!pos)
3122 return;
3123 button += 32;
3124 sendEvent(button, pos);
cd70d298 3125 }
8dd11f55
PK
3126 function encode(data, ch) {
3127 if (!self.utfMouse) {
3128 if (ch === 255)
3129 return data.push(0);
3130 if (ch > 127)
3131 ch = 127;
3132 data.push(ch);
3133 }
3134 else {
3135 if (ch === 2047)
3136 return data.push(0);
3137 if (ch < 127) {
3138 data.push(ch);
cd70d298 3139 }
8dd11f55
PK
3140 else {
3141 if (ch > 2047)
3142 ch = 2047;
3143 data.push(0xC0 | (ch >> 6));
3144 data.push(0x80 | (ch & 0x3F));
cd70d298
PK
3145 }
3146 }
3147 }
8dd11f55
PK
3148 function sendEvent(button, pos) {
3149 if (self.vt300Mouse) {
3150 button &= 3;
3151 pos.x -= 32;
3152 pos.y -= 32;
3153 var data = EscapeSequences_1.C0.ESC + '[24';
3154 if (button === 0)
3155 data += '1';
3156 else if (button === 1)
3157 data += '3';
3158 else if (button === 2)
3159 data += '5';
3160 else if (button === 3)
3161 return;
3162 else
3163 data += '0';
3164 data += '~[' + pos.x + ',' + pos.y + ']\r';
3165 self.send(data);
3166 return;
3167 }
3168 if (self.decLocator) {
3169 button &= 3;
3170 pos.x -= 32;
3171 pos.y -= 32;
3172 if (button === 0)
3173 button = 2;
3174 else if (button === 1)
3175 button = 4;
3176 else if (button === 2)
3177 button = 6;
3178 else if (button === 3)
3179 button = 3;
3180 self.send(EscapeSequences_1.C0.ESC + '['
3181 + button
3182 + ';'
3183 + (button === 3 ? 4 : 0)
3184 + ';'
3185 + pos.y
3186 + ';'
3187 + pos.x
3188 + ';'
3189 + (pos.page || 0)
3190 + '&w');
3191 return;
3192 }
3193 if (self.urxvtMouse) {
3194 pos.x -= 32;
3195 pos.y -= 32;
3196 pos.x++;
3197 pos.y++;
3198 self.send(EscapeSequences_1.C0.ESC + '[' + button + ';' + pos.x + ';' + pos.y + 'M');
3199 return;
3200 }
3201 if (self.sgrMouse) {
3202 pos.x -= 32;
3203 pos.y -= 32;
3204 self.send(EscapeSequences_1.C0.ESC + '[<'
3205 + (((button & 3) === 3 ? button & ~3 : button) - 32)
3206 + ';'
3207 + pos.x
3208 + ';'
3209 + pos.y
3210 + ((button & 3) === 3 ? 'm' : 'M'));
3211 return;
3212 }
3213 var data = [];
3214 encode(data, button);
3215 encode(data, pos.x);
3216 encode(data, pos.y);
3217 self.send(EscapeSequences_1.C0.ESC + '[M' + String.fromCharCode.apply(String, data));
3218 }
3219 function getButton(ev) {
3220 var button, shift, meta, ctrl, mod;
3221 switch (ev.overrideType || ev.type) {
3222 case 'mousedown':
3223 button = ev.button != null
3224 ? +ev.button
3225 : ev.which != null
3226 ? ev.which - 1
3227 : null;
3228 if (self.browser.isMSIE) {
3229 button = button === 1 ? 0 : button === 4 ? 1 : button;
cd70d298 3230 }
8dd11f55
PK
3231 break;
3232 case 'mouseup':
3233 button = 3;
3234 break;
3235 case 'DOMMouseScroll':
3236 button = ev.detail < 0
3237 ? 64
3238 : 65;
3239 break;
3240 case 'wheel':
3241 button = ev.wheelDeltaY > 0
3242 ? 64
3243 : 65;
3244 break;
cd70d298 3245 }
8dd11f55
PK
3246 shift = ev.shiftKey ? 4 : 0;
3247 meta = ev.metaKey ? 8 : 0;
3248 ctrl = ev.ctrlKey ? 16 : 0;
3249 mod = shift | meta | ctrl;
3250 if (self.vt200Mouse) {
3251 mod &= ctrl;
3252 }
3253 else if (!self.normalMouse) {
3254 mod = 0;
3255 }
3256 button = (32 + (mod << 2)) + button;
3257 return button;
cd70d298 3258 }
8dd11f55
PK
3259 function getCoords(ev) {
3260 var x, y, w, h, el;
3261 if (ev.pageX == null)
3262 return;
3263 x = ev.pageX;
3264 y = ev.pageY;
3265 el = self.element;
3266 while (el && el !== self.document.documentElement) {
3267 x -= el.offsetLeft;
3268 y -= el.offsetTop;
3269 el = 'offsetParent' in el
3270 ? el.offsetParent
3271 : el.parentNode;
3272 }
b1619e42
PK
3273 x = Math.ceil(x / self.charMeasure.width);
3274 y = Math.ceil(y / self.charMeasure.height);
8dd11f55
PK
3275 if (x < 0)
3276 x = 0;
3277 if (x > self.cols)
3278 x = self.cols;
3279 if (y < 0)
3280 y = 0;
3281 if (y > self.rows)
3282 y = self.rows;
3283 x += 32;
3284 y += 32;
3285 return {
3286 x: x,
3287 y: y,
3288 type: 'wheel'
3289 };
cd70d298 3290 }
8dd11f55
PK
3291 on(el, 'mousedown', function (ev) {
3292 if (!self.mouseEvents)
3293 return;
3294 sendButton(ev);
3295 self.focus();
3296 if (self.vt200Mouse) {
3297 ev.overrideType = 'mouseup';
3298 sendButton(ev);
3299 return self.cancel(ev);
3300 }
3301 if (self.normalMouse)
3302 on(self.document, 'mousemove', sendMove);
3303 if (!self.x10Mouse) {
3304 on(self.document, 'mouseup', function up(ev) {
3305 sendButton(ev);
3306 if (self.normalMouse)
3307 off(self.document, 'mousemove', sendMove);
3308 off(self.document, 'mouseup', up);
3309 return self.cancel(ev);
3310 });
3311 }
3312 return self.cancel(ev);
3313 });
3314 on(el, 'wheel', function (ev) {
3315 if (!self.mouseEvents)
3316 return;
3317 if (self.x10Mouse
3318 || self.vt300Mouse
3319 || self.decLocator)
3320 return;
3321 sendButton(ev);
3322 return self.cancel(ev);
3323 });
3324 on(el, 'wheel', function (ev) {
3325 if (self.mouseEvents)
3326 return;
3327 self.viewport.onWheel(ev);
3328 return self.cancel(ev);
3329 });
3330};
3331Terminal.prototype.destroy = function () {
3332 this.readable = false;
3333 this.writable = false;
3334 this._events = {};
3335 this.handler = function () { };
3336 this.write = function () { };
3337 if (this.element && this.element.parentNode) {
3338 this.element.parentNode.removeChild(this.element);
cd70d298 3339 }
cd70d298 3340};
8dd11f55
PK
3341Terminal.prototype.refresh = function (start, end) {
3342 if (this.renderer) {
3343 this.renderer.queueRefresh(start, end);
3344 }
cd70d298 3345};
b1619e42
PK
3346Terminal.prototype.queueLinkification = function (start, end) {
3347 if (this.linkifier) {
3348 for (var i = start; i <= end; i++) {
3349 this.linkifier.linkifyRow(i);
3350 }
3351 }
3352};
8dd11f55
PK
3353Terminal.prototype.showCursor = function () {
3354 if (!this.cursorState) {
3355 this.cursorState = 1;
3356 this.refresh(this.y, this.y);
3357 }
cd70d298 3358};
8dd11f55
PK
3359Terminal.prototype.scroll = function () {
3360 var row;
3361 if (this.lines.length === this.lines.maxLength) {
3362 this.lines.trimStart(1);
3363 this.ybase--;
3364 if (this.ydisp !== 0) {
3365 this.ydisp--;
cd70d298
PK
3366 }
3367 }
8dd11f55
PK
3368 this.ybase++;
3369 if (!this.userScrolling) {
3370 this.ydisp = this.ybase;
cd70d298 3371 }
8dd11f55
PK
3372 row = this.ybase + this.rows - 1;
3373 row -= this.rows - 1 - this.scrollBottom;
3374 if (row === this.lines.length) {
3375 this.lines.push(this.blankLine());
cd70d298 3376 }
8dd11f55
PK
3377 else {
3378 this.lines.splice(row, 0, this.blankLine());
cd70d298 3379 }
8dd11f55
PK
3380 if (this.scrollTop !== 0) {
3381 if (this.ybase !== 0) {
3382 this.ybase--;
3383 if (!this.userScrolling) {
3384 this.ydisp = this.ybase;
3385 }
3386 }
3387 this.lines.splice(this.ybase + this.scrollTop, 1);
cd70d298 3388 }
8dd11f55
PK
3389 this.updateRange(this.scrollTop);
3390 this.updateRange(this.scrollBottom);
cd70d298
PK
3391 this.emit('scroll', this.ydisp);
3392};
8dd11f55
PK
3393Terminal.prototype.scrollDisp = function (disp, suppressScrollEvent) {
3394 if (disp < 0) {
3395 this.userScrolling = true;
cd70d298 3396 }
8dd11f55
PK
3397 else if (disp + this.ydisp >= this.ybase) {
3398 this.userScrolling = false;
cd70d298 3399 }
8dd11f55
PK
3400 this.ydisp += disp;
3401 if (this.ydisp > this.ybase) {
3402 this.ydisp = this.ybase;
cd70d298 3403 }
8dd11f55
PK
3404 else if (this.ydisp < 0) {
3405 this.ydisp = 0;
3406 }
3407 if (!suppressScrollEvent) {
3408 this.emit('scroll', this.ydisp);
cd70d298 3409 }
cd70d298 3410 this.refresh(0, this.rows - 1);
cd70d298 3411};
8dd11f55
PK
3412Terminal.prototype.scrollPages = function (pageCount) {
3413 this.scrollDisp(pageCount * (this.rows - 1));
3414};
3415Terminal.prototype.scrollToTop = function () {
3416 this.scrollDisp(-this.ydisp);
cd70d298 3417};
8dd11f55
PK
3418Terminal.prototype.scrollToBottom = function () {
3419 this.scrollDisp(this.ybase - this.ydisp);
cd70d298 3420};
8dd11f55
PK
3421Terminal.prototype.write = function (data) {
3422 this.writeBuffer.push(data);
3423 if (this.options.useFlowControl && !this.xoffSentToCatchUp && this.writeBuffer.length >= WRITE_BUFFER_PAUSE_THRESHOLD) {
3424 this.send(EscapeSequences_1.C0.DC3);
3425 this.xoffSentToCatchUp = true;
3426 }
3427 if (!this.writeInProgress && this.writeBuffer.length > 0) {
3428 this.writeInProgress = true;
3429 var self = this;
3430 setTimeout(function () {
3431 self.innerWrite();
3432 });
cd70d298
PK
3433 }
3434};
8dd11f55
PK
3435Terminal.prototype.innerWrite = function () {
3436 var writeBatch = this.writeBuffer.splice(0, WRITE_BATCH_SIZE);
3437 while (writeBatch.length > 0) {
3438 var data = writeBatch.shift();
3439 var l = data.length, i = 0, j, cs, ch, code, low, ch_width, row;
3440 if (this.xoffSentToCatchUp && writeBatch.length === 0 && this.writeBuffer.length === 0) {
3441 this.send(EscapeSequences_1.C0.DC1);
3442 this.xoffSentToCatchUp = false;
3443 }
3444 this.refreshStart = this.y;
3445 this.refreshEnd = this.y;
3446 this.parser.parse(data);
3447 this.updateRange(this.y);
3448 this.refresh(this.refreshStart, this.refreshEnd);
3449 }
3450 if (this.writeBuffer.length > 0) {
3451 var self = this;
3452 setTimeout(function () {
3453 self.innerWrite();
3454 }, 0);
3455 }
3456 else {
3457 this.writeInProgress = false;
cd70d298
PK
3458 }
3459};
8dd11f55
PK
3460Terminal.prototype.writeln = function (data) {
3461 this.write(data + '\r\n');
3462};
3463Terminal.prototype.attachCustomKeydownHandler = function (customKeydownHandler) {
3464 this.customKeydownHandler = customKeydownHandler;
cd70d298 3465};
d2f8f9dc 3466Terminal.prototype.setHypertextLinkHandler = function (handler) {
b1619e42
PK
3467 if (!this.linkifier) {
3468 throw new Error('Cannot attach a hypertext link handler before Terminal.open is called');
3469 }
d2f8f9dc
PK
3470 this.linkifier.setHypertextLinkHandler(handler);
3471 this.refresh(0, this.rows - 1);
3472};
3473Terminal.prototype.setHypertextValidationCallback = function (handler) {
3474 if (!this.linkifier) {
3475 throw new Error('Cannot attach a hypertext validation callback before Terminal.open is called');
3476 }
3477 this.linkifier.setHypertextValidationCallback(handler);
b1619e42
PK
3478 this.refresh(0, this.rows - 1);
3479};
3480Terminal.prototype.registerLinkMatcher = function (regex, handler, options) {
3481 if (this.linkifier) {
3482 var matcherId = this.linkifier.registerLinkMatcher(regex, handler, options);
3483 this.refresh(0, this.rows - 1);
3484 return matcherId;
3485 }
3486};
3487Terminal.prototype.deregisterLinkMatcher = function (matcherId) {
3488 if (this.linkifier) {
3489 if (this.linkifier.deregisterLinkMatcher(matcherId)) {
3490 this.refresh(0, this.rows - 1);
3491 }
3492 }
3493};
8dd11f55
PK
3494Terminal.prototype.keyDown = function (ev) {
3495 if (this.customKeydownHandler && this.customKeydownHandler(ev) === false) {
3496 return false;
cd70d298 3497 }
d2f8f9dc 3498 this.restartCursorBlinking();
8dd11f55
PK
3499 if (!this.compositionHelper.keydown.bind(this.compositionHelper)(ev)) {
3500 if (this.ybase !== this.ydisp) {
3501 this.scrollToBottom();
3502 }
3503 return false;
3504 }
3505 var self = this;
3506 var result = this.evaluateKeyEscapeSequence(ev);
3507 if (result.key === EscapeSequences_1.C0.DC3) {
3508 this.writeStopped = true;
cd70d298 3509 }
8dd11f55
PK
3510 else if (result.key === EscapeSequences_1.C0.DC1) {
3511 this.writeStopped = false;
3512 }
3513 if (result.scrollDisp) {
3514 this.scrollDisp(result.scrollDisp);
3515 return this.cancel(ev, true);
cd70d298 3516 }
8dd11f55
PK
3517 if (isThirdLevelShift(this, ev)) {
3518 return true;
cd70d298 3519 }
8dd11f55
PK
3520 if (result.cancel) {
3521 this.cancel(ev, true);
cd70d298 3522 }
8dd11f55
PK
3523 if (!result.key) {
3524 return true;
cd70d298 3525 }
8dd11f55
PK
3526 this.emit('keydown', ev);
3527 this.emit('key', result.key, ev);
3528 this.showCursor();
3529 this.handler(result.key);
3530 return this.cancel(ev, true);
cd70d298 3531};
8dd11f55
PK
3532Terminal.prototype.evaluateKeyEscapeSequence = function (ev) {
3533 var result = {
3534 cancel: false,
3535 key: undefined,
3536 scrollDisp: undefined
3537 };
3538 var modifiers = ev.shiftKey << 0 | ev.altKey << 1 | ev.ctrlKey << 2 | ev.metaKey << 3;
3539 switch (ev.keyCode) {
3540 case 8:
3541 if (ev.shiftKey) {
3542 result.key = EscapeSequences_1.C0.BS;
3543 break;
3544 }
3545 result.key = EscapeSequences_1.C0.DEL;
3546 break;
3547 case 9:
3548 if (ev.shiftKey) {
3549 result.key = EscapeSequences_1.C0.ESC + '[Z';
3550 break;
3551 }
3552 result.key = EscapeSequences_1.C0.HT;
3553 result.cancel = true;
3554 break;
3555 case 13:
3556 result.key = EscapeSequences_1.C0.CR;
3557 result.cancel = true;
3558 break;
3559 case 27:
3560 result.key = EscapeSequences_1.C0.ESC;
3561 result.cancel = true;
3562 break;
3563 case 37:
3564 if (modifiers) {
3565 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'D';
3566 if (result.key == EscapeSequences_1.C0.ESC + '[1;3D') {
3567 result.key = (this.browser.isMac) ? EscapeSequences_1.C0.ESC + 'b' : EscapeSequences_1.C0.ESC + '[1;5D';
3568 }
3569 }
3570 else if (this.applicationCursor) {
3571 result.key = EscapeSequences_1.C0.ESC + 'OD';
3572 }
3573 else {
3574 result.key = EscapeSequences_1.C0.ESC + '[D';
3575 }
3576 break;
3577 case 39:
3578 if (modifiers) {
3579 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'C';
3580 if (result.key == EscapeSequences_1.C0.ESC + '[1;3C') {
3581 result.key = (this.browser.isMac) ? EscapeSequences_1.C0.ESC + 'f' : EscapeSequences_1.C0.ESC + '[1;5C';
3582 }
3583 }
3584 else if (this.applicationCursor) {
3585 result.key = EscapeSequences_1.C0.ESC + 'OC';
3586 }
3587 else {
3588 result.key = EscapeSequences_1.C0.ESC + '[C';
3589 }
3590 break;
3591 case 38:
3592 if (modifiers) {
3593 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'A';
3594 if (result.key == EscapeSequences_1.C0.ESC + '[1;3A') {
3595 result.key = EscapeSequences_1.C0.ESC + '[1;5A';
3596 }
3597 }
3598 else if (this.applicationCursor) {
3599 result.key = EscapeSequences_1.C0.ESC + 'OA';
3600 }
3601 else {
3602 result.key = EscapeSequences_1.C0.ESC + '[A';
3603 }
3604 break;
3605 case 40:
3606 if (modifiers) {
3607 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'B';
3608 if (result.key == EscapeSequences_1.C0.ESC + '[1;3B') {
3609 result.key = EscapeSequences_1.C0.ESC + '[1;5B';
3610 }
3611 }
3612 else if (this.applicationCursor) {
3613 result.key = EscapeSequences_1.C0.ESC + 'OB';
3614 }
3615 else {
3616 result.key = EscapeSequences_1.C0.ESC + '[B';
3617 }
3618 break;
3619 case 45:
3620 if (!ev.shiftKey && !ev.ctrlKey) {
3621 result.key = EscapeSequences_1.C0.ESC + '[2~';
3622 }
3623 break;
3624 case 46:
3625 if (modifiers) {
3626 result.key = EscapeSequences_1.C0.ESC + '[3;' + (modifiers + 1) + '~';
3627 }
3628 else {
3629 result.key = EscapeSequences_1.C0.ESC + '[3~';
3630 }
3631 break;
3632 case 36:
3633 if (modifiers)
3634 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'H';
3635 else if (this.applicationCursor)
3636 result.key = EscapeSequences_1.C0.ESC + 'OH';
3637 else
3638 result.key = EscapeSequences_1.C0.ESC + '[H';
3639 break;
3640 case 35:
3641 if (modifiers)
3642 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'F';
3643 else if (this.applicationCursor)
3644 result.key = EscapeSequences_1.C0.ESC + 'OF';
3645 else
3646 result.key = EscapeSequences_1.C0.ESC + '[F';
3647 break;
3648 case 33:
3649 if (ev.shiftKey) {
3650 result.scrollDisp = -(this.rows - 1);
3651 }
3652 else {
3653 result.key = EscapeSequences_1.C0.ESC + '[5~';
3654 }
3655 break;
3656 case 34:
3657 if (ev.shiftKey) {
3658 result.scrollDisp = this.rows - 1;
3659 }
3660 else {
3661 result.key = EscapeSequences_1.C0.ESC + '[6~';
3662 }
3663 break;
3664 case 112:
3665 if (modifiers) {
3666 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'P';
3667 }
3668 else {
3669 result.key = EscapeSequences_1.C0.ESC + 'OP';
3670 }
3671 break;
3672 case 113:
3673 if (modifiers) {
3674 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'Q';
3675 }
3676 else {
3677 result.key = EscapeSequences_1.C0.ESC + 'OQ';
3678 }
3679 break;
3680 case 114:
3681 if (modifiers) {
3682 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'R';
3683 }
3684 else {
3685 result.key = EscapeSequences_1.C0.ESC + 'OR';
3686 }
3687 break;
3688 case 115:
3689 if (modifiers) {
3690 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'S';
3691 }
3692 else {
3693 result.key = EscapeSequences_1.C0.ESC + 'OS';
3694 }
3695 break;
3696 case 116:
3697 if (modifiers) {
3698 result.key = EscapeSequences_1.C0.ESC + '[15;' + (modifiers + 1) + '~';
3699 }
3700 else {
3701 result.key = EscapeSequences_1.C0.ESC + '[15~';
3702 }
3703 break;
3704 case 117:
3705 if (modifiers) {
3706 result.key = EscapeSequences_1.C0.ESC + '[17;' + (modifiers + 1) + '~';
3707 }
3708 else {
3709 result.key = EscapeSequences_1.C0.ESC + '[17~';
3710 }
3711 break;
3712 case 118:
3713 if (modifiers) {
3714 result.key = EscapeSequences_1.C0.ESC + '[18;' + (modifiers + 1) + '~';
3715 }
3716 else {
3717 result.key = EscapeSequences_1.C0.ESC + '[18~';
3718 }
3719 break;
3720 case 119:
3721 if (modifiers) {
3722 result.key = EscapeSequences_1.C0.ESC + '[19;' + (modifiers + 1) + '~';
3723 }
3724 else {
3725 result.key = EscapeSequences_1.C0.ESC + '[19~';
3726 }
3727 break;
3728 case 120:
3729 if (modifiers) {
3730 result.key = EscapeSequences_1.C0.ESC + '[20;' + (modifiers + 1) + '~';
3731 }
3732 else {
3733 result.key = EscapeSequences_1.C0.ESC + '[20~';
3734 }
3735 break;
3736 case 121:
3737 if (modifiers) {
3738 result.key = EscapeSequences_1.C0.ESC + '[21;' + (modifiers + 1) + '~';
3739 }
3740 else {
3741 result.key = EscapeSequences_1.C0.ESC + '[21~';
3742 }
3743 break;
3744 case 122:
3745 if (modifiers) {
3746 result.key = EscapeSequences_1.C0.ESC + '[23;' + (modifiers + 1) + '~';
3747 }
3748 else {
3749 result.key = EscapeSequences_1.C0.ESC + '[23~';
3750 }
3751 break;
3752 case 123:
3753 if (modifiers) {
3754 result.key = EscapeSequences_1.C0.ESC + '[24;' + (modifiers + 1) + '~';
3755 }
3756 else {
3757 result.key = EscapeSequences_1.C0.ESC + '[24~';
cd70d298
PK
3758 }
3759 break;
8dd11f55
PK
3760 default:
3761 if (ev.ctrlKey && !ev.shiftKey && !ev.altKey && !ev.metaKey) {
3762 if (ev.keyCode >= 65 && ev.keyCode <= 90) {
3763 result.key = String.fromCharCode(ev.keyCode - 64);
3764 }
3765 else if (ev.keyCode === 32) {
3766 result.key = String.fromCharCode(0);
3767 }
3768 else if (ev.keyCode >= 51 && ev.keyCode <= 55) {
3769 result.key = String.fromCharCode(ev.keyCode - 51 + 27);
3770 }
3771 else if (ev.keyCode === 56) {
3772 result.key = String.fromCharCode(127);
3773 }
3774 else if (ev.keyCode === 219) {
3775 result.key = String.fromCharCode(27);
3776 }
3777 else if (ev.keyCode === 220) {
3778 result.key = String.fromCharCode(28);
3779 }
3780 else if (ev.keyCode === 221) {
3781 result.key = String.fromCharCode(29);
3782 }
3783 }
3784 else if (!this.browser.isMac && ev.altKey && !ev.ctrlKey && !ev.metaKey) {
3785 if (ev.keyCode >= 65 && ev.keyCode <= 90) {
3786 result.key = EscapeSequences_1.C0.ESC + String.fromCharCode(ev.keyCode + 32);
3787 }
3788 else if (ev.keyCode === 192) {
3789 result.key = EscapeSequences_1.C0.ESC + '`';
3790 }
3791 else if (ev.keyCode >= 48 && ev.keyCode <= 57) {
3792 result.key = EscapeSequences_1.C0.ESC + (ev.keyCode - 48);
3793 }
cd70d298
PK
3794 }
3795 break;
cd70d298 3796 }
8dd11f55 3797 return result;
cd70d298 3798};
8dd11f55
PK
3799Terminal.prototype.setgLevel = function (g) {
3800 this.glevel = g;
3801 this.charset = this.charsets[g];
cd70d298 3802};
8dd11f55
PK
3803Terminal.prototype.setgCharset = function (g, charset) {
3804 this.charsets[g] = charset;
3805 if (this.glevel === g) {
3806 this.charset = charset;
cd70d298 3807 }
cd70d298 3808};
8dd11f55
PK
3809Terminal.prototype.keyPress = function (ev) {
3810 var key;
3811 this.cancel(ev);
3812 if (ev.charCode) {
3813 key = ev.charCode;
cd70d298 3814 }
8dd11f55
PK
3815 else if (ev.which == null) {
3816 key = ev.keyCode;
cd70d298 3817 }
8dd11f55
PK
3818 else if (ev.which !== 0 && ev.charCode !== 0) {
3819 key = ev.which;
cd70d298 3820 }
8dd11f55
PK
3821 else {
3822 return false;
cd70d298 3823 }
8dd11f55
PK
3824 if (!key || ((ev.altKey || ev.ctrlKey || ev.metaKey) && !isThirdLevelShift(this, ev))) {
3825 return false;
cd70d298 3826 }
8dd11f55
PK
3827 key = String.fromCharCode(key);
3828 this.emit('keypress', key, ev);
3829 this.emit('key', key, ev);
3830 this.showCursor();
3831 this.handler(key);
3832 return false;
cd70d298 3833};
8dd11f55
PK
3834Terminal.prototype.send = function (data) {
3835 var self = this;
3836 if (!this.queue) {
3837 setTimeout(function () {
3838 self.handler(self.queue);
3839 self.queue = '';
3840 }, 1);
cd70d298 3841 }
8dd11f55 3842 this.queue += data;
cd70d298 3843};
8dd11f55
PK
3844Terminal.prototype.bell = function () {
3845 if (!this.visualBell)
3846 return;
3847 var self = this;
3848 this.element.style.borderColor = 'white';
3849 setTimeout(function () {
3850 self.element.style.borderColor = '';
3851 }, 10);
3852 if (this.popOnBell)
3853 this.focus();
cd70d298 3854};
8dd11f55
PK
3855Terminal.prototype.log = function () {
3856 if (!this.debug)
3857 return;
3858 if (!this.context.console || !this.context.console.log)
3859 return;
3860 var args = Array.prototype.slice.call(arguments);
3861 this.context.console.log.apply(this.context.console, args);
cd70d298 3862};
8dd11f55
PK
3863Terminal.prototype.error = function () {
3864 if (!this.debug)
3865 return;
3866 if (!this.context.console || !this.context.console.error)
3867 return;
3868 var args = Array.prototype.slice.call(arguments);
3869 this.context.console.error.apply(this.context.console, args);
cd70d298 3870};
8dd11f55 3871Terminal.prototype.resize = function (x, y) {
639a2fd5 3872 if (isNaN(x) || isNaN(y)) {
8dd11f55 3873 return;
cd70d298 3874 }
8dd11f55
PK
3875 var line, el, i, j, ch, addToY;
3876 if (x === this.cols && y === this.rows) {
cd70d298 3877 return;
cd70d298 3878 }
8dd11f55
PK
3879 if (x < 1)
3880 x = 1;
3881 if (y < 1)
3882 y = 1;
3883 j = this.cols;
3884 if (j < x) {
3885 ch = [this.defAttr, ' ', 1];
3886 i = this.lines.length;
3887 while (i--) {
3888 while (this.lines.get(i).length < x) {
3889 this.lines.get(i).push(ch);
3890 }
cd70d298
PK
3891 }
3892 }
8dd11f55
PK
3893 this.cols = x;
3894 this.setupStops(this.cols);
3895 j = this.rows;
3896 addToY = 0;
3897 if (j < y) {
3898 el = this.element;
3899 while (j++ < y) {
3900 if (this.lines.length < y + this.ybase) {
3901 if (this.ybase > 0 && this.lines.length <= this.ybase + this.y + addToY + 1) {
3902 this.ybase--;
3903 addToY++;
3904 if (this.ydisp > 0) {
3905 this.ydisp--;
3906 }
3907 }
3908 else {
3909 this.lines.push(this.blankLine());
3910 }
3911 }
3912 if (this.children.length < y) {
3913 this.insertRow();
3914 }
cd70d298
PK
3915 }
3916 }
8dd11f55
PK
3917 else {
3918 while (j-- > y) {
3919 if (this.lines.length > y + this.ybase) {
3920 if (this.lines.length > this.ybase + this.y + 1) {
3921 this.lines.pop();
cd70d298 3922 }
8dd11f55
PK
3923 else {
3924 this.ybase++;
3925 this.ydisp++;
3926 }
3927 }
3928 if (this.children.length > y) {
3929 el = this.children.shift();
3930 if (!el)
3931 continue;
3932 el.parentNode.removeChild(el);
3933 }
cd70d298
PK
3934 }
3935 }
8dd11f55
PK
3936 this.rows = y;
3937 if (this.y >= y) {
3938 this.y = y - 1;
cd70d298 3939 }
8dd11f55
PK
3940 if (addToY) {
3941 this.y += addToY;
cd70d298 3942 }
8dd11f55
PK
3943 if (this.x >= x) {
3944 this.x = x - 1;
3945 }
3946 this.scrollTop = 0;
3947 this.scrollBottom = y - 1;
3948 this.charMeasure.measure();
3949 this.refresh(0, this.rows - 1);
3950 this.normal = null;
3951 this.geometry = [this.cols, this.rows];
3952 this.emit('resize', { terminal: this, cols: x, rows: y });
3953};
3954Terminal.prototype.updateRange = function (y) {
3955 if (y < this.refreshStart)
3956 this.refreshStart = y;
3957 if (y > this.refreshEnd)
3958 this.refreshEnd = y;
3959};
3960Terminal.prototype.maxRange = function () {
3961 this.refreshStart = 0;
3962 this.refreshEnd = this.rows - 1;
3963};
3964Terminal.prototype.setupStops = function (i) {
3965 if (i != null) {
3966 if (!this.tabs[i]) {
3967 i = this.prevStop(i);
cd70d298
PK
3968 }
3969 }
8dd11f55
PK
3970 else {
3971 this.tabs = {};
3972 i = 0;
3973 }
3974 for (; i < this.cols; i += this.getOption('tabStopWidth')) {
3975 this.tabs[i] = true;
3976 }
cd70d298 3977};
8dd11f55
PK
3978Terminal.prototype.prevStop = function (x) {
3979 if (x == null)
3980 x = this.x;
3981 while (!this.tabs[--x] && x > 0)
3982 ;
3983 return x >= this.cols
3984 ? this.cols - 1
3985 : x < 0 ? 0 : x;
cd70d298 3986};
8dd11f55
PK
3987Terminal.prototype.nextStop = function (x) {
3988 if (x == null)
3989 x = this.x;
3990 while (!this.tabs[++x] && x < this.cols)
3991 ;
3992 return x >= this.cols
3993 ? this.cols - 1
3994 : x < 0 ? 0 : x;
cd70d298 3995};
8dd11f55
PK
3996Terminal.prototype.eraseRight = function (x, y) {
3997 var line = this.lines.get(this.ybase + y);
3998 if (!line) {
3999 return;
cd70d298 4000 }
8dd11f55
PK
4001 var ch = [this.eraseAttr(), ' ', 1];
4002 for (; x < this.cols; x++) {
4003 line[x] = ch;
cd70d298 4004 }
8dd11f55 4005 this.updateRange(y);
cd70d298 4006};
8dd11f55
PK
4007Terminal.prototype.eraseLeft = function (x, y) {
4008 var line = this.lines.get(this.ybase + y);
4009 if (!line) {
4010 return;
cd70d298 4011 }
8dd11f55
PK
4012 var ch = [this.eraseAttr(), ' ', 1];
4013 x++;
4014 while (x--) {
4015 line[x] = ch;
cd70d298 4016 }
8dd11f55 4017 this.updateRange(y);
cd70d298 4018};
8dd11f55
PK
4019Terminal.prototype.clear = function () {
4020 if (this.ybase === 0 && this.y === 0) {
4021 return;
cd70d298 4022 }
8dd11f55
PK
4023 this.lines.set(0, this.lines.get(this.ybase + this.y));
4024 this.lines.length = 1;
4025 this.ydisp = 0;
4026 this.ybase = 0;
4027 this.y = 0;
4028 for (var i = 1; i < this.rows; i++) {
4029 this.lines.push(this.blankLine());
cd70d298 4030 }
8dd11f55
PK
4031 this.refresh(0, this.rows - 1);
4032 this.emit('scroll', this.ydisp);
cd70d298 4033};
8dd11f55
PK
4034Terminal.prototype.eraseLine = function (y) {
4035 this.eraseRight(0, y);
cd70d298 4036};
8dd11f55
PK
4037Terminal.prototype.blankLine = function (cur) {
4038 var attr = cur
4039 ? this.eraseAttr()
4040 : this.defAttr;
4041 var ch = [attr, ' ', 1], line = [], i = 0;
4042 for (; i < this.cols; i++) {
4043 line[i] = ch;
4044 }
4045 return line;
cd70d298 4046};
8dd11f55
PK
4047Terminal.prototype.ch = function (cur) {
4048 return cur
4049 ? [this.eraseAttr(), ' ', 1]
4050 : [this.defAttr, ' ', 1];
cd70d298 4051};
8dd11f55
PK
4052Terminal.prototype.is = function (term) {
4053 var name = this.termName;
4054 return (name + '').indexOf(term) === 0;
cd70d298 4055};
8dd11f55
PK
4056Terminal.prototype.handler = function (data) {
4057 if (this.options.disableStdin) {
4058 return;
cd70d298 4059 }
8dd11f55
PK
4060 if (this.ybase !== this.ydisp) {
4061 this.scrollToBottom();
cd70d298 4062 }
8dd11f55 4063 this.emit('data', data);
cd70d298 4064};
8dd11f55
PK
4065Terminal.prototype.handleTitle = function (title) {
4066 this.emit('title', title);
cd70d298 4067};
8dd11f55
PK
4068Terminal.prototype.index = function () {
4069 this.y++;
4070 if (this.y > this.scrollBottom) {
4071 this.y--;
4072 this.scroll();
cd70d298 4073 }
8dd11f55
PK
4074 if (this.x >= this.cols) {
4075 this.x--;
cd70d298 4076 }
cd70d298 4077};
8dd11f55
PK
4078Terminal.prototype.reverseIndex = function () {
4079 var j;
4080 if (this.y === this.scrollTop) {
4081 this.lines.shiftElements(this.y + this.ybase, this.rows - 1, 1);
4082 this.lines.set(this.y + this.ybase, this.blankLine(true));
4083 this.updateRange(this.scrollTop);
4084 this.updateRange(this.scrollBottom);
4085 }
4086 else {
4087 this.y--;
cd70d298 4088 }
cd70d298 4089};
8dd11f55
PK
4090Terminal.prototype.reset = function () {
4091 this.options.rows = this.rows;
4092 this.options.cols = this.cols;
4093 var customKeydownHandler = this.customKeydownHandler;
4094 Terminal.call(this, this.options);
4095 this.customKeydownHandler = customKeydownHandler;
4096 this.refresh(0, this.rows - 1);
4097 this.viewport.syncScrollArea();
4098};
4099Terminal.prototype.tabSet = function () {
4100 this.tabs[this.x] = true;
cd70d298 4101};
cd70d298
PK
4102function on(el, type, handler, capture) {
4103 if (!Array.isArray(el)) {
4104 el = [el];
4105 }
4106 el.forEach(function (element) {
4107 element.addEventListener(type, handler, capture || false);
4108 });
4109}
4110function off(el, type, handler, capture) {
4111 el.removeEventListener(type, handler, capture || false);
4112}
4113function cancel(ev, force) {
4114 if (!this.cancelEvents && !force) {
4115 return;
4116 }
4117 ev.preventDefault();
4118 ev.stopPropagation();
4119 return false;
4120}
4121function inherits(child, parent) {
4122 function f() {
4123 this.constructor = child;
4124 }
4125 f.prototype = parent.prototype;
4126 child.prototype = new f;
4127}
cd70d298
PK
4128function indexOf(obj, el) {
4129 var i = obj.length;
4130 while (i--) {
4131 if (obj[i] === el)
4132 return i;
4133 }
4134 return -1;
4135}
4136function isThirdLevelShift(term, ev) {
4137 var thirdLevelKey = (term.browser.isMac && ev.altKey && !ev.ctrlKey && !ev.metaKey) ||
4138 (term.browser.isMSWindows && ev.altKey && ev.ctrlKey && !ev.metaKey);
4139 if (ev.type == 'keypress') {
4140 return thirdLevelKey;
4141 }
cd70d298
PK
4142 return thirdLevelKey && (!ev.keyCode || ev.keyCode > 47);
4143}
8dd11f55 4144Terminal.prototype.matchColor = matchColor;
cd70d298
PK
4145function matchColor(r1, g1, b1) {
4146 var hash = (r1 << 16) | (g1 << 8) | b1;
4147 if (matchColor._cache[hash] != null) {
4148 return matchColor._cache[hash];
4149 }
4150 var ldiff = Infinity, li = -1, i = 0, c, r2, g2, b2, diff;
4151 for (; i < Terminal.vcolors.length; i++) {
4152 c = Terminal.vcolors[i];
4153 r2 = c[0];
4154 g2 = c[1];
4155 b2 = c[2];
4156 diff = matchColor.distance(r1, g1, b1, r2, g2, b2);
4157 if (diff === 0) {
4158 li = i;
4159 break;
4160 }
4161 if (diff < ldiff) {
4162 ldiff = diff;
4163 li = i;
4164 }
4165 }
4166 return matchColor._cache[hash] = li;
4167}
4168matchColor._cache = {};
cd70d298
PK
4169matchColor.distance = function (r1, g1, b1, r2, g2, b2) {
4170 return Math.pow(30 * (r1 - r2), 2)
4171 + Math.pow(59 * (g1 - g2), 2)
4172 + Math.pow(11 * (b1 - b2), 2);
4173};
4174function each(obj, iter, con) {
4175 if (obj.forEach)
4176 return obj.forEach(iter, con);
4177 for (var i = 0; i < obj.length; i++) {
4178 iter.call(con, obj[i], i, obj);
4179 }
4180}
8dd11f55
PK
4181function wasMondifierKeyOnlyEvent(ev) {
4182 return ev.keyCode === 16 ||
4183 ev.keyCode === 17 ||
4184 ev.keyCode === 18;
4185}
cd70d298
PK
4186function keys(obj) {
4187 if (Object.keys)
4188 return Object.keys(obj);
4189 var key, keys = [];
4190 for (key in obj) {
4191 if (Object.prototype.hasOwnProperty.call(obj, key)) {
4192 keys.push(key);
4193 }
4194 }
4195 return keys;
4196}
8dd11f55 4197Terminal.EventEmitter = EventEmitter_1.EventEmitter;
cd70d298 4198Terminal.inherits = inherits;
cd70d298
PK
4199Terminal.on = on;
4200Terminal.off = off;
4201Terminal.cancel = cancel;
4202module.exports = Terminal;
5ce522a4 4203
8fd44266
PK
4204
4205
b1619e42 4206},{"./CompositionHelper":2,"./EscapeSequences":3,"./EventEmitter":4,"./InputHandler":5,"./Linkifier":6,"./Parser":7,"./Renderer":8,"./Viewport":9,"./handlers/Clipboard":10,"./utils/Browser":11,"./utils/CharMeasure":12,"./utils/CircularList":13}]},{},[15])(15)
5ce522a4
PK
4207});
4208//# sourceMappingURL=xterm.js.map