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
){
3 Object
.defineProperty(exports
, "__esModule", { value
: true });
4 var CircularList_1
= require("./utils/CircularList");
5 var Buffer
= (function () {
6 function Buffer(terminal
, ydisp
, ybase
, y
, x
, scrollBottom
, scrollTop
, tabs
) {
7 if (ydisp
=== void 0) { ydisp
= 0; }
8 if (ybase
=== void 0) { ybase
= 0; }
9 if (y
=== void 0) { y
= 0; }
10 if (x
=== void 0) { x
= 0; }
11 if (scrollBottom
=== void 0) { scrollBottom
= 0; }
12 if (scrollTop
=== void 0) { scrollTop
= 0; }
13 if (tabs
=== void 0) { tabs
= {}; }
14 this.terminal
= terminal
;
19 this.scrollBottom
= scrollBottom
;
20 this.scrollTop
= scrollTop
;
22 this.lines
= new CircularList_1
.CircularList(this.terminal
.scrollback
);
23 this.scrollBottom
= this.terminal
.rows
- 1;
27 exports
.Buffer
= Buffer
;
31 },{"./utils/CircularList":18}],2:[function(require
,module
,exports
){
33 var __extends
= (this && this.__extends
) || (function () {
34 var extendStatics
= Object
.setPrototypeOf
||
35 ({ __proto__
: [] } instanceof Array
&& function (d
, b
) { d
.__proto__
= b
; }) ||
36 function (d
, b
) { for (var p
in b
) if (b
.hasOwnProperty(p
)) d
[p
] = b
[p
]; };
37 return function (d
, b
) {
39 function __() { this.constructor = d
; }
40 d
.prototype = b
=== null ? Object
.create(b
) : (__
.prototype = b
.prototype, new __());
43 Object
.defineProperty(exports
, "__esModule", { value
: true });
44 var Buffer_1
= require("./Buffer");
45 var EventEmitter_1
= require("./EventEmitter");
46 var BufferSet
= (function (_super
) {
47 __extends(BufferSet
, _super
);
48 function BufferSet(_terminal
) {
49 var _this
= _super
.call(this) || this;
50 _this
._terminal
= _terminal
;
51 _this
._normal
= new Buffer_1
.Buffer(_this
._terminal
);
52 _this
._alt
= new Buffer_1
.Buffer(_this
._terminal
);
53 _this
._activeBuffer
= _this
._normal
;
56 Object
.defineProperty(BufferSet
.prototype, "alt", {
63 Object
.defineProperty(BufferSet
.prototype, "active", {
65 return this._activeBuffer
;
70 Object
.defineProperty(BufferSet
.prototype, "normal", {
77 BufferSet
.prototype.activateNormalBuffer = function () {
78 this._activeBuffer
= this._normal
;
79 this.emit('activate', this._normal
);
81 BufferSet
.prototype.activateAltBuffer = function () {
82 this._activeBuffer
= this._alt
;
83 this.emit('activate', this._alt
);
86 }(EventEmitter_1
.EventEmitter
));
87 exports
.BufferSet
= BufferSet
;
91 },{"./Buffer":1,"./EventEmitter":6}],3:[function(require
,module
,exports
){
93 Object
.defineProperty(exports
, "__esModule", { value
: true });
94 exports
.CHARSETS
= {};
95 exports
.DEFAULT_CHARSET
= exports
.CHARSETS
['B'];
96 exports
.CHARSETS
['0'] = {
129 exports
.CHARSETS
['A'] = {
132 exports
.CHARSETS
['B'] = null;
133 exports
.CHARSETS
['4'] = {
144 exports
.CHARSETS
['C'] =
145 exports
.CHARSETS
['5'] = {
156 exports
.CHARSETS
['R'] = {
167 exports
.CHARSETS
['Q'] = {
179 exports
.CHARSETS
['K'] = {
189 exports
.CHARSETS
['Y'] = {
201 exports
.CHARSETS
['E'] =
202 exports
.CHARSETS
['6'] = {
214 exports
.CHARSETS
['Z'] = {
224 exports
.CHARSETS
['H'] =
225 exports
.CHARSETS
['7'] = {
237 exports
.CHARSETS
['='] = {
254 },{}],4:[function(require
,module
,exports
){
256 Object
.defineProperty(exports
, "__esModule", { value
: true });
257 var CompositionHelper
= (function () {
258 function CompositionHelper(textarea
, compositionView
, terminal
) {
259 this.textarea
= textarea
;
260 this.compositionView
= compositionView
;
261 this.terminal
= terminal
;
262 this.isComposing
= false;
263 this.isSendingComposition
= false;
264 this.compositionPosition
= { start
: null, end
: null };
266 CompositionHelper
.prototype.compositionstart = function () {
267 this.isComposing
= true;
268 this.compositionPosition
.start
= this.textarea
.value
.length
;
269 this.compositionView
.textContent
= '';
270 this.compositionView
.classList
.add('active');
272 CompositionHelper
.prototype.compositionupdate = function (ev
) {
274 this.compositionView
.textContent
= ev
.data
;
275 this.updateCompositionElements();
276 setTimeout(function () {
277 _this
.compositionPosition
.end
= _this
.textarea
.value
.length
;
280 CompositionHelper
.prototype.compositionend = function () {
281 this.finalizeComposition(true);
283 CompositionHelper
.prototype.keydown = function (ev
) {
284 if (this.isComposing
|| this.isSendingComposition
) {
285 if (ev
.keyCode
=== 229) {
288 else if (ev
.keyCode
=== 16 || ev
.keyCode
=== 17 || ev
.keyCode
=== 18) {
292 this.finalizeComposition(false);
295 if (ev
.keyCode
=== 229) {
296 this.handleAnyTextareaChanges();
301 CompositionHelper
.prototype.finalizeComposition = function (waitForPropogation
) {
303 this.compositionView
.classList
.remove('active');
304 this.isComposing
= false;
305 this.clearTextareaPosition();
306 if (!waitForPropogation
) {
307 this.isSendingComposition
= false;
308 var input
= this.textarea
.value
.substring(this.compositionPosition
.start
, this.compositionPosition
.end
);
309 this.terminal
.handler(input
);
312 var currentCompositionPosition_1
= {
313 start
: this.compositionPosition
.start
,
314 end
: this.compositionPosition
.end
,
316 this.isSendingComposition
= true;
317 setTimeout(function () {
318 if (_this
.isSendingComposition
) {
319 _this
.isSendingComposition
= false;
321 if (_this
.isComposing
) {
322 input
= _this
.textarea
.value
.substring(currentCompositionPosition_1
.start
, currentCompositionPosition_1
.end
);
325 input
= _this
.textarea
.value
.substring(currentCompositionPosition_1
.start
);
327 _this
.terminal
.handler(input
);
332 CompositionHelper
.prototype.handleAnyTextareaChanges = function () {
334 var oldValue
= this.textarea
.value
;
335 setTimeout(function () {
336 if (!_this
.isComposing
) {
337 var newValue
= _this
.textarea
.value
;
338 var diff
= newValue
.replace(oldValue
, '');
339 if (diff
.length
> 0) {
340 _this
.terminal
.handler(diff
);
345 CompositionHelper
.prototype.updateCompositionElements = function (dontRecurse
) {
347 if (!this.isComposing
) {
350 var cursor
= this.terminal
.element
.querySelector('.terminal-cursor');
352 var xtermRows
= this.terminal
.element
.querySelector('.xterm-rows');
353 var cursorTop
= xtermRows
.offsetTop
+ cursor
.offsetTop
;
354 this.compositionView
.style
.left
= cursor
.offsetLeft
+ 'px';
355 this.compositionView
.style
.top
= cursorTop
+ 'px';
356 this.compositionView
.style
.height
= cursor
.offsetHeight
+ 'px';
357 this.compositionView
.style
.lineHeight
= cursor
.offsetHeight
+ 'px';
358 var compositionViewBounds
= this.compositionView
.getBoundingClientRect();
359 this.textarea
.style
.left
= cursor
.offsetLeft
+ 'px';
360 this.textarea
.style
.top
= cursorTop
+ 'px';
361 this.textarea
.style
.width
= compositionViewBounds
.width
+ 'px';
362 this.textarea
.style
.height
= compositionViewBounds
.height
+ 'px';
363 this.textarea
.style
.lineHeight
= compositionViewBounds
.height
+ 'px';
366 setTimeout(function () { return _this
.updateCompositionElements(true); }, 0);
370 CompositionHelper
.prototype.clearTextareaPosition = function () {
371 this.textarea
.style
.left
= '';
372 this.textarea
.style
.top
= '';
375 return CompositionHelper
;
377 exports
.CompositionHelper
= CompositionHelper
;
381 },{}],5:[function(require
,module
,exports
){
383 Object
.defineProperty(exports
, "__esModule", { value
: true });
420 })(C0
= exports
.C0
|| (exports
.C0
= {}));
425 },{}],6:[function(require
,module
,exports
){
427 Object
.defineProperty(exports
, "__esModule", { value
: true });
429 var EventEmitter
= (function () {
430 function EventEmitter() {
431 this._events
= this._events
|| {};
433 EventEmitter
.prototype.on = function (type
, listener
) {
434 this._events
[type
] = this._events
[type
] || [];
435 this._events
[type
].push(listener
);
437 EventEmitter
.prototype.off = function (type
, listener
) {
438 if (!this._events
[type
]) {
441 var obj
= this._events
[type
];
444 if (obj
[i
] === listener
|| obj
[i
].listener
=== listener
) {
450 EventEmitter
.prototype.removeAllListeners = function (type
) {
451 if (this._events
[type
]) {
452 delete this._events
[type
];
455 EventEmitter
.prototype.once = function (type
, listener
) {
457 var args
= Array
.prototype.slice
.call(arguments
);
459 return listener
.apply(this, args
);
461 on
.listener
= listener
;
462 return this.on(type
, on
);
464 EventEmitter
.prototype.emit = function (type
) {
466 for (var _i
= 1; _i
< arguments
.length
; _i
++) {
467 args
[_i
- 1] = arguments
[_i
];
469 if (!this._events
[type
]) {
472 var obj
= this._events
[type
];
473 for (var i
= 0; i
< obj
.length
; i
++) {
474 obj
[i
].apply(this, args
);
477 EventEmitter
.prototype.listeners = function (type
) {
478 return this._events
[type
] || [];
482 exports
.EventEmitter
= EventEmitter
;
486 },{}],7:[function(require
,module
,exports
){
488 Object
.defineProperty(exports
, "__esModule", { value
: true });
489 var EscapeSequences_1
= require("./EscapeSequences");
490 var Charsets_1
= require("./Charsets");
491 var InputHandler
= (function () {
492 function InputHandler(_terminal
) {
493 this._terminal
= _terminal
;
495 InputHandler
.prototype.addChar = function (char, code
) {
497 var ch_width
= exports
.wcwidth(code
);
498 if (this._terminal
.charset
&& this._terminal
.charset
[char]) {
499 char = this._terminal
.charset
[char];
501 var row
= this._terminal
.buffer
.y
+ this._terminal
.buffer
.ybase
;
502 if (!ch_width
&& this._terminal
.buffer
.x
) {
503 if (this._terminal
.buffer
.lines
.get(row
)[this._terminal
.buffer
.x
- 1]) {
504 if (!this._terminal
.buffer
.lines
.get(row
)[this._terminal
.buffer
.x
- 1][2]) {
505 if (this._terminal
.buffer
.lines
.get(row
)[this._terminal
.buffer
.x
- 2])
506 this._terminal
.buffer
.lines
.get(row
)[this._terminal
.buffer
.x
- 2][1] += char;
509 this._terminal
.buffer
.lines
.get(row
)[this._terminal
.buffer
.x
- 1][1] += char;
511 this._terminal
.updateRange(this._terminal
.buffer
.y
);
515 if (this._terminal
.buffer
.x
+ ch_width
- 1 >= this._terminal
.cols
) {
516 if (this._terminal
.wraparoundMode
) {
517 this._terminal
.buffer
.x
= 0;
518 this._terminal
.buffer
.y
++;
519 if (this._terminal
.buffer
.y
> this._terminal
.buffer
.scrollBottom
) {
520 this._terminal
.buffer
.y
--;
521 this._terminal
.scroll(true);
524 this._terminal
.buffer
.lines
.get(this._terminal
.buffer
.y
).isWrapped
= true;
532 row
= this._terminal
.buffer
.y
+ this._terminal
.buffer
.ybase
;
533 if (this._terminal
.insertMode
) {
534 for (var moves
= 0; moves
< ch_width
; ++moves
) {
535 var removed
= this._terminal
.buffer
.lines
.get(this._terminal
.buffer
.y
+ this._terminal
.buffer
.ybase
).pop();
537 && this._terminal
.buffer
.lines
.get(row
)[this._terminal
.cols
- 2]
538 && this._terminal
.buffer
.lines
.get(row
)[this._terminal
.cols
- 2][2] === 2) {
539 this._terminal
.buffer
.lines
.get(row
)[this._terminal
.cols
- 2] = [this._terminal
.curAttr
, ' ', 1];
541 this._terminal
.buffer
.lines
.get(row
).splice(this._terminal
.buffer
.x
, 0, [this._terminal
.curAttr
, ' ', 1]);
544 this._terminal
.buffer
.lines
.get(row
)[this._terminal
.buffer
.x
] = [this._terminal
.curAttr
, char, ch_width
];
545 this._terminal
.buffer
.x
++;
546 this._terminal
.updateRange(this._terminal
.buffer
.y
);
547 if (ch_width
=== 2) {
548 this._terminal
.buffer
.lines
.get(row
)[this._terminal
.buffer
.x
] = [this._terminal
.curAttr
, '', 0];
549 this._terminal
.buffer
.x
++;
553 InputHandler
.prototype.bell = function () {
555 if (!this._terminal
.visualBell
) {
558 this._terminal
.element
.style
.borderColor
= 'white';
559 setTimeout(function () { return _this
._terminal
.element
.style
.borderColor
= ''; }, 10);
560 if (this._terminal
.popOnBell
) {
561 this._terminal
.focus();
564 InputHandler
.prototype.lineFeed = function () {
565 if (this._terminal
.convertEol
) {
566 this._terminal
.buffer
.x
= 0;
568 this._terminal
.buffer
.y
++;
569 if (this._terminal
.buffer
.y
> this._terminal
.buffer
.scrollBottom
) {
570 this._terminal
.buffer
.y
--;
571 this._terminal
.scroll();
573 if (this._terminal
.buffer
.x
>= this._terminal
.cols
) {
574 this._terminal
.buffer
.x
--;
576 this._terminal
.emit('lineFeed');
578 InputHandler
.prototype.carriageReturn = function () {
579 this._terminal
.buffer
.x
= 0;
581 InputHandler
.prototype.backspace = function () {
582 if (this._terminal
.buffer
.x
> 0) {
583 this._terminal
.buffer
.x
--;
586 InputHandler
.prototype.tab = function () {
587 this._terminal
.buffer
.x
= this._terminal
.nextStop();
589 InputHandler
.prototype.shiftOut = function () {
590 this._terminal
.setgLevel(1);
592 InputHandler
.prototype.shiftIn = function () {
593 this._terminal
.setgLevel(0);
595 InputHandler
.prototype.insertChars = function (params
) {
596 var param
, row
, j
, ch
;
600 row
= this._terminal
.buffer
.y
+ this._terminal
.buffer
.ybase
;
601 j
= this._terminal
.buffer
.x
;
602 ch
= [this._terminal
.eraseAttr(), ' ', 1];
603 while (param
-- && j
< this._terminal
.cols
) {
604 this._terminal
.buffer
.lines
.get(row
).splice(j
++, 0, ch
);
605 this._terminal
.buffer
.lines
.get(row
).pop();
608 InputHandler
.prototype.cursorUp = function (params
) {
609 var param
= params
[0];
613 this._terminal
.buffer
.y
-= param
;
614 if (this._terminal
.buffer
.y
< 0) {
615 this._terminal
.buffer
.y
= 0;
618 InputHandler
.prototype.cursorDown = function (params
) {
619 var param
= params
[0];
623 this._terminal
.buffer
.y
+= param
;
624 if (this._terminal
.buffer
.y
>= this._terminal
.rows
) {
625 this._terminal
.buffer
.y
= this._terminal
.rows
- 1;
627 if (this._terminal
.buffer
.x
>= this._terminal
.cols
) {
628 this._terminal
.buffer
.x
--;
631 InputHandler
.prototype.cursorForward = function (params
) {
632 var param
= params
[0];
636 this._terminal
.buffer
.x
+= param
;
637 if (this._terminal
.buffer
.x
>= this._terminal
.cols
) {
638 this._terminal
.buffer
.x
= this._terminal
.cols
- 1;
641 InputHandler
.prototype.cursorBackward = function (params
) {
642 var param
= params
[0];
646 if (this._terminal
.buffer
.x
>= this._terminal
.cols
) {
647 this._terminal
.buffer
.x
--;
649 this._terminal
.buffer
.x
-= param
;
650 if (this._terminal
.buffer
.x
< 0) {
651 this._terminal
.buffer
.x
= 0;
654 InputHandler
.prototype.cursorNextLine = function (params
) {
655 var param
= params
[0];
659 this._terminal
.buffer
.y
+= param
;
660 if (this._terminal
.buffer
.y
>= this._terminal
.rows
) {
661 this._terminal
.buffer
.y
= this._terminal
.rows
- 1;
663 this._terminal
.buffer
.x
= 0;
665 InputHandler
.prototype.cursorPrecedingLine = function (params
) {
666 var param
= params
[0];
670 this._terminal
.buffer
.y
-= param
;
671 if (this._terminal
.buffer
.y
< 0) {
672 this._terminal
.buffer
.y
= 0;
674 this._terminal
.buffer
.x
= 0;
676 InputHandler
.prototype.cursorCharAbsolute = function (params
) {
677 var param
= params
[0];
681 this._terminal
.buffer
.x
= param
- 1;
683 InputHandler
.prototype.cursorPosition = function (params
) {
686 if (params
.length
>= 2) {
695 else if (row
>= this._terminal
.rows
) {
696 row
= this._terminal
.rows
- 1;
701 else if (col
>= this._terminal
.cols
) {
702 col
= this._terminal
.cols
- 1;
704 this._terminal
.buffer
.x
= col
;
705 this._terminal
.buffer
.y
= row
;
707 InputHandler
.prototype.cursorForwardTab = function (params
) {
708 var param
= params
[0] || 1;
710 this._terminal
.buffer
.x
= this._terminal
.nextStop();
713 InputHandler
.prototype.eraseInDisplay = function (params
) {
717 this._terminal
.eraseRight(this._terminal
.buffer
.x
, this._terminal
.buffer
.y
);
718 j
= this._terminal
.buffer
.y
+ 1;
719 for (; j
< this._terminal
.rows
; j
++) {
720 this._terminal
.eraseLine(j
);
724 this._terminal
.eraseLeft(this._terminal
.buffer
.x
, this._terminal
.buffer
.y
);
725 j
= this._terminal
.buffer
.y
;
727 this._terminal
.eraseLine(j
);
731 j
= this._terminal
.rows
;
733 this._terminal
.eraseLine(j
);
736 var scrollBackSize
= this._terminal
.buffer
.lines
.length
- this._terminal
.rows
;
737 if (scrollBackSize
> 0) {
738 this._terminal
.buffer
.lines
.trimStart(scrollBackSize
);
739 this._terminal
.buffer
.ybase
= Math
.max(this._terminal
.buffer
.ybase
- scrollBackSize
, 0);
740 this._terminal
.buffer
.ydisp
= Math
.max(this._terminal
.buffer
.ydisp
- scrollBackSize
, 0);
741 this._terminal
.emit('scroll', 0);
746 InputHandler
.prototype.eraseInLine = function (params
) {
749 this._terminal
.eraseRight(this._terminal
.buffer
.x
, this._terminal
.buffer
.y
);
752 this._terminal
.eraseLeft(this._terminal
.buffer
.x
, this._terminal
.buffer
.y
);
755 this._terminal
.eraseLine(this._terminal
.buffer
.y
);
759 InputHandler
.prototype.insertLines = function (params
) {
765 row
= this._terminal
.buffer
.y
+ this._terminal
.buffer
.ybase
;
766 j
= this._terminal
.rows
- 1 - this._terminal
.buffer
.scrollBottom
;
767 j
= this._terminal
.rows
- 1 + this._terminal
.buffer
.ybase
- j
+ 1;
769 if (this._terminal
.buffer
.lines
.length
=== this._terminal
.buffer
.lines
.maxLength
) {
770 this._terminal
.buffer
.lines
.trimStart(1);
771 this._terminal
.buffer
.ybase
--;
772 this._terminal
.buffer
.ydisp
--;
776 this._terminal
.buffer
.lines
.splice(row
, 0, this._terminal
.blankLine(true));
777 this._terminal
.buffer
.lines
.splice(j
, 1);
779 this._terminal
.updateRange(this._terminal
.buffer
.y
);
780 this._terminal
.updateRange(this._terminal
.buffer
.scrollBottom
);
782 InputHandler
.prototype.deleteLines = function (params
) {
788 row
= this._terminal
.buffer
.y
+ this._terminal
.buffer
.ybase
;
789 j
= this._terminal
.rows
- 1 - this._terminal
.buffer
.scrollBottom
;
790 j
= this._terminal
.rows
- 1 + this._terminal
.buffer
.ybase
- j
;
792 if (this._terminal
.buffer
.lines
.length
=== this._terminal
.buffer
.lines
.maxLength
) {
793 this._terminal
.buffer
.lines
.trimStart(1);
794 this._terminal
.buffer
.ybase
-= 1;
795 this._terminal
.buffer
.ydisp
-= 1;
797 this._terminal
.buffer
.lines
.splice(j
+ 1, 0, this._terminal
.blankLine(true));
798 this._terminal
.buffer
.lines
.splice(row
, 1);
800 this._terminal
.updateRange(this._terminal
.buffer
.y
);
801 this._terminal
.updateRange(this._terminal
.buffer
.scrollBottom
);
803 InputHandler
.prototype.deleteChars = function (params
) {
809 row
= this._terminal
.buffer
.y
+ this._terminal
.buffer
.ybase
;
810 ch
= [this._terminal
.eraseAttr(), ' ', 1];
812 this._terminal
.buffer
.lines
.get(row
).splice(this._terminal
.buffer
.x
, 1);
813 this._terminal
.buffer
.lines
.get(row
).push(ch
);
816 InputHandler
.prototype.scrollUp = function (params
) {
817 var param
= params
[0] || 1;
819 this._terminal
.buffer
.lines
.splice(this._terminal
.buffer
.ybase
+ this._terminal
.buffer
.scrollTop
, 1);
820 this._terminal
.buffer
.lines
.splice(this._terminal
.buffer
.ybase
+ this._terminal
.buffer
.scrollBottom
, 0, this._terminal
.blankLine());
822 this._terminal
.updateRange(this._terminal
.buffer
.scrollTop
);
823 this._terminal
.updateRange(this._terminal
.buffer
.scrollBottom
);
825 InputHandler
.prototype.scrollDown = function (params
) {
826 var param
= params
[0] || 1;
828 this._terminal
.buffer
.lines
.splice(this._terminal
.buffer
.ybase
+ this._terminal
.buffer
.scrollBottom
, 1);
829 this._terminal
.buffer
.lines
.splice(this._terminal
.buffer
.ybase
+ this._terminal
.buffer
.scrollTop
, 0, this._terminal
.blankLine());
831 this._terminal
.updateRange(this._terminal
.buffer
.scrollTop
);
832 this._terminal
.updateRange(this._terminal
.buffer
.scrollBottom
);
834 InputHandler
.prototype.eraseChars = function (params
) {
835 var param
, row
, j
, ch
;
840 row
= this._terminal
.buffer
.y
+ this._terminal
.buffer
.ybase
;
841 j
= this._terminal
.buffer
.x
;
842 ch
= [this._terminal
.eraseAttr(), ' ', 1];
843 while (param
-- && j
< this._terminal
.cols
) {
844 this._terminal
.buffer
.lines
.get(row
)[j
++] = ch
;
847 InputHandler
.prototype.cursorBackwardTab = function (params
) {
848 var param
= params
[0] || 1;
850 this._terminal
.buffer
.x
= this._terminal
.prevStop();
853 InputHandler
.prototype.charPosAbsolute = function (params
) {
854 var param
= params
[0];
858 this._terminal
.buffer
.x
= param
- 1;
859 if (this._terminal
.buffer
.x
>= this._terminal
.cols
) {
860 this._terminal
.buffer
.x
= this._terminal
.cols
- 1;
863 InputHandler
.prototype.HPositionRelative = function (params
) {
864 var param
= params
[0];
868 this._terminal
.buffer
.x
+= param
;
869 if (this._terminal
.buffer
.x
>= this._terminal
.cols
) {
870 this._terminal
.buffer
.x
= this._terminal
.cols
- 1;
873 InputHandler
.prototype.repeatPrecedingCharacter = function (params
) {
874 var param
= params
[0] || 1, line
= this._terminal
.buffer
.lines
.get(this._terminal
.buffer
.ybase
+ this._terminal
.buffer
.y
), ch
= line
[this._terminal
.buffer
.x
- 1] || [this._terminal
.defAttr
, ' ', 1];
876 line
[this._terminal
.buffer
.x
++] = ch
;
879 InputHandler
.prototype.sendDeviceAttributes = function (params
) {
883 if (!this._terminal
.prefix
) {
884 if (this._terminal
.is('xterm') || this._terminal
.is('rxvt-unicode') || this._terminal
.is('screen')) {
885 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?1;2c');
887 else if (this._terminal
.is('linux')) {
888 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?6c');
891 else if (this._terminal
.prefix
=== '>') {
892 if (this._terminal
.is('xterm')) {
893 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>0;276;0c');
895 else if (this._terminal
.is('rxvt-unicode')) {
896 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>85;95;0c');
898 else if (this._terminal
.is('linux')) {
899 this._terminal
.send(params
[0] + 'c');
901 else if (this._terminal
.is('screen')) {
902 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>83;40003;0c');
906 InputHandler
.prototype.linePosAbsolute = function (params
) {
907 var param
= params
[0];
911 this._terminal
.buffer
.y
= param
- 1;
912 if (this._terminal
.buffer
.y
>= this._terminal
.rows
) {
913 this._terminal
.buffer
.y
= this._terminal
.rows
- 1;
916 InputHandler
.prototype.VPositionRelative = function (params
) {
917 var param
= params
[0];
921 this._terminal
.buffer
.y
+= param
;
922 if (this._terminal
.buffer
.y
>= this._terminal
.rows
) {
923 this._terminal
.buffer
.y
= this._terminal
.rows
- 1;
925 if (this._terminal
.buffer
.x
>= this._terminal
.cols
) {
926 this._terminal
.buffer
.x
--;
929 InputHandler
.prototype.HVPosition = function (params
) {
934 this._terminal
.buffer
.y
= params
[0] - 1;
935 if (this._terminal
.buffer
.y
>= this._terminal
.rows
) {
936 this._terminal
.buffer
.y
= this._terminal
.rows
- 1;
938 this._terminal
.buffer
.x
= params
[1] - 1;
939 if (this._terminal
.buffer
.x
>= this._terminal
.cols
) {
940 this._terminal
.buffer
.x
= this._terminal
.cols
- 1;
943 InputHandler
.prototype.tabClear = function (params
) {
944 var param
= params
[0];
946 delete this._terminal
.buffer
.tabs
[this._terminal
.buffer
.x
];
948 else if (param
=== 3) {
949 this._terminal
.buffer
.tabs
= {};
952 InputHandler
.prototype.setMode = function (params
) {
953 if (params
.length
> 1) {
954 for (var i
= 0; i
< params
.length
; i
++) {
955 this.setMode([params
[i
]]);
959 if (!this._terminal
.prefix
) {
962 this._terminal
.insertMode
= true;
968 else if (this._terminal
.prefix
=== '?') {
971 this._terminal
.applicationCursor
= true;
974 this._terminal
.setgCharset(0, Charsets_1
.DEFAULT_CHARSET
);
975 this._terminal
.setgCharset(1, Charsets_1
.DEFAULT_CHARSET
);
976 this._terminal
.setgCharset(2, Charsets_1
.DEFAULT_CHARSET
);
977 this._terminal
.setgCharset(3, Charsets_1
.DEFAULT_CHARSET
);
980 this._terminal
.savedCols
= this._terminal
.cols
;
981 this._terminal
.resize(132, this._terminal
.rows
);
984 this._terminal
.originMode
= true;
987 this._terminal
.wraparoundMode
= true;
992 this._terminal
.log('Serial port requested application keypad.');
993 this._terminal
.applicationKeypad
= true;
994 this._terminal
.viewport
.syncScrollArea();
1000 this._terminal
.x10Mouse
= params
[0] === 9;
1001 this._terminal
.vt200Mouse
= params
[0] === 1000;
1002 this._terminal
.normalMouse
= params
[0] > 1000;
1003 this._terminal
.mouseEvents
= true;
1004 this._terminal
.element
.classList
.add('enable-mouse-events');
1005 this._terminal
.selectionManager
.disable();
1006 this._terminal
.log('Binding to mouse events.');
1009 this._terminal
.sendFocus
= true;
1012 this._terminal
.utfMouse
= true;
1015 this._terminal
.sgrMouse
= true;
1018 this._terminal
.urxvtMouse
= true;
1021 this._terminal
.cursorHidden
= false;
1026 this._terminal
.buffers
.activateAltBuffer();
1027 this._terminal
.reset();
1028 this._terminal
.viewport
.syncScrollArea();
1029 this._terminal
.showCursor();
1034 InputHandler
.prototype.resetMode = function (params
) {
1035 if (params
.length
> 1) {
1036 for (var i
= 0; i
< params
.length
; i
++) {
1037 this.resetMode([params
[i
]]);
1041 if (!this._terminal
.prefix
) {
1042 switch (params
[0]) {
1044 this._terminal
.insertMode
= false;
1050 else if (this._terminal
.prefix
=== '?') {
1051 switch (params
[0]) {
1053 this._terminal
.applicationCursor
= false;
1056 if (this._terminal
.cols
=== 132 && this._terminal
.savedCols
) {
1057 this._terminal
.resize(this._terminal
.savedCols
, this._terminal
.rows
);
1059 delete this._terminal
.savedCols
;
1062 this._terminal
.originMode
= false;
1065 this._terminal
.wraparoundMode
= false;
1070 this._terminal
.log('Switching back to normal keypad.');
1071 this._terminal
.applicationKeypad
= false;
1072 this._terminal
.viewport
.syncScrollArea();
1078 this._terminal
.x10Mouse
= false;
1079 this._terminal
.vt200Mouse
= false;
1080 this._terminal
.normalMouse
= false;
1081 this._terminal
.mouseEvents
= false;
1082 this._terminal
.element
.classList
.remove('enable-mouse-events');
1083 this._terminal
.selectionManager
.enable();
1086 this._terminal
.sendFocus
= false;
1089 this._terminal
.utfMouse
= false;
1092 this._terminal
.sgrMouse
= false;
1095 this._terminal
.urxvtMouse
= false;
1098 this._terminal
.cursorHidden
= true;
1103 this._terminal
.buffers
.activateNormalBuffer();
1104 this._terminal
.selectionManager
.setBuffer(this._terminal
.buffer
.lines
);
1105 this._terminal
.refresh(0, this._terminal
.rows
- 1);
1106 this._terminal
.viewport
.syncScrollArea();
1107 this._terminal
.showCursor();
1112 InputHandler
.prototype.charAttributes = function (params
) {
1113 if (params
.length
=== 1 && params
[0] === 0) {
1114 this._terminal
.curAttr
= this._terminal
.defAttr
;
1117 var l
= params
.length
, i
= 0, flags
= this._terminal
.curAttr
>> 18, fg
= (this._terminal
.curAttr
>> 9) & 0x1ff, bg
= this._terminal
.curAttr
& 0x1ff, p
;
1118 for (; i
< l
; i
++) {
1120 if (p
>= 30 && p
<= 37) {
1123 else if (p
>= 40 && p
<= 47) {
1126 else if (p
>= 90 && p
<= 97) {
1130 else if (p
>= 100 && p
<= 107) {
1135 flags
= this._terminal
.defAttr
>> 18;
1136 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1137 bg
= this._terminal
.defAttr
& 0x1ff;
1154 else if (p
=== 22) {
1157 else if (p
=== 24) {
1160 else if (p
=== 25) {
1163 else if (p
=== 27) {
1166 else if (p
=== 28) {
1169 else if (p
=== 39) {
1170 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1172 else if (p
=== 49) {
1173 bg
= this._terminal
.defAttr
& 0x1ff;
1175 else if (p
=== 38) {
1176 if (params
[i
+ 1] === 2) {
1178 fg
= this._terminal
.matchColor(params
[i
] & 0xff, params
[i
+ 1] & 0xff, params
[i
+ 2] & 0xff);
1183 else if (params
[i
+ 1] === 5) {
1185 p
= params
[i
] & 0xff;
1189 else if (p
=== 48) {
1190 if (params
[i
+ 1] === 2) {
1192 bg
= this._terminal
.matchColor(params
[i
] & 0xff, params
[i
+ 1] & 0xff, params
[i
+ 2] & 0xff);
1197 else if (params
[i
+ 1] === 5) {
1199 p
= params
[i
] & 0xff;
1203 else if (p
=== 100) {
1204 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1205 bg
= this._terminal
.defAttr
& 0x1ff;
1208 this._terminal
.error('Unknown SGR attribute: %d.', p
);
1211 this._terminal
.curAttr
= (flags
<< 18) | (fg
<< 9) | bg
;
1213 InputHandler
.prototype.deviceStatus = function (params
) {
1214 if (!this._terminal
.prefix
) {
1215 switch (params
[0]) {
1217 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[0n');
1220 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '['
1221 + (this._terminal
.buffer
.y
+ 1)
1223 + (this._terminal
.buffer
.x
+ 1)
1228 else if (this._terminal
.prefix
=== '?') {
1229 switch (params
[0]) {
1231 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?'
1232 + (this._terminal
.buffer
.y
+ 1)
1234 + (this._terminal
.buffer
.x
+ 1)
1248 InputHandler
.prototype.softReset = function (params
) {
1249 this._terminal
.cursorHidden
= false;
1250 this._terminal
.insertMode
= false;
1251 this._terminal
.originMode
= false;
1252 this._terminal
.wraparoundMode
= true;
1253 this._terminal
.applicationKeypad
= false;
1254 this._terminal
.viewport
.syncScrollArea();
1255 this._terminal
.applicationCursor
= false;
1256 this._terminal
.buffer
.scrollTop
= 0;
1257 this._terminal
.buffer
.scrollBottom
= this._terminal
.rows
- 1;
1258 this._terminal
.curAttr
= this._terminal
.defAttr
;
1259 this._terminal
.buffer
.x
= this._terminal
.buffer
.y
= 0;
1260 this._terminal
.charset
= null;
1261 this._terminal
.glevel
= 0;
1262 this._terminal
.charsets
= [null];
1264 InputHandler
.prototype.setCursorStyle = function (params
) {
1265 var param
= params
[0] < 1 ? 1 : params
[0];
1269 this._terminal
.setOption('cursorStyle', 'block');
1273 this._terminal
.setOption('cursorStyle', 'underline');
1277 this._terminal
.setOption('cursorStyle', 'bar');
1280 var isBlinking
= param
% 2 === 1;
1281 this._terminal
.setOption('cursorBlink', isBlinking
);
1283 InputHandler
.prototype.setScrollRegion = function (params
) {
1284 if (this._terminal
.prefix
)
1286 this._terminal
.buffer
.scrollTop
= (params
[0] || 1) - 1;
1287 this._terminal
.buffer
.scrollBottom
= (params
[1] && params
[1] <= this._terminal
.rows
? params
[1] : this._terminal
.rows
) - 1;
1288 this._terminal
.buffer
.x
= 0;
1289 this._terminal
.buffer
.y
= 0;
1291 InputHandler
.prototype.saveCursor = function (params
) {
1292 this._terminal
.buffer
.savedX
= this._terminal
.buffer
.x
;
1293 this._terminal
.buffer
.savedY
= this._terminal
.buffer
.y
;
1295 InputHandler
.prototype.restoreCursor = function (params
) {
1296 this._terminal
.buffer
.x
= this._terminal
.buffer
.savedX
|| 0;
1297 this._terminal
.buffer
.y
= this._terminal
.buffer
.savedY
|| 0;
1299 return InputHandler
;
1301 exports
.InputHandler
= InputHandler
;
1302 exports
.wcwidth
= (function (opts
) {
1303 var COMBINING_BMP
= [
1304 [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
1305 [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
1306 [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
1307 [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670],
1308 [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED],
1309 [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A],
1310 [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902],
1311 [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D],
1312 [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981],
1313 [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD],
1314 [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C],
1315 [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D],
1316 [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC],
1317 [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD],
1318 [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C],
1319 [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D],
1320 [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0],
1321 [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48],
1322 [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC],
1323 [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD],
1324 [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D],
1325 [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6],
1326 [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E],
1327 [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC],
1328 [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35],
1329 [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E],
1330 [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97],
1331 [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030],
1332 [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039],
1333 [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F],
1334 [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753],
1335 [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD],
1336 [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD],
1337 [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922],
1338 [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B],
1339 [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34],
1340 [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42],
1341 [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF],
1342 [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063],
1343 [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F],
1344 [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B],
1345 [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F],
1346 [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB],
1348 var COMBINING_HIGH
= [
1349 [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F],
1350 [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169],
1351 [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD],
1352 [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F],
1355 function bisearch(ucs
, data
) {
1357 var max
= data
.length
- 1;
1359 if (ucs
< data
[0][0] || ucs
> data
[max
][1])
1361 while (max
>= min
) {
1362 mid
= (min
+ max
) >> 1;
1363 if (ucs
> data
[mid
][1])
1365 else if (ucs
< data
[mid
][0])
1372 function wcwidthBMP(ucs
) {
1375 if (ucs
< 32 || (ucs
>= 0x7f && ucs
< 0xa0))
1376 return opts
.control
;
1377 if (bisearch(ucs
, COMBINING_BMP
))
1379 if (isWideBMP(ucs
)) {
1384 function isWideBMP(ucs
) {
1385 return (ucs
>= 0x1100 && (ucs
<= 0x115f ||
1388 (ucs
>= 0x2e80 && ucs
<= 0xa4cf && ucs
!== 0x303f) ||
1389 (ucs
>= 0xac00 && ucs
<= 0xd7a3) ||
1390 (ucs
>= 0xf900 && ucs
<= 0xfaff) ||
1391 (ucs
>= 0xfe10 && ucs
<= 0xfe19) ||
1392 (ucs
>= 0xfe30 && ucs
<= 0xfe6f) ||
1393 (ucs
>= 0xff00 && ucs
<= 0xff60) ||
1394 (ucs
>= 0xffe0 && ucs
<= 0xffe6)));
1396 function wcwidthHigh(ucs
) {
1397 if (bisearch(ucs
, COMBINING_HIGH
))
1399 if ((ucs
>= 0x20000 && ucs
<= 0x2fffd) || (ucs
>= 0x30000 && ucs
<= 0x3fffd)) {
1404 var control
= opts
.control
| 0;
1406 function init_table() {
1407 var CODEPOINTS
= 65536;
1410 var CONTAINERSIZE
= CODEPOINTS
* BITWIDTH
/ ITEMSIZE
;
1411 var CODEPOINTS_PER_ITEM
= ITEMSIZE
/ BITWIDTH
;
1412 table
= (typeof Uint32Array
=== 'undefined')
1413 ? new Array(CONTAINERSIZE
)
1414 : new Uint32Array(CONTAINERSIZE
);
1415 for (var i
= 0; i
< CONTAINERSIZE
; ++i
) {
1417 var pos
= CODEPOINTS_PER_ITEM
;
1419 num
= (num
<< 2) | wcwidthBMP(CODEPOINTS_PER_ITEM
* i
+ pos
);
1424 return function (num
) {
1430 var t
= table
|| init_table();
1432 return t
[num
>> 4] >> ((num
& 15) << 1) & 3;
1433 return wcwidthHigh(num
);
1435 })({ nul
: 0, control
: 0 });
1439 },{"./Charsets":3,"./EscapeSequences":5}],8:[function(require
,module
,exports
){
1441 Object
.defineProperty(exports
, "__esModule", { value
: true });
1442 var INVALID_LINK_CLASS
= 'xterm-invalid-link';
1443 var protocolClause
= '(https?:\\/\\/)';
1444 var domainCharacterSet
= '[\\da-z\\.-]+';
1445 var negatedDomainCharacterSet
= '[^\\da-z\\.-]+';
1446 var domainBodyClause
= '(' + domainCharacterSet
+ ')';
1447 var tldClause
= '([a-z\\.]{2,6})';
1448 var ipClause
= '((\\d{1,3}\\.){3}\\d{1,3})';
1449 var localHostClause
= '(localhost)';
1450 var portClause
= '(:\\d{1,5})';
1451 var hostClause
= '((' + domainBodyClause
+ '\\.' + tldClause
+ ')|' + ipClause
+ '|' + localHostClause
+ ')' + portClause
+ '?';
1452 var pathClause
= '(\\/[\\/\\w\\.\\-%~]*)*';
1453 var queryStringHashFragmentCharacterSet
= '[0-9\\w\\[\\]\\(\\)\\/\\?\\!#@$%&\'*+,:;~\\=\\.\\-]*';
1454 var queryStringClause
= '(\\?' + queryStringHashFragmentCharacterSet
+ ')?';
1455 var hashFragmentClause
= '(#' + queryStringHashFragmentCharacterSet
+ ')?';
1456 var negatedPathCharacterSet
= '[^\\/\\w\\.\\-%]+';
1457 var bodyClause
= hostClause
+ pathClause
+ queryStringClause
+ hashFragmentClause
;
1458 var start
= '(?:^|' + negatedDomainCharacterSet
+ ')(';
1459 var end
= ')($|' + negatedPathCharacterSet
+ ')';
1460 var strictUrlRegex
= new RegExp(start
+ protocolClause
+ bodyClause
+ end
);
1461 var HYPERTEXT_LINK_MATCHER_ID
= 0;
1462 var Linkifier
= (function () {
1463 function Linkifier() {
1464 this._nextLinkMatcherId
= HYPERTEXT_LINK_MATCHER_ID
;
1465 this._rowTimeoutIds
= [];
1466 this._linkMatchers
= [];
1467 this.registerLinkMatcher(strictUrlRegex
, null, { matchIndex
: 1 });
1469 Linkifier
.prototype.attachToDom = function (document
, rows
) {
1470 this._document
= document
;
1473 Linkifier
.prototype.linkifyRow = function (rowIndex
) {
1474 if (!this._document
) {
1477 var timeoutId
= this._rowTimeoutIds
[rowIndex
];
1479 clearTimeout(timeoutId
);
1481 this._rowTimeoutIds
[rowIndex
] = setTimeout(this._linkifyRow
.bind(this, rowIndex
), Linkifier
.TIME_BEFORE_LINKIFY
);
1483 Linkifier
.prototype.setHypertextLinkHandler = function (handler
) {
1484 this._linkMatchers
[HYPERTEXT_LINK_MATCHER_ID
].handler
= handler
;
1486 Linkifier
.prototype.setHypertextValidationCallback = function (callback
) {
1487 this._linkMatchers
[HYPERTEXT_LINK_MATCHER_ID
].validationCallback
= callback
;
1489 Linkifier
.prototype.registerLinkMatcher = function (regex
, handler
, options
) {
1490 if (options
=== void 0) { options
= {}; }
1491 if (this._nextLinkMatcherId
!== HYPERTEXT_LINK_MATCHER_ID
&& !handler
) {
1492 throw new Error('handler must be defined');
1495 id
: this._nextLinkMatcherId
++,
1498 matchIndex
: options
.matchIndex
,
1499 validationCallback
: options
.validationCallback
,
1500 priority
: options
.priority
|| 0
1502 this._addLinkMatcherToList(matcher
);
1505 Linkifier
.prototype._addLinkMatcherToList = function (matcher
) {
1506 if (this._linkMatchers
.length
=== 0) {
1507 this._linkMatchers
.push(matcher
);
1510 for (var i
= this._linkMatchers
.length
- 1; i
>= 0; i
--) {
1511 if (matcher
.priority
<= this._linkMatchers
[i
].priority
) {
1512 this._linkMatchers
.splice(i
+ 1, 0, matcher
);
1516 this._linkMatchers
.splice(0, 0, matcher
);
1518 Linkifier
.prototype.deregisterLinkMatcher = function (matcherId
) {
1519 for (var i
= 1; i
< this._linkMatchers
.length
; i
++) {
1520 if (this._linkMatchers
[i
].id
=== matcherId
) {
1521 this._linkMatchers
.splice(i
, 1);
1527 Linkifier
.prototype._linkifyRow = function (rowIndex
) {
1528 var row
= this._rows
[rowIndex
];
1532 var text
= row
.textContent
;
1533 for (var i
= 0; i
< this._linkMatchers
.length
; i
++) {
1534 var matcher
= this._linkMatchers
[i
];
1535 var linkElements
= this._doLinkifyRow(row
, matcher
);
1536 if (linkElements
.length
> 0) {
1537 if (matcher
.validationCallback
) {
1538 var _loop_1 = function (j
) {
1539 var element
= linkElements
[j
];
1540 matcher
.validationCallback(element
.textContent
, element
, function (isValid
) {
1542 element
.classList
.add(INVALID_LINK_CLASS
);
1546 for (var j
= 0; j
< linkElements
.length
; j
++) {
1554 Linkifier
.prototype._doLinkifyRow = function (row
, matcher
) {
1556 var isHttpLinkMatcher
= matcher
.id
=== HYPERTEXT_LINK_MATCHER_ID
;
1557 var nodes
= row
.childNodes
;
1558 var match
= row
.textContent
.match(matcher
.regex
);
1559 if (!match
|| match
.length
=== 0) {
1562 var uri
= match
[typeof matcher
.matchIndex
!== 'number' ? 0 : matcher
.matchIndex
];
1563 var rowStartIndex
= match
.index
+ uri
.length
;
1564 for (var i
= 0; i
< nodes
.length
; i
++) {
1565 var node
= nodes
[i
];
1566 var searchIndex
= node
.textContent
.indexOf(uri
);
1567 if (searchIndex
>= 0) {
1568 var linkElement
= this._createAnchorElement(uri
, matcher
.handler
, isHttpLinkMatcher
);
1569 if (node
.textContent
.length
=== uri
.length
) {
1570 if (node
.nodeType
=== 3) {
1571 this._replaceNode(node
, linkElement
);
1575 if (element
.nodeName
=== 'A') {
1578 element
.innerHTML
= '';
1579 element
.appendChild(linkElement
);
1582 else if (node
.childNodes
.length
> 1) {
1583 for (var j
= 0; j
< node
.childNodes
.length
; j
++) {
1584 var childNode
= node
.childNodes
[j
];
1585 var childSearchIndex
= childNode
.textContent
.indexOf(uri
);
1586 if (childSearchIndex
!== -1) {
1587 this._replaceNodeSubstringWithNode(childNode
, linkElement
, uri
, childSearchIndex
);
1593 var nodesAdded
= this._replaceNodeSubstringWithNode(node
, linkElement
, uri
, searchIndex
);
1596 result
.push(linkElement
);
1597 match
= row
.textContent
.substring(rowStartIndex
).match(matcher
.regex
);
1598 if (!match
|| match
.length
=== 0) {
1601 uri
= match
[typeof matcher
.matchIndex
!== 'number' ? 0 : matcher
.matchIndex
];
1602 rowStartIndex
+= match
.index
+ uri
.length
;
1607 Linkifier
.prototype._createAnchorElement = function (uri
, handler
, isHypertextLinkHandler
) {
1608 var element
= this._document
.createElement('a');
1609 element
.textContent
= uri
;
1610 element
.draggable
= false;
1611 if (isHypertextLinkHandler
) {
1613 element
.target
= '_blank';
1614 element
.addEventListener('click', function (event
) {
1616 return handler(event
, uri
);
1621 element
.addEventListener('click', function (event
) {
1622 if (element
.classList
.contains(INVALID_LINK_CLASS
)) {
1625 return handler(event
, uri
);
1630 Linkifier
.prototype._replaceNode = function (oldNode
) {
1632 for (var _i
= 1; _i
< arguments
.length
; _i
++) {
1633 newNodes
[_i
- 1] = arguments
[_i
];
1635 var parent
= oldNode
.parentNode
;
1636 for (var i
= 0; i
< newNodes
.length
; i
++) {
1637 parent
.insertBefore(newNodes
[i
], oldNode
);
1639 parent
.removeChild(oldNode
);
1641 Linkifier
.prototype._replaceNodeSubstringWithNode = function (targetNode
, newNode
, substring
, substringIndex
) {
1642 if (targetNode
.childNodes
.length
=== 1) {
1643 targetNode
= targetNode
.childNodes
[0];
1645 if (targetNode
.nodeType
!== 3) {
1646 throw new Error('targetNode must be a text node or only contain a single text node');
1648 var fullText
= targetNode
.textContent
;
1649 if (substringIndex
=== 0) {
1650 var rightText_1
= fullText
.substring(substring
.length
);
1651 var rightTextNode_1
= this._document
.createTextNode(rightText_1
);
1652 this._replaceNode(targetNode
, newNode
, rightTextNode_1
);
1655 if (substringIndex
=== targetNode
.textContent
.length
- substring
.length
) {
1656 var leftText_1
= fullText
.substring(0, substringIndex
);
1657 var leftTextNode_1
= this._document
.createTextNode(leftText_1
);
1658 this._replaceNode(targetNode
, leftTextNode_1
, newNode
);
1661 var leftText
= fullText
.substring(0, substringIndex
);
1662 var leftTextNode
= this._document
.createTextNode(leftText
);
1663 var rightText
= fullText
.substring(substringIndex
+ substring
.length
);
1664 var rightTextNode
= this._document
.createTextNode(rightText
);
1665 this._replaceNode(targetNode
, leftTextNode
, newNode
, rightTextNode
);
1670 Linkifier
.TIME_BEFORE_LINKIFY
= 200;
1671 exports
.Linkifier
= Linkifier
;
1675 },{}],9:[function(require
,module
,exports
){
1677 Object
.defineProperty(exports
, "__esModule", { value
: true });
1678 var EscapeSequences_1
= require("./EscapeSequences");
1679 var Charsets_1
= require("./Charsets");
1680 var normalStateHandler
= {};
1681 normalStateHandler
[EscapeSequences_1
.C0
.BEL
] = function (parser
, handler
) { return handler
.bell(); };
1682 normalStateHandler
[EscapeSequences_1
.C0
.LF
] = function (parser
, handler
) { return handler
.lineFeed(); };
1683 normalStateHandler
[EscapeSequences_1
.C0
.VT
] = normalStateHandler
[EscapeSequences_1
.C0
.LF
];
1684 normalStateHandler
[EscapeSequences_1
.C0
.FF
] = normalStateHandler
[EscapeSequences_1
.C0
.LF
];
1685 normalStateHandler
[EscapeSequences_1
.C0
.CR
] = function (parser
, handler
) { return handler
.carriageReturn(); };
1686 normalStateHandler
[EscapeSequences_1
.C0
.BS
] = function (parser
, handler
) { return handler
.backspace(); };
1687 normalStateHandler
[EscapeSequences_1
.C0
.HT
] = function (parser
, handler
) { return handler
.tab(); };
1688 normalStateHandler
[EscapeSequences_1
.C0
.SO
] = function (parser
, handler
) { return handler
.shiftOut(); };
1689 normalStateHandler
[EscapeSequences_1
.C0
.SI
] = function (parser
, handler
) { return handler
.shiftIn(); };
1690 normalStateHandler
[EscapeSequences_1
.C0
.ESC
] = function (parser
, handler
) { return parser
.setState(ParserState
.ESCAPED
); };
1691 var escapedStateHandler
= {};
1692 escapedStateHandler
['['] = function (parser
, terminal
) {
1693 terminal
.params
= [];
1694 terminal
.currentParam
= 0;
1695 parser
.setState(ParserState
.CSI_PARAM
);
1697 escapedStateHandler
[']'] = function (parser
, terminal
) {
1698 terminal
.params
= [];
1699 terminal
.currentParam
= 0;
1700 parser
.setState(ParserState
.OSC
);
1702 escapedStateHandler
['P'] = function (parser
, terminal
) {
1703 terminal
.params
= [];
1704 terminal
.currentParam
= 0;
1705 parser
.setState(ParserState
.DCS
);
1707 escapedStateHandler
['_'] = function (parser
, terminal
) {
1708 parser
.setState(ParserState
.IGNORE
);
1710 escapedStateHandler
['^'] = function (parser
, terminal
) {
1711 parser
.setState(ParserState
.IGNORE
);
1713 escapedStateHandler
['c'] = function (parser
, terminal
) {
1716 escapedStateHandler
['E'] = function (parser
, terminal
) {
1717 terminal
.buffer
.x
= 0;
1719 parser
.setState(ParserState
.NORMAL
);
1721 escapedStateHandler
['D'] = function (parser
, terminal
) {
1723 parser
.setState(ParserState
.NORMAL
);
1725 escapedStateHandler
['M'] = function (parser
, terminal
) {
1726 terminal
.reverseIndex();
1727 parser
.setState(ParserState
.NORMAL
);
1729 escapedStateHandler
['%'] = function (parser
, terminal
) {
1730 terminal
.setgLevel(0);
1731 terminal
.setgCharset(0, Charsets_1
.DEFAULT_CHARSET
);
1732 parser
.setState(ParserState
.NORMAL
);
1733 parser
.skipNextChar();
1735 escapedStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (parser
) { return parser
.setState(ParserState
.NORMAL
); };
1736 var csiParamStateHandler
= {};
1737 csiParamStateHandler
['?'] = function (parser
) { return parser
.setPrefix('?'); };
1738 csiParamStateHandler
['>'] = function (parser
) { return parser
.setPrefix('>'); };
1739 csiParamStateHandler
['!'] = function (parser
) { return parser
.setPrefix('!'); };
1740 csiParamStateHandler
['0'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10); };
1741 csiParamStateHandler
['1'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 1); };
1742 csiParamStateHandler
['2'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 2); };
1743 csiParamStateHandler
['3'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 3); };
1744 csiParamStateHandler
['4'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 4); };
1745 csiParamStateHandler
['5'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 5); };
1746 csiParamStateHandler
['6'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 6); };
1747 csiParamStateHandler
['7'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 7); };
1748 csiParamStateHandler
['8'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 8); };
1749 csiParamStateHandler
['9'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 9); };
1750 csiParamStateHandler
['$'] = function (parser
) { return parser
.setPostfix('$'); };
1751 csiParamStateHandler
['"'] = function (parser
) { return parser
.setPostfix('"'); };
1752 csiParamStateHandler
[' '] = function (parser
) { return parser
.setPostfix(' '); };
1753 csiParamStateHandler
['\''] = function (parser
) { return parser
.setPostfix('\''); };
1754 csiParamStateHandler
[';'] = function (parser
) { return parser
.finalizeParam(); };
1755 csiParamStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (parser
) { return parser
.setState(ParserState
.NORMAL
); };
1756 var csiStateHandler
= {};
1757 csiStateHandler
['@'] = function (handler
, params
, prefix
) { return handler
.insertChars(params
); };
1758 csiStateHandler
['A'] = function (handler
, params
, prefix
) { return handler
.cursorUp(params
); };
1759 csiStateHandler
['B'] = function (handler
, params
, prefix
) { return handler
.cursorDown(params
); };
1760 csiStateHandler
['C'] = function (handler
, params
, prefix
) { return handler
.cursorForward(params
); };
1761 csiStateHandler
['D'] = function (handler
, params
, prefix
) { return handler
.cursorBackward(params
); };
1762 csiStateHandler
['E'] = function (handler
, params
, prefix
) { return handler
.cursorNextLine(params
); };
1763 csiStateHandler
['F'] = function (handler
, params
, prefix
) { return handler
.cursorPrecedingLine(params
); };
1764 csiStateHandler
['G'] = function (handler
, params
, prefix
) { return handler
.cursorCharAbsolute(params
); };
1765 csiStateHandler
['H'] = function (handler
, params
, prefix
) { return handler
.cursorPosition(params
); };
1766 csiStateHandler
['I'] = function (handler
, params
, prefix
) { return handler
.cursorForwardTab(params
); };
1767 csiStateHandler
['J'] = function (handler
, params
, prefix
) { return handler
.eraseInDisplay(params
); };
1768 csiStateHandler
['K'] = function (handler
, params
, prefix
) { return handler
.eraseInLine(params
); };
1769 csiStateHandler
['L'] = function (handler
, params
, prefix
) { return handler
.insertLines(params
); };
1770 csiStateHandler
['M'] = function (handler
, params
, prefix
) { return handler
.deleteLines(params
); };
1771 csiStateHandler
['P'] = function (handler
, params
, prefix
) { return handler
.deleteChars(params
); };
1772 csiStateHandler
['S'] = function (handler
, params
, prefix
) { return handler
.scrollUp(params
); };
1773 csiStateHandler
['T'] = function (handler
, params
, prefix
) {
1774 if (params
.length
< 2 && !prefix
) {
1775 handler
.scrollDown(params
);
1778 csiStateHandler
['X'] = function (handler
, params
, prefix
) { return handler
.eraseChars(params
); };
1779 csiStateHandler
['Z'] = function (handler
, params
, prefix
) { return handler
.cursorBackwardTab(params
); };
1780 csiStateHandler
['`'] = function (handler
, params
, prefix
) { return handler
.charPosAbsolute(params
); };
1781 csiStateHandler
['a'] = function (handler
, params
, prefix
) { return handler
.HPositionRelative(params
); };
1782 csiStateHandler
['b'] = function (handler
, params
, prefix
) { return handler
.repeatPrecedingCharacter(params
); };
1783 csiStateHandler
['c'] = function (handler
, params
, prefix
) { return handler
.sendDeviceAttributes(params
); };
1784 csiStateHandler
['d'] = function (handler
, params
, prefix
) { return handler
.linePosAbsolute(params
); };
1785 csiStateHandler
['e'] = function (handler
, params
, prefix
) { return handler
.VPositionRelative(params
); };
1786 csiStateHandler
['f'] = function (handler
, params
, prefix
) { return handler
.HVPosition(params
); };
1787 csiStateHandler
['g'] = function (handler
, params
, prefix
) { return handler
.tabClear(params
); };
1788 csiStateHandler
['h'] = function (handler
, params
, prefix
) { return handler
.setMode(params
); };
1789 csiStateHandler
['l'] = function (handler
, params
, prefix
) { return handler
.resetMode(params
); };
1790 csiStateHandler
['m'] = function (handler
, params
, prefix
) { return handler
.charAttributes(params
); };
1791 csiStateHandler
['n'] = function (handler
, params
, prefix
) { return handler
.deviceStatus(params
); };
1792 csiStateHandler
['p'] = function (handler
, params
, prefix
) {
1795 handler
.softReset(params
);
1799 csiStateHandler
['q'] = function (handler
, params
, prefix
, postfix
) {
1800 if (postfix
=== ' ') {
1801 handler
.setCursorStyle(params
);
1804 csiStateHandler
['r'] = function (handler
, params
) { return handler
.setScrollRegion(params
); };
1805 csiStateHandler
['s'] = function (handler
, params
) { return handler
.saveCursor(params
); };
1806 csiStateHandler
['u'] = function (handler
, params
) { return handler
.restoreCursor(params
); };
1807 csiStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (handler
, params
, prefix
, postfix
, parser
) { return parser
.setState(ParserState
.NORMAL
); };
1809 (function (ParserState
) {
1810 ParserState
[ParserState
["NORMAL"] = 0] = "NORMAL";
1811 ParserState
[ParserState
["ESCAPED"] = 1] = "ESCAPED";
1812 ParserState
[ParserState
["CSI_PARAM"] = 2] = "CSI_PARAM";
1813 ParserState
[ParserState
["CSI"] = 3] = "CSI";
1814 ParserState
[ParserState
["OSC"] = 4] = "OSC";
1815 ParserState
[ParserState
["CHARSET"] = 5] = "CHARSET";
1816 ParserState
[ParserState
["DCS"] = 6] = "DCS";
1817 ParserState
[ParserState
["IGNORE"] = 7] = "IGNORE";
1818 })(ParserState
|| (ParserState
= {}));
1819 var Parser
= (function () {
1820 function Parser(_inputHandler
, _terminal
) {
1821 this._inputHandler
= _inputHandler
;
1822 this._terminal
= _terminal
;
1823 this._state
= ParserState
.NORMAL
;
1825 Parser
.prototype.parse = function (data
) {
1826 var l
= data
.length
, j
, cs
, ch
, code
, low
;
1827 if (this._terminal
.debug
) {
1828 this._terminal
.log('data: ' + data
);
1831 if (this._terminal
.surrogate_high
) {
1832 data
= this._terminal
.surrogate_high
+ data
;
1833 this._terminal
.surrogate_high
= '';
1835 for (; this._position
< l
; this._position
++) {
1836 ch
= data
[this._position
];
1837 code
= data
.charCodeAt(this._position
);
1838 if (0xD800 <= code
&& code
<= 0xDBFF) {
1839 low
= data
.charCodeAt(this._position
+ 1);
1841 this._terminal
.surrogate_high
= ch
;
1844 code
= ((code
- 0xD800) * 0x400) + (low
- 0xDC00) + 0x10000;
1845 ch
+= data
.charAt(this._position
+ 1);
1847 if (0xDC00 <= code
&& code
<= 0xDFFF)
1849 switch (this._state
) {
1850 case ParserState
.NORMAL
:
1851 if (ch
in normalStateHandler
) {
1852 normalStateHandler
[ch
](this, this._inputHandler
);
1855 this._inputHandler
.addChar(ch
, code
);
1858 case ParserState
.ESCAPED
:
1859 if (ch
in escapedStateHandler
) {
1860 escapedStateHandler
[ch
](this, this._terminal
);
1872 this._terminal
.gcharset
= 0;
1875 this._terminal
.gcharset
= 1;
1878 this._terminal
.gcharset
= 2;
1881 this._terminal
.gcharset
= 3;
1884 this._terminal
.gcharset
= 1;
1887 this._terminal
.gcharset
= 2;
1890 this._state
= ParserState
.CHARSET
;
1893 this._terminal
.gcharset
= 3;
1894 this._state
= ParserState
.CHARSET
;
1902 this._terminal
.setgLevel(2);
1905 this._terminal
.setgLevel(3);
1908 this._terminal
.setgLevel(3);
1911 this._terminal
.setgLevel(2);
1914 this._terminal
.setgLevel(1);
1917 this._inputHandler
.saveCursor();
1918 this._state
= ParserState
.NORMAL
;
1921 this._inputHandler
.restoreCursor();
1922 this._state
= ParserState
.NORMAL
;
1925 this._state
= ParserState
.NORMAL
;
1929 this._terminal
.tabSet();
1930 this._state
= ParserState
.NORMAL
;
1933 this._terminal
.log('Serial port requested application keypad.');
1934 this._terminal
.applicationKeypad
= true;
1935 this._terminal
.viewport
.syncScrollArea();
1936 this._state
= ParserState
.NORMAL
;
1939 this._terminal
.log('Switching back to normal keypad.');
1940 this._terminal
.applicationKeypad
= false;
1941 this._terminal
.viewport
.syncScrollArea();
1942 this._state
= ParserState
.NORMAL
;
1945 this._state
= ParserState
.NORMAL
;
1946 this._terminal
.error('Unknown ESC control: %s.', ch
);
1950 case ParserState
.CHARSET
:
1951 if (ch
in Charsets_1
.CHARSETS
) {
1952 cs
= Charsets_1
.CHARSETS
[ch
];
1954 this.skipNextChar();
1958 cs
= Charsets_1
.DEFAULT_CHARSET
;
1960 this._terminal
.setgCharset(this._terminal
.gcharset
, cs
);
1961 this._terminal
.gcharset
= null;
1962 this._state
= ParserState
.NORMAL
;
1964 case ParserState
.OSC
:
1965 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
1966 if (ch
=== EscapeSequences_1
.C0
.ESC
)
1968 this._terminal
.params
.push(this._terminal
.currentParam
);
1969 switch (this._terminal
.params
[0]) {
1973 if (this._terminal
.params
[1]) {
1974 this._terminal
.title
= this._terminal
.params
[1];
1975 this._terminal
.handleTitle(this._terminal
.title
);
2015 this._terminal
.params
= [];
2016 this._terminal
.currentParam
= 0;
2017 this._state
= ParserState
.NORMAL
;
2020 if (!this._terminal
.params
.length
) {
2021 if (ch
>= '0' && ch
<= '9') {
2022 this._terminal
.currentParam
=
2023 this._terminal
.currentParam
* 10 + ch
.charCodeAt(0) - 48;
2025 else if (ch
=== ';') {
2026 this._terminal
.params
.push(this._terminal
.currentParam
);
2027 this._terminal
.currentParam
= '';
2031 this._terminal
.currentParam
+= ch
;
2035 case ParserState
.CSI_PARAM
:
2036 if (ch
in csiParamStateHandler
) {
2037 csiParamStateHandler
[ch
](this);
2040 this.finalizeParam();
2041 this._state
= ParserState
.CSI
;
2042 case ParserState
.CSI
:
2043 if (ch
in csiStateHandler
) {
2044 if (this._terminal
.debug
) {
2045 this._terminal
.log("CSI " + (this._terminal
.prefix
? this._terminal
.prefix
: '') + " " + (this._terminal
.params
? this._terminal
.params
.join(';') : '') + " " + (this._terminal
.postfix
? this._terminal
.postfix
: '') + " " + ch
);
2047 csiStateHandler
[ch
](this._inputHandler
, this._terminal
.params
, this._terminal
.prefix
, this._terminal
.postfix
, this);
2050 this._terminal
.error('Unknown CSI code: %s.', ch
);
2052 this._state
= ParserState
.NORMAL
;
2053 this._terminal
.prefix
= '';
2054 this._terminal
.postfix
= '';
2056 case ParserState
.DCS
:
2057 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
2058 if (ch
=== EscapeSequences_1
.C0
.ESC
)
2062 switch (this._terminal
.prefix
) {
2066 pt
= this._terminal
.currentParam
;
2077 + (this._terminal
.buffer
.scrollTop
+ 1)
2079 + (this._terminal
.buffer
.scrollBottom
+ 1)
2086 this._terminal
.error('Unknown DCS Pt: %s.', pt
);
2090 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ 'P' + +valid
+ '$r' + pt
+ EscapeSequences_1
.C0
.ESC
+ '\\');
2095 pt
= this._terminal
.currentParam
;
2097 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ 'P' + +valid
+ '+r' + pt
+ EscapeSequences_1
.C0
.ESC
+ '\\');
2100 this._terminal
.error('Unknown DCS prefix: %s.', this._terminal
.prefix
);
2103 this._terminal
.currentParam
= 0;
2104 this._terminal
.prefix
= '';
2105 this._state
= ParserState
.NORMAL
;
2107 else if (!this._terminal
.currentParam
) {
2108 if (!this._terminal
.prefix
&& ch
!== '$' && ch
!== '+') {
2109 this._terminal
.currentParam
= ch
;
2111 else if (this._terminal
.prefix
.length
=== 2) {
2112 this._terminal
.currentParam
= ch
;
2115 this._terminal
.prefix
+= ch
;
2119 this._terminal
.currentParam
+= ch
;
2122 case ParserState
.IGNORE
:
2123 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
2124 if (ch
=== EscapeSequences_1
.C0
.ESC
)
2126 this._state
= ParserState
.NORMAL
;
2133 Parser
.prototype.setState = function (state
) {
2134 this._state
= state
;
2136 Parser
.prototype.setPrefix = function (prefix
) {
2137 this._terminal
.prefix
= prefix
;
2139 Parser
.prototype.setPostfix = function (postfix
) {
2140 this._terminal
.postfix
= postfix
;
2142 Parser
.prototype.setParam = function (param
) {
2143 this._terminal
.currentParam
= param
;
2145 Parser
.prototype.getParam = function () {
2146 return this._terminal
.currentParam
;
2148 Parser
.prototype.finalizeParam = function () {
2149 this._terminal
.params
.push(this._terminal
.currentParam
);
2150 this._terminal
.currentParam
= 0;
2152 Parser
.prototype.skipNextChar = function () {
2157 exports
.Parser
= Parser
;
2161 },{"./Charsets":3,"./EscapeSequences":5}],10:[function(require
,module
,exports
){
2163 Object
.defineProperty(exports
, "__esModule", { value
: true });
2164 var DomElementObjectPool_1
= require("./utils/DomElementObjectPool");
2165 var MAX_REFRESH_FRAME_SKIP
= 5;
2168 FLAGS
[FLAGS
["BOLD"] = 1] = "BOLD";
2169 FLAGS
[FLAGS
["UNDERLINE"] = 2] = "UNDERLINE";
2170 FLAGS
[FLAGS
["BLINK"] = 4] = "BLINK";
2171 FLAGS
[FLAGS
["INVERSE"] = 8] = "INVERSE";
2172 FLAGS
[FLAGS
["INVISIBLE"] = 16] = "INVISIBLE";
2173 })(FLAGS
|| (FLAGS
= {}));
2175 var brokenBold
= null;
2176 var Renderer
= (function () {
2177 function Renderer(_terminal
) {
2178 this._terminal
= _terminal
;
2179 this._refreshRowsQueue
= [];
2180 this._refreshFramesSkipped
= 0;
2181 this._refreshAnimationFrame
= null;
2182 this._spanElementObjectPool
= new DomElementObjectPool_1
.DomElementObjectPool('span');
2183 if (brokenBold
=== null) {
2184 brokenBold
= checkBoldBroken(this._terminal
.element
);
2186 this._spanElementObjectPool
= new DomElementObjectPool_1
.DomElementObjectPool('span');
2188 Renderer
.prototype.queueRefresh = function (start
, end
) {
2189 this._refreshRowsQueue
.push({ start
: start
, end
: end
});
2190 if (!this._refreshAnimationFrame
) {
2191 this._refreshAnimationFrame
= window
.requestAnimationFrame(this._refreshLoop
.bind(this));
2194 Renderer
.prototype._refreshLoop = function () {
2195 var skipFrame
= this._terminal
.writeBuffer
.length
> 0 && this._refreshFramesSkipped
++ <= MAX_REFRESH_FRAME_SKIP
;
2197 this._refreshAnimationFrame
= window
.requestAnimationFrame(this._refreshLoop
.bind(this));
2200 this._refreshFramesSkipped
= 0;
2203 if (this._refreshRowsQueue
.length
> 4) {
2205 end
= this._terminal
.rows
- 1;
2208 start
= this._refreshRowsQueue
[0].start
;
2209 end
= this._refreshRowsQueue
[0].end
;
2210 for (var i
= 1; i
< this._refreshRowsQueue
.length
; i
++) {
2211 if (this._refreshRowsQueue
[i
].start
< start
) {
2212 start
= this._refreshRowsQueue
[i
].start
;
2214 if (this._refreshRowsQueue
[i
].end
> end
) {
2215 end
= this._refreshRowsQueue
[i
].end
;
2219 this._refreshRowsQueue
= [];
2220 this._refreshAnimationFrame
= null;
2221 this._refresh(start
, end
);
2223 Renderer
.prototype._refresh = function (start
, end
) {
2225 if (end
- start
>= this._terminal
.rows
/ 2) {
2226 parent
= this._terminal
.element
.parentNode
;
2228 this._terminal
.element
.removeChild(this._terminal
.rowContainer
);
2231 var width
= this._terminal
.cols
;
2233 if (end
>= this._terminal
.rows
) {
2234 this._terminal
.log('`end` is too large. Most likely a bad CSR.');
2235 end
= this._terminal
.rows
- 1;
2237 for (; y
<= end
; y
++) {
2238 var row
= y
+ this._terminal
.buffer
.ydisp
;
2239 var line
= this._terminal
.buffer
.lines
.get(row
);
2241 if (this._terminal
.buffer
.y
=== y
- (this._terminal
.buffer
.ybase
- this._terminal
.buffer
.ydisp
) &&
2242 this._terminal
.cursorState
&&
2243 !this._terminal
.cursorHidden
) {
2244 x
= this._terminal
.buffer
.x
;
2249 var attr
= this._terminal
.defAttr
;
2250 var documentFragment
= document
.createDocumentFragment();
2252 var currentElement
= void 0;
2253 while (this._terminal
.children
[y
].children
.length
) {
2254 var child
= this._terminal
.children
[y
].children
[0];
2255 this._terminal
.children
[y
].removeChild(child
);
2256 this._spanElementObjectPool
.release(child
);
2258 for (var i
= 0; i
< width
; i
++) {
2259 var data
= line
[i
][0];
2260 var ch
= line
[i
][1];
2261 var ch_width
= line
[i
][2];
2262 var isCursor
= i
=== x
;
2266 if (data
!== attr
|| isCursor
) {
2267 if (attr
!== this._terminal
.defAttr
&& !isCursor
) {
2269 currentElement
.innerHTML
= innerHTML
;
2272 documentFragment
.appendChild(currentElement
);
2273 currentElement
= null;
2275 if (data
!== this._terminal
.defAttr
|| isCursor
) {
2276 if (innerHTML
&& !currentElement
) {
2277 currentElement
= this._spanElementObjectPool
.acquire();
2279 if (currentElement
) {
2281 currentElement
.innerHTML
= innerHTML
;
2284 documentFragment
.appendChild(currentElement
);
2286 currentElement
= this._spanElementObjectPool
.acquire();
2287 var bg
= data
& 0x1ff;
2288 var fg
= (data
>> 9) & 0x1ff;
2289 var flags
= data
>> 18;
2291 currentElement
.classList
.add('reverse-video');
2292 currentElement
.classList
.add('terminal-cursor');
2294 if (flags
& FLAGS
.BOLD
) {
2296 currentElement
.classList
.add('xterm-bold');
2302 if (flags
& FLAGS
.UNDERLINE
) {
2303 currentElement
.classList
.add('xterm-underline');
2305 if (flags
& FLAGS
.BLINK
) {
2306 currentElement
.classList
.add('xterm-blink');
2308 if (flags
& FLAGS
.INVERSE
) {
2312 if ((flags
& 1) && fg
< 8) {
2316 if (flags
& FLAGS
.INVISIBLE
&& !isCursor
) {
2317 currentElement
.classList
.add('xterm-hidden');
2319 if (flags
& FLAGS
.INVERSE
) {
2328 currentElement
.classList
.add("xterm-bg-color-" + bg
);
2331 currentElement
.classList
.add("xterm-color-" + fg
);
2335 if (ch_width
=== 2) {
2336 innerHTML
+= "<span class=\"xterm-wide-char\">" + ch
+ "</span>";
2338 else if (ch
.charCodeAt(0) > 255) {
2339 innerHTML
+= "<span class=\"xterm-normal-char\">" + ch
+ "</span>";
2344 innerHTML
+= '&';
2347 innerHTML
+= '<';
2350 innerHTML
+= '>';
2354 innerHTML
+= ' ';
2362 attr
= isCursor
? -1 : data
;
2364 if (innerHTML
&& !currentElement
) {
2365 currentElement
= this._spanElementObjectPool
.acquire();
2367 if (currentElement
) {
2369 currentElement
.innerHTML
= innerHTML
;
2372 documentFragment
.appendChild(currentElement
);
2373 currentElement
= null;
2375 this._terminal
.children
[y
].appendChild(documentFragment
);
2378 this._terminal
.element
.appendChild(this._terminal
.rowContainer
);
2380 this._terminal
.emit('refresh', { element
: this._terminal
.element
, start
: start
, end
: end
});
2383 Renderer
.prototype.refreshSelection = function (start
, end
) {
2384 while (this._terminal
.selectionContainer
.children
.length
) {
2385 this._terminal
.selectionContainer
.removeChild(this._terminal
.selectionContainer
.children
[0]);
2387 if (!start
|| !end
) {
2390 var viewportStartRow
= start
[1] - this._terminal
.buffer
.ydisp
;
2391 var viewportEndRow
= end
[1] - this._terminal
.buffer
.ydisp
;
2392 var viewportCappedStartRow
= Math
.max(viewportStartRow
, 0);
2393 var viewportCappedEndRow
= Math
.min(viewportEndRow
, this._terminal
.rows
- 1);
2394 if (viewportCappedStartRow
>= this._terminal
.rows
|| viewportCappedEndRow
< 0) {
2397 var documentFragment
= document
.createDocumentFragment();
2398 var startCol
= viewportStartRow
=== viewportCappedStartRow
? start
[0] : 0;
2399 var endCol
= viewportCappedStartRow
=== viewportCappedEndRow
? end
[0] : this._terminal
.cols
;
2400 documentFragment
.appendChild(this._createSelectionElement(viewportCappedStartRow
, startCol
, endCol
));
2401 var middleRowsCount
= viewportCappedEndRow
- viewportCappedStartRow
- 1;
2402 documentFragment
.appendChild(this._createSelectionElement(viewportCappedStartRow
+ 1, 0, this._terminal
.cols
, middleRowsCount
));
2403 if (viewportCappedStartRow
!== viewportCappedEndRow
) {
2404 var endCol_1
= viewportEndRow
=== viewportCappedEndRow
? end
[0] : this._terminal
.cols
;
2405 documentFragment
.appendChild(this._createSelectionElement(viewportCappedEndRow
, 0, endCol_1
));
2407 this._terminal
.selectionContainer
.appendChild(documentFragment
);
2409 Renderer
.prototype._createSelectionElement = function (row
, colStart
, colEnd
, rowCount
) {
2410 if (rowCount
=== void 0) { rowCount
= 1; }
2411 var element
= document
.createElement('div');
2412 element
.style
.height
= rowCount
* this._terminal
.charMeasure
.height
+ "px";
2413 element
.style
.top
= row
* this._terminal
.charMeasure
.height
+ "px";
2414 element
.style
.left
= colStart
* this._terminal
.charMeasure
.width
+ "px";
2415 element
.style
.width
= this._terminal
.charMeasure
.width
* (colEnd
- colStart
) + "px";
2420 exports
.Renderer
= Renderer
;
2421 function checkBoldBroken(terminal
) {
2422 var document
= terminal
.ownerDocument
;
2423 var el
= document
.createElement('span');
2424 el
.innerHTML
= 'hello world';
2425 terminal
.appendChild(el
);
2426 var w1
= el
.offsetWidth
;
2427 var h1
= el
.offsetHeight
;
2428 el
.style
.fontWeight
= 'bold';
2429 var w2
= el
.offsetWidth
;
2430 var h2
= el
.offsetHeight
;
2431 terminal
.removeChild(el
);
2432 return w1
!== w2
|| h1
!== h2
;
2437 },{"./utils/DomElementObjectPool":19}],11:[function(require
,module
,exports
){
2439 var __extends
= (this && this.__extends
) || (function () {
2440 var extendStatics
= Object
.setPrototypeOf
||
2441 ({ __proto__
: [] } instanceof Array
&& function (d
, b
) { d
.__proto__
= b
; }) ||
2442 function (d
, b
) { for (var p
in b
) if (b
.hasOwnProperty(p
)) d
[p
] = b
[p
]; };
2443 return function (d
, b
) {
2444 extendStatics(d
, b
);
2445 function __() { this.constructor = d
; }
2446 d
.prototype = b
=== null ? Object
.create(b
) : (__
.prototype = b
.prototype, new __());
2449 Object
.defineProperty(exports
, "__esModule", { value
: true });
2450 var Mouse
= require("./utils/Mouse");
2451 var Browser
= require("./utils/Browser");
2452 var EventEmitter_1
= require("./EventEmitter");
2453 var SelectionModel_1
= require("./SelectionModel");
2454 var BufferLine_1
= require("./utils/BufferLine");
2455 var DRAG_SCROLL_MAX_THRESHOLD
= 50;
2456 var DRAG_SCROLL_MAX_SPEED
= 15;
2457 var DRAG_SCROLL_INTERVAL
= 50;
2458 var WORD_SEPARATORS
= ' ()[]{}\'"';
2459 var LINE_DATA_CHAR_INDEX
= 1;
2460 var LINE_DATA_WIDTH_INDEX
= 2;
2461 var NON_BREAKING_SPACE_CHAR
= String
.fromCharCode(160);
2462 var ALL_NON_BREAKING_SPACE_REGEX
= new RegExp(NON_BREAKING_SPACE_CHAR
, 'g');
2464 (function (SelectionMode
) {
2465 SelectionMode
[SelectionMode
["NORMAL"] = 0] = "NORMAL";
2466 SelectionMode
[SelectionMode
["WORD"] = 1] = "WORD";
2467 SelectionMode
[SelectionMode
["LINE"] = 2] = "LINE";
2468 })(SelectionMode
|| (SelectionMode
= {}));
2469 var SelectionManager
= (function (_super
) {
2470 __extends(SelectionManager
, _super
);
2471 function SelectionManager(_terminal
, _buffer
, _rowContainer
, _charMeasure
) {
2472 var _this
= _super
.call(this) || this;
2473 _this
._terminal
= _terminal
;
2474 _this
._buffer
= _buffer
;
2475 _this
._rowContainer
= _rowContainer
;
2476 _this
._charMeasure
= _charMeasure
;
2477 _this
._enabled
= true;
2478 _this
._initListeners();
2480 _this
._model
= new SelectionModel_1
.SelectionModel(_terminal
);
2481 _this
._activeSelectionMode
= SelectionMode
.NORMAL
;
2484 SelectionManager
.prototype._initListeners = function () {
2486 this._mouseMoveListener = function (event
) { return _this
._onMouseMove(event
); };
2487 this._mouseUpListener = function (event
) { return _this
._onMouseUp(event
); };
2488 this._rowContainer
.addEventListener('mousedown', function (event
) { return _this
._onMouseDown(event
); });
2489 this._buffer
.on('trim', function (amount
) { return _this
._onTrim(amount
); });
2491 SelectionManager
.prototype.disable = function () {
2492 this.clearSelection();
2493 this._enabled
= false;
2495 SelectionManager
.prototype.enable = function () {
2496 this._enabled
= true;
2498 SelectionManager
.prototype.setBuffer = function (buffer
) {
2499 this._buffer
= buffer
;
2500 this.clearSelection();
2502 Object
.defineProperty(SelectionManager
.prototype, "selectionStart", {
2503 get: function () { return this._model
.finalSelectionStart
; },
2507 Object
.defineProperty(SelectionManager
.prototype, "selectionEnd", {
2508 get: function () { return this._model
.finalSelectionEnd
; },
2512 Object
.defineProperty(SelectionManager
.prototype, "hasSelection", {
2514 var start
= this._model
.finalSelectionStart
;
2515 var end
= this._model
.finalSelectionEnd
;
2516 if (!start
|| !end
) {
2519 return start
[0] !== end
[0] || start
[1] !== end
[1];
2524 Object
.defineProperty(SelectionManager
.prototype, "selectionText", {
2526 var start
= this._model
.finalSelectionStart
;
2527 var end
= this._model
.finalSelectionEnd
;
2528 if (!start
|| !end
) {
2531 var startRowEndCol
= start
[1] === end
[1] ? end
[0] : null;
2533 result
.push(BufferLine_1
.translateBufferLineToString(this._buffer
.get(start
[1]), true, start
[0], startRowEndCol
));
2534 for (var i
= start
[1] + 1; i
<= end
[1] - 1; i
++) {
2535 var bufferLine
= this._buffer
.get(i
);
2536 var lineText
= BufferLine_1
.translateBufferLineToString(bufferLine
, true);
2537 if (bufferLine
.isWrapped
) {
2538 result
[result
.length
- 1] += lineText
;
2541 result
.push(lineText
);
2544 if (start
[1] !== end
[1]) {
2545 var bufferLine
= this._buffer
.get(end
[1]);
2546 var lineText
= BufferLine_1
.translateBufferLineToString(bufferLine
, true, 0, end
[0]);
2547 if (bufferLine
.isWrapped
) {
2548 result
[result
.length
- 1] += lineText
;
2551 result
.push(lineText
);
2554 var formattedResult
= result
.map(function (line
) {
2555 return line
.replace(ALL_NON_BREAKING_SPACE_REGEX
, ' ');
2556 }).join(Browser
.isMSWindows
? '\r\n' : '\n');
2557 return formattedResult
;
2562 SelectionManager
.prototype.clearSelection = function () {
2563 this._model
.clearSelection();
2564 this._removeMouseDownListeners();
2567 SelectionManager
.prototype.refresh = function (isNewSelection
) {
2569 if (!this._refreshAnimationFrame
) {
2570 this._refreshAnimationFrame
= window
.requestAnimationFrame(function () { return _this
._refresh(); });
2572 if (Browser
.isLinux
&& isNewSelection
) {
2573 var selectionText
= this.selectionText
;
2574 if (selectionText
.length
) {
2575 this.emit('newselection', this.selectionText
);
2579 SelectionManager
.prototype._refresh = function () {
2580 this._refreshAnimationFrame
= null;
2581 this.emit('refresh', { start
: this._model
.finalSelectionStart
, end
: this._model
.finalSelectionEnd
});
2583 SelectionManager
.prototype.selectAll = function () {
2584 this._model
.isSelectAllActive
= true;
2587 SelectionManager
.prototype._onTrim = function (amount
) {
2588 var needsRefresh
= this._model
.onTrim(amount
);
2593 SelectionManager
.prototype._getMouseBufferCoords = function (event
) {
2594 var coords
= Mouse
.getCoords(event
, this._rowContainer
, this._charMeasure
, this._terminal
.cols
, this._terminal
.rows
, true);
2600 coords
[1] += this._terminal
.buffer
.ydisp
;
2603 SelectionManager
.prototype._getMouseEventScrollAmount = function (event
) {
2604 var offset
= Mouse
.getCoordsRelativeToElement(event
, this._rowContainer
)[1];
2605 var terminalHeight
= this._terminal
.rows
* this._charMeasure
.height
;
2606 if (offset
>= 0 && offset
<= terminalHeight
) {
2609 if (offset
> terminalHeight
) {
2610 offset
-= terminalHeight
;
2612 offset
= Math
.min(Math
.max(offset
, -DRAG_SCROLL_MAX_THRESHOLD
), DRAG_SCROLL_MAX_THRESHOLD
);
2613 offset
/= DRAG_SCROLL_MAX_THRESHOLD
;
2614 return (offset
/ Math
.abs(offset
)) + Math
.round(offset
* (DRAG_SCROLL_MAX_SPEED
- 1));
2616 SelectionManager
.prototype._onMouseDown = function (event
) {
2617 if (event
.button
=== 2 && this.hasSelection
) {
2618 event
.stopPropagation();
2621 if (event
.button
!== 0) {
2624 if (!this._enabled
) {
2625 var shouldForceSelection
= Browser
.isMac
&& event
.altKey
;
2626 if (!shouldForceSelection
) {
2629 event
.stopPropagation();
2631 event
.preventDefault();
2632 this._dragScrollAmount
= 0;
2633 if (this._enabled
&& event
.shiftKey
) {
2634 this._onIncrementalClick(event
);
2637 if (event
.detail
=== 1) {
2638 this._onSingleClick(event
);
2640 else if (event
.detail
=== 2) {
2641 this._onDoubleClick(event
);
2643 else if (event
.detail
=== 3) {
2644 this._onTripleClick(event
);
2647 this._addMouseDownListeners();
2650 SelectionManager
.prototype._addMouseDownListeners = function () {
2652 this._rowContainer
.ownerDocument
.addEventListener('mousemove', this._mouseMoveListener
);
2653 this._rowContainer
.ownerDocument
.addEventListener('mouseup', this._mouseUpListener
);
2654 this._dragScrollIntervalTimer
= setInterval(function () { return _this
._dragScroll(); }, DRAG_SCROLL_INTERVAL
);
2656 SelectionManager
.prototype._removeMouseDownListeners = function () {
2657 this._rowContainer
.ownerDocument
.removeEventListener('mousemove', this._mouseMoveListener
);
2658 this._rowContainer
.ownerDocument
.removeEventListener('mouseup', this._mouseUpListener
);
2659 clearInterval(this._dragScrollIntervalTimer
);
2660 this._dragScrollIntervalTimer
= null;
2662 SelectionManager
.prototype._onIncrementalClick = function (event
) {
2663 if (this._model
.selectionStart
) {
2664 this._model
.selectionEnd
= this._getMouseBufferCoords(event
);
2667 SelectionManager
.prototype._onSingleClick = function (event
) {
2668 this._model
.selectionStartLength
= 0;
2669 this._model
.isSelectAllActive
= false;
2670 this._activeSelectionMode
= SelectionMode
.NORMAL
;
2671 this._model
.selectionStart
= this._getMouseBufferCoords(event
);
2672 if (!this._model
.selectionStart
) {
2675 this._model
.selectionEnd
= null;
2676 var line
= this._buffer
.get(this._model
.selectionStart
[1]);
2680 var char = line
[this._model
.selectionStart
[0]];
2681 if (char[LINE_DATA_WIDTH_INDEX
] === 0) {
2682 this._model
.selectionStart
[0]++;
2685 SelectionManager
.prototype._onDoubleClick = function (event
) {
2686 var coords
= this._getMouseBufferCoords(event
);
2688 this._activeSelectionMode
= SelectionMode
.WORD
;
2689 this._selectWordAt(coords
);
2692 SelectionManager
.prototype._onTripleClick = function (event
) {
2693 var coords
= this._getMouseBufferCoords(event
);
2695 this._activeSelectionMode
= SelectionMode
.LINE
;
2696 this._selectLineAt(coords
[1]);
2699 SelectionManager
.prototype._onMouseMove = function (event
) {
2700 var previousSelectionEnd
= this._model
.selectionEnd
? [this._model
.selectionEnd
[0], this._model
.selectionEnd
[1]] : null;
2701 this._model
.selectionEnd
= this._getMouseBufferCoords(event
);
2702 if (!this._model
.selectionEnd
) {
2706 if (this._activeSelectionMode
=== SelectionMode
.LINE
) {
2707 if (this._model
.selectionEnd
[1] < this._model
.selectionStart
[1]) {
2708 this._model
.selectionEnd
[0] = 0;
2711 this._model
.selectionEnd
[0] = this._terminal
.cols
;
2714 else if (this._activeSelectionMode
=== SelectionMode
.WORD
) {
2715 this._selectToWordAt(this._model
.selectionEnd
);
2717 this._dragScrollAmount
= this._getMouseEventScrollAmount(event
);
2718 if (this._dragScrollAmount
> 0) {
2719 this._model
.selectionEnd
[0] = this._terminal
.cols
- 1;
2721 else if (this._dragScrollAmount
< 0) {
2722 this._model
.selectionEnd
[0] = 0;
2724 if (this._model
.selectionEnd
[1] < this._buffer
.length
) {
2725 var char = this._buffer
.get(this._model
.selectionEnd
[1])[this._model
.selectionEnd
[0]];
2726 if (char && char[2] === 0) {
2727 this._model
.selectionEnd
[0]++;
2730 if (!previousSelectionEnd
||
2731 previousSelectionEnd
[0] !== this._model
.selectionEnd
[0] ||
2732 previousSelectionEnd
[1] !== this._model
.selectionEnd
[1]) {
2736 SelectionManager
.prototype._dragScroll = function () {
2737 if (this._dragScrollAmount
) {
2738 this._terminal
.scrollDisp(this._dragScrollAmount
, false);
2739 if (this._dragScrollAmount
> 0) {
2740 this._model
.selectionEnd
= [this._terminal
.cols
- 1, this._terminal
.buffer
.ydisp
+ this._terminal
.rows
];
2743 this._model
.selectionEnd
= [0, this._terminal
.buffer
.ydisp
];
2748 SelectionManager
.prototype._onMouseUp = function (event
) {
2749 this._removeMouseDownListeners();
2751 SelectionManager
.prototype._convertViewportColToCharacterIndex = function (bufferLine
, coords
) {
2752 var charIndex
= coords
[0];
2753 for (var i
= 0; coords
[0] >= i
; i
++) {
2754 var char = bufferLine
[i
];
2755 if (char[LINE_DATA_WIDTH_INDEX
] === 0) {
2761 SelectionManager
.prototype.setSelection = function (col
, row
, length
) {
2762 this._model
.clearSelection();
2763 this._removeMouseDownListeners();
2764 this._model
.selectionStart
= [col
, row
];
2765 this._model
.selectionStartLength
= length
;
2768 SelectionManager
.prototype._getWordAt = function (coords
) {
2769 var bufferLine
= this._buffer
.get(coords
[1]);
2773 var line
= BufferLine_1
.translateBufferLineToString(bufferLine
, false);
2774 var endIndex
= this._convertViewportColToCharacterIndex(bufferLine
, coords
);
2775 var startIndex
= endIndex
;
2776 var charOffset
= coords
[0] - startIndex
;
2777 var leftWideCharCount
= 0;
2778 var rightWideCharCount
= 0;
2779 if (line
.charAt(startIndex
) === ' ') {
2780 while (startIndex
> 0 && line
.charAt(startIndex
- 1) === ' ') {
2783 while (endIndex
< line
.length
&& line
.charAt(endIndex
+ 1) === ' ') {
2788 var startCol
= coords
[0];
2789 var endCol
= coords
[0];
2790 if (bufferLine
[startCol
][LINE_DATA_WIDTH_INDEX
] === 0) {
2791 leftWideCharCount
++;
2794 if (bufferLine
[endCol
][LINE_DATA_WIDTH_INDEX
] === 2) {
2795 rightWideCharCount
++;
2798 while (startIndex
> 0 && !this._isCharWordSeparator(line
.charAt(startIndex
- 1))) {
2799 if (bufferLine
[startCol
- 1][LINE_DATA_WIDTH_INDEX
] === 0) {
2800 leftWideCharCount
++;
2806 while (endIndex
+ 1 < line
.length
&& !this._isCharWordSeparator(line
.charAt(endIndex
+ 1))) {
2807 if (bufferLine
[endCol
+ 1][LINE_DATA_WIDTH_INDEX
] === 2) {
2808 rightWideCharCount
++;
2815 var start
= startIndex
+ charOffset
- leftWideCharCount
;
2816 var length
= Math
.min(endIndex
- startIndex
+ leftWideCharCount
+ rightWideCharCount
+ 1, this._terminal
.cols
);
2817 return { start
: start
, length
: length
};
2819 SelectionManager
.prototype._selectWordAt = function (coords
) {
2820 var wordPosition
= this._getWordAt(coords
);
2822 this._model
.selectionStart
= [wordPosition
.start
, coords
[1]];
2823 this._model
.selectionStartLength
= wordPosition
.length
;
2826 SelectionManager
.prototype._selectToWordAt = function (coords
) {
2827 var wordPosition
= this._getWordAt(coords
);
2829 this._model
.selectionEnd
= [this._model
.areSelectionValuesReversed() ? wordPosition
.start
: (wordPosition
.start
+ wordPosition
.length
), coords
[1]];
2832 SelectionManager
.prototype._isCharWordSeparator = function (char) {
2833 return WORD_SEPARATORS
.indexOf(char) >= 0;
2835 SelectionManager
.prototype._selectLineAt = function (line
) {
2836 this._model
.selectionStart
= [0, line
];
2837 this._model
.selectionStartLength
= this._terminal
.cols
;
2839 return SelectionManager
;
2840 }(EventEmitter_1
.EventEmitter
));
2841 exports
.SelectionManager
= SelectionManager
;
2845 },{"./EventEmitter":6,"./SelectionModel":12,"./utils/Browser":15,"./utils/BufferLine":16,"./utils/Mouse":21}],12:[function(require
,module
,exports
){
2847 Object
.defineProperty(exports
, "__esModule", { value
: true });
2848 var SelectionModel
= (function () {
2849 function SelectionModel(_terminal
) {
2850 this._terminal
= _terminal
;
2851 this.clearSelection();
2853 SelectionModel
.prototype.clearSelection = function () {
2854 this.selectionStart
= null;
2855 this.selectionEnd
= null;
2856 this.isSelectAllActive
= false;
2857 this.selectionStartLength
= 0;
2859 Object
.defineProperty(SelectionModel
.prototype, "finalSelectionStart", {
2861 if (this.isSelectAllActive
) {
2864 if (!this.selectionEnd
|| !this.selectionStart
) {
2865 return this.selectionStart
;
2867 return this.areSelectionValuesReversed() ? this.selectionEnd
: this.selectionStart
;
2872 Object
.defineProperty(SelectionModel
.prototype, "finalSelectionEnd", {
2874 if (this.isSelectAllActive
) {
2875 return [this._terminal
.cols
, this._terminal
.buffer
.ybase
+ this._terminal
.rows
- 1];
2877 if (!this.selectionStart
) {
2880 if (!this.selectionEnd
|| this.areSelectionValuesReversed()) {
2881 return [this.selectionStart
[0] + this.selectionStartLength
, this.selectionStart
[1]];
2883 if (this.selectionStartLength
) {
2884 if (this.selectionEnd
[1] === this.selectionStart
[1]) {
2885 return [Math
.max(this.selectionStart
[0] + this.selectionStartLength
, this.selectionEnd
[0]), this.selectionEnd
[1]];
2888 return this.selectionEnd
;
2893 SelectionModel
.prototype.areSelectionValuesReversed = function () {
2894 var start
= this.selectionStart
;
2895 var end
= this.selectionEnd
;
2896 return start
[1] > end
[1] || (start
[1] === end
[1] && start
[0] > end
[0]);
2898 SelectionModel
.prototype.onTrim = function (amount
) {
2899 if (this.selectionStart
) {
2900 this.selectionStart
[1] -= amount
;
2902 if (this.selectionEnd
) {
2903 this.selectionEnd
[1] -= amount
;
2905 if (this.selectionEnd
&& this.selectionEnd
[1] < 0) {
2906 this.clearSelection();
2909 if (this.selectionStart
&& this.selectionStart
[1] < 0) {
2910 this.selectionStart
[1] = 0;
2914 return SelectionModel
;
2916 exports
.SelectionModel
= SelectionModel
;
2920 },{}],13:[function(require
,module
,exports
){
2922 Object
.defineProperty(exports
, "__esModule", { value
: true });
2923 var Viewport
= (function () {
2924 function Viewport(terminal
, viewportElement
, scrollArea
, charMeasure
) {
2926 this.terminal
= terminal
;
2927 this.viewportElement
= viewportElement
;
2928 this.scrollArea
= scrollArea
;
2929 this.charMeasure
= charMeasure
;
2930 this.currentRowHeight
= 0;
2931 this.lastRecordedBufferLength
= 0;
2932 this.lastRecordedViewportHeight
= 0;
2933 this.terminal
.on('scroll', this.syncScrollArea
.bind(this));
2934 this.terminal
.on('resize', this.syncScrollArea
.bind(this));
2935 this.viewportElement
.addEventListener('scroll', this.onScroll
.bind(this));
2936 setTimeout(function () { return _this
.syncScrollArea(); }, 0);
2938 Viewport
.prototype.refresh = function () {
2939 if (this.charMeasure
.height
> 0) {
2940 var rowHeightChanged
= this.charMeasure
.height
!== this.currentRowHeight
;
2941 if (rowHeightChanged
) {
2942 this.currentRowHeight
= this.charMeasure
.height
;
2943 this.viewportElement
.style
.lineHeight
= this.charMeasure
.height
+ 'px';
2944 this.terminal
.rowContainer
.style
.lineHeight
= this.charMeasure
.height
+ 'px';
2946 var viewportHeightChanged
= this.lastRecordedViewportHeight
!== this.terminal
.rows
;
2947 if (rowHeightChanged
|| viewportHeightChanged
) {
2948 this.lastRecordedViewportHeight
= this.terminal
.rows
;
2949 this.viewportElement
.style
.height
= this.charMeasure
.height
* this.terminal
.rows
+ 'px';
2950 this.terminal
.selectionContainer
.style
.height
= this.viewportElement
.style
.height
;
2952 this.scrollArea
.style
.height
= (this.charMeasure
.height
* this.lastRecordedBufferLength
) + 'px';
2955 Viewport
.prototype.syncScrollArea = function () {
2956 if (this.lastRecordedBufferLength
!== this.terminal
.buffer
.lines
.length
) {
2957 this.lastRecordedBufferLength
= this.terminal
.buffer
.lines
.length
;
2960 else if (this.lastRecordedViewportHeight
!== this.terminal
.rows
) {
2964 if (this.charMeasure
.height
!== this.currentRowHeight
) {
2968 var scrollTop
= this.terminal
.buffer
.ydisp
* this.currentRowHeight
;
2969 if (this.viewportElement
.scrollTop
!== scrollTop
) {
2970 this.viewportElement
.scrollTop
= scrollTop
;
2973 Viewport
.prototype.onScroll = function (ev
) {
2974 var newRow
= Math
.round(this.viewportElement
.scrollTop
/ this.currentRowHeight
);
2975 var diff
= newRow
- this.terminal
.buffer
.ydisp
;
2976 this.terminal
.scrollDisp(diff
, true);
2978 Viewport
.prototype.onWheel = function (ev
) {
2979 if (ev
.deltaY
=== 0) {
2983 if (ev
.deltaMode
=== WheelEvent
.DOM_DELTA_LINE
) {
2984 multiplier
= this.currentRowHeight
;
2986 else if (ev
.deltaMode
=== WheelEvent
.DOM_DELTA_PAGE
) {
2987 multiplier
= this.currentRowHeight
* this.terminal
.rows
;
2989 this.viewportElement
.scrollTop
+= ev
.deltaY
* multiplier
;
2990 ev
.preventDefault();
2993 Viewport
.prototype.onTouchStart = function (ev
) {
2994 this.lastTouchY
= ev
.touches
[0].pageY
;
2997 Viewport
.prototype.onTouchMove = function (ev
) {
2998 var deltaY
= this.lastTouchY
- ev
.touches
[0].pageY
;
2999 this.lastTouchY
= ev
.touches
[0].pageY
;
3003 this.viewportElement
.scrollTop
+= deltaY
;
3004 ev
.preventDefault();
3009 exports
.Viewport
= Viewport
;
3013 },{}],14:[function(require
,module
,exports
){
3015 Object
.defineProperty(exports
, "__esModule", { value
: true });
3016 function prepareTextForTerminal(text
, isMSWindows
) {
3018 return text
.replace(/\r?\n/g, '\r');
3022 exports
.prepareTextForTerminal
= prepareTextForTerminal
;
3023 function copyHandler(ev
, term
, selectionManager
) {
3024 if (term
.browser
.isMSIE
) {
3025 window
.clipboardData
.setData('Text', selectionManager
.selectionText
);
3028 ev
.clipboardData
.setData('text/plain', selectionManager
.selectionText
);
3030 ev
.preventDefault();
3032 exports
.copyHandler
= copyHandler
;
3033 function pasteHandler(ev
, term
) {
3034 ev
.stopPropagation();
3036 var dispatchPaste = function (text
) {
3037 text
= prepareTextForTerminal(text
, term
.browser
.isMSWindows
);
3039 term
.textarea
.value
= '';
3040 term
.emit('paste', text
);
3041 return term
.cancel(ev
);
3043 if (term
.browser
.isMSIE
) {
3044 if (window
.clipboardData
) {
3045 text
= window
.clipboardData
.getData('Text');
3046 dispatchPaste(text
);
3050 if (ev
.clipboardData
) {
3051 text
= ev
.clipboardData
.getData('text/plain');
3052 dispatchPaste(text
);
3056 exports
.pasteHandler
= pasteHandler
;
3057 function moveTextAreaUnderMouseCursor(ev
, textarea
) {
3058 textarea
.style
.position
= 'fixed';
3059 textarea
.style
.width
= '20px';
3060 textarea
.style
.height
= '20px';
3061 textarea
.style
.left
= (ev
.clientX
- 10) + 'px';
3062 textarea
.style
.top
= (ev
.clientY
- 10) + 'px';
3063 textarea
.style
.zIndex
= '1000';
3065 setTimeout(function () {
3066 textarea
.style
.position
= null;
3067 textarea
.style
.width
= null;
3068 textarea
.style
.height
= null;
3069 textarea
.style
.left
= null;
3070 textarea
.style
.top
= null;
3071 textarea
.style
.zIndex
= null;
3074 exports
.moveTextAreaUnderMouseCursor
= moveTextAreaUnderMouseCursor
;
3075 function rightClickHandler(ev
, textarea
, selectionManager
) {
3076 moveTextAreaUnderMouseCursor(ev
, textarea
);
3077 textarea
.value
= selectionManager
.selectionText
;
3080 exports
.rightClickHandler
= rightClickHandler
;
3084 },{}],15:[function(require
,module
,exports
){
3086 Object
.defineProperty(exports
, "__esModule", { value
: true });
3087 var Generic_1
= require("./Generic");
3088 var isNode
= (typeof navigator
=== 'undefined') ? true : false;
3089 var userAgent
= (isNode
) ? 'node' : navigator
.userAgent
;
3090 var platform
= (isNode
) ? 'node' : navigator
.platform
;
3091 exports
.isFirefox
= !!~userAgent
.indexOf('Firefox');
3092 exports
.isMSIE
= !!~userAgent
.indexOf('MSIE') || !!~userAgent
.indexOf('Trident');
3093 exports
.isMac
= Generic_1
.contains(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], platform
);
3094 exports
.isIpad
= platform
=== 'iPad';
3095 exports
.isIphone
= platform
=== 'iPhone';
3096 exports
.isMSWindows
= Generic_1
.contains(['Windows', 'Win16', 'Win32', 'WinCE'], platform
);
3097 exports
.isLinux
= platform
.indexOf('Linux') >= 0;
3101 },{"./Generic":20}],16:[function(require
,module
,exports
){
3103 Object
.defineProperty(exports
, "__esModule", { value
: true });
3104 var LINE_DATA_CHAR_INDEX
= 1;
3105 var LINE_DATA_WIDTH_INDEX
= 2;
3106 function translateBufferLineToString(line
, trimRight
, startCol
, endCol
) {
3107 if (startCol
=== void 0) { startCol
= 0; }
3108 if (endCol
=== void 0) { endCol
= null; }
3109 var lineString
= '';
3110 var widthAdjustedStartCol
= startCol
;
3111 var widthAdjustedEndCol
= endCol
;
3112 for (var i
= 0; i
< line
.length
; i
++) {
3114 lineString
+= char[LINE_DATA_CHAR_INDEX
];
3115 if (char[LINE_DATA_WIDTH_INDEX
] === 0) {
3116 if (startCol
>= i
) {
3117 widthAdjustedStartCol
--;
3120 widthAdjustedEndCol
--;
3124 var finalEndCol
= widthAdjustedEndCol
|| line
.length
;
3126 var rightWhitespaceIndex
= lineString
.search(/\s+$/);
3127 if (rightWhitespaceIndex
!== -1) {
3128 finalEndCol
= Math
.min(finalEndCol
, rightWhitespaceIndex
);
3130 if (finalEndCol
<= widthAdjustedStartCol
) {
3134 return lineString
.substring(widthAdjustedStartCol
, finalEndCol
);
3136 exports
.translateBufferLineToString
= translateBufferLineToString
;
3140 },{}],17:[function(require
,module
,exports
){
3142 var __extends
= (this && this.__extends
) || (function () {
3143 var extendStatics
= Object
.setPrototypeOf
||
3144 ({ __proto__
: [] } instanceof Array
&& function (d
, b
) { d
.__proto__
= b
; }) ||
3145 function (d
, b
) { for (var p
in b
) if (b
.hasOwnProperty(p
)) d
[p
] = b
[p
]; };
3146 return function (d
, b
) {
3147 extendStatics(d
, b
);
3148 function __() { this.constructor = d
; }
3149 d
.prototype = b
=== null ? Object
.create(b
) : (__
.prototype = b
.prototype, new __());
3152 Object
.defineProperty(exports
, "__esModule", { value
: true });
3153 var EventEmitter_js_1
= require("../EventEmitter.js");
3154 var CharMeasure
= (function (_super
) {
3155 __extends(CharMeasure
, _super
);
3156 function CharMeasure(document
, parentElement
) {
3157 var _this
= _super
.call(this) || this;
3158 _this
._document
= document
;
3159 _this
._parentElement
= parentElement
;
3162 Object
.defineProperty(CharMeasure
.prototype, "width", {
3169 Object
.defineProperty(CharMeasure
.prototype, "height", {
3171 return this._height
;
3176 CharMeasure
.prototype.measure = function () {
3178 if (!this._measureElement
) {
3179 this._measureElement
= this._document
.createElement('span');
3180 this._measureElement
.style
.position
= 'absolute';
3181 this._measureElement
.style
.top
= '0';
3182 this._measureElement
.style
.left
= '-9999em';
3183 this._measureElement
.textContent
= 'W';
3184 this._measureElement
.setAttribute('aria-hidden', 'true');
3185 this._parentElement
.appendChild(this._measureElement
);
3186 setTimeout(function () { return _this
._doMeasure(); }, 0);
3192 CharMeasure
.prototype._doMeasure = function () {
3193 var geometry
= this._measureElement
.getBoundingClientRect();
3194 if (geometry
.width
=== 0 || geometry
.height
=== 0) {
3197 if (this._width
!== geometry
.width
|| this._height
!== geometry
.height
) {
3198 this._width
= geometry
.width
;
3199 this._height
= geometry
.height
;
3200 this.emit('charsizechanged');
3204 }(EventEmitter_js_1
.EventEmitter
));
3205 exports
.CharMeasure
= CharMeasure
;
3209 },{"../EventEmitter.js":6}],18:[function(require
,module
,exports
){
3211 var __extends
= (this && this.__extends
) || (function () {
3212 var extendStatics
= Object
.setPrototypeOf
||
3213 ({ __proto__
: [] } instanceof Array
&& function (d
, b
) { d
.__proto__
= b
; }) ||
3214 function (d
, b
) { for (var p
in b
) if (b
.hasOwnProperty(p
)) d
[p
] = b
[p
]; };
3215 return function (d
, b
) {
3216 extendStatics(d
, b
);
3217 function __() { this.constructor = d
; }
3218 d
.prototype = b
=== null ? Object
.create(b
) : (__
.prototype = b
.prototype, new __());
3221 Object
.defineProperty(exports
, "__esModule", { value
: true });
3222 var EventEmitter_1
= require("../EventEmitter");
3223 var CircularList
= (function (_super
) {
3224 __extends(CircularList
, _super
);
3225 function CircularList(maxLength
) {
3226 var _this
= _super
.call(this) || this;
3227 _this
._array
= new Array(maxLength
);
3228 _this
._startIndex
= 0;
3232 Object
.defineProperty(CircularList
.prototype, "maxLength", {
3234 return this._array
.length
;
3236 set: function (newMaxLength
) {
3237 var newArray
= new Array(newMaxLength
);
3238 for (var i
= 0; i
< Math
.min(newMaxLength
, this.length
); i
++) {
3239 newArray
[i
] = this._array
[this._getCyclicIndex(i
)];
3241 this._array
= newArray
;
3242 this._startIndex
= 0;
3247 Object
.defineProperty(CircularList
.prototype, "length", {
3249 return this._length
;
3251 set: function (newLength
) {
3252 if (newLength
> this._length
) {
3253 for (var i
= this._length
; i
< newLength
; i
++) {
3254 this._array
[i
] = undefined;
3257 this._length
= newLength
;
3262 Object
.defineProperty(CircularList
.prototype, "forEach", {
3265 return function (callbackfn
) {
3267 var length
= _this
.length
;
3268 for (var i_1
= 0; i_1
< length
; i_1
++) {
3269 callbackfn(_this
.get(i_1
), i_1
);
3276 CircularList
.prototype.get = function (index
) {
3277 return this._array
[this._getCyclicIndex(index
)];
3279 CircularList
.prototype.set = function (index
, value
) {
3280 this._array
[this._getCyclicIndex(index
)] = value
;
3282 CircularList
.prototype.push = function (value
) {
3283 this._array
[this._getCyclicIndex(this._length
)] = value
;
3284 if (this._length
=== this.maxLength
) {
3286 if (this._startIndex
=== this.maxLength
) {
3287 this._startIndex
= 0;
3289 this.emit('trim', 1);
3295 CircularList
.prototype.pop = function () {
3296 return this._array
[this._getCyclicIndex(this._length
-- - 1)];
3298 CircularList
.prototype.splice = function (start
, deleteCount
) {
3300 for (var _i
= 2; _i
< arguments
.length
; _i
++) {
3301 items
[_i
- 2] = arguments
[_i
];
3304 for (var i
= start
; i
< this._length
- deleteCount
; i
++) {
3305 this._array
[this._getCyclicIndex(i
)] = this._array
[this._getCyclicIndex(i
+ deleteCount
)];
3307 this._length
-= deleteCount
;
3309 if (items
&& items
.length
) {
3310 for (var i
= this._length
- 1; i
>= start
; i
--) {
3311 this._array
[this._getCyclicIndex(i
+ items
.length
)] = this._array
[this._getCyclicIndex(i
)];
3313 for (var i
= 0; i
< items
.length
; i
++) {
3314 this._array
[this._getCyclicIndex(start
+ i
)] = items
[i
];
3316 if (this._length
+ items
.length
> this.maxLength
) {
3317 var countToTrim
= (this._length
+ items
.length
) - this.maxLength
;
3318 this._startIndex
+= countToTrim
;
3319 this._length
= this.maxLength
;
3320 this.emit('trim', countToTrim
);
3323 this._length
+= items
.length
;
3327 CircularList
.prototype.trimStart = function (count
) {
3328 if (count
> this._length
) {
3329 count
= this._length
;
3331 this._startIndex
+= count
;
3332 this._length
-= count
;
3333 this.emit('trim', count
);
3335 CircularList
.prototype.shiftElements = function (start
, count
, offset
) {
3339 if (start
< 0 || start
>= this._length
) {
3340 throw new Error('start argument out of range');
3342 if (start
+ offset
< 0) {
3343 throw new Error('Cannot shift elements in list beyond index 0');
3346 for (var i
= count
- 1; i
>= 0; i
--) {
3347 this.set(start
+ i
+ offset
, this.get(start
+ i
));
3349 var expandListBy
= (start
+ count
+ offset
) - this._length
;
3350 if (expandListBy
> 0) {
3351 this._length
+= expandListBy
;
3352 while (this._length
> this.maxLength
) {
3355 this.emit('trim', 1);
3360 for (var i
= 0; i
< count
; i
++) {
3361 this.set(start
+ i
+ offset
, this.get(start
+ i
));
3365 CircularList
.prototype._getCyclicIndex = function (index
) {
3366 return (this._startIndex
+ index
) % this.maxLength
;
3368 return CircularList
;
3369 }(EventEmitter_1
.EventEmitter
));
3370 exports
.CircularList
= CircularList
;
3374 },{"../EventEmitter":6}],19:[function(require
,module
,exports
){
3376 Object
.defineProperty(exports
, "__esModule", { value
: true });
3377 var DomElementObjectPool
= (function () {
3378 function DomElementObjectPool(type
) {
3384 DomElementObjectPool
.prototype.acquire = function () {
3386 if (this._pool
.length
=== 0) {
3387 element
= this._createNew();
3390 element
= this._pool
.pop();
3392 this._inUse
[element
.getAttribute(DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
)] = element
;
3395 DomElementObjectPool
.prototype.release = function (element
) {
3396 if (!this._inUse
[element
.getAttribute(DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
)]) {
3397 throw new Error('Could not release an element not yet acquired');
3399 delete this._inUse
[element
.getAttribute(DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
)];
3400 this._cleanElement(element
);
3401 this._pool
.push(element
);
3403 DomElementObjectPool
.prototype._createNew = function () {
3404 var element
= document
.createElement(this._type
);
3405 var id
= DomElementObjectPool
._objectCount
++;
3406 element
.setAttribute(DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
, id
.toString(10));
3409 DomElementObjectPool
.prototype._cleanElement = function (element
) {
3410 element
.className
= '';
3411 element
.innerHTML
= '';
3413 return DomElementObjectPool
;
3415 DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
= 'data-obj-id';
3416 DomElementObjectPool
._objectCount
= 0;
3417 exports
.DomElementObjectPool
= DomElementObjectPool
;
3421 },{}],20:[function(require
,module
,exports
){
3423 Object
.defineProperty(exports
, "__esModule", { value
: true });
3424 function contains(arr
, el
) {
3425 return arr
.indexOf(el
) >= 0;
3427 exports
.contains
= contains
;
3432 },{}],21:[function(require
,module
,exports
){
3434 Object
.defineProperty(exports
, "__esModule", { value
: true });
3435 function getCoordsRelativeToElement(event
, element
) {
3436 if (event
.pageX
== null) {
3439 var x
= event
.pageX
;
3440 var y
= event
.pageY
;
3441 while (element
&& element
!== self
.document
.documentElement
) {
3442 x
-= element
.offsetLeft
;
3443 y
-= element
.offsetTop
;
3444 element
= 'offsetParent' in element
? element
.offsetParent
: element
.parentElement
;
3448 exports
.getCoordsRelativeToElement
= getCoordsRelativeToElement
;
3449 function getCoords(event
, rowContainer
, charMeasure
, colCount
, rowCount
, isSelection
) {
3450 if (!charMeasure
.width
|| !charMeasure
.height
) {
3453 var coords
= getCoordsRelativeToElement(event
, rowContainer
);
3457 coords
[0] = Math
.ceil((coords
[0] + (isSelection
? charMeasure
.width
/ 2 : 0)) / charMeasure
.width
);
3458 coords
[1] = Math
.ceil(coords
[1] / charMeasure
.height
);
3459 coords
[0] = Math
.min(Math
.max(coords
[0], 1), colCount
+ 1);
3460 coords
[1] = Math
.min(Math
.max(coords
[1], 1), rowCount
+ 1);
3463 exports
.getCoords
= getCoords
;
3464 function getRawByteCoords(event
, rowContainer
, charMeasure
, colCount
, rowCount
) {
3465 var coords
= getCoords(event
, rowContainer
, charMeasure
, colCount
, rowCount
);
3470 return { x
: x
, y
: y
};
3472 exports
.getRawByteCoords
= getRawByteCoords
;
3476 },{}],22:[function(require
,module
,exports
){
3478 Object
.defineProperty(exports
, "__esModule", { value
: true });
3479 var BufferSet_1
= require("./BufferSet");
3480 var CompositionHelper_1
= require("./CompositionHelper");
3481 var EventEmitter_1
= require("./EventEmitter");
3482 var Viewport_1
= require("./Viewport");
3483 var Clipboard_1
= require("./handlers/Clipboard");
3484 var EscapeSequences_1
= require("./EscapeSequences");
3485 var InputHandler_1
= require("./InputHandler");
3486 var Parser_1
= require("./Parser");
3487 var Renderer_1
= require("./Renderer");
3488 var Linkifier_1
= require("./Linkifier");
3489 var SelectionManager_1
= require("./SelectionManager");
3490 var CharMeasure_1
= require("./utils/CharMeasure");
3491 var Browser
= require("./utils/Browser");
3492 var Mouse_1
= require("./utils/Mouse");
3493 var BufferLine_1
= require("./utils/BufferLine");
3494 var document
= (typeof window
!= 'undefined') ? window
.document
: null;
3495 var WRITE_BUFFER_PAUSE_THRESHOLD
= 5;
3496 var WRITE_BATCH_SIZE
= 300;
3497 var CURSOR_BLINK_INTERVAL
= 600;
3498 function Terminal(options
) {
3500 if (!(this instanceof Terminal
)) {
3501 return new Terminal(arguments
[0], arguments
[1], arguments
[2]);
3503 self
.browser
= Browser
;
3504 self
.cancel
= Terminal
.cancel
;
3505 EventEmitter_1
.EventEmitter
.call(this);
3506 if (typeof options
=== 'number') {
3510 handler
: arguments
[2]
3513 options
= options
|| {};
3514 Object
.keys(Terminal
.defaults
).forEach(function (key
) {
3515 if (options
[key
] == null) {
3516 options
[key
] = Terminal
.options
[key
];
3517 if (Terminal
[key
] !== Terminal
.defaults
[key
]) {
3518 options
[key
] = Terminal
[key
];
3521 self
[key
] = options
[key
];
3523 if (options
.colors
.length
=== 8) {
3524 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(8));
3526 else if (options
.colors
.length
=== 16) {
3527 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16));
3529 else if (options
.colors
.length
=== 10) {
3530 options
.colors
= options
.colors
.slice(0, -2).concat(Terminal
._colors
.slice(8, -2), options
.colors
.slice(-2));
3532 else if (options
.colors
.length
=== 18) {
3533 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16, -2), options
.colors
.slice(-2));
3535 this.colors
= options
.colors
;
3536 this.options
= options
;
3537 this.parent
= options
.body
|| options
.parent
|| (document
? document
.getElementsByTagName('body')[0] : null);
3538 this.cols
= options
.cols
|| options
.geometry
[0];
3539 this.rows
= options
.rows
|| options
.geometry
[1];
3540 this.geometry
= [this.cols
, this.rows
];
3541 if (options
.handler
) {
3542 this.on('data', options
.handler
);
3544 this.cursorState
= 0;
3545 this.cursorHidden
= false;
3548 this.customKeyEventHandler
= null;
3549 this.cursorBlinkInterval
= null;
3550 this.applicationKeypad
= false;
3551 this.applicationCursor
= false;
3552 this.originMode
= false;
3553 this.insertMode
= false;
3554 this.wraparoundMode
= true;
3555 this.charset
= null;
3556 this.gcharset
= null;
3558 this.charsets
= [null];
3576 this.readable
= true;
3577 this.writable
= true;
3578 this.defAttr
= (0 << 18) | (257 << 9) | (256 << 0);
3579 this.curAttr
= this.defAttr
;
3581 this.currentParam
= 0;
3584 this.inputHandler
= new InputHandler_1
.InputHandler(this);
3585 this.parser
= new Parser_1
.Parser(this.inputHandler
, this);
3586 this.renderer
= this.renderer
|| null;
3587 this.selectionManager
= this.selectionManager
|| null;
3588 this.linkifier
= this.linkifier
|| new Linkifier_1
.Linkifier();
3589 this.writeBuffer
= [];
3590 this.writeInProgress
= false;
3591 this.xoffSentToCatchUp
= false;
3592 this.writeStopped
= false;
3593 this.surrogate_high
= '';
3594 this.buffers
= new BufferSet_1
.BufferSet(this);
3595 this.buffer
= this.buffers
.active
;
3596 this.buffers
.on('activate', function (buffer
) {
3597 this._terminal
.buffer
= buffer
;
3601 this.buffer
.lines
.push(this.blankLine());
3603 if (this.selectionManager
) {
3604 this.selectionManager
.setBuffer(this.buffer
.lines
);
3607 this.userScrolling
= false;
3609 inherits(Terminal
, EventEmitter_1
.EventEmitter
);
3610 Terminal
.prototype.eraseAttr = function () {
3611 return (this.defAttr
& ~0x1ff) | (this.curAttr
& 0x1ff);
3613 Terminal
.tangoColors
= [
3631 Terminal
.colors
= (function () {
3632 var colors
= Terminal
.tangoColors
.slice(), r
= [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff], i
;
3634 for (; i
< 216; i
++) {
3635 out(r
[(i
/ 36) % 6 | 0], r
[(i
/ 6) % 6 | 0], r
[i
% 6]);
3638 for (; i
< 24; i
++) {
3642 function out(r
, g
, b
) {
3643 colors
.push('#' + hex(r
) + hex(g
) + hex(b
));
3647 return c
.length
< 2 ? '0' + c
: c
;
3651 Terminal
._colors
= Terminal
.colors
.slice();
3652 Terminal
.vcolors
= (function () {
3653 var out
= [], colors
= Terminal
.colors
, i
= 0, color
;
3654 for (; i
< 256; i
++) {
3655 color
= parseInt(colors
[i
].substring(1), 16);
3657 (color
>> 16) & 0xff,
3658 (color
>> 8) & 0xff,
3664 Terminal
.defaults
= {
3665 colors
: Terminal
.colors
,
3671 cursorStyle
: 'block',
3677 cancelEvents
: false,
3678 disableStdin
: false,
3679 useFlowControl
: false,
3682 Terminal
.options
= {};
3683 Terminal
.focus
= null;
3684 each(keys(Terminal
.defaults
), function (key
) {
3685 Terminal
[key
] = Terminal
.defaults
[key
];
3686 Terminal
.options
[key
] = Terminal
.defaults
[key
];
3688 Terminal
.prototype.focus = function () {
3689 return this.textarea
.focus();
3691 Terminal
.prototype.getOption = function (key
) {
3692 if (!(key
in Terminal
.defaults
)) {
3693 throw new Error('No option with key "' + key
+ '"');
3695 if (typeof this.options
[key
] !== 'undefined') {
3696 return this.options
[key
];
3700 Terminal
.prototype.setOption = function (key
, value
) {
3701 if (!(key
in Terminal
.defaults
)) {
3702 throw new Error('No option with key "' + key
+ '"');
3706 if (value
< this.rows
) {
3707 var msg
= 'Setting the scrollback value less than the number of rows ';
3708 msg
+= "(" + this.rows
+ ") is not allowed.";
3712 if (this.options
[key
] !== value
) {
3713 if (this.buffer
.lines
.length
> value
) {
3714 var amountToTrim
= this.buffer
.lines
.length
- value
;
3715 var needsRefresh
= (this.buffer
.ydisp
- amountToTrim
< 0);
3716 this.buffer
.lines
.trimStart(amountToTrim
);
3717 this.buffer
.ybase
= Math
.max(this.buffer
.ybase
- amountToTrim
, 0);
3718 this.buffer
.ydisp
= Math
.max(this.buffer
.ydisp
- amountToTrim
, 0);
3720 this.refresh(0, this.rows
- 1);
3723 this.buffer
.lines
.maxLength
= value
;
3724 this.viewport
.syncScrollArea();
3729 this.options
[key
] = value
;
3732 this.setCursorBlinking(value
);
3735 this.element
.classList
.toggle("xterm-cursor-style-block", value
=== 'block');
3736 this.element
.classList
.toggle("xterm-cursor-style-underline", value
=== 'underline');
3737 this.element
.classList
.toggle("xterm-cursor-style-bar", value
=== 'bar');
3739 case 'tabStopWidth':
3744 Terminal
.prototype.restartCursorBlinking = function () {
3745 this.setCursorBlinking(this.options
.cursorBlink
);
3747 Terminal
.prototype.setCursorBlinking = function (enabled
) {
3748 this.element
.classList
.toggle('xterm-cursor-blink', enabled
);
3749 this.clearCursorBlinkingInterval();
3752 this.cursorBlinkInterval
= setInterval(function () {
3753 self
.element
.classList
.toggle('xterm-cursor-blink-on');
3754 }, CURSOR_BLINK_INTERVAL
);
3757 Terminal
.prototype.clearCursorBlinkingInterval = function () {
3758 this.element
.classList
.remove('xterm-cursor-blink-on');
3759 if (this.cursorBlinkInterval
) {
3760 clearInterval(this.cursorBlinkInterval
);
3761 this.cursorBlinkInterval
= null;
3764 Terminal
.bindFocus = function (term
) {
3765 on(term
.textarea
, 'focus', function (ev
) {
3766 if (term
.sendFocus
) {
3767 term
.send(EscapeSequences_1
.C0
.ESC
+ '[I');
3769 term
.element
.classList
.add('focus');
3771 term
.restartCursorBlinking
.apply(term
);
3772 Terminal
.focus
= term
;
3773 term
.emit('focus', { terminal
: term
});
3776 Terminal
.prototype.blur = function () {
3777 return this.textarea
.blur();
3779 Terminal
.bindBlur = function (term
) {
3780 on(term
.textarea
, 'blur', function (ev
) {
3781 term
.refresh(term
.buffer
.y
, term
.buffer
.y
);
3782 if (term
.sendFocus
) {
3783 term
.send(EscapeSequences_1
.C0
.ESC
+ '[O');
3785 term
.element
.classList
.remove('focus');
3786 term
.clearCursorBlinkingInterval
.apply(term
);
3787 Terminal
.focus
= null;
3788 term
.emit('blur', { terminal
: term
});
3791 Terminal
.prototype.initGlobal = function () {
3794 Terminal
.bindKeys(this);
3795 Terminal
.bindFocus(this);
3796 Terminal
.bindBlur(this);
3797 on(this.element
, 'copy', function (event
) {
3798 if (!term
.hasSelection()) {
3801 Clipboard_1
.copyHandler(event
, term
, _this
.selectionManager
);
3803 var pasteHandlerWrapper = function (event
) { return Clipboard_1
.pasteHandler(event
, term
); };
3804 on(this.textarea
, 'paste', pasteHandlerWrapper
);
3805 on(this.element
, 'paste', pasteHandlerWrapper
);
3806 if (term
.browser
.isFirefox
) {
3807 on(this.element
, 'mousedown', function (event
) {
3808 if (event
.button
== 2) {
3809 Clipboard_1
.rightClickHandler(event
, _this
.textarea
, _this
.selectionManager
);
3814 on(this.element
, 'contextmenu', function (event
) {
3815 Clipboard_1
.rightClickHandler(event
, _this
.textarea
, _this
.selectionManager
);
3818 if (term
.browser
.isLinux
) {
3819 on(this.element
, 'auxclick', function (event
) {
3820 if (event
.button
=== 1) {
3821 Clipboard_1
.moveTextAreaUnderMouseCursor(event
, _this
.textarea
, _this
.selectionManager
);
3826 Terminal
.bindKeys = function (term
) {
3827 on(term
.element
, 'keydown', function (ev
) {
3828 if (document
.activeElement
!= this) {
3833 on(term
.element
, 'keypress', function (ev
) {
3834 if (document
.activeElement
!= this) {
3839 on(term
.element
, 'keyup', function (ev
) {
3840 if (!wasMondifierKeyOnlyEvent(ev
)) {
3844 on(term
.textarea
, 'keydown', function (ev
) {
3847 on(term
.textarea
, 'keypress', function (ev
) {
3851 on(term
.textarea
, 'compositionstart', term
.compositionHelper
.compositionstart
.bind(term
.compositionHelper
));
3852 on(term
.textarea
, 'compositionupdate', term
.compositionHelper
.compositionupdate
.bind(term
.compositionHelper
));
3853 on(term
.textarea
, 'compositionend', term
.compositionHelper
.compositionend
.bind(term
.compositionHelper
));
3854 term
.on('refresh', term
.compositionHelper
.updateCompositionElements
.bind(term
.compositionHelper
));
3855 term
.on('refresh', function (data
) {
3856 term
.queueLinkification(data
.start
, data
.end
);
3859 Terminal
.prototype.insertRow = function (row
) {
3860 if (typeof row
!= 'object') {
3861 row
= document
.createElement('div');
3863 this.rowContainer
.appendChild(row
);
3864 this.children
.push(row
);
3867 Terminal
.prototype.open = function (parent
, focus
) {
3869 var self
= this, i
= 0, div
;
3870 this.parent
= parent
|| this.parent
;
3872 throw new Error('Terminal requires a parent element.');
3874 this.context
= this.parent
.ownerDocument
.defaultView
;
3875 this.document
= this.parent
.ownerDocument
;
3876 this.body
= this.document
.getElementsByTagName('body')[0];
3877 this.element
= this.document
.createElement('div');
3878 this.element
.classList
.add('terminal');
3879 this.element
.classList
.add('xterm');
3880 this.element
.classList
.add('xterm-theme-' + this.theme
);
3881 this.element
.classList
.add("xterm-cursor-style-" + this.options
.cursorStyle
);
3882 this.setCursorBlinking(this.options
.cursorBlink
);
3883 this.element
.setAttribute('tabindex', 0);
3884 this.viewportElement
= document
.createElement('div');
3885 this.viewportElement
.classList
.add('xterm-viewport');
3886 this.element
.appendChild(this.viewportElement
);
3887 this.viewportScrollArea
= document
.createElement('div');
3888 this.viewportScrollArea
.classList
.add('xterm-scroll-area');
3889 this.viewportElement
.appendChild(this.viewportScrollArea
);
3890 this.selectionContainer
= document
.createElement('div');
3891 this.selectionContainer
.classList
.add('xterm-selection');
3892 this.element
.appendChild(this.selectionContainer
);
3893 this.rowContainer
= document
.createElement('div');
3894 this.rowContainer
.classList
.add('xterm-rows');
3895 this.element
.appendChild(this.rowContainer
);
3897 this.linkifier
.attachToDom(document
, this.children
);
3898 this.helperContainer
= document
.createElement('div');
3899 this.helperContainer
.classList
.add('xterm-helpers');
3900 this.element
.appendChild(this.helperContainer
);
3901 this.textarea
= document
.createElement('textarea');
3902 this.textarea
.classList
.add('xterm-helper-textarea');
3903 this.textarea
.setAttribute('autocorrect', 'off');
3904 this.textarea
.setAttribute('autocapitalize', 'off');
3905 this.textarea
.setAttribute('spellcheck', 'false');
3906 this.textarea
.tabIndex
= 0;
3907 this.textarea
.addEventListener('focus', function () {
3908 self
.emit('focus', { terminal
: self
});
3910 this.textarea
.addEventListener('blur', function () {
3911 self
.emit('blur', { terminal
: self
});
3913 this.helperContainer
.appendChild(this.textarea
);
3914 this.compositionView
= document
.createElement('div');
3915 this.compositionView
.classList
.add('composition-view');
3916 this.compositionHelper
= new CompositionHelper_1
.CompositionHelper(this.textarea
, this.compositionView
, this);
3917 this.helperContainer
.appendChild(this.compositionView
);
3918 this.charSizeStyleElement
= document
.createElement('style');
3919 this.helperContainer
.appendChild(this.charSizeStyleElement
);
3920 for (; i
< this.rows
; i
++) {
3923 this.parent
.appendChild(this.element
);
3924 this.charMeasure
= new CharMeasure_1
.CharMeasure(document
, this.helperContainer
);
3925 this.charMeasure
.on('charsizechanged', function () {
3926 self
.updateCharSizeStyles();
3928 this.charMeasure
.measure();
3929 this.viewport
= new Viewport_1
.Viewport(this, this.viewportElement
, this.viewportScrollArea
, this.charMeasure
);
3930 this.renderer
= new Renderer_1
.Renderer(this);
3931 this.selectionManager
= new SelectionManager_1
.SelectionManager(this, this.buffer
.lines
, this.rowContainer
, this.charMeasure
);
3932 this.selectionManager
.on('refresh', function (data
) {
3933 _this
.renderer
.refreshSelection(data
.start
, data
.end
);
3935 this.selectionManager
.on('newselection', function (text
) {
3936 _this
.textarea
.value
= text
;
3937 _this
.textarea
.focus();
3938 _this
.textarea
.select();
3940 this.on('scroll', function () { return _this
.selectionManager
.refresh(); });
3941 this.viewportElement
.addEventListener('scroll', function () { return _this
.selectionManager
.refresh(); });
3942 this.refresh(0, this.rows
- 1);
3944 if (typeof focus
== 'undefined') {
3945 var message
= 'You did not pass the `focus` argument in `Terminal.prototype.open()`.\n';
3946 message
+= 'The `focus` argument now defaults to `true` but starting with xterm.js 3.0 ';
3947 message
+= 'it will default to `false`.';
3948 console
.warn(message
);
3957 Terminal
.loadAddon = function (addon
, callback
) {
3958 if (typeof exports
=== 'object' && typeof module
=== 'object') {
3959 return require('./addons/' + addon
+ '/' + addon
);
3961 else if (typeof define
== 'function') {
3962 return require(['./addons/' + addon
+ '/' + addon
], callback
);
3965 console
.error('Cannot load a module without a CommonJS or RequireJS environment.');
3969 Terminal
.prototype.updateCharSizeStyles = function () {
3970 this.charSizeStyleElement
.textContent
=
3971 ".xterm-wide-char{width:" + this.charMeasure
.width
* 2 + "px;}" +
3972 (".xterm-normal-char{width:" + this.charMeasure
.width
+ "px;}") +
3973 (".xterm-rows > div{height:" + this.charMeasure
.height
+ "px;}");
3975 Terminal
.prototype.bindMouse = function () {
3976 var el
= this.element
, self
= this, pressed
= 32;
3977 function sendButton(ev
) {
3979 button
= getButton(ev
);
3980 pos
= Mouse_1
.getRawByteCoords(ev
, self
.rowContainer
, self
.charMeasure
, self
.cols
, self
.rows
);
3983 sendEvent(button
, pos
);
3984 switch (ev
.overrideType
|| ev
.type
) {
3995 function sendMove(ev
) {
3996 var button
= pressed
, pos
;
3997 pos
= Mouse_1
.getRawByteCoords(ev
, self
.rowContainer
, self
.charMeasure
, self
.cols
, self
.rows
);
4001 sendEvent(button
, pos
);
4003 function encode(data
, ch
) {
4004 if (!self
.utfMouse
) {
4006 return data
.push(0);
4013 return data
.push(0);
4020 data
.push(0xC0 | (ch
>> 6));
4021 data
.push(0x80 | (ch
& 0x3F));
4025 function sendEvent(button
, pos
) {
4026 if (self
.vt300Mouse
) {
4030 var data
= EscapeSequences_1
.C0
.ESC
+ '[24';
4033 else if (button
=== 1)
4035 else if (button
=== 2)
4037 else if (button
=== 3)
4041 data
+= '~[' + pos
.x
+ ',' + pos
.y
+ ']\r';
4045 if (self
.decLocator
) {
4051 else if (button
=== 1)
4053 else if (button
=== 2)
4055 else if (button
=== 3)
4057 self
.send(EscapeSequences_1
.C0
.ESC
+ '['
4060 + (button
=== 3 ? 4 : 0)
4070 if (self
.urxvtMouse
) {
4075 self
.send(EscapeSequences_1
.C0
.ESC
+ '[' + button
+ ';' + pos
.x
+ ';' + pos
.y
+ 'M');
4078 if (self
.sgrMouse
) {
4081 self
.send(EscapeSequences_1
.C0
.ESC
+ '[<'
4082 + (((button
& 3) === 3 ? button
& ~3 : button
) - 32)
4087 + ((button
& 3) === 3 ? 'm' : 'M'));
4091 encode(data
, button
);
4092 encode(data
, pos
.x
);
4093 encode(data
, pos
.y
);
4094 self
.send(EscapeSequences_1
.C0
.ESC
+ '[M' + String
.fromCharCode
.apply(String
, data
));
4096 function getButton(ev
) {
4097 var button
, shift
, meta
, ctrl
, mod
;
4098 switch (ev
.overrideType
|| ev
.type
) {
4100 button
= ev
.button
!= null
4105 if (self
.browser
.isMSIE
) {
4106 button
= button
=== 1 ? 0 : button
=== 4 ? 1 : button
;
4112 case 'DOMMouseScroll':
4113 button
= ev
.detail
< 0
4118 button
= ev
.wheelDeltaY
> 0
4123 shift
= ev
.shiftKey
? 4 : 0;
4124 meta
= ev
.metaKey
? 8 : 0;
4125 ctrl
= ev
.ctrlKey
? 16 : 0;
4126 mod
= shift
| meta
| ctrl
;
4127 if (self
.vt200Mouse
) {
4130 else if (!self
.normalMouse
) {
4133 button
= (32 + (mod
<< 2)) + button
;
4136 on(el
, 'mousedown', function (ev
) {
4137 ev
.preventDefault();
4139 if (!self
.mouseEvents
)
4142 if (self
.vt200Mouse
) {
4143 ev
.overrideType
= 'mouseup';
4145 return self
.cancel(ev
);
4147 if (self
.normalMouse
)
4148 on(self
.document
, 'mousemove', sendMove
);
4149 if (!self
.x10Mouse
) {
4150 on(self
.document
, 'mouseup', function up(ev
) {
4152 if (self
.normalMouse
)
4153 off(self
.document
, 'mousemove', sendMove
);
4154 off(self
.document
, 'mouseup', up
);
4155 return self
.cancel(ev
);
4158 return self
.cancel(ev
);
4160 on(el
, 'wheel', function (ev
) {
4161 if (!self
.mouseEvents
)
4168 return self
.cancel(ev
);
4170 on(el
, 'wheel', function (ev
) {
4171 if (self
.mouseEvents
)
4173 self
.viewport
.onWheel(ev
);
4174 return self
.cancel(ev
);
4176 on(el
, 'touchstart', function (ev
) {
4177 if (self
.mouseEvents
)
4179 self
.viewport
.onTouchStart(ev
);
4180 return self
.cancel(ev
);
4182 on(el
, 'touchmove', function (ev
) {
4183 if (self
.mouseEvents
)
4185 self
.viewport
.onTouchMove(ev
);
4186 return self
.cancel(ev
);
4189 Terminal
.prototype.destroy = function () {
4190 this.readable
= false;
4191 this.writable
= false;
4193 this.handler = function () { };
4194 this.write = function () { };
4195 if (this.element
&& this.element
.parentNode
) {
4196 this.element
.parentNode
.removeChild(this.element
);
4199 Terminal
.prototype.refresh = function (start
, end
) {
4200 if (this.renderer
) {
4201 this.renderer
.queueRefresh(start
, end
);
4204 Terminal
.prototype.queueLinkification = function (start
, end
) {
4205 if (this.linkifier
) {
4206 for (var i
= start
; i
<= end
; i
++) {
4207 this.linkifier
.linkifyRow(i
);
4211 Terminal
.prototype.showCursor = function () {
4212 if (!this.cursorState
) {
4213 this.cursorState
= 1;
4214 this.refresh(this.buffer
.y
, this.buffer
.y
);
4217 Terminal
.prototype.scroll = function (isWrapped
) {
4219 if (this.buffer
.lines
.length
=== this.buffer
.lines
.maxLength
) {
4220 this.buffer
.lines
.trimStart(1);
4221 this.buffer
.ybase
--;
4222 if (this.buffer
.ydisp
!== 0) {
4223 this.buffer
.ydisp
--;
4226 this.buffer
.ybase
++;
4227 if (!this.userScrolling
) {
4228 this.buffer
.ydisp
= this.buffer
.ybase
;
4230 row
= this.buffer
.ybase
+ this.rows
- 1;
4231 row
-= this.rows
- 1 - this.buffer
.scrollBottom
;
4232 if (row
=== this.buffer
.lines
.length
) {
4233 this.buffer
.lines
.push(this.blankLine(undefined, isWrapped
));
4236 this.buffer
.lines
.splice(row
, 0, this.blankLine(undefined, isWrapped
));
4238 if (this.buffer
.scrollTop
!== 0) {
4239 if (this.buffer
.ybase
!== 0) {
4240 this.buffer
.ybase
--;
4241 if (!this.userScrolling
) {
4242 this.buffer
.ydisp
= this.buffer
.ybase
;
4245 this.buffer
.lines
.splice(this.buffer
.ybase
+ this.buffer
.scrollTop
, 1);
4247 this.updateRange(this.buffer
.scrollTop
);
4248 this.updateRange(this.buffer
.scrollBottom
);
4249 this.emit('scroll', this.buffer
.ydisp
);
4251 Terminal
.prototype.scrollDisp = function (disp
, suppressScrollEvent
) {
4253 if (this.buffer
.ydisp
=== 0) {
4256 this.userScrolling
= true;
4258 else if (disp
+ this.buffer
.ydisp
>= this.buffer
.ybase
) {
4259 this.userScrolling
= false;
4261 var oldYdisp
= this.buffer
.ydisp
;
4262 this.buffer
.ydisp
= Math
.max(Math
.min(this.buffer
.ydisp
+ disp
, this.buffer
.ybase
), 0);
4263 if (oldYdisp
=== this.buffer
.ydisp
) {
4266 if (!suppressScrollEvent
) {
4267 this.emit('scroll', this.buffer
.ydisp
);
4269 this.refresh(0, this.rows
- 1);
4271 Terminal
.prototype.scrollPages = function (pageCount
) {
4272 this.scrollDisp(pageCount
* (this.rows
- 1));
4274 Terminal
.prototype.scrollToTop = function () {
4275 this.scrollDisp(-this.buffer
.ydisp
);
4277 Terminal
.prototype.scrollToBottom = function () {
4278 this.scrollDisp(this.buffer
.ybase
- this.buffer
.ydisp
);
4280 Terminal
.prototype.write = function (data
) {
4281 this.writeBuffer
.push(data
);
4282 if (this.options
.useFlowControl
&& !this.xoffSentToCatchUp
&& this.writeBuffer
.length
>= WRITE_BUFFER_PAUSE_THRESHOLD
) {
4283 this.send(EscapeSequences_1
.C0
.DC3
);
4284 this.xoffSentToCatchUp
= true;
4286 if (!this.writeInProgress
&& this.writeBuffer
.length
> 0) {
4287 this.writeInProgress
= true;
4289 setTimeout(function () {
4294 Terminal
.prototype.innerWrite = function () {
4295 var writeBatch
= this.writeBuffer
.splice(0, WRITE_BATCH_SIZE
);
4296 while (writeBatch
.length
> 0) {
4297 var data
= writeBatch
.shift();
4298 var l
= data
.length
, i
= 0, j
, cs
, ch
, code
, low
, ch_width
, row
;
4299 if (this.xoffSentToCatchUp
&& writeBatch
.length
=== 0 && this.writeBuffer
.length
=== 0) {
4300 this.send(EscapeSequences_1
.C0
.DC1
);
4301 this.xoffSentToCatchUp
= false;
4303 this.refreshStart
= this.buffer
.y
;
4304 this.refreshEnd
= this.buffer
.y
;
4305 var state
= this.parser
.parse(data
);
4306 this.parser
.setState(state
);
4307 this.updateRange(this.buffer
.y
);
4308 this.refresh(this.refreshStart
, this.refreshEnd
);
4310 if (this.writeBuffer
.length
> 0) {
4312 setTimeout(function () {
4317 this.writeInProgress
= false;
4320 Terminal
.prototype.writeln = function (data
) {
4321 this.write(data
+ '\r\n');
4323 Terminal
.prototype.attachCustomKeydownHandler = function (customKeydownHandler
) {
4324 var message
= 'attachCustomKeydownHandler() is DEPRECATED and will be removed soon. Please use attachCustomKeyEventHandler() instead.';
4325 console
.warn(message
);
4326 this.attachCustomKeyEventHandler(customKeydownHandler
);
4328 Terminal
.prototype.attachCustomKeyEventHandler = function (customKeyEventHandler
) {
4329 this.customKeyEventHandler
= customKeyEventHandler
;
4331 Terminal
.prototype.setHypertextLinkHandler = function (handler
) {
4332 if (!this.linkifier
) {
4333 throw new Error('Cannot attach a hypertext link handler before Terminal.open is called');
4335 this.linkifier
.setHypertextLinkHandler(handler
);
4336 this.refresh(0, this.rows
- 1);
4338 Terminal
.prototype.setHypertextValidationCallback = function (callback
) {
4339 if (!this.linkifier
) {
4340 throw new Error('Cannot attach a hypertext validation callback before Terminal.open is called');
4342 this.linkifier
.setHypertextValidationCallback(callback
);
4343 this.refresh(0, this.rows
- 1);
4345 Terminal
.prototype.registerLinkMatcher = function (regex
, handler
, options
) {
4346 if (this.linkifier
) {
4347 var matcherId
= this.linkifier
.registerLinkMatcher(regex
, handler
, options
);
4348 this.refresh(0, this.rows
- 1);
4352 Terminal
.prototype.deregisterLinkMatcher = function (matcherId
) {
4353 if (this.linkifier
) {
4354 if (this.linkifier
.deregisterLinkMatcher(matcherId
)) {
4355 this.refresh(0, this.rows
- 1);
4359 Terminal
.prototype.hasSelection = function () {
4360 return this.selectionManager
? this.selectionManager
.hasSelection
: false;
4362 Terminal
.prototype.getSelection = function () {
4363 return this.selectionManager
? this.selectionManager
.selectionText
: '';
4365 Terminal
.prototype.clearSelection = function () {
4366 if (this.selectionManager
) {
4367 this.selectionManager
.clearSelection();
4370 Terminal
.prototype.selectAll = function () {
4371 if (this.selectionManager
) {
4372 this.selectionManager
.selectAll();
4375 Terminal
.prototype.keyDown = function (ev
) {
4376 if (this.customKeyEventHandler
&& this.customKeyEventHandler(ev
) === false) {
4379 this.restartCursorBlinking();
4380 if (!this.compositionHelper
.keydown
.bind(this.compositionHelper
)(ev
)) {
4381 if (this.buffer
.ybase
!== this.buffer
.ydisp
) {
4382 this.scrollToBottom();
4387 var result
= this.evaluateKeyEscapeSequence(ev
);
4388 if (result
.key
=== EscapeSequences_1
.C0
.DC3
) {
4389 this.writeStopped
= true;
4391 else if (result
.key
=== EscapeSequences_1
.C0
.DC1
) {
4392 this.writeStopped
= false;
4394 if (result
.scrollDisp
) {
4395 this.scrollDisp(result
.scrollDisp
);
4396 return this.cancel(ev
, true);
4398 if (isThirdLevelShift(this, ev
)) {
4401 if (result
.cancel
) {
4402 this.cancel(ev
, true);
4407 this.emit('keydown', ev
);
4408 this.emit('key', result
.key
, ev
);
4410 this.handler(result
.key
);
4411 return this.cancel(ev
, true);
4413 Terminal
.prototype.evaluateKeyEscapeSequence = function (ev
) {
4417 scrollDisp
: undefined
4419 var modifiers
= ev
.shiftKey
<< 0 | ev
.altKey
<< 1 | ev
.ctrlKey
<< 2 | ev
.metaKey
<< 3;
4420 switch (ev
.keyCode
) {
4423 result
.key
= EscapeSequences_1
.C0
.BS
;
4426 result
.key
= EscapeSequences_1
.C0
.DEL
;
4430 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[Z';
4433 result
.key
= EscapeSequences_1
.C0
.HT
;
4434 result
.cancel
= true;
4437 result
.key
= EscapeSequences_1
.C0
.CR
;
4438 result
.cancel
= true;
4441 result
.key
= EscapeSequences_1
.C0
.ESC
;
4442 result
.cancel
= true;
4446 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'D';
4447 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3D') {
4448 result
.key
= (this.browser
.isMac
) ? EscapeSequences_1
.C0
.ESC
+ 'b' : EscapeSequences_1
.C0
.ESC
+ '[1;5D';
4451 else if (this.applicationCursor
) {
4452 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OD';
4455 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[D';
4460 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'C';
4461 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3C') {
4462 result
.key
= (this.browser
.isMac
) ? EscapeSequences_1
.C0
.ESC
+ 'f' : EscapeSequences_1
.C0
.ESC
+ '[1;5C';
4465 else if (this.applicationCursor
) {
4466 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OC';
4469 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[C';
4474 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'A';
4475 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3A') {
4476 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;5A';
4479 else if (this.applicationCursor
) {
4480 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OA';
4483 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[A';
4488 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'B';
4489 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3B') {
4490 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;5B';
4493 else if (this.applicationCursor
) {
4494 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OB';
4497 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[B';
4501 if (!ev
.shiftKey
&& !ev
.ctrlKey
) {
4502 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[2~';
4507 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[3;' + (modifiers
+ 1) + '~';
4510 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[3~';
4515 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'H';
4516 else if (this.applicationCursor
)
4517 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OH';
4519 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[H';
4523 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'F';
4524 else if (this.applicationCursor
)
4525 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OF';
4527 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[F';
4531 result
.scrollDisp
= -(this.rows
- 1);
4534 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[5~';
4539 result
.scrollDisp
= this.rows
- 1;
4542 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[6~';
4547 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'P';
4550 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OP';
4555 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'Q';
4558 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OQ';
4563 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'R';
4566 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OR';
4571 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'S';
4574 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OS';
4579 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[15;' + (modifiers
+ 1) + '~';
4582 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[15~';
4587 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[17;' + (modifiers
+ 1) + '~';
4590 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[17~';
4595 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[18;' + (modifiers
+ 1) + '~';
4598 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[18~';
4603 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[19;' + (modifiers
+ 1) + '~';
4606 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[19~';
4611 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[20;' + (modifiers
+ 1) + '~';
4614 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[20~';
4619 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[21;' + (modifiers
+ 1) + '~';
4622 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[21~';
4627 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[23;' + (modifiers
+ 1) + '~';
4630 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[23~';
4635 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[24;' + (modifiers
+ 1) + '~';
4638 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[24~';
4642 if (ev
.ctrlKey
&& !ev
.shiftKey
&& !ev
.altKey
&& !ev
.metaKey
) {
4643 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
4644 result
.key
= String
.fromCharCode(ev
.keyCode
- 64);
4646 else if (ev
.keyCode
=== 32) {
4647 result
.key
= String
.fromCharCode(0);
4649 else if (ev
.keyCode
>= 51 && ev
.keyCode
<= 55) {
4650 result
.key
= String
.fromCharCode(ev
.keyCode
- 51 + 27);
4652 else if (ev
.keyCode
=== 56) {
4653 result
.key
= String
.fromCharCode(127);
4655 else if (ev
.keyCode
=== 219) {
4656 result
.key
= String
.fromCharCode(27);
4658 else if (ev
.keyCode
=== 220) {
4659 result
.key
= String
.fromCharCode(28);
4661 else if (ev
.keyCode
=== 221) {
4662 result
.key
= String
.fromCharCode(29);
4665 else if (!this.browser
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) {
4666 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
4667 result
.key
= EscapeSequences_1
.C0
.ESC
+ String
.fromCharCode(ev
.keyCode
+ 32);
4669 else if (ev
.keyCode
=== 192) {
4670 result
.key
= EscapeSequences_1
.C0
.ESC
+ '`';
4672 else if (ev
.keyCode
>= 48 && ev
.keyCode
<= 57) {
4673 result
.key
= EscapeSequences_1
.C0
.ESC
+ (ev
.keyCode
- 48);
4676 else if (this.browser
.isMac
&& !ev
.altKey
&& !ev
.ctrlKey
&& ev
.metaKey
) {
4677 if (ev
.keyCode
=== 65) {
4685 Terminal
.prototype.setgLevel = function (g
) {
4687 this.charset
= this.charsets
[g
];
4689 Terminal
.prototype.setgCharset = function (g
, charset
) {
4690 this.charsets
[g
] = charset
;
4691 if (this.glevel
=== g
) {
4692 this.charset
= charset
;
4695 Terminal
.prototype.keyPress = function (ev
) {
4697 if (this.customKeyEventHandler
&& this.customKeyEventHandler(ev
) === false) {
4704 else if (ev
.which
== null) {
4707 else if (ev
.which
!== 0 && ev
.charCode
!== 0) {
4713 if (!key
|| ((ev
.altKey
|| ev
.ctrlKey
|| ev
.metaKey
) && !isThirdLevelShift(this, ev
))) {
4716 key
= String
.fromCharCode(key
);
4717 this.emit('keypress', key
, ev
);
4718 this.emit('key', key
, ev
);
4723 Terminal
.prototype.send = function (data
) {
4726 setTimeout(function () {
4727 self
.handler(self
.queue
);
4733 Terminal
.prototype.bell = function () {
4734 if (!this.visualBell
)
4737 this.element
.style
.borderColor
= 'white';
4738 setTimeout(function () {
4739 self
.element
.style
.borderColor
= '';
4744 Terminal
.prototype.log = function () {
4747 if (!this.context
.console
|| !this.context
.console
.log
)
4749 var args
= Array
.prototype.slice
.call(arguments
);
4750 this.context
.console
.log
.apply(this.context
.console
, args
);
4752 Terminal
.prototype.error = function () {
4755 if (!this.context
.console
|| !this.context
.console
.error
)
4757 var args
= Array
.prototype.slice
.call(arguments
);
4758 this.context
.console
.error
.apply(this.context
.console
, args
);
4760 Terminal
.prototype.resize = function (x
, y
) {
4761 if (isNaN(x
) || isNaN(y
)) {
4764 if (y
> this.getOption('scrollback')) {
4765 this.setOption('scrollback', y
);
4767 var line
, el
, i
, j
, ch
, addToY
;
4768 if (x
=== this.cols
&& y
=== this.rows
) {
4769 if (!this.charMeasure
.width
|| !this.charMeasure
.height
) {
4770 this.charMeasure
.measure();
4780 ch
= [this.defAttr
, ' ', 1];
4781 i
= this.buffer
.lines
.length
;
4783 if (this.buffer
.lines
.get(i
) === undefined) {
4784 this.buffer
.lines
.set(i
, this.blankLine());
4786 while (this.buffer
.lines
.get(i
).length
< x
) {
4787 this.buffer
.lines
.get(i
).push(ch
);
4792 this.setupStops(this.cols
);
4798 if (this.buffer
.lines
.length
< y
+ this.buffer
.ybase
) {
4799 if (this.buffer
.ybase
> 0 && this.buffer
.lines
.length
<= this.buffer
.ybase
+ this.buffer
.y
+ addToY
+ 1) {
4800 this.buffer
.ybase
--;
4802 if (this.buffer
.ydisp
> 0) {
4803 this.buffer
.ydisp
--;
4807 this.buffer
.lines
.push(this.blankLine());
4810 if (this.children
.length
< y
) {
4817 if (this.buffer
.lines
.length
> y
+ this.buffer
.ybase
) {
4818 if (this.buffer
.lines
.length
> this.buffer
.ybase
+ this.buffer
.y
+ 1) {
4819 this.buffer
.lines
.pop();
4822 this.buffer
.ybase
++;
4823 this.buffer
.ydisp
++;
4826 if (this.children
.length
> y
) {
4827 el
= this.children
.shift();
4830 el
.parentNode
.removeChild(el
);
4835 if (this.buffer
.y
>= y
) {
4836 this.buffer
.y
= y
- 1;
4839 this.buffer
.y
+= addToY
;
4841 if (this.buffer
.x
>= x
) {
4842 this.buffer
.x
= x
- 1;
4844 this.buffer
.scrollTop
= 0;
4845 this.buffer
.scrollBottom
= y
- 1;
4846 this.charMeasure
.measure();
4847 this.refresh(0, this.rows
- 1);
4848 this.geometry
= [this.cols
, this.rows
];
4849 this.emit('resize', { terminal
: this, cols
: x
, rows
: y
});
4851 Terminal
.prototype.updateRange = function (y
) {
4852 if (y
< this.refreshStart
)
4853 this.refreshStart
= y
;
4854 if (y
> this.refreshEnd
)
4855 this.refreshEnd
= y
;
4857 Terminal
.prototype.maxRange = function () {
4858 this.refreshStart
= 0;
4859 this.refreshEnd
= this.rows
- 1;
4861 Terminal
.prototype.setupStops = function (i
) {
4863 if (!this.buffer
.tabs
[i
]) {
4864 i
= this.prevStop(i
);
4868 this.buffer
.tabs
= {};
4871 for (; i
< this.cols
; i
+= this.getOption('tabStopWidth')) {
4872 this.buffer
.tabs
[i
] = true;
4875 Terminal
.prototype.prevStop = function (x
) {
4878 while (!this.buffer
.tabs
[--x
] && x
> 0)
4880 return x
>= this.cols
4884 Terminal
.prototype.nextStop = function (x
) {
4887 while (!this.buffer
.tabs
[++x
] && x
< this.cols
)
4889 return x
>= this.cols
4893 Terminal
.prototype.eraseRight = function (x
, y
) {
4894 var line
= this.buffer
.lines
.get(this.buffer
.ybase
+ y
);
4898 var ch
= [this.eraseAttr(), ' ', 1];
4899 for (; x
< this.cols
; x
++) {
4902 this.updateRange(y
);
4904 Terminal
.prototype.eraseLeft = function (x
, y
) {
4905 var line
= this.buffer
.lines
.get(this.buffer
.ybase
+ y
);
4909 var ch
= [this.eraseAttr(), ' ', 1];
4914 this.updateRange(y
);
4916 Terminal
.prototype.clear = function () {
4917 if (this.buffer
.ybase
=== 0 && this.buffer
.y
=== 0) {
4920 this.buffer
.lines
.set(0, this.buffer
.lines
.get(this.buffer
.ybase
+ this.buffer
.y
));
4921 this.buffer
.lines
.length
= 1;
4922 this.buffer
.ydisp
= 0;
4923 this.buffer
.ybase
= 0;
4925 for (var i
= 1; i
< this.rows
; i
++) {
4926 this.buffer
.lines
.push(this.blankLine());
4928 this.refresh(0, this.rows
- 1);
4929 this.emit('scroll', this.buffer
.ydisp
);
4931 Terminal
.prototype.eraseLine = function (y
) {
4932 this.eraseRight(0, y
);
4934 Terminal
.prototype.blankLine = function (cur
, isWrapped
) {
4938 var ch
= [attr
, ' ', 1], line
= [], i
= 0;
4940 line
.isWrapped
= isWrapped
;
4942 for (; i
< this.cols
; i
++) {
4947 Terminal
.prototype.ch = function (cur
) {
4949 ? [this.eraseAttr(), ' ', 1]
4950 : [this.defAttr
, ' ', 1];
4952 Terminal
.prototype.is = function (term
) {
4953 var name
= this.termName
;
4954 return (name
+ '').indexOf(term
) === 0;
4956 Terminal
.prototype.handler = function (data
) {
4957 if (this.options
.disableStdin
) {
4960 if (this.selectionManager
&& this.selectionManager
.hasSelection
) {
4961 this.selectionManager
.clearSelection();
4963 if (this.buffer
.ybase
!== this.buffer
.ydisp
) {
4964 this.scrollToBottom();
4966 this.emit('data', data
);
4968 Terminal
.prototype.handleTitle = function (title
) {
4969 this.emit('title', title
);
4971 Terminal
.prototype.index = function () {
4973 if (this.buffer
.y
> this.buffer
.scrollBottom
) {
4977 if (this.buffer
.x
>= this.cols
) {
4981 Terminal
.prototype.reverseIndex = function () {
4983 if (this.buffer
.y
=== this.buffer
.scrollTop
) {
4984 this.buffer
.lines
.shiftElements(this.buffer
.y
+ this.buffer
.ybase
, this.rows
- 1, 1);
4985 this.buffer
.lines
.set(this.buffer
.y
+ this.buffer
.ybase
, this.blankLine(true));
4986 this.updateRange(this.buffer
.scrollTop
);
4987 this.updateRange(this.buffer
.scrollBottom
);
4993 Terminal
.prototype.reset = function () {
4994 this.options
.rows
= this.rows
;
4995 this.options
.cols
= this.cols
;
4996 var customKeyEventHandler
= this.customKeyEventHandler
;
4997 var cursorBlinkInterval
= this.cursorBlinkInterval
;
4998 var inputHandler
= this.inputHandler
;
4999 var buffers
= this.buffers
;
5000 Terminal
.call(this, this.options
);
5001 this.customKeyEventHandler
= customKeyEventHandler
;
5002 this.cursorBlinkInterval
= cursorBlinkInterval
;
5003 this.inputHandler
= inputHandler
;
5004 this.buffers
= buffers
;
5005 this.refresh(0, this.rows
- 1);
5006 this.viewport
.syncScrollArea();
5008 Terminal
.prototype.tabSet = function () {
5009 this.buffer
.tabs
[this.buffer
.x
] = true;
5011 function on(el
, type
, handler
, capture
) {
5012 if (!Array
.isArray(el
)) {
5015 el
.forEach(function (element
) {
5016 element
.addEventListener(type
, handler
, capture
|| false);
5019 function off(el
, type
, handler
, capture
) {
5020 el
.removeEventListener(type
, handler
, capture
|| false);
5022 function cancel(ev
, force
) {
5023 if (!this.cancelEvents
&& !force
) {
5026 ev
.preventDefault();
5027 ev
.stopPropagation();
5030 function inherits(child
, parent
) {
5032 this.constructor = child
;
5034 f
.prototype = parent
.prototype;
5035 child
.prototype = new f
;
5037 function indexOf(obj
, el
) {
5045 function isThirdLevelShift(term
, ev
) {
5046 var thirdLevelKey
= (term
.browser
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) ||
5047 (term
.browser
.isMSWindows
&& ev
.altKey
&& ev
.ctrlKey
&& !ev
.metaKey
);
5048 if (ev
.type
== 'keypress') {
5049 return thirdLevelKey
;
5051 return thirdLevelKey
&& (!ev
.keyCode
|| ev
.keyCode
> 47);
5053 Terminal
.prototype.matchColor
= matchColor
;
5054 function matchColor(r1
, g1
, b1
) {
5055 var hash
= (r1
<< 16) | (g1
<< 8) | b1
;
5056 if (matchColor
._cache
[hash
] != null) {
5057 return matchColor
._cache
[hash
];
5059 var ldiff
= Infinity
, li
= -1, i
= 0, c
, r2
, g2
, b2
, diff
;
5060 for (; i
< Terminal
.vcolors
.length
; i
++) {
5061 c
= Terminal
.vcolors
[i
];
5065 diff
= matchColor
.distance(r1
, g1
, b1
, r2
, g2
, b2
);
5075 return matchColor
._cache
[hash
] = li
;
5077 matchColor
._cache
= {};
5078 matchColor
.distance = function (r1
, g1
, b1
, r2
, g2
, b2
) {
5079 return Math
.pow(30 * (r1
- r2
), 2)
5080 + Math
.pow(59 * (g1
- g2
), 2)
5081 + Math
.pow(11 * (b1
- b2
), 2);
5083 function each(obj
, iter
, con
) {
5085 return obj
.forEach(iter
, con
);
5086 for (var i
= 0; i
< obj
.length
; i
++) {
5087 iter
.call(con
, obj
[i
], i
, obj
);
5090 function wasMondifierKeyOnlyEvent(ev
) {
5091 return ev
.keyCode
=== 16 ||
5092 ev
.keyCode
=== 17 ||
5095 function keys(obj
) {
5097 return Object
.keys(obj
);
5100 if (Object
.prototype.hasOwnProperty
.call(obj
, key
)) {
5106 Terminal
.translateBufferLineToString
= BufferLine_1
.translateBufferLineToString
;
5107 Terminal
.EventEmitter
= EventEmitter_1
.EventEmitter
;
5108 Terminal
.inherits
= inherits
;
5111 Terminal
.cancel
= cancel
;
5112 module
.exports
= Terminal
;
5116 },{"./BufferSet":2,"./CompositionHelper":4,"./EscapeSequences":5,"./EventEmitter":6,"./InputHandler":7,"./Linkifier":8,"./Parser":9,"./Renderer":10,"./SelectionManager":11,"./Viewport":13,"./handlers/Clipboard":14,"./utils/Browser":15,"./utils/BufferLine":16,"./utils/CharMeasure":17,"./utils/Mouse":21}]},{},[22])(22)
5118 //# sourceMappingURL=xterm.js.map