]> git.proxmox.com Git - mirror_xterm.js.git/blob - dist/xterm.js
Merge pull request #535 from Tyriar/534_phantomjs
[mirror_xterm.js.git] / dist / xterm.js
1 (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Terminal = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2 "use strict";
3 exports.CHARSETS = {};
4 exports.DEFAULT_CHARSET = exports.CHARSETS['B'];
5 exports.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 };
38 exports.CHARSETS['A'] = {
39 '#': '£'
40 };
41 exports.CHARSETS['B'] = null;
42 exports.CHARSETS['4'] = {
43 '#': '£',
44 '@': '¾',
45 '[': 'ij',
46 '\\': '½',
47 ']': '|',
48 '{': '¨',
49 '|': 'f',
50 '}': '¼',
51 '~': '´'
52 };
53 exports.CHARSETS['C'] =
54 exports.CHARSETS['5'] = {
55 '[': 'Ä',
56 '\\': 'Ö',
57 ']': 'Å',
58 '^': 'Ü',
59 '`': 'é',
60 '{': 'ä',
61 '|': 'ö',
62 '}': 'å',
63 '~': 'ü'
64 };
65 exports.CHARSETS['R'] = {
66 '#': '£',
67 '@': 'à',
68 '[': '°',
69 '\\': 'ç',
70 ']': '§',
71 '{': 'é',
72 '|': 'ù',
73 '}': 'è',
74 '~': '¨'
75 };
76 exports.CHARSETS['Q'] = {
77 '@': 'à',
78 '[': 'â',
79 '\\': 'ç',
80 ']': 'ê',
81 '^': 'î',
82 '`': 'ô',
83 '{': 'é',
84 '|': 'ù',
85 '}': 'è',
86 '~': 'û'
87 };
88 exports.CHARSETS['K'] = {
89 '@': '§',
90 '[': 'Ä',
91 '\\': 'Ö',
92 ']': 'Ü',
93 '{': 'ä',
94 '|': 'ö',
95 '}': 'ü',
96 '~': 'ß'
97 };
98 exports.CHARSETS['Y'] = {
99 '#': '£',
100 '@': '§',
101 '[': '°',
102 '\\': 'ç',
103 ']': 'é',
104 '`': 'ù',
105 '{': 'à',
106 '|': 'ò',
107 '}': 'è',
108 '~': 'ì'
109 };
110 exports.CHARSETS['E'] =
111 exports.CHARSETS['6'] = {
112 '@': 'Ä',
113 '[': 'Æ',
114 '\\': 'Ø',
115 ']': 'Å',
116 '^': 'Ü',
117 '`': 'ä',
118 '{': 'æ',
119 '|': 'ø',
120 '}': 'å',
121 '~': 'ü'
122 };
123 exports.CHARSETS['Z'] = {
124 '#': '£',
125 '@': '§',
126 '[': '¡',
127 '\\': 'Ñ',
128 ']': '¿',
129 '{': '°',
130 '|': 'ñ',
131 '}': 'ç'
132 };
133 exports.CHARSETS['H'] =
134 exports.CHARSETS['7'] = {
135 '@': 'É',
136 '[': 'Ä',
137 '\\': 'Ö',
138 ']': 'Å',
139 '^': 'Ü',
140 '`': 'é',
141 '{': 'ä',
142 '|': 'ö',
143 '}': 'å',
144 '~': 'ü'
145 };
146 exports.CHARSETS['='] = {
147 '#': 'ù',
148 '@': 'à',
149 '[': 'é',
150 '\\': 'ç',
151 ']': 'ê',
152 '^': 'î',
153 '_': 'è',
154 '`': 'ô',
155 '{': 'ä',
156 '|': 'ö',
157 '}': 'ü',
158 '~': 'û'
159 };
160
161
162
163 },{}],2:[function(require,module,exports){
164 "use strict";
165 var CompositionHelper = (function () {
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 }
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');
179 };
180 CompositionHelper.prototype.compositionupdate = function (ev) {
181 var _this = this;
182 this.compositionView.textContent = ev.data;
183 this.updateCompositionElements();
184 setTimeout(function () {
185 _this.compositionPosition.end = _this.textarea.value.length;
186 }, 0);
187 };
188 CompositionHelper.prototype.compositionend = function () {
189 this.finalizeComposition(true);
190 };
191 CompositionHelper.prototype.keydown = function (ev) {
192 if (this.isComposing || this.isSendingComposition) {
193 if (ev.keyCode === 229) {
194 return false;
195 }
196 else if (ev.keyCode === 16 || ev.keyCode === 17 || ev.keyCode === 18) {
197 return false;
198 }
199 else {
200 this.finalizeComposition(false);
201 }
202 }
203 if (ev.keyCode === 229) {
204 this.handleAnyTextareaChanges();
205 return false;
206 }
207 return true;
208 };
209 CompositionHelper.prototype.finalizeComposition = function (waitForPropogation) {
210 var _this = this;
211 this.compositionView.classList.remove('active');
212 this.isComposing = false;
213 this.clearTextareaPosition();
214 if (!waitForPropogation) {
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 {
220 var currentCompositionPosition_1 = {
221 start: this.compositionPosition.start,
222 end: this.compositionPosition.end,
223 };
224 this.isSendingComposition = true;
225 setTimeout(function () {
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);
231 }
232 else {
233 input = _this.textarea.value.substring(currentCompositionPosition_1.start);
234 }
235 _this.terminal.handler(input);
236 }
237 }, 0);
238 }
239 };
240 CompositionHelper.prototype.handleAnyTextareaChanges = function () {
241 var _this = this;
242 var oldValue = this.textarea.value;
243 setTimeout(function () {
244 if (!_this.isComposing) {
245 var newValue = _this.textarea.value;
246 var diff = newValue.replace(oldValue, '');
247 if (diff.length > 0) {
248 _this.terminal.handler(diff);
249 }
250 }
251 }, 0);
252 };
253 CompositionHelper.prototype.updateCompositionElements = function (dontRecurse) {
254 var _this = this;
255 if (!this.isComposing) {
256 return;
257 }
258 var cursor = this.terminal.element.querySelector('.terminal-cursor');
259 if (cursor) {
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';
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) {
274 setTimeout(function () { return _this.updateCompositionElements(true); }, 0);
275 }
276 };
277 ;
278 CompositionHelper.prototype.clearTextareaPosition = function () {
279 this.textarea.style.left = '';
280 this.textarea.style.top = '';
281 };
282 ;
283 return CompositionHelper;
284 }());
285 exports.CompositionHelper = CompositionHelper;
286
287
288
289 },{}],3:[function(require,module,exports){
290 "use strict";
291 var 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
330
331
332 },{}],4:[function(require,module,exports){
333 "use strict";
334 ;
335 var 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]) {
345 return;
346 }
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 }());
385 exports.EventEmitter = EventEmitter;
386
387
388
389 },{}],5:[function(require,module,exports){
390 "use strict";
391 var EscapeSequences_1 = require("./EscapeSequences");
392 var Charsets_1 = require("./Charsets");
393 var 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;
416 }
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++;
448 }
449 }
450 };
451 InputHandler.prototype.bell = function () {
452 var _this = this;
453 if (!this._terminal.visualBell) {
454 return;
455 }
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();
460 }
461 };
462 InputHandler.prototype.lineFeed = function () {
463 if (this._terminal.convertEol) {
464 this._terminal.x = 0;
465 }
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--;
473 }
474 };
475 InputHandler.prototype.carriageReturn = function () {
476 this._terminal.x = 0;
477 };
478 InputHandler.prototype.backspace = function () {
479 if (this._terminal.x > 0) {
480 this._terminal.x--;
481 }
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();
503 }
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--;
526 }
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;
561 };
562 ;
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;
573 };
574 ;
575 InputHandler.prototype.cursorCharAbsolute = function (params) {
576 var param = params[0];
577 if (param < 1) {
578 param = 1;
579 }
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;
587 }
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 ;
636 break;
637 }
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;
650 }
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);
707 }
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;
738 }
739 };
740 InputHandler.prototype.cursorBackwardTab = function (params) {
741 var param = params[0] || 1;
742 while (param--) {
743 this._terminal.x = this._terminal.prevStop();
744 }
745 };
746 InputHandler.prototype.charPosAbsolute = function (params) {
747 var param = params[0];
748 if (param < 1) {
749 param = 1;
750 }
751 this._terminal.x = param - 1;
752 if (this._terminal.x >= this._terminal.cols) {
753 this._terminal.x = this._terminal.cols - 1;
754 }
755 };
756 InputHandler.prototype.HPositionRelative = function (params) {
757 var param = params[0];
758 if (param < 1) {
759 param = 1;
760 }
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();
934 }
935 break;
936 }
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;
950 break;
951 case 20:
952 break;
953 }
954 }
955 else if (this._terminal.prefix === '?') {
956 switch (params[0]) {
957 case 1:
958 this._terminal.applicationCursor = false;
959 break;
960 case 3:
961 if (this._terminal.cols === 132 && this._terminal.savedCols) {
962 this._terminal.resize(this._terminal.savedCols, this._terminal.rows);
963 }
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();
1021 }
1022 break;
1023 }
1024 }
1025 };
1026 InputHandler.prototype.charAttributes = function (params) {
1027 if (params.length === 1 && params[0] === 0) {
1028 this._terminal.curAttr = this._terminal.defAttr;
1029 return;
1030 }
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);
1123 }
1124 }
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;
1166 this._terminal.wraparoundMode = false;
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 }());
1215 exports.InputHandler = InputHandler;
1216 var 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;
1283 }
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)));
1309 }
1310 return wcwidth;
1311 })({ nul: 0, control: 0 });
1312
1313
1314
1315 },{"./Charsets":1,"./EscapeSequences":3}],6:[function(require,module,exports){
1316 "use strict";
1317 var EscapeSequences_1 = require("./EscapeSequences");
1318 var Charsets_1 = require("./Charsets");
1319 var normalStateHandler = {};
1320 normalStateHandler[EscapeSequences_1.C0.BEL] = function (parser, handler) { return handler.bell(); };
1321 normalStateHandler[EscapeSequences_1.C0.LF] = function (parser, handler) { return handler.lineFeed(); };
1322 normalStateHandler[EscapeSequences_1.C0.VT] = normalStateHandler[EscapeSequences_1.C0.LF];
1323 normalStateHandler[EscapeSequences_1.C0.FF] = normalStateHandler[EscapeSequences_1.C0.LF];
1324 normalStateHandler[EscapeSequences_1.C0.CR] = function (parser, handler) { return handler.carriageReturn(); };
1325 normalStateHandler[EscapeSequences_1.C0.BS] = function (parser, handler) { return handler.backspace(); };
1326 normalStateHandler[EscapeSequences_1.C0.HT] = function (parser, handler) { return handler.tab(); };
1327 normalStateHandler[EscapeSequences_1.C0.SO] = function (parser, handler) { return handler.shiftOut(); };
1328 normalStateHandler[EscapeSequences_1.C0.SI] = function (parser, handler) { return handler.shiftIn(); };
1329 normalStateHandler[EscapeSequences_1.C0.ESC] = function (parser, handler) { return parser.setState(ParserState.ESCAPED); };
1330 var escapedStateHandler = {};
1331 escapedStateHandler['['] = function (parser, terminal) {
1332 terminal.params = [];
1333 terminal.currentParam = 0;
1334 parser.setState(ParserState.CSI_PARAM);
1335 };
1336 escapedStateHandler[']'] = function (parser, terminal) {
1337 terminal.params = [];
1338 terminal.currentParam = 0;
1339 parser.setState(ParserState.OSC);
1340 };
1341 escapedStateHandler['P'] = function (parser, terminal) {
1342 terminal.params = [];
1343 terminal.currentParam = 0;
1344 parser.setState(ParserState.DCS);
1345 };
1346 escapedStateHandler['_'] = function (parser, terminal) {
1347 parser.setState(ParserState.IGNORE);
1348 };
1349 escapedStateHandler['^'] = function (parser, terminal) {
1350 parser.setState(ParserState.IGNORE);
1351 };
1352 escapedStateHandler['c'] = function (parser, terminal) {
1353 terminal.reset();
1354 };
1355 escapedStateHandler['E'] = function (parser, terminal) {
1356 terminal.x = 0;
1357 terminal.index();
1358 parser.setState(ParserState.NORMAL);
1359 };
1360 escapedStateHandler['D'] = function (parser, terminal) {
1361 terminal.index();
1362 parser.setState(ParserState.NORMAL);
1363 };
1364 escapedStateHandler['M'] = function (parser, terminal) {
1365 terminal.reverseIndex();
1366 parser.setState(ParserState.NORMAL);
1367 };
1368 escapedStateHandler['%'] = function (parser, terminal) {
1369 terminal.setgLevel(0);
1370 terminal.setgCharset(0, Charsets_1.DEFAULT_CHARSET);
1371 parser.setState(ParserState.NORMAL);
1372 parser.skipNextChar();
1373 };
1374 escapedStateHandler[EscapeSequences_1.C0.CAN] = function (parser) { return parser.setState(ParserState.NORMAL); };
1375 var csiParamStateHandler = {};
1376 csiParamStateHandler['?'] = function (parser) { return parser.setPrefix('?'); };
1377 csiParamStateHandler['>'] = function (parser) { return parser.setPrefix('>'); };
1378 csiParamStateHandler['!'] = function (parser) { return parser.setPrefix('!'); };
1379 csiParamStateHandler['0'] = function (parser) { return parser.setParam(parser.getParam() * 10); };
1380 csiParamStateHandler['1'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 1); };
1381 csiParamStateHandler['2'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 2); };
1382 csiParamStateHandler['3'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 3); };
1383 csiParamStateHandler['4'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 4); };
1384 csiParamStateHandler['5'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 5); };
1385 csiParamStateHandler['6'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 6); };
1386 csiParamStateHandler['7'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 7); };
1387 csiParamStateHandler['8'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 8); };
1388 csiParamStateHandler['9'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 9); };
1389 csiParamStateHandler['$'] = function (parser) { return parser.setPostfix('$'); };
1390 csiParamStateHandler['"'] = function (parser) { return parser.setPostfix('"'); };
1391 csiParamStateHandler[' '] = function (parser) { return parser.setPostfix(' '); };
1392 csiParamStateHandler['\''] = function (parser) { return parser.setPostfix('\''); };
1393 csiParamStateHandler[';'] = function (parser) { return parser.finalizeParam(); };
1394 csiParamStateHandler[EscapeSequences_1.C0.CAN] = function (parser) { return parser.setState(ParserState.NORMAL); };
1395 var csiStateHandler = {};
1396 csiStateHandler['@'] = function (handler, params, prefix) { return handler.insertChars(params); };
1397 csiStateHandler['A'] = function (handler, params, prefix) { return handler.cursorUp(params); };
1398 csiStateHandler['B'] = function (handler, params, prefix) { return handler.cursorDown(params); };
1399 csiStateHandler['C'] = function (handler, params, prefix) { return handler.cursorForward(params); };
1400 csiStateHandler['D'] = function (handler, params, prefix) { return handler.cursorBackward(params); };
1401 csiStateHandler['E'] = function (handler, params, prefix) { return handler.cursorNextLine(params); };
1402 csiStateHandler['F'] = function (handler, params, prefix) { return handler.cursorPrecedingLine(params); };
1403 csiStateHandler['G'] = function (handler, params, prefix) { return handler.cursorCharAbsolute(params); };
1404 csiStateHandler['H'] = function (handler, params, prefix) { return handler.cursorPosition(params); };
1405 csiStateHandler['I'] = function (handler, params, prefix) { return handler.cursorForwardTab(params); };
1406 csiStateHandler['J'] = function (handler, params, prefix) { return handler.eraseInDisplay(params); };
1407 csiStateHandler['K'] = function (handler, params, prefix) { return handler.eraseInLine(params); };
1408 csiStateHandler['L'] = function (handler, params, prefix) { return handler.insertLines(params); };
1409 csiStateHandler['M'] = function (handler, params, prefix) { return handler.deleteLines(params); };
1410 csiStateHandler['P'] = function (handler, params, prefix) { return handler.deleteChars(params); };
1411 csiStateHandler['S'] = function (handler, params, prefix) { return handler.scrollUp(params); };
1412 csiStateHandler['T'] = function (handler, params, prefix) {
1413 if (params.length < 2 && !prefix) {
1414 handler.scrollDown(params);
1415 }
1416 };
1417 csiStateHandler['X'] = function (handler, params, prefix) { return handler.eraseChars(params); };
1418 csiStateHandler['Z'] = function (handler, params, prefix) { return handler.cursorBackwardTab(params); };
1419 csiStateHandler['`'] = function (handler, params, prefix) { return handler.charPosAbsolute(params); };
1420 csiStateHandler['a'] = function (handler, params, prefix) { return handler.HPositionRelative(params); };
1421 csiStateHandler['b'] = function (handler, params, prefix) { return handler.repeatPrecedingCharacter(params); };
1422 csiStateHandler['c'] = function (handler, params, prefix) { return handler.sendDeviceAttributes(params); };
1423 csiStateHandler['d'] = function (handler, params, prefix) { return handler.linePosAbsolute(params); };
1424 csiStateHandler['e'] = function (handler, params, prefix) { return handler.VPositionRelative(params); };
1425 csiStateHandler['f'] = function (handler, params, prefix) { return handler.HVPosition(params); };
1426 csiStateHandler['g'] = function (handler, params, prefix) { return handler.tabClear(params); };
1427 csiStateHandler['h'] = function (handler, params, prefix) { return handler.setMode(params); };
1428 csiStateHandler['l'] = function (handler, params, prefix) { return handler.resetMode(params); };
1429 csiStateHandler['m'] = function (handler, params, prefix) { return handler.charAttributes(params); };
1430 csiStateHandler['n'] = function (handler, params, prefix) { return handler.deviceStatus(params); };
1431 csiStateHandler['p'] = function (handler, params, prefix) {
1432 switch (prefix) {
1433 case '!':
1434 handler.softReset(params);
1435 break;
1436 }
1437 };
1438 csiStateHandler['q'] = function (handler, params, prefix, postfix) {
1439 if (postfix === ' ') {
1440 handler.setCursorStyle(params);
1441 }
1442 };
1443 csiStateHandler['r'] = function (handler, params) { return handler.setScrollRegion(params); };
1444 csiStateHandler['s'] = function (handler, params) { return handler.saveCursor(params); };
1445 csiStateHandler['u'] = function (handler, params) { return handler.restoreCursor(params); };
1446 csiStateHandler[EscapeSequences_1.C0.CAN] = function (handler, params, prefix, postfix, parser) { return parser.setState(ParserState.NORMAL); };
1447 var ParserState;
1448 (function (ParserState) {
1449 ParserState[ParserState["NORMAL"] = 0] = "NORMAL";
1450 ParserState[ParserState["ESCAPED"] = 1] = "ESCAPED";
1451 ParserState[ParserState["CSI_PARAM"] = 2] = "CSI_PARAM";
1452 ParserState[ParserState["CSI"] = 3] = "CSI";
1453 ParserState[ParserState["OSC"] = 4] = "OSC";
1454 ParserState[ParserState["CHARSET"] = 5] = "CHARSET";
1455 ParserState[ParserState["DCS"] = 6] = "DCS";
1456 ParserState[ParserState["IGNORE"] = 7] = "IGNORE";
1457 })(ParserState || (ParserState = {}));
1458 var Parser = (function () {
1459 function Parser(_inputHandler, _terminal) {
1460 this._inputHandler = _inputHandler;
1461 this._terminal = _terminal;
1462 this._state = ParserState.NORMAL;
1463 }
1464 Parser.prototype.parse = function (data) {
1465 var l = data.length, j, cs, ch, code, low;
1466 this._position = 0;
1467 if (this._terminal.surrogate_high) {
1468 data = this._terminal.surrogate_high + data;
1469 this._terminal.surrogate_high = '';
1470 }
1471 for (; this._position < l; this._position++) {
1472 ch = data[this._position];
1473 code = data.charCodeAt(this._position);
1474 if (0xD800 <= code && code <= 0xDBFF) {
1475 low = data.charCodeAt(this._position + 1);
1476 if (isNaN(low)) {
1477 this._terminal.surrogate_high = ch;
1478 continue;
1479 }
1480 code = ((code - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
1481 ch += data.charAt(this._position + 1);
1482 }
1483 if (0xDC00 <= code && code <= 0xDFFF)
1484 continue;
1485 switch (this._state) {
1486 case ParserState.NORMAL:
1487 if (ch in normalStateHandler) {
1488 normalStateHandler[ch](this, this._inputHandler);
1489 }
1490 else {
1491 this._inputHandler.addChar(ch, code);
1492 }
1493 break;
1494 case ParserState.ESCAPED:
1495 if (ch in escapedStateHandler) {
1496 escapedStateHandler[ch](this, this._terminal);
1497 break;
1498 }
1499 switch (ch) {
1500 case '(':
1501 case ')':
1502 case '*':
1503 case '+':
1504 case '-':
1505 case '.':
1506 switch (ch) {
1507 case '(':
1508 this._terminal.gcharset = 0;
1509 break;
1510 case ')':
1511 this._terminal.gcharset = 1;
1512 break;
1513 case '*':
1514 this._terminal.gcharset = 2;
1515 break;
1516 case '+':
1517 this._terminal.gcharset = 3;
1518 break;
1519 case '-':
1520 this._terminal.gcharset = 1;
1521 break;
1522 case '.':
1523 this._terminal.gcharset = 2;
1524 break;
1525 }
1526 this._state = ParserState.CHARSET;
1527 break;
1528 case '/':
1529 this._terminal.gcharset = 3;
1530 this._state = ParserState.CHARSET;
1531 this._position--;
1532 break;
1533 case 'N':
1534 break;
1535 case 'O':
1536 break;
1537 case 'n':
1538 this._terminal.setgLevel(2);
1539 break;
1540 case 'o':
1541 this._terminal.setgLevel(3);
1542 break;
1543 case '|':
1544 this._terminal.setgLevel(3);
1545 break;
1546 case '}':
1547 this._terminal.setgLevel(2);
1548 break;
1549 case '~':
1550 this._terminal.setgLevel(1);
1551 break;
1552 case '7':
1553 this._inputHandler.saveCursor();
1554 this._state = ParserState.NORMAL;
1555 break;
1556 case '8':
1557 this._inputHandler.restoreCursor();
1558 this._state = ParserState.NORMAL;
1559 break;
1560 case '#':
1561 this._state = ParserState.NORMAL;
1562 this._position++;
1563 break;
1564 case 'H':
1565 this._terminal.tabSet();
1566 this._state = ParserState.NORMAL;
1567 break;
1568 case '=':
1569 this._terminal.log('Serial port requested application keypad.');
1570 this._terminal.applicationKeypad = true;
1571 this._terminal.viewport.syncScrollArea();
1572 this._state = ParserState.NORMAL;
1573 break;
1574 case '>':
1575 this._terminal.log('Switching back to normal keypad.');
1576 this._terminal.applicationKeypad = false;
1577 this._terminal.viewport.syncScrollArea();
1578 this._state = ParserState.NORMAL;
1579 break;
1580 default:
1581 this._state = ParserState.NORMAL;
1582 this._terminal.error('Unknown ESC control: %s.', ch);
1583 break;
1584 }
1585 break;
1586 case ParserState.CHARSET:
1587 if (ch in Charsets_1.CHARSETS) {
1588 cs = Charsets_1.CHARSETS[ch];
1589 if (ch === '/') {
1590 this.skipNextChar();
1591 }
1592 }
1593 else {
1594 cs = Charsets_1.DEFAULT_CHARSET;
1595 }
1596 this._terminal.setgCharset(this._terminal.gcharset, cs);
1597 this._terminal.gcharset = null;
1598 this._state = ParserState.NORMAL;
1599 break;
1600 case ParserState.OSC:
1601 if (ch === EscapeSequences_1.C0.ESC || ch === EscapeSequences_1.C0.BEL) {
1602 if (ch === EscapeSequences_1.C0.ESC)
1603 this._position++;
1604 this._terminal.params.push(this._terminal.currentParam);
1605 switch (this._terminal.params[0]) {
1606 case 0:
1607 case 1:
1608 case 2:
1609 if (this._terminal.params[1]) {
1610 this._terminal.title = this._terminal.params[1];
1611 this._terminal.handleTitle(this._terminal.title);
1612 }
1613 break;
1614 case 3:
1615 break;
1616 case 4:
1617 case 5:
1618 break;
1619 case 10:
1620 case 11:
1621 case 12:
1622 case 13:
1623 case 14:
1624 case 15:
1625 case 16:
1626 case 17:
1627 case 18:
1628 case 19:
1629 break;
1630 case 46:
1631 break;
1632 case 50:
1633 break;
1634 case 51:
1635 break;
1636 case 52:
1637 break;
1638 case 104:
1639 case 105:
1640 case 110:
1641 case 111:
1642 case 112:
1643 case 113:
1644 case 114:
1645 case 115:
1646 case 116:
1647 case 117:
1648 case 118:
1649 break;
1650 }
1651 this._terminal.params = [];
1652 this._terminal.currentParam = 0;
1653 this._state = ParserState.NORMAL;
1654 }
1655 else {
1656 if (!this._terminal.params.length) {
1657 if (ch >= '0' && ch <= '9') {
1658 this._terminal.currentParam =
1659 this._terminal.currentParam * 10 + ch.charCodeAt(0) - 48;
1660 }
1661 else if (ch === ';') {
1662 this._terminal.params.push(this._terminal.currentParam);
1663 this._terminal.currentParam = '';
1664 }
1665 }
1666 else {
1667 this._terminal.currentParam += ch;
1668 }
1669 }
1670 break;
1671 case ParserState.CSI_PARAM:
1672 if (ch in csiParamStateHandler) {
1673 csiParamStateHandler[ch](this);
1674 break;
1675 }
1676 this.finalizeParam();
1677 this._state = ParserState.CSI;
1678 case ParserState.CSI:
1679 if (ch in csiStateHandler) {
1680 csiStateHandler[ch](this._inputHandler, this._terminal.params, this._terminal.prefix, this._terminal.postfix, this);
1681 }
1682 else {
1683 this._terminal.error('Unknown CSI code: %s.', ch);
1684 }
1685 this._state = ParserState.NORMAL;
1686 this._terminal.prefix = '';
1687 this._terminal.postfix = '';
1688 break;
1689 case ParserState.DCS:
1690 if (ch === EscapeSequences_1.C0.ESC || ch === EscapeSequences_1.C0.BEL) {
1691 if (ch === EscapeSequences_1.C0.ESC)
1692 this._position++;
1693 switch (this._terminal.prefix) {
1694 case '':
1695 break;
1696 case '$q':
1697 var pt = this._terminal.currentParam, valid = false;
1698 switch (pt) {
1699 case '"q':
1700 pt = '0"q';
1701 break;
1702 case '"p':
1703 pt = '61"p';
1704 break;
1705 case 'r':
1706 pt = ''
1707 + (this._terminal.scrollTop + 1)
1708 + ';'
1709 + (this._terminal.scrollBottom + 1)
1710 + 'r';
1711 break;
1712 case 'm':
1713 pt = '0m';
1714 break;
1715 default:
1716 this._terminal.error('Unknown DCS Pt: %s.', pt);
1717 pt = '';
1718 break;
1719 }
1720 this._terminal.send(EscapeSequences_1.C0.ESC + 'P' + +valid + '$r' + pt + EscapeSequences_1.C0.ESC + '\\');
1721 break;
1722 case '+p':
1723 break;
1724 case '+q':
1725 pt = this._terminal.currentParam
1726 , valid = false;
1727 this._terminal.send(EscapeSequences_1.C0.ESC + 'P' + +valid + '+r' + pt + EscapeSequences_1.C0.ESC + '\\');
1728 break;
1729 default:
1730 this._terminal.error('Unknown DCS prefix: %s.', this._terminal.prefix);
1731 break;
1732 }
1733 this._terminal.currentParam = 0;
1734 this._terminal.prefix = '';
1735 this._state = ParserState.NORMAL;
1736 }
1737 else if (!this._terminal.currentParam) {
1738 if (!this._terminal.prefix && ch !== '$' && ch !== '+') {
1739 this._terminal.currentParam = ch;
1740 }
1741 else if (this._terminal.prefix.length === 2) {
1742 this._terminal.currentParam = ch;
1743 }
1744 else {
1745 this._terminal.prefix += ch;
1746 }
1747 }
1748 else {
1749 this._terminal.currentParam += ch;
1750 }
1751 break;
1752 case ParserState.IGNORE:
1753 if (ch === EscapeSequences_1.C0.ESC || ch === EscapeSequences_1.C0.BEL) {
1754 if (ch === EscapeSequences_1.C0.ESC)
1755 this._position++;
1756 this._state = ParserState.NORMAL;
1757 }
1758 break;
1759 }
1760 }
1761 };
1762 Parser.prototype.setState = function (state) {
1763 this._state = state;
1764 };
1765 Parser.prototype.setPrefix = function (prefix) {
1766 this._terminal.prefix = prefix;
1767 };
1768 Parser.prototype.setPostfix = function (postfix) {
1769 this._terminal.postfix = postfix;
1770 };
1771 Parser.prototype.setParam = function (param) {
1772 this._terminal.currentParam = param;
1773 };
1774 Parser.prototype.getParam = function () {
1775 return this._terminal.currentParam;
1776 };
1777 Parser.prototype.finalizeParam = function () {
1778 this._terminal.params.push(this._terminal.currentParam);
1779 this._terminal.currentParam = 0;
1780 };
1781 Parser.prototype.skipNextChar = function () {
1782 this._position++;
1783 };
1784 return Parser;
1785 }());
1786 exports.Parser = Parser;
1787
1788
1789
1790 },{"./Charsets":1,"./EscapeSequences":3}],7:[function(require,module,exports){
1791 "use strict";
1792 var MAX_REFRESH_FRAME_SKIP = 5;
1793 var FLAGS;
1794 (function (FLAGS) {
1795 FLAGS[FLAGS["BOLD"] = 1] = "BOLD";
1796 FLAGS[FLAGS["UNDERLINE"] = 2] = "UNDERLINE";
1797 FLAGS[FLAGS["BLINK"] = 4] = "BLINK";
1798 FLAGS[FLAGS["INVERSE"] = 8] = "INVERSE";
1799 FLAGS[FLAGS["INVISIBLE"] = 16] = "INVISIBLE";
1800 })(FLAGS || (FLAGS = {}));
1801 ;
1802 var brokenBold = null;
1803 var Renderer = (function () {
1804 function Renderer(_terminal) {
1805 this._terminal = _terminal;
1806 this._refreshRowsQueue = [];
1807 this._refreshFramesSkipped = 0;
1808 this._refreshAnimationFrame = null;
1809 if (brokenBold === null) {
1810 brokenBold = checkBoldBroken(this._terminal.document);
1811 }
1812 }
1813 Renderer.prototype.queueRefresh = function (start, end) {
1814 this._refreshRowsQueue.push({ start: start, end: end });
1815 if (!this._refreshAnimationFrame) {
1816 this._refreshAnimationFrame = window.requestAnimationFrame(this._refreshLoop.bind(this));
1817 }
1818 };
1819 Renderer.prototype._refreshLoop = function () {
1820 var skipFrame = this._terminal.writeBuffer.length > 0 && this._refreshFramesSkipped++ <= MAX_REFRESH_FRAME_SKIP;
1821 if (skipFrame) {
1822 this._refreshAnimationFrame = window.requestAnimationFrame(this._refreshLoop.bind(this));
1823 return;
1824 }
1825 this._refreshFramesSkipped = 0;
1826 var start;
1827 var end;
1828 if (this._refreshRowsQueue.length > 4) {
1829 start = 0;
1830 end = this._terminal.rows - 1;
1831 }
1832 else {
1833 start = this._refreshRowsQueue[0].start;
1834 end = this._refreshRowsQueue[0].end;
1835 for (var i = 1; i < this._refreshRowsQueue.length; i++) {
1836 if (this._refreshRowsQueue[i].start < start) {
1837 start = this._refreshRowsQueue[i].start;
1838 }
1839 if (this._refreshRowsQueue[i].end > end) {
1840 end = this._refreshRowsQueue[i].end;
1841 }
1842 }
1843 }
1844 this._refreshRowsQueue = [];
1845 this._refreshAnimationFrame = null;
1846 this._refresh(start, end);
1847 };
1848 Renderer.prototype._refresh = function (start, end) {
1849 var x, y, i, line, out, ch, ch_width, width, data, attr, bg, fg, flags, row, parent, focused = document.activeElement;
1850 if (end - start >= this._terminal.rows / 2) {
1851 parent = this._terminal.element.parentNode;
1852 if (parent) {
1853 this._terminal.element.removeChild(this._terminal.rowContainer);
1854 }
1855 }
1856 width = this._terminal.cols;
1857 y = start;
1858 if (end >= this._terminal.rows) {
1859 this._terminal.log('`end` is too large. Most likely a bad CSR.');
1860 end = this._terminal.rows - 1;
1861 }
1862 for (; y <= end; y++) {
1863 row = y + this._terminal.ydisp;
1864 line = this._terminal.lines.get(row);
1865 if (!line || !this._terminal.children[y]) {
1866 continue;
1867 }
1868 out = '';
1869 if (this._terminal.y === y - (this._terminal.ybase - this._terminal.ydisp)
1870 && this._terminal.cursorState
1871 && !this._terminal.cursorHidden) {
1872 x = this._terminal.x;
1873 }
1874 else {
1875 x = -1;
1876 }
1877 attr = this._terminal.defAttr;
1878 i = 0;
1879 for (; i < width; i++) {
1880 if (!line[i]) {
1881 continue;
1882 }
1883 data = line[i][0];
1884 ch = line[i][1];
1885 ch_width = line[i][2];
1886 if (!ch_width)
1887 continue;
1888 if (i === x)
1889 data = -1;
1890 if (data !== attr) {
1891 if (attr !== this._terminal.defAttr) {
1892 out += '</span>';
1893 }
1894 if (data !== this._terminal.defAttr) {
1895 if (data === -1) {
1896 out += '<span class="reverse-video terminal-cursor">';
1897 }
1898 else {
1899 var classNames = [];
1900 bg = data & 0x1ff;
1901 fg = (data >> 9) & 0x1ff;
1902 flags = data >> 18;
1903 if (flags & FLAGS.BOLD) {
1904 if (!brokenBold) {
1905 classNames.push('xterm-bold');
1906 }
1907 if (fg < 8)
1908 fg += 8;
1909 }
1910 if (flags & FLAGS.UNDERLINE) {
1911 classNames.push('xterm-underline');
1912 }
1913 if (flags & FLAGS.BLINK) {
1914 classNames.push('xterm-blink');
1915 }
1916 if (flags & FLAGS.INVERSE) {
1917 bg = [fg, fg = bg][0];
1918 if ((flags & 1) && fg < 8)
1919 fg += 8;
1920 }
1921 if (flags & FLAGS.INVISIBLE) {
1922 classNames.push('xterm-hidden');
1923 }
1924 if (flags & FLAGS.INVERSE) {
1925 if (bg === 257) {
1926 bg = 15;
1927 }
1928 if (fg === 256) {
1929 fg = 0;
1930 }
1931 }
1932 if (bg < 256) {
1933 classNames.push('xterm-bg-color-' + bg);
1934 }
1935 if (fg < 256) {
1936 classNames.push('xterm-color-' + fg);
1937 }
1938 out += '<span';
1939 if (classNames.length) {
1940 out += ' class="' + classNames.join(' ') + '"';
1941 }
1942 out += '>';
1943 }
1944 }
1945 }
1946 if (ch_width === 2) {
1947 out += '<span class="xterm-wide-char">';
1948 }
1949 switch (ch) {
1950 case '&':
1951 out += '&amp;';
1952 break;
1953 case '<':
1954 out += '&lt;';
1955 break;
1956 case '>':
1957 out += '&gt;';
1958 break;
1959 default:
1960 if (ch <= ' ') {
1961 out += '&nbsp;';
1962 }
1963 else {
1964 out += ch;
1965 }
1966 break;
1967 }
1968 if (ch_width === 2) {
1969 out += '</span>';
1970 }
1971 attr = data;
1972 }
1973 if (attr !== this._terminal.defAttr) {
1974 out += '</span>';
1975 }
1976 this._terminal.children[y].innerHTML = out;
1977 }
1978 if (parent) {
1979 this._terminal.element.appendChild(this._terminal.rowContainer);
1980 }
1981 this._terminal.emit('refresh', { element: this._terminal.element, start: start, end: end });
1982 };
1983 ;
1984 return Renderer;
1985 }());
1986 exports.Renderer = Renderer;
1987 function checkBoldBroken(document) {
1988 var body = document.getElementsByTagName('body')[0];
1989 var el = document.createElement('span');
1990 el.innerHTML = 'hello world';
1991 body.appendChild(el);
1992 var w1 = el.scrollWidth;
1993 el.style.fontWeight = 'bold';
1994 var w2 = el.scrollWidth;
1995 body.removeChild(el);
1996 return w1 !== w2;
1997 }
1998
1999
2000
2001 },{}],8:[function(require,module,exports){
2002 "use strict";
2003 var Viewport = (function () {
2004 function Viewport(terminal, viewportElement, scrollArea, charMeasure) {
2005 var _this = this;
2006 this.terminal = terminal;
2007 this.viewportElement = viewportElement;
2008 this.scrollArea = scrollArea;
2009 this.charMeasure = charMeasure;
2010 this.currentRowHeight = 0;
2011 this.lastRecordedBufferLength = 0;
2012 this.lastRecordedViewportHeight = 0;
2013 this.terminal.on('scroll', this.syncScrollArea.bind(this));
2014 this.terminal.on('resize', this.syncScrollArea.bind(this));
2015 this.viewportElement.addEventListener('scroll', this.onScroll.bind(this));
2016 setTimeout(function () { return _this.syncScrollArea(); }, 0);
2017 }
2018 Viewport.prototype.refresh = function () {
2019 if (this.charMeasure.height > 0) {
2020 var rowHeightChanged = this.charMeasure.height !== this.currentRowHeight;
2021 if (rowHeightChanged) {
2022 this.currentRowHeight = this.charMeasure.height;
2023 this.viewportElement.style.lineHeight = this.charMeasure.height + 'px';
2024 this.terminal.rowContainer.style.lineHeight = this.charMeasure.height + 'px';
2025 }
2026 var viewportHeightChanged = this.lastRecordedViewportHeight !== this.terminal.rows;
2027 if (rowHeightChanged || viewportHeightChanged) {
2028 this.lastRecordedViewportHeight = this.terminal.rows;
2029 this.viewportElement.style.height = this.charMeasure.height * this.terminal.rows + 'px';
2030 }
2031 this.scrollArea.style.height = (this.charMeasure.height * this.lastRecordedBufferLength) + 'px';
2032 }
2033 };
2034 Viewport.prototype.syncScrollArea = function () {
2035 if (this.lastRecordedBufferLength !== this.terminal.lines.length) {
2036 this.lastRecordedBufferLength = this.terminal.lines.length;
2037 this.refresh();
2038 }
2039 else if (this.lastRecordedViewportHeight !== this.terminal.rows) {
2040 this.refresh();
2041 }
2042 else {
2043 if (this.charMeasure.height !== this.currentRowHeight) {
2044 this.refresh();
2045 }
2046 }
2047 var scrollTop = this.terminal.ydisp * this.currentRowHeight;
2048 if (this.viewportElement.scrollTop !== scrollTop) {
2049 this.viewportElement.scrollTop = scrollTop;
2050 }
2051 };
2052 Viewport.prototype.onScroll = function (ev) {
2053 var newRow = Math.round(this.viewportElement.scrollTop / this.currentRowHeight);
2054 var diff = newRow - this.terminal.ydisp;
2055 this.terminal.scrollDisp(diff, true);
2056 };
2057 Viewport.prototype.onWheel = function (ev) {
2058 if (ev.deltaY === 0) {
2059 return;
2060 }
2061 var multiplier = 1;
2062 if (ev.deltaMode === WheelEvent.DOM_DELTA_LINE) {
2063 multiplier = this.currentRowHeight;
2064 }
2065 else if (ev.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
2066 multiplier = this.currentRowHeight * this.terminal.rows;
2067 }
2068 this.viewportElement.scrollTop += ev.deltaY * multiplier;
2069 ev.preventDefault();
2070 };
2071 ;
2072 return Viewport;
2073 }());
2074 exports.Viewport = Viewport;
2075
2076
2077
2078 },{}],9:[function(require,module,exports){
2079 "use strict";
2080 function prepareTextForClipboard(text) {
2081 var space = String.fromCharCode(32), nonBreakingSpace = String.fromCharCode(160), allNonBreakingSpaces = new RegExp(nonBreakingSpace, 'g'), processedText = text.split('\n').map(function (line) {
2082 var processedLine = line.replace(/\s+$/g, '').replace(allNonBreakingSpaces, space);
2083 return processedLine;
2084 }).join('\n');
2085 return processedText;
2086 }
2087 exports.prepareTextForClipboard = prepareTextForClipboard;
2088 function copyHandler(ev, term) {
2089 var copiedText = window.getSelection().toString(), text = prepareTextForClipboard(copiedText);
2090 if (term.browser.isMSIE) {
2091 window.clipboardData.setData('Text', text);
2092 }
2093 else {
2094 ev.clipboardData.setData('text/plain', text);
2095 }
2096 ev.preventDefault();
2097 }
2098 exports.copyHandler = copyHandler;
2099 function pasteHandler(ev, term) {
2100 ev.stopPropagation();
2101 var text;
2102 var dispatchPaste = function (text) {
2103 term.handler(text);
2104 term.textarea.value = '';
2105 return term.cancel(ev);
2106 };
2107 if (term.browser.isMSIE) {
2108 if (window.clipboardData) {
2109 text = window.clipboardData.getData('Text');
2110 dispatchPaste(text);
2111 }
2112 }
2113 else {
2114 if (ev.clipboardData) {
2115 text = ev.clipboardData.getData('text/plain');
2116 dispatchPaste(text);
2117 }
2118 }
2119 }
2120 exports.pasteHandler = pasteHandler;
2121 function rightClickHandler(ev, term) {
2122 var s = document.getSelection(), selectedText = prepareTextForClipboard(s.toString()), clickIsOnSelection = false, x = ev.clientX, y = ev.clientY;
2123 if (s.rangeCount) {
2124 var r = s.getRangeAt(0), cr = r.getClientRects();
2125 for (var i = 0; i < cr.length; i++) {
2126 var rect = cr[i];
2127 clickIsOnSelection = ((x > rect.left) && (x < rect.right) &&
2128 (y > rect.top) && (y < rect.bottom));
2129 if (clickIsOnSelection) {
2130 break;
2131 }
2132 }
2133 if (selectedText.match(/^\s$/) || !selectedText.length) {
2134 clickIsOnSelection = false;
2135 }
2136 }
2137 if (!clickIsOnSelection) {
2138 term.textarea.style.position = 'fixed';
2139 term.textarea.style.width = '20px';
2140 term.textarea.style.height = '20px';
2141 term.textarea.style.left = (x - 10) + 'px';
2142 term.textarea.style.top = (y - 10) + 'px';
2143 term.textarea.style.zIndex = '1000';
2144 term.textarea.focus();
2145 setTimeout(function () {
2146 term.textarea.style.position = null;
2147 term.textarea.style.width = null;
2148 term.textarea.style.height = null;
2149 term.textarea.style.left = null;
2150 term.textarea.style.top = null;
2151 term.textarea.style.zIndex = null;
2152 }, 4);
2153 }
2154 }
2155 exports.rightClickHandler = rightClickHandler;
2156
2157
2158
2159 },{}],10:[function(require,module,exports){
2160 "use strict";
2161 var Generic_1 = require("./Generic");
2162 var isNode = (typeof navigator === 'undefined') ? true : false;
2163 var userAgent = (isNode) ? 'node' : navigator.userAgent;
2164 var platform = (isNode) ? 'node' : navigator.platform;
2165 exports.isFirefox = !!~userAgent.indexOf('Firefox');
2166 exports.isMSIE = !!~userAgent.indexOf('MSIE') || !!~userAgent.indexOf('Trident');
2167 exports.isMac = Generic_1.contains(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], platform);
2168 exports.isIpad = platform === 'iPad';
2169 exports.isIphone = platform === 'iPhone';
2170 exports.isMSWindows = Generic_1.contains(['Windows', 'Win16', 'Win32', 'WinCE'], platform);
2171
2172
2173
2174 },{"./Generic":13}],11:[function(require,module,exports){
2175 "use strict";
2176 var __extends = (this && this.__extends) || function (d, b) {
2177 for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
2178 function __() { this.constructor = d; }
2179 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
2180 };
2181 var EventEmitter_js_1 = require("../EventEmitter.js");
2182 var CharMeasure = (function (_super) {
2183 __extends(CharMeasure, _super);
2184 function CharMeasure(parentElement) {
2185 var _this = _super.call(this) || this;
2186 _this._parentElement = parentElement;
2187 return _this;
2188 }
2189 Object.defineProperty(CharMeasure.prototype, "width", {
2190 get: function () {
2191 return this._width;
2192 },
2193 enumerable: true,
2194 configurable: true
2195 });
2196 Object.defineProperty(CharMeasure.prototype, "height", {
2197 get: function () {
2198 return this._height;
2199 },
2200 enumerable: true,
2201 configurable: true
2202 });
2203 CharMeasure.prototype.measure = function () {
2204 var _this = this;
2205 if (!this._measureElement) {
2206 this._measureElement = document.createElement('span');
2207 this._measureElement.style.position = 'absolute';
2208 this._measureElement.style.top = '0';
2209 this._measureElement.style.left = '-9999em';
2210 this._measureElement.textContent = 'W';
2211 this._parentElement.appendChild(this._measureElement);
2212 setTimeout(function () { return _this._doMeasure(); }, 0);
2213 }
2214 else {
2215 this._doMeasure();
2216 }
2217 };
2218 CharMeasure.prototype._doMeasure = function () {
2219 var geometry = this._measureElement.getBoundingClientRect();
2220 if (geometry.width === 0 || geometry.height === 0) {
2221 return;
2222 }
2223 if (this._width !== geometry.width || this._height !== geometry.height) {
2224 this._width = geometry.width;
2225 this._height = geometry.height;
2226 this.emit('charsizechanged');
2227 }
2228 };
2229 return CharMeasure;
2230 }(EventEmitter_js_1.EventEmitter));
2231 exports.CharMeasure = CharMeasure;
2232
2233
2234
2235 },{"../EventEmitter.js":4}],12:[function(require,module,exports){
2236 "use strict";
2237 var CircularList = (function () {
2238 function CircularList(maxLength) {
2239 this._array = new Array(maxLength);
2240 this._startIndex = 0;
2241 this._length = 0;
2242 }
2243 Object.defineProperty(CircularList.prototype, "maxLength", {
2244 get: function () {
2245 return this._array.length;
2246 },
2247 set: function (newMaxLength) {
2248 var newArray = new Array(newMaxLength);
2249 for (var i = 0; i < Math.min(newMaxLength, this.length); i++) {
2250 newArray[i] = this._array[this._getCyclicIndex(i)];
2251 }
2252 this._array = newArray;
2253 this._startIndex = 0;
2254 },
2255 enumerable: true,
2256 configurable: true
2257 });
2258 Object.defineProperty(CircularList.prototype, "length", {
2259 get: function () {
2260 return this._length;
2261 },
2262 set: function (newLength) {
2263 if (newLength > this._length) {
2264 for (var i = this._length; i < newLength; i++) {
2265 this._array[i] = undefined;
2266 }
2267 }
2268 this._length = newLength;
2269 },
2270 enumerable: true,
2271 configurable: true
2272 });
2273 Object.defineProperty(CircularList.prototype, "forEach", {
2274 get: function () {
2275 return this._array.forEach;
2276 },
2277 enumerable: true,
2278 configurable: true
2279 });
2280 CircularList.prototype.get = function (index) {
2281 return this._array[this._getCyclicIndex(index)];
2282 };
2283 CircularList.prototype.set = function (index, value) {
2284 this._array[this._getCyclicIndex(index)] = value;
2285 };
2286 CircularList.prototype.push = function (value) {
2287 this._array[this._getCyclicIndex(this._length)] = value;
2288 if (this._length === this.maxLength) {
2289 this._startIndex++;
2290 if (this._startIndex === this.maxLength) {
2291 this._startIndex = 0;
2292 }
2293 }
2294 else {
2295 this._length++;
2296 }
2297 };
2298 CircularList.prototype.pop = function () {
2299 return this._array[this._getCyclicIndex(this._length-- - 1)];
2300 };
2301 CircularList.prototype.splice = function (start, deleteCount) {
2302 var items = [];
2303 for (var _i = 2; _i < arguments.length; _i++) {
2304 items[_i - 2] = arguments[_i];
2305 }
2306 if (deleteCount) {
2307 for (var i = start; i < this._length - deleteCount; i++) {
2308 this._array[this._getCyclicIndex(i)] = this._array[this._getCyclicIndex(i + deleteCount)];
2309 }
2310 this._length -= deleteCount;
2311 }
2312 if (items && items.length) {
2313 for (var i = this._length - 1; i >= start; i--) {
2314 this._array[this._getCyclicIndex(i + items.length)] = this._array[this._getCyclicIndex(i)];
2315 }
2316 for (var i = 0; i < items.length; i++) {
2317 this._array[this._getCyclicIndex(start + i)] = items[i];
2318 }
2319 if (this._length + items.length > this.maxLength) {
2320 this._startIndex += (this._length + items.length) - this.maxLength;
2321 this._length = this.maxLength;
2322 }
2323 else {
2324 this._length += items.length;
2325 }
2326 }
2327 };
2328 CircularList.prototype.trimStart = function (count) {
2329 if (count > this._length) {
2330 count = this._length;
2331 }
2332 this._startIndex += count;
2333 this._length -= count;
2334 };
2335 CircularList.prototype.shiftElements = function (start, count, offset) {
2336 if (count <= 0) {
2337 return;
2338 }
2339 if (start < 0 || start >= this._length) {
2340 throw new Error('start argument out of range');
2341 }
2342 if (start + offset < 0) {
2343 throw new Error('Cannot shift elements in list beyond index 0');
2344 }
2345 if (offset > 0) {
2346 for (var i = count - 1; i >= 0; i--) {
2347 this.set(start + i + offset, this.get(start + i));
2348 }
2349 var expandListBy = (start + count + offset) - this._length;
2350 if (expandListBy > 0) {
2351 this._length += expandListBy;
2352 while (this._length > this.maxLength) {
2353 this._length--;
2354 this._startIndex++;
2355 }
2356 }
2357 }
2358 else {
2359 for (var i = 0; i < count; i++) {
2360 this.set(start + i + offset, this.get(start + i));
2361 }
2362 }
2363 };
2364 CircularList.prototype._getCyclicIndex = function (index) {
2365 return (this._startIndex + index) % this.maxLength;
2366 };
2367 return CircularList;
2368 }());
2369 exports.CircularList = CircularList;
2370
2371
2372
2373 },{}],13:[function(require,module,exports){
2374 "use strict";
2375 function contains(arr, el) {
2376 return arr.indexOf(el) >= 0;
2377 }
2378 exports.contains = contains;
2379 ;
2380
2381
2382
2383 },{}],14:[function(require,module,exports){
2384 "use strict";
2385 var CompositionHelper_1 = require("./CompositionHelper");
2386 var EventEmitter_1 = require("./EventEmitter");
2387 var Viewport_1 = require("./Viewport");
2388 var Clipboard_1 = require("./handlers/Clipboard");
2389 var CircularList_1 = require("./utils/CircularList");
2390 var EscapeSequences_1 = require("./EscapeSequences");
2391 var InputHandler_1 = require("./InputHandler");
2392 var Parser_1 = require("./Parser");
2393 var Renderer_1 = require("./Renderer");
2394 var CharMeasure_1 = require("./utils/CharMeasure");
2395 var Browser = require("./utils/Browser");
2396 var document = (typeof window != 'undefined') ? window.document : null;
2397 var WRITE_BUFFER_PAUSE_THRESHOLD = 5;
2398 var WRITE_BATCH_SIZE = 300;
2399 function Terminal(options) {
2400 var self = this;
2401 if (!(this instanceof Terminal)) {
2402 return new Terminal(arguments[0], arguments[1], arguments[2]);
2403 }
2404 self.browser = Browser;
2405 self.cancel = Terminal.cancel;
2406 EventEmitter_1.EventEmitter.call(this);
2407 if (typeof options === 'number') {
2408 options = {
2409 cols: arguments[0],
2410 rows: arguments[1],
2411 handler: arguments[2]
2412 };
2413 }
2414 options = options || {};
2415 Object.keys(Terminal.defaults).forEach(function (key) {
2416 if (options[key] == null) {
2417 options[key] = Terminal.options[key];
2418 if (Terminal[key] !== Terminal.defaults[key]) {
2419 options[key] = Terminal[key];
2420 }
2421 }
2422 self[key] = options[key];
2423 });
2424 if (options.colors.length === 8) {
2425 options.colors = options.colors.concat(Terminal._colors.slice(8));
2426 }
2427 else if (options.colors.length === 16) {
2428 options.colors = options.colors.concat(Terminal._colors.slice(16));
2429 }
2430 else if (options.colors.length === 10) {
2431 options.colors = options.colors.slice(0, -2).concat(Terminal._colors.slice(8, -2), options.colors.slice(-2));
2432 }
2433 else if (options.colors.length === 18) {
2434 options.colors = options.colors.concat(Terminal._colors.slice(16, -2), options.colors.slice(-2));
2435 }
2436 this.colors = options.colors;
2437 this.options = options;
2438 this.parent = options.body || options.parent || (document ? document.getElementsByTagName('body')[0] : null);
2439 this.cols = options.cols || options.geometry[0];
2440 this.rows = options.rows || options.geometry[1];
2441 this.geometry = [this.cols, this.rows];
2442 if (options.handler) {
2443 this.on('data', options.handler);
2444 }
2445 this.ybase = 0;
2446 this.ydisp = 0;
2447 this.x = 0;
2448 this.y = 0;
2449 this.cursorState = 0;
2450 this.cursorHidden = false;
2451 this.convertEol;
2452 this.queue = '';
2453 this.scrollTop = 0;
2454 this.scrollBottom = this.rows - 1;
2455 this.customKeydownHandler = null;
2456 this.applicationKeypad = false;
2457 this.applicationCursor = false;
2458 this.originMode = false;
2459 this.insertMode = false;
2460 this.wraparoundMode = true;
2461 this.normal = null;
2462 this.charset = null;
2463 this.gcharset = null;
2464 this.glevel = 0;
2465 this.charsets = [null];
2466 this.decLocator;
2467 this.x10Mouse;
2468 this.vt200Mouse;
2469 this.vt300Mouse;
2470 this.normalMouse;
2471 this.mouseEvents;
2472 this.sendFocus;
2473 this.utfMouse;
2474 this.sgrMouse;
2475 this.urxvtMouse;
2476 this.element;
2477 this.children;
2478 this.refreshStart;
2479 this.refreshEnd;
2480 this.savedX;
2481 this.savedY;
2482 this.savedCols;
2483 this.readable = true;
2484 this.writable = true;
2485 this.defAttr = (0 << 18) | (257 << 9) | (256 << 0);
2486 this.curAttr = this.defAttr;
2487 this.params = [];
2488 this.currentParam = 0;
2489 this.prefix = '';
2490 this.postfix = '';
2491 this.inputHandler = new InputHandler_1.InputHandler(this);
2492 this.parser = new Parser_1.Parser(this.inputHandler, this);
2493 this.renderer = this.renderer || null;
2494 this.writeBuffer = [];
2495 this.writeInProgress = false;
2496 this.xoffSentToCatchUp = false;
2497 this.writeStopped = false;
2498 this.surrogate_high = '';
2499 this.lines = new CircularList_1.CircularList(this.scrollback);
2500 var i = this.rows;
2501 while (i--) {
2502 this.lines.push(this.blankLine());
2503 }
2504 this.tabs;
2505 this.setupStops();
2506 this.userScrolling = false;
2507 }
2508 inherits(Terminal, EventEmitter_1.EventEmitter);
2509 Terminal.prototype.eraseAttr = function () {
2510 return (this.defAttr & ~0x1ff) | (this.curAttr & 0x1ff);
2511 };
2512 Terminal.tangoColors = [
2513 '#2e3436',
2514 '#cc0000',
2515 '#4e9a06',
2516 '#c4a000',
2517 '#3465a4',
2518 '#75507b',
2519 '#06989a',
2520 '#d3d7cf',
2521 '#555753',
2522 '#ef2929',
2523 '#8ae234',
2524 '#fce94f',
2525 '#729fcf',
2526 '#ad7fa8',
2527 '#34e2e2',
2528 '#eeeeec'
2529 ];
2530 Terminal.colors = (function () {
2531 var colors = Terminal.tangoColors.slice(), r = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff], i;
2532 i = 0;
2533 for (; i < 216; i++) {
2534 out(r[(i / 36) % 6 | 0], r[(i / 6) % 6 | 0], r[i % 6]);
2535 }
2536 i = 0;
2537 for (; i < 24; i++) {
2538 r = 8 + i * 10;
2539 out(r, r, r);
2540 }
2541 function out(r, g, b) {
2542 colors.push('#' + hex(r) + hex(g) + hex(b));
2543 }
2544 function hex(c) {
2545 c = c.toString(16);
2546 return c.length < 2 ? '0' + c : c;
2547 }
2548 return colors;
2549 })();
2550 Terminal._colors = Terminal.colors.slice();
2551 Terminal.vcolors = (function () {
2552 var out = [], colors = Terminal.colors, i = 0, color;
2553 for (; i < 256; i++) {
2554 color = parseInt(colors[i].substring(1), 16);
2555 out.push([
2556 (color >> 16) & 0xff,
2557 (color >> 8) & 0xff,
2558 color & 0xff
2559 ]);
2560 }
2561 return out;
2562 })();
2563 Terminal.defaults = {
2564 colors: Terminal.colors,
2565 theme: 'default',
2566 convertEol: false,
2567 termName: 'xterm',
2568 geometry: [80, 24],
2569 cursorBlink: false,
2570 cursorStyle: 'block',
2571 visualBell: false,
2572 popOnBell: false,
2573 scrollback: 1000,
2574 screenKeys: false,
2575 debug: false,
2576 cancelEvents: false,
2577 disableStdin: false,
2578 useFlowControl: false,
2579 tabStopWidth: 8
2580 };
2581 Terminal.options = {};
2582 Terminal.focus = null;
2583 each(keys(Terminal.defaults), function (key) {
2584 Terminal[key] = Terminal.defaults[key];
2585 Terminal.options[key] = Terminal.defaults[key];
2586 });
2587 Terminal.prototype.focus = function () {
2588 return this.textarea.focus();
2589 };
2590 Terminal.prototype.getOption = function (key, value) {
2591 if (!(key in Terminal.defaults)) {
2592 throw new Error('No option with key "' + key + '"');
2593 }
2594 if (typeof this.options[key] !== 'undefined') {
2595 return this.options[key];
2596 }
2597 return this[key];
2598 };
2599 Terminal.prototype.setOption = function (key, value) {
2600 if (!(key in Terminal.defaults)) {
2601 throw new Error('No option with key "' + key + '"');
2602 }
2603 switch (key) {
2604 case 'scrollback':
2605 if (this.options[key] !== value) {
2606 if (this.lines.length > value) {
2607 var amountToTrim = this.lines.length - value;
2608 var needsRefresh = (this.ydisp - amountToTrim < 0);
2609 this.lines.trimStart(amountToTrim);
2610 this.ybase = Math.max(this.ybase - amountToTrim, 0);
2611 this.ydisp = Math.max(this.ydisp - amountToTrim, 0);
2612 if (needsRefresh) {
2613 this.refresh(0, this.rows - 1);
2614 }
2615 }
2616 this.lines.maxLength = value;
2617 this.viewport.syncScrollArea();
2618 }
2619 break;
2620 }
2621 this[key] = value;
2622 this.options[key] = value;
2623 switch (key) {
2624 case 'cursorBlink':
2625 this.element.classList.toggle('xterm-cursor-blink', value);
2626 break;
2627 case 'cursorStyle':
2628 this.element.classList.toggle("xterm-cursor-style-underline", value === 'underline');
2629 this.element.classList.toggle("xterm-cursor-style-bar", value === 'bar');
2630 break;
2631 case 'tabStopWidth':
2632 this.setupStops();
2633 break;
2634 }
2635 };
2636 Terminal.bindFocus = function (term) {
2637 on(term.textarea, 'focus', function (ev) {
2638 if (term.sendFocus) {
2639 term.send(EscapeSequences_1.C0.ESC + '[I');
2640 }
2641 term.element.classList.add('focus');
2642 term.showCursor();
2643 Terminal.focus = term;
2644 term.emit('focus', { terminal: term });
2645 });
2646 };
2647 Terminal.prototype.blur = function () {
2648 return this.textarea.blur();
2649 };
2650 Terminal.bindBlur = function (term) {
2651 on(term.textarea, 'blur', function (ev) {
2652 term.refresh(term.y, term.y);
2653 if (term.sendFocus) {
2654 term.send(EscapeSequences_1.C0.ESC + '[O');
2655 }
2656 term.element.classList.remove('focus');
2657 Terminal.focus = null;
2658 term.emit('blur', { terminal: term });
2659 });
2660 };
2661 Terminal.prototype.initGlobal = function () {
2662 var term = this;
2663 Terminal.bindKeys(this);
2664 Terminal.bindFocus(this);
2665 Terminal.bindBlur(this);
2666 on(this.element, 'copy', function (ev) {
2667 Clipboard_1.copyHandler.call(this, ev, term);
2668 });
2669 on(this.textarea, 'paste', function (ev) {
2670 Clipboard_1.pasteHandler.call(this, ev, term);
2671 });
2672 on(this.element, 'paste', function (ev) {
2673 Clipboard_1.pasteHandler.call(this, ev, term);
2674 });
2675 function rightClickHandlerWrapper(ev) {
2676 Clipboard_1.rightClickHandler.call(this, ev, term);
2677 }
2678 if (term.browser.isFirefox) {
2679 on(this.element, 'mousedown', function (ev) {
2680 if (ev.button == 2) {
2681 rightClickHandlerWrapper(ev);
2682 }
2683 });
2684 }
2685 else {
2686 on(this.element, 'contextmenu', rightClickHandlerWrapper);
2687 }
2688 };
2689 Terminal.bindKeys = function (term) {
2690 on(term.element, 'keydown', function (ev) {
2691 if (document.activeElement != this) {
2692 return;
2693 }
2694 term.keyDown(ev);
2695 }, true);
2696 on(term.element, 'keypress', function (ev) {
2697 if (document.activeElement != this) {
2698 return;
2699 }
2700 term.keyPress(ev);
2701 }, true);
2702 on(term.element, 'keyup', function (ev) {
2703 if (!wasMondifierKeyOnlyEvent(ev)) {
2704 term.focus(term);
2705 }
2706 }, true);
2707 on(term.textarea, 'keydown', function (ev) {
2708 term.keyDown(ev);
2709 }, true);
2710 on(term.textarea, 'keypress', function (ev) {
2711 term.keyPress(ev);
2712 this.value = '';
2713 }, true);
2714 on(term.textarea, 'compositionstart', term.compositionHelper.compositionstart.bind(term.compositionHelper));
2715 on(term.textarea, 'compositionupdate', term.compositionHelper.compositionupdate.bind(term.compositionHelper));
2716 on(term.textarea, 'compositionend', term.compositionHelper.compositionend.bind(term.compositionHelper));
2717 term.on('refresh', term.compositionHelper.updateCompositionElements.bind(term.compositionHelper));
2718 };
2719 Terminal.prototype.insertRow = function (row) {
2720 if (typeof row != 'object') {
2721 row = document.createElement('div');
2722 }
2723 this.rowContainer.appendChild(row);
2724 this.children.push(row);
2725 return row;
2726 };
2727 Terminal.prototype.open = function (parent) {
2728 var self = this, i = 0, div;
2729 this.parent = parent || this.parent;
2730 if (!this.parent) {
2731 throw new Error('Terminal requires a parent element.');
2732 }
2733 this.context = this.parent.ownerDocument.defaultView;
2734 this.document = this.parent.ownerDocument;
2735 this.body = this.document.getElementsByTagName('body')[0];
2736 this.element = this.document.createElement('div');
2737 this.element.classList.add('terminal');
2738 this.element.classList.add('xterm');
2739 this.element.classList.add('xterm-theme-' + this.theme);
2740 this.element.classList.toggle('xterm-cursor-blink', this.options.cursorBlink);
2741 this.element.style.height;
2742 this.element.setAttribute('tabindex', 0);
2743 this.viewportElement = document.createElement('div');
2744 this.viewportElement.classList.add('xterm-viewport');
2745 this.element.appendChild(this.viewportElement);
2746 this.viewportScrollArea = document.createElement('div');
2747 this.viewportScrollArea.classList.add('xterm-scroll-area');
2748 this.viewportElement.appendChild(this.viewportScrollArea);
2749 this.rowContainer = document.createElement('div');
2750 this.rowContainer.classList.add('xterm-rows');
2751 this.element.appendChild(this.rowContainer);
2752 this.children = [];
2753 this.helperContainer = document.createElement('div');
2754 this.helperContainer.classList.add('xterm-helpers');
2755 this.element.appendChild(this.helperContainer);
2756 this.textarea = document.createElement('textarea');
2757 this.textarea.classList.add('xterm-helper-textarea');
2758 this.textarea.setAttribute('autocorrect', 'off');
2759 this.textarea.setAttribute('autocapitalize', 'off');
2760 this.textarea.setAttribute('spellcheck', 'false');
2761 this.textarea.tabIndex = 0;
2762 this.textarea.addEventListener('focus', function () {
2763 self.emit('focus', { terminal: self });
2764 });
2765 this.textarea.addEventListener('blur', function () {
2766 self.emit('blur', { terminal: self });
2767 });
2768 this.helperContainer.appendChild(this.textarea);
2769 this.compositionView = document.createElement('div');
2770 this.compositionView.classList.add('composition-view');
2771 this.compositionHelper = new CompositionHelper_1.CompositionHelper(this.textarea, this.compositionView, this);
2772 this.helperContainer.appendChild(this.compositionView);
2773 this.charSizeStyleElement = document.createElement('style');
2774 this.helperContainer.appendChild(this.charSizeStyleElement);
2775 for (; i < this.rows; i++) {
2776 this.insertRow();
2777 }
2778 this.parent.appendChild(this.element);
2779 this.charMeasure = new CharMeasure_1.CharMeasure(this.helperContainer);
2780 this.charMeasure.on('charsizechanged', function () {
2781 self.updateCharSizeCSS();
2782 });
2783 this.charMeasure.measure();
2784 this.viewport = new Viewport_1.Viewport(this, this.viewportElement, this.viewportScrollArea, this.charMeasure);
2785 this.renderer = new Renderer_1.Renderer(this);
2786 this.refresh(0, this.rows - 1);
2787 this.initGlobal();
2788 this.focus();
2789 on(this.element, 'click', function () {
2790 var selection = document.getSelection(), collapsed = selection.isCollapsed, isRange = typeof collapsed == 'boolean' ? !collapsed : selection.type == 'Range';
2791 if (!isRange) {
2792 self.focus();
2793 }
2794 });
2795 this.bindMouse();
2796 this.emit('open');
2797 };
2798 Terminal.loadAddon = function (addon, callback) {
2799 if (typeof exports === 'object' && typeof module === 'object') {
2800 return require('./addons/' + addon + '/' + addon);
2801 }
2802 else if (typeof define == 'function') {
2803 return require(['./addons/' + addon + '/' + addon], callback);
2804 }
2805 else {
2806 console.error('Cannot load a module without a CommonJS or RequireJS environment.');
2807 return false;
2808 }
2809 };
2810 Terminal.prototype.updateCharSizeCSS = function () {
2811 this.charSizeStyleElement.textContent = '.xterm-wide-char{width:' + (this.charMeasure.width * 2) + 'px;}';
2812 };
2813 Terminal.prototype.bindMouse = function () {
2814 var el = this.element, self = this, pressed = 32;
2815 function sendButton(ev) {
2816 var button, pos;
2817 button = getButton(ev);
2818 pos = getCoords(ev);
2819 if (!pos)
2820 return;
2821 sendEvent(button, pos);
2822 switch (ev.overrideType || ev.type) {
2823 case 'mousedown':
2824 pressed = button;
2825 break;
2826 case 'mouseup':
2827 pressed = 32;
2828 break;
2829 case 'wheel':
2830 break;
2831 }
2832 }
2833 function sendMove(ev) {
2834 var button = pressed, pos;
2835 pos = getCoords(ev);
2836 if (!pos)
2837 return;
2838 button += 32;
2839 sendEvent(button, pos);
2840 }
2841 function encode(data, ch) {
2842 if (!self.utfMouse) {
2843 if (ch === 255)
2844 return data.push(0);
2845 if (ch > 127)
2846 ch = 127;
2847 data.push(ch);
2848 }
2849 else {
2850 if (ch === 2047)
2851 return data.push(0);
2852 if (ch < 127) {
2853 data.push(ch);
2854 }
2855 else {
2856 if (ch > 2047)
2857 ch = 2047;
2858 data.push(0xC0 | (ch >> 6));
2859 data.push(0x80 | (ch & 0x3F));
2860 }
2861 }
2862 }
2863 function sendEvent(button, pos) {
2864 if (self.vt300Mouse) {
2865 button &= 3;
2866 pos.x -= 32;
2867 pos.y -= 32;
2868 var data = EscapeSequences_1.C0.ESC + '[24';
2869 if (button === 0)
2870 data += '1';
2871 else if (button === 1)
2872 data += '3';
2873 else if (button === 2)
2874 data += '5';
2875 else if (button === 3)
2876 return;
2877 else
2878 data += '0';
2879 data += '~[' + pos.x + ',' + pos.y + ']\r';
2880 self.send(data);
2881 return;
2882 }
2883 if (self.decLocator) {
2884 button &= 3;
2885 pos.x -= 32;
2886 pos.y -= 32;
2887 if (button === 0)
2888 button = 2;
2889 else if (button === 1)
2890 button = 4;
2891 else if (button === 2)
2892 button = 6;
2893 else if (button === 3)
2894 button = 3;
2895 self.send(EscapeSequences_1.C0.ESC + '['
2896 + button
2897 + ';'
2898 + (button === 3 ? 4 : 0)
2899 + ';'
2900 + pos.y
2901 + ';'
2902 + pos.x
2903 + ';'
2904 + (pos.page || 0)
2905 + '&w');
2906 return;
2907 }
2908 if (self.urxvtMouse) {
2909 pos.x -= 32;
2910 pos.y -= 32;
2911 pos.x++;
2912 pos.y++;
2913 self.send(EscapeSequences_1.C0.ESC + '[' + button + ';' + pos.x + ';' + pos.y + 'M');
2914 return;
2915 }
2916 if (self.sgrMouse) {
2917 pos.x -= 32;
2918 pos.y -= 32;
2919 self.send(EscapeSequences_1.C0.ESC + '[<'
2920 + (((button & 3) === 3 ? button & ~3 : button) - 32)
2921 + ';'
2922 + pos.x
2923 + ';'
2924 + pos.y
2925 + ((button & 3) === 3 ? 'm' : 'M'));
2926 return;
2927 }
2928 var data = [];
2929 encode(data, button);
2930 encode(data, pos.x);
2931 encode(data, pos.y);
2932 self.send(EscapeSequences_1.C0.ESC + '[M' + String.fromCharCode.apply(String, data));
2933 }
2934 function getButton(ev) {
2935 var button, shift, meta, ctrl, mod;
2936 switch (ev.overrideType || ev.type) {
2937 case 'mousedown':
2938 button = ev.button != null
2939 ? +ev.button
2940 : ev.which != null
2941 ? ev.which - 1
2942 : null;
2943 if (self.browser.isMSIE) {
2944 button = button === 1 ? 0 : button === 4 ? 1 : button;
2945 }
2946 break;
2947 case 'mouseup':
2948 button = 3;
2949 break;
2950 case 'DOMMouseScroll':
2951 button = ev.detail < 0
2952 ? 64
2953 : 65;
2954 break;
2955 case 'wheel':
2956 button = ev.wheelDeltaY > 0
2957 ? 64
2958 : 65;
2959 break;
2960 }
2961 shift = ev.shiftKey ? 4 : 0;
2962 meta = ev.metaKey ? 8 : 0;
2963 ctrl = ev.ctrlKey ? 16 : 0;
2964 mod = shift | meta | ctrl;
2965 if (self.vt200Mouse) {
2966 mod &= ctrl;
2967 }
2968 else if (!self.normalMouse) {
2969 mod = 0;
2970 }
2971 button = (32 + (mod << 2)) + button;
2972 return button;
2973 }
2974 function getCoords(ev) {
2975 var x, y, w, h, el;
2976 if (ev.pageX == null)
2977 return;
2978 x = ev.pageX;
2979 y = ev.pageY;
2980 el = self.element;
2981 while (el && el !== self.document.documentElement) {
2982 x -= el.offsetLeft;
2983 y -= el.offsetTop;
2984 el = 'offsetParent' in el
2985 ? el.offsetParent
2986 : el.parentNode;
2987 }
2988 w = self.element.clientWidth;
2989 h = self.element.clientHeight;
2990 x = Math.ceil((x / w) * self.cols);
2991 y = Math.ceil((y / h) * self.rows);
2992 if (x < 0)
2993 x = 0;
2994 if (x > self.cols)
2995 x = self.cols;
2996 if (y < 0)
2997 y = 0;
2998 if (y > self.rows)
2999 y = self.rows;
3000 x += 32;
3001 y += 32;
3002 return {
3003 x: x,
3004 y: y,
3005 type: 'wheel'
3006 };
3007 }
3008 on(el, 'mousedown', function (ev) {
3009 if (!self.mouseEvents)
3010 return;
3011 sendButton(ev);
3012 self.focus();
3013 if (self.vt200Mouse) {
3014 ev.overrideType = 'mouseup';
3015 sendButton(ev);
3016 return self.cancel(ev);
3017 }
3018 if (self.normalMouse)
3019 on(self.document, 'mousemove', sendMove);
3020 if (!self.x10Mouse) {
3021 on(self.document, 'mouseup', function up(ev) {
3022 sendButton(ev);
3023 if (self.normalMouse)
3024 off(self.document, 'mousemove', sendMove);
3025 off(self.document, 'mouseup', up);
3026 return self.cancel(ev);
3027 });
3028 }
3029 return self.cancel(ev);
3030 });
3031 on(el, 'wheel', function (ev) {
3032 if (!self.mouseEvents)
3033 return;
3034 if (self.x10Mouse
3035 || self.vt300Mouse
3036 || self.decLocator)
3037 return;
3038 sendButton(ev);
3039 return self.cancel(ev);
3040 });
3041 on(el, 'wheel', function (ev) {
3042 if (self.mouseEvents)
3043 return;
3044 self.viewport.onWheel(ev);
3045 return self.cancel(ev);
3046 });
3047 };
3048 Terminal.prototype.destroy = function () {
3049 this.readable = false;
3050 this.writable = false;
3051 this._events = {};
3052 this.handler = function () { };
3053 this.write = function () { };
3054 if (this.element && this.element.parentNode) {
3055 this.element.parentNode.removeChild(this.element);
3056 }
3057 };
3058 Terminal.prototype.refresh = function (start, end) {
3059 if (this.renderer) {
3060 this.renderer.queueRefresh(start, end);
3061 }
3062 };
3063 Terminal.prototype.showCursor = function () {
3064 if (!this.cursorState) {
3065 this.cursorState = 1;
3066 this.refresh(this.y, this.y);
3067 }
3068 };
3069 Terminal.prototype.scroll = function () {
3070 var row;
3071 if (this.lines.length === this.lines.maxLength) {
3072 this.lines.trimStart(1);
3073 this.ybase--;
3074 if (this.ydisp !== 0) {
3075 this.ydisp--;
3076 }
3077 }
3078 this.ybase++;
3079 if (!this.userScrolling) {
3080 this.ydisp = this.ybase;
3081 }
3082 row = this.ybase + this.rows - 1;
3083 row -= this.rows - 1 - this.scrollBottom;
3084 if (row === this.lines.length) {
3085 this.lines.push(this.blankLine());
3086 }
3087 else {
3088 this.lines.splice(row, 0, this.blankLine());
3089 }
3090 if (this.scrollTop !== 0) {
3091 if (this.ybase !== 0) {
3092 this.ybase--;
3093 if (!this.userScrolling) {
3094 this.ydisp = this.ybase;
3095 }
3096 }
3097 this.lines.splice(this.ybase + this.scrollTop, 1);
3098 }
3099 this.updateRange(this.scrollTop);
3100 this.updateRange(this.scrollBottom);
3101 this.emit('scroll', this.ydisp);
3102 };
3103 Terminal.prototype.scrollDisp = function (disp, suppressScrollEvent) {
3104 if (disp < 0) {
3105 this.userScrolling = true;
3106 }
3107 else if (disp + this.ydisp >= this.ybase) {
3108 this.userScrolling = false;
3109 }
3110 this.ydisp += disp;
3111 if (this.ydisp > this.ybase) {
3112 this.ydisp = this.ybase;
3113 }
3114 else if (this.ydisp < 0) {
3115 this.ydisp = 0;
3116 }
3117 if (!suppressScrollEvent) {
3118 this.emit('scroll', this.ydisp);
3119 }
3120 this.refresh(0, this.rows - 1);
3121 };
3122 Terminal.prototype.scrollPages = function (pageCount) {
3123 this.scrollDisp(pageCount * (this.rows - 1));
3124 };
3125 Terminal.prototype.scrollToTop = function () {
3126 this.scrollDisp(-this.ydisp);
3127 };
3128 Terminal.prototype.scrollToBottom = function () {
3129 this.scrollDisp(this.ybase - this.ydisp);
3130 };
3131 Terminal.prototype.write = function (data) {
3132 this.writeBuffer.push(data);
3133 if (this.options.useFlowControl && !this.xoffSentToCatchUp && this.writeBuffer.length >= WRITE_BUFFER_PAUSE_THRESHOLD) {
3134 this.send(EscapeSequences_1.C0.DC3);
3135 this.xoffSentToCatchUp = true;
3136 }
3137 if (!this.writeInProgress && this.writeBuffer.length > 0) {
3138 this.writeInProgress = true;
3139 var self = this;
3140 setTimeout(function () {
3141 self.innerWrite();
3142 });
3143 }
3144 };
3145 Terminal.prototype.innerWrite = function () {
3146 var writeBatch = this.writeBuffer.splice(0, WRITE_BATCH_SIZE);
3147 while (writeBatch.length > 0) {
3148 var data = writeBatch.shift();
3149 var l = data.length, i = 0, j, cs, ch, code, low, ch_width, row;
3150 if (this.xoffSentToCatchUp && writeBatch.length === 0 && this.writeBuffer.length === 0) {
3151 this.send(EscapeSequences_1.C0.DC1);
3152 this.xoffSentToCatchUp = false;
3153 }
3154 this.refreshStart = this.y;
3155 this.refreshEnd = this.y;
3156 this.parser.parse(data);
3157 this.updateRange(this.y);
3158 this.refresh(this.refreshStart, this.refreshEnd);
3159 }
3160 if (this.writeBuffer.length > 0) {
3161 var self = this;
3162 setTimeout(function () {
3163 self.innerWrite();
3164 }, 0);
3165 }
3166 else {
3167 this.writeInProgress = false;
3168 }
3169 };
3170 Terminal.prototype.writeln = function (data) {
3171 this.write(data + '\r\n');
3172 };
3173 Terminal.prototype.attachCustomKeydownHandler = function (customKeydownHandler) {
3174 this.customKeydownHandler = customKeydownHandler;
3175 };
3176 Terminal.prototype.keyDown = function (ev) {
3177 if (this.customKeydownHandler && this.customKeydownHandler(ev) === false) {
3178 return false;
3179 }
3180 if (!this.compositionHelper.keydown.bind(this.compositionHelper)(ev)) {
3181 if (this.ybase !== this.ydisp) {
3182 this.scrollToBottom();
3183 }
3184 return false;
3185 }
3186 var self = this;
3187 var result = this.evaluateKeyEscapeSequence(ev);
3188 if (result.key === EscapeSequences_1.C0.DC3) {
3189 this.writeStopped = true;
3190 }
3191 else if (result.key === EscapeSequences_1.C0.DC1) {
3192 this.writeStopped = false;
3193 }
3194 if (result.scrollDisp) {
3195 this.scrollDisp(result.scrollDisp);
3196 return this.cancel(ev, true);
3197 }
3198 if (isThirdLevelShift(this, ev)) {
3199 return true;
3200 }
3201 if (result.cancel) {
3202 this.cancel(ev, true);
3203 }
3204 if (!result.key) {
3205 return true;
3206 }
3207 this.emit('keydown', ev);
3208 this.emit('key', result.key, ev);
3209 this.showCursor();
3210 this.handler(result.key);
3211 return this.cancel(ev, true);
3212 };
3213 Terminal.prototype.evaluateKeyEscapeSequence = function (ev) {
3214 var result = {
3215 cancel: false,
3216 key: undefined,
3217 scrollDisp: undefined
3218 };
3219 var modifiers = ev.shiftKey << 0 | ev.altKey << 1 | ev.ctrlKey << 2 | ev.metaKey << 3;
3220 switch (ev.keyCode) {
3221 case 8:
3222 if (ev.shiftKey) {
3223 result.key = EscapeSequences_1.C0.BS;
3224 break;
3225 }
3226 result.key = EscapeSequences_1.C0.DEL;
3227 break;
3228 case 9:
3229 if (ev.shiftKey) {
3230 result.key = EscapeSequences_1.C0.ESC + '[Z';
3231 break;
3232 }
3233 result.key = EscapeSequences_1.C0.HT;
3234 result.cancel = true;
3235 break;
3236 case 13:
3237 result.key = EscapeSequences_1.C0.CR;
3238 result.cancel = true;
3239 break;
3240 case 27:
3241 result.key = EscapeSequences_1.C0.ESC;
3242 result.cancel = true;
3243 break;
3244 case 37:
3245 if (modifiers) {
3246 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'D';
3247 if (result.key == EscapeSequences_1.C0.ESC + '[1;3D') {
3248 result.key = (this.browser.isMac) ? EscapeSequences_1.C0.ESC + 'b' : EscapeSequences_1.C0.ESC + '[1;5D';
3249 }
3250 }
3251 else if (this.applicationCursor) {
3252 result.key = EscapeSequences_1.C0.ESC + 'OD';
3253 }
3254 else {
3255 result.key = EscapeSequences_1.C0.ESC + '[D';
3256 }
3257 break;
3258 case 39:
3259 if (modifiers) {
3260 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'C';
3261 if (result.key == EscapeSequences_1.C0.ESC + '[1;3C') {
3262 result.key = (this.browser.isMac) ? EscapeSequences_1.C0.ESC + 'f' : EscapeSequences_1.C0.ESC + '[1;5C';
3263 }
3264 }
3265 else if (this.applicationCursor) {
3266 result.key = EscapeSequences_1.C0.ESC + 'OC';
3267 }
3268 else {
3269 result.key = EscapeSequences_1.C0.ESC + '[C';
3270 }
3271 break;
3272 case 38:
3273 if (modifiers) {
3274 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'A';
3275 if (result.key == EscapeSequences_1.C0.ESC + '[1;3A') {
3276 result.key = EscapeSequences_1.C0.ESC + '[1;5A';
3277 }
3278 }
3279 else if (this.applicationCursor) {
3280 result.key = EscapeSequences_1.C0.ESC + 'OA';
3281 }
3282 else {
3283 result.key = EscapeSequences_1.C0.ESC + '[A';
3284 }
3285 break;
3286 case 40:
3287 if (modifiers) {
3288 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'B';
3289 if (result.key == EscapeSequences_1.C0.ESC + '[1;3B') {
3290 result.key = EscapeSequences_1.C0.ESC + '[1;5B';
3291 }
3292 }
3293 else if (this.applicationCursor) {
3294 result.key = EscapeSequences_1.C0.ESC + 'OB';
3295 }
3296 else {
3297 result.key = EscapeSequences_1.C0.ESC + '[B';
3298 }
3299 break;
3300 case 45:
3301 if (!ev.shiftKey && !ev.ctrlKey) {
3302 result.key = EscapeSequences_1.C0.ESC + '[2~';
3303 }
3304 break;
3305 case 46:
3306 if (modifiers) {
3307 result.key = EscapeSequences_1.C0.ESC + '[3;' + (modifiers + 1) + '~';
3308 }
3309 else {
3310 result.key = EscapeSequences_1.C0.ESC + '[3~';
3311 }
3312 break;
3313 case 36:
3314 if (modifiers)
3315 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'H';
3316 else if (this.applicationCursor)
3317 result.key = EscapeSequences_1.C0.ESC + 'OH';
3318 else
3319 result.key = EscapeSequences_1.C0.ESC + '[H';
3320 break;
3321 case 35:
3322 if (modifiers)
3323 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'F';
3324 else if (this.applicationCursor)
3325 result.key = EscapeSequences_1.C0.ESC + 'OF';
3326 else
3327 result.key = EscapeSequences_1.C0.ESC + '[F';
3328 break;
3329 case 33:
3330 if (ev.shiftKey) {
3331 result.scrollDisp = -(this.rows - 1);
3332 }
3333 else {
3334 result.key = EscapeSequences_1.C0.ESC + '[5~';
3335 }
3336 break;
3337 case 34:
3338 if (ev.shiftKey) {
3339 result.scrollDisp = this.rows - 1;
3340 }
3341 else {
3342 result.key = EscapeSequences_1.C0.ESC + '[6~';
3343 }
3344 break;
3345 case 112:
3346 if (modifiers) {
3347 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'P';
3348 }
3349 else {
3350 result.key = EscapeSequences_1.C0.ESC + 'OP';
3351 }
3352 break;
3353 case 113:
3354 if (modifiers) {
3355 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'Q';
3356 }
3357 else {
3358 result.key = EscapeSequences_1.C0.ESC + 'OQ';
3359 }
3360 break;
3361 case 114:
3362 if (modifiers) {
3363 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'R';
3364 }
3365 else {
3366 result.key = EscapeSequences_1.C0.ESC + 'OR';
3367 }
3368 break;
3369 case 115:
3370 if (modifiers) {
3371 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'S';
3372 }
3373 else {
3374 result.key = EscapeSequences_1.C0.ESC + 'OS';
3375 }
3376 break;
3377 case 116:
3378 if (modifiers) {
3379 result.key = EscapeSequences_1.C0.ESC + '[15;' + (modifiers + 1) + '~';
3380 }
3381 else {
3382 result.key = EscapeSequences_1.C0.ESC + '[15~';
3383 }
3384 break;
3385 case 117:
3386 if (modifiers) {
3387 result.key = EscapeSequences_1.C0.ESC + '[17;' + (modifiers + 1) + '~';
3388 }
3389 else {
3390 result.key = EscapeSequences_1.C0.ESC + '[17~';
3391 }
3392 break;
3393 case 118:
3394 if (modifiers) {
3395 result.key = EscapeSequences_1.C0.ESC + '[18;' + (modifiers + 1) + '~';
3396 }
3397 else {
3398 result.key = EscapeSequences_1.C0.ESC + '[18~';
3399 }
3400 break;
3401 case 119:
3402 if (modifiers) {
3403 result.key = EscapeSequences_1.C0.ESC + '[19;' + (modifiers + 1) + '~';
3404 }
3405 else {
3406 result.key = EscapeSequences_1.C0.ESC + '[19~';
3407 }
3408 break;
3409 case 120:
3410 if (modifiers) {
3411 result.key = EscapeSequences_1.C0.ESC + '[20;' + (modifiers + 1) + '~';
3412 }
3413 else {
3414 result.key = EscapeSequences_1.C0.ESC + '[20~';
3415 }
3416 break;
3417 case 121:
3418 if (modifiers) {
3419 result.key = EscapeSequences_1.C0.ESC + '[21;' + (modifiers + 1) + '~';
3420 }
3421 else {
3422 result.key = EscapeSequences_1.C0.ESC + '[21~';
3423 }
3424 break;
3425 case 122:
3426 if (modifiers) {
3427 result.key = EscapeSequences_1.C0.ESC + '[23;' + (modifiers + 1) + '~';
3428 }
3429 else {
3430 result.key = EscapeSequences_1.C0.ESC + '[23~';
3431 }
3432 break;
3433 case 123:
3434 if (modifiers) {
3435 result.key = EscapeSequences_1.C0.ESC + '[24;' + (modifiers + 1) + '~';
3436 }
3437 else {
3438 result.key = EscapeSequences_1.C0.ESC + '[24~';
3439 }
3440 break;
3441 default:
3442 if (ev.ctrlKey && !ev.shiftKey && !ev.altKey && !ev.metaKey) {
3443 if (ev.keyCode >= 65 && ev.keyCode <= 90) {
3444 result.key = String.fromCharCode(ev.keyCode - 64);
3445 }
3446 else if (ev.keyCode === 32) {
3447 result.key = String.fromCharCode(0);
3448 }
3449 else if (ev.keyCode >= 51 && ev.keyCode <= 55) {
3450 result.key = String.fromCharCode(ev.keyCode - 51 + 27);
3451 }
3452 else if (ev.keyCode === 56) {
3453 result.key = String.fromCharCode(127);
3454 }
3455 else if (ev.keyCode === 219) {
3456 result.key = String.fromCharCode(27);
3457 }
3458 else if (ev.keyCode === 220) {
3459 result.key = String.fromCharCode(28);
3460 }
3461 else if (ev.keyCode === 221) {
3462 result.key = String.fromCharCode(29);
3463 }
3464 }
3465 else if (!this.browser.isMac && ev.altKey && !ev.ctrlKey && !ev.metaKey) {
3466 if (ev.keyCode >= 65 && ev.keyCode <= 90) {
3467 result.key = EscapeSequences_1.C0.ESC + String.fromCharCode(ev.keyCode + 32);
3468 }
3469 else if (ev.keyCode === 192) {
3470 result.key = EscapeSequences_1.C0.ESC + '`';
3471 }
3472 else if (ev.keyCode >= 48 && ev.keyCode <= 57) {
3473 result.key = EscapeSequences_1.C0.ESC + (ev.keyCode - 48);
3474 }
3475 }
3476 break;
3477 }
3478 return result;
3479 };
3480 Terminal.prototype.setgLevel = function (g) {
3481 this.glevel = g;
3482 this.charset = this.charsets[g];
3483 };
3484 Terminal.prototype.setgCharset = function (g, charset) {
3485 this.charsets[g] = charset;
3486 if (this.glevel === g) {
3487 this.charset = charset;
3488 }
3489 };
3490 Terminal.prototype.keyPress = function (ev) {
3491 var key;
3492 this.cancel(ev);
3493 if (ev.charCode) {
3494 key = ev.charCode;
3495 }
3496 else if (ev.which == null) {
3497 key = ev.keyCode;
3498 }
3499 else if (ev.which !== 0 && ev.charCode !== 0) {
3500 key = ev.which;
3501 }
3502 else {
3503 return false;
3504 }
3505 if (!key || ((ev.altKey || ev.ctrlKey || ev.metaKey) && !isThirdLevelShift(this, ev))) {
3506 return false;
3507 }
3508 key = String.fromCharCode(key);
3509 this.emit('keypress', key, ev);
3510 this.emit('key', key, ev);
3511 this.showCursor();
3512 this.handler(key);
3513 return false;
3514 };
3515 Terminal.prototype.send = function (data) {
3516 var self = this;
3517 if (!this.queue) {
3518 setTimeout(function () {
3519 self.handler(self.queue);
3520 self.queue = '';
3521 }, 1);
3522 }
3523 this.queue += data;
3524 };
3525 Terminal.prototype.bell = function () {
3526 if (!this.visualBell)
3527 return;
3528 var self = this;
3529 this.element.style.borderColor = 'white';
3530 setTimeout(function () {
3531 self.element.style.borderColor = '';
3532 }, 10);
3533 if (this.popOnBell)
3534 this.focus();
3535 };
3536 Terminal.prototype.log = function () {
3537 if (!this.debug)
3538 return;
3539 if (!this.context.console || !this.context.console.log)
3540 return;
3541 var args = Array.prototype.slice.call(arguments);
3542 this.context.console.log.apply(this.context.console, args);
3543 };
3544 Terminal.prototype.error = function () {
3545 if (!this.debug)
3546 return;
3547 if (!this.context.console || !this.context.console.error)
3548 return;
3549 var args = Array.prototype.slice.call(arguments);
3550 this.context.console.error.apply(this.context.console, args);
3551 };
3552 Terminal.prototype.resize = function (x, y) {
3553 if (isNaN(x) || isNaN(y)) {
3554 return;
3555 }
3556 var line, el, i, j, ch, addToY;
3557 if (x === this.cols && y === this.rows) {
3558 return;
3559 }
3560 if (x < 1)
3561 x = 1;
3562 if (y < 1)
3563 y = 1;
3564 j = this.cols;
3565 if (j < x) {
3566 ch = [this.defAttr, ' ', 1];
3567 i = this.lines.length;
3568 while (i--) {
3569 while (this.lines.get(i).length < x) {
3570 this.lines.get(i).push(ch);
3571 }
3572 }
3573 }
3574 else {
3575 i = this.lines.length;
3576 while (i--) {
3577 while (this.lines.get(i).length > x) {
3578 this.lines.get(i).pop();
3579 }
3580 }
3581 }
3582 this.cols = x;
3583 this.setupStops(this.cols);
3584 j = this.rows;
3585 addToY = 0;
3586 if (j < y) {
3587 el = this.element;
3588 while (j++ < y) {
3589 if (this.lines.length < y + this.ybase) {
3590 if (this.ybase > 0 && this.lines.length <= this.ybase + this.y + addToY + 1) {
3591 this.ybase--;
3592 addToY++;
3593 if (this.ydisp > 0) {
3594 this.ydisp--;
3595 }
3596 }
3597 else {
3598 this.lines.push(this.blankLine());
3599 }
3600 }
3601 if (this.children.length < y) {
3602 this.insertRow();
3603 }
3604 }
3605 }
3606 else {
3607 while (j-- > y) {
3608 if (this.lines.length > y + this.ybase) {
3609 if (this.lines.length > this.ybase + this.y + 1) {
3610 this.lines.pop();
3611 }
3612 else {
3613 this.ybase++;
3614 this.ydisp++;
3615 }
3616 }
3617 if (this.children.length > y) {
3618 el = this.children.shift();
3619 if (!el)
3620 continue;
3621 el.parentNode.removeChild(el);
3622 }
3623 }
3624 }
3625 this.rows = y;
3626 if (this.y >= y) {
3627 this.y = y - 1;
3628 }
3629 if (addToY) {
3630 this.y += addToY;
3631 }
3632 if (this.x >= x) {
3633 this.x = x - 1;
3634 }
3635 this.scrollTop = 0;
3636 this.scrollBottom = y - 1;
3637 this.charMeasure.measure();
3638 this.refresh(0, this.rows - 1);
3639 this.normal = null;
3640 this.geometry = [this.cols, this.rows];
3641 this.emit('resize', { terminal: this, cols: x, rows: y });
3642 };
3643 Terminal.prototype.updateRange = function (y) {
3644 if (y < this.refreshStart)
3645 this.refreshStart = y;
3646 if (y > this.refreshEnd)
3647 this.refreshEnd = y;
3648 };
3649 Terminal.prototype.maxRange = function () {
3650 this.refreshStart = 0;
3651 this.refreshEnd = this.rows - 1;
3652 };
3653 Terminal.prototype.setupStops = function (i) {
3654 if (i != null) {
3655 if (!this.tabs[i]) {
3656 i = this.prevStop(i);
3657 }
3658 }
3659 else {
3660 this.tabs = {};
3661 i = 0;
3662 }
3663 for (; i < this.cols; i += this.getOption('tabStopWidth')) {
3664 this.tabs[i] = true;
3665 }
3666 };
3667 Terminal.prototype.prevStop = function (x) {
3668 if (x == null)
3669 x = this.x;
3670 while (!this.tabs[--x] && x > 0)
3671 ;
3672 return x >= this.cols
3673 ? this.cols - 1
3674 : x < 0 ? 0 : x;
3675 };
3676 Terminal.prototype.nextStop = function (x) {
3677 if (x == null)
3678 x = this.x;
3679 while (!this.tabs[++x] && x < this.cols)
3680 ;
3681 return x >= this.cols
3682 ? this.cols - 1
3683 : x < 0 ? 0 : x;
3684 };
3685 Terminal.prototype.eraseRight = function (x, y) {
3686 var line = this.lines.get(this.ybase + y);
3687 if (!line) {
3688 return;
3689 }
3690 var ch = [this.eraseAttr(), ' ', 1];
3691 for (; x < this.cols; x++) {
3692 line[x] = ch;
3693 }
3694 this.updateRange(y);
3695 };
3696 Terminal.prototype.eraseLeft = function (x, y) {
3697 var line = this.lines.get(this.ybase + y);
3698 if (!line) {
3699 return;
3700 }
3701 var ch = [this.eraseAttr(), ' ', 1];
3702 x++;
3703 while (x--) {
3704 line[x] = ch;
3705 }
3706 this.updateRange(y);
3707 };
3708 Terminal.prototype.clear = function () {
3709 if (this.ybase === 0 && this.y === 0) {
3710 return;
3711 }
3712 this.lines.set(0, this.lines.get(this.ybase + this.y));
3713 this.lines.length = 1;
3714 this.ydisp = 0;
3715 this.ybase = 0;
3716 this.y = 0;
3717 for (var i = 1; i < this.rows; i++) {
3718 this.lines.push(this.blankLine());
3719 }
3720 this.refresh(0, this.rows - 1);
3721 this.emit('scroll', this.ydisp);
3722 };
3723 Terminal.prototype.eraseLine = function (y) {
3724 this.eraseRight(0, y);
3725 };
3726 Terminal.prototype.blankLine = function (cur) {
3727 var attr = cur
3728 ? this.eraseAttr()
3729 : this.defAttr;
3730 var ch = [attr, ' ', 1], line = [], i = 0;
3731 for (; i < this.cols; i++) {
3732 line[i] = ch;
3733 }
3734 return line;
3735 };
3736 Terminal.prototype.ch = function (cur) {
3737 return cur
3738 ? [this.eraseAttr(), ' ', 1]
3739 : [this.defAttr, ' ', 1];
3740 };
3741 Terminal.prototype.is = function (term) {
3742 var name = this.termName;
3743 return (name + '').indexOf(term) === 0;
3744 };
3745 Terminal.prototype.handler = function (data) {
3746 if (this.options.disableStdin) {
3747 return;
3748 }
3749 if (this.ybase !== this.ydisp) {
3750 this.scrollToBottom();
3751 }
3752 this.emit('data', data);
3753 };
3754 Terminal.prototype.handleTitle = function (title) {
3755 this.emit('title', title);
3756 };
3757 Terminal.prototype.index = function () {
3758 this.y++;
3759 if (this.y > this.scrollBottom) {
3760 this.y--;
3761 this.scroll();
3762 }
3763 if (this.x >= this.cols) {
3764 this.x--;
3765 }
3766 };
3767 Terminal.prototype.reverseIndex = function () {
3768 var j;
3769 if (this.y === this.scrollTop) {
3770 this.lines.shiftElements(this.y + this.ybase, this.rows - 1, 1);
3771 this.lines.set(this.y + this.ybase, this.blankLine(true));
3772 this.updateRange(this.scrollTop);
3773 this.updateRange(this.scrollBottom);
3774 }
3775 else {
3776 this.y--;
3777 }
3778 };
3779 Terminal.prototype.reset = function () {
3780 this.options.rows = this.rows;
3781 this.options.cols = this.cols;
3782 var customKeydownHandler = this.customKeydownHandler;
3783 Terminal.call(this, this.options);
3784 this.customKeydownHandler = customKeydownHandler;
3785 this.refresh(0, this.rows - 1);
3786 this.viewport.syncScrollArea();
3787 };
3788 Terminal.prototype.tabSet = function () {
3789 this.tabs[this.x] = true;
3790 };
3791 function on(el, type, handler, capture) {
3792 if (!Array.isArray(el)) {
3793 el = [el];
3794 }
3795 el.forEach(function (element) {
3796 element.addEventListener(type, handler, capture || false);
3797 });
3798 }
3799 function off(el, type, handler, capture) {
3800 el.removeEventListener(type, handler, capture || false);
3801 }
3802 function cancel(ev, force) {
3803 if (!this.cancelEvents && !force) {
3804 return;
3805 }
3806 ev.preventDefault();
3807 ev.stopPropagation();
3808 return false;
3809 }
3810 function inherits(child, parent) {
3811 function f() {
3812 this.constructor = child;
3813 }
3814 f.prototype = parent.prototype;
3815 child.prototype = new f;
3816 }
3817 function indexOf(obj, el) {
3818 var i = obj.length;
3819 while (i--) {
3820 if (obj[i] === el)
3821 return i;
3822 }
3823 return -1;
3824 }
3825 function isThirdLevelShift(term, ev) {
3826 var thirdLevelKey = (term.browser.isMac && ev.altKey && !ev.ctrlKey && !ev.metaKey) ||
3827 (term.browser.isMSWindows && ev.altKey && ev.ctrlKey && !ev.metaKey);
3828 if (ev.type == 'keypress') {
3829 return thirdLevelKey;
3830 }
3831 return thirdLevelKey && (!ev.keyCode || ev.keyCode > 47);
3832 }
3833 Terminal.prototype.matchColor = matchColor;
3834 function matchColor(r1, g1, b1) {
3835 var hash = (r1 << 16) | (g1 << 8) | b1;
3836 if (matchColor._cache[hash] != null) {
3837 return matchColor._cache[hash];
3838 }
3839 var ldiff = Infinity, li = -1, i = 0, c, r2, g2, b2, diff;
3840 for (; i < Terminal.vcolors.length; i++) {
3841 c = Terminal.vcolors[i];
3842 r2 = c[0];
3843 g2 = c[1];
3844 b2 = c[2];
3845 diff = matchColor.distance(r1, g1, b1, r2, g2, b2);
3846 if (diff === 0) {
3847 li = i;
3848 break;
3849 }
3850 if (diff < ldiff) {
3851 ldiff = diff;
3852 li = i;
3853 }
3854 }
3855 return matchColor._cache[hash] = li;
3856 }
3857 matchColor._cache = {};
3858 matchColor.distance = function (r1, g1, b1, r2, g2, b2) {
3859 return Math.pow(30 * (r1 - r2), 2)
3860 + Math.pow(59 * (g1 - g2), 2)
3861 + Math.pow(11 * (b1 - b2), 2);
3862 };
3863 function each(obj, iter, con) {
3864 if (obj.forEach)
3865 return obj.forEach(iter, con);
3866 for (var i = 0; i < obj.length; i++) {
3867 iter.call(con, obj[i], i, obj);
3868 }
3869 }
3870 function wasMondifierKeyOnlyEvent(ev) {
3871 return ev.keyCode === 16 ||
3872 ev.keyCode === 17 ||
3873 ev.keyCode === 18;
3874 }
3875 function keys(obj) {
3876 if (Object.keys)
3877 return Object.keys(obj);
3878 var key, keys = [];
3879 for (key in obj) {
3880 if (Object.prototype.hasOwnProperty.call(obj, key)) {
3881 keys.push(key);
3882 }
3883 }
3884 return keys;
3885 }
3886 Terminal.EventEmitter = EventEmitter_1.EventEmitter;
3887 Terminal.inherits = inherits;
3888 Terminal.on = on;
3889 Terminal.off = off;
3890 Terminal.cancel = cancel;
3891 module.exports = Terminal;
3892
3893
3894
3895 },{"./CompositionHelper":2,"./EscapeSequences":3,"./EventEmitter":4,"./InputHandler":5,"./Parser":6,"./Renderer":7,"./Viewport":8,"./handlers/Clipboard":9,"./utils/Browser":10,"./utils/CharMeasure":11,"./utils/CircularList":12}]},{},[14])(14)
3896 });
3897 //# sourceMappingURL=xterm.js.map