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