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