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
) {
7 this._terminal
= _terminal
;
10 Object
.defineProperty(Buffer
.prototype, "lines", {
17 Buffer
.prototype.fillViewportRows = function () {
18 if (this._lines
.length
=== 0) {
19 var i
= this._terminal
.rows
;
21 this.lines
.push(this._terminal
.blankLine());
25 Buffer
.prototype.clear = function () {
30 this.scrollBottom
= 0;
33 this._lines
= new CircularList_1
.CircularList(this._terminal
.scrollback
);
34 this.scrollBottom
= this._terminal
.rows
- 1;
36 Buffer
.prototype.resize = function (newCols
, newRows
) {
37 if (this._lines
.length
=== 0) {
40 if (this._terminal
.cols
< newCols
) {
41 var ch
= [this._terminal
.defAttr
, ' ', 1];
42 for (var i
= 0; i
< this._lines
.length
; i
++) {
43 if (this._lines
.get(i
) === undefined) {
44 this._lines
.set(i
, this._terminal
.blankLine());
46 while (this._lines
.get(i
).length
< newCols
) {
47 this._lines
.get(i
).push(ch
);
52 if (this._terminal
.rows
< newRows
) {
53 for (var y
= this._terminal
.rows
; y
< newRows
; y
++) {
54 if (this._lines
.length
< newRows
+ this.ybase
) {
55 if (this.ybase
> 0 && this._lines
.length
<= this.ybase
+ this.y
+ addToY
+ 1) {
63 this._lines
.push(this._terminal
.blankLine());
69 for (var y
= this._terminal
.rows
; y
> newRows
; y
--) {
70 if (this._lines
.length
> newRows
+ this.ybase
) {
71 if (this._lines
.length
> this.ybase
+ this.y
+ 1) {
81 if (this.y
>= newRows
) {
87 if (this.x
>= newCols
) {
91 this.scrollBottom
= newRows
- 1;
95 exports
.Buffer
= Buffer
;
99 },{"./utils/CircularList":18}],2:[function(require
,module
,exports
){
101 var __extends
= (this && this.__extends
) || (function () {
102 var extendStatics
= Object
.setPrototypeOf
||
103 ({ __proto__
: [] } instanceof Array
&& function (d
, b
) { d
.__proto__
= b
; }) ||
104 function (d
, b
) { for (var p
in b
) if (b
.hasOwnProperty(p
)) d
[p
] = b
[p
]; };
105 return function (d
, b
) {
107 function __() { this.constructor = d
; }
108 d
.prototype = b
=== null ? Object
.create(b
) : (__
.prototype = b
.prototype, new __());
111 Object
.defineProperty(exports
, "__esModule", { value
: true });
112 var Buffer_1
= require("./Buffer");
113 var EventEmitter_1
= require("./EventEmitter");
114 var BufferSet
= (function (_super
) {
115 __extends(BufferSet
, _super
);
116 function BufferSet(_terminal
) {
117 var _this
= _super
.call(this) || this;
118 _this
._terminal
= _terminal
;
119 _this
._normal
= new Buffer_1
.Buffer(_this
._terminal
);
120 _this
._normal
.fillViewportRows();
121 _this
._alt
= new Buffer_1
.Buffer(_this
._terminal
);
122 _this
._activeBuffer
= _this
._normal
;
125 Object
.defineProperty(BufferSet
.prototype, "alt", {
132 Object
.defineProperty(BufferSet
.prototype, "active", {
134 return this._activeBuffer
;
139 Object
.defineProperty(BufferSet
.prototype, "normal", {
146 BufferSet
.prototype.activateNormalBuffer = function () {
148 this._activeBuffer
= this._normal
;
149 this.emit('activate', this._normal
);
151 BufferSet
.prototype.activateAltBuffer = function () {
152 this._alt
.fillViewportRows();
153 this._activeBuffer
= this._alt
;
154 this.emit('activate', this._alt
);
156 BufferSet
.prototype.resize = function (newCols
, newRows
) {
157 this._normal
.resize(newCols
, newRows
);
158 this._alt
.resize(newCols
, newRows
);
161 }(EventEmitter_1
.EventEmitter
));
162 exports
.BufferSet
= BufferSet
;
166 },{"./Buffer":1,"./EventEmitter":6}],3:[function(require
,module
,exports
){
168 Object
.defineProperty(exports
, "__esModule", { value
: true });
169 exports
.CHARSETS
= {};
170 exports
.DEFAULT_CHARSET
= exports
.CHARSETS
['B'];
171 exports
.CHARSETS
['0'] = {
204 exports
.CHARSETS
['A'] = {
207 exports
.CHARSETS
['B'] = null;
208 exports
.CHARSETS
['4'] = {
219 exports
.CHARSETS
['C'] =
220 exports
.CHARSETS
['5'] = {
231 exports
.CHARSETS
['R'] = {
242 exports
.CHARSETS
['Q'] = {
254 exports
.CHARSETS
['K'] = {
264 exports
.CHARSETS
['Y'] = {
276 exports
.CHARSETS
['E'] =
277 exports
.CHARSETS
['6'] = {
289 exports
.CHARSETS
['Z'] = {
299 exports
.CHARSETS
['H'] =
300 exports
.CHARSETS
['7'] = {
312 exports
.CHARSETS
['='] = {
329 },{}],4:[function(require
,module
,exports
){
331 Object
.defineProperty(exports
, "__esModule", { value
: true });
332 var CompositionHelper
= (function () {
333 function CompositionHelper(textarea
, compositionView
, terminal
) {
334 this.textarea
= textarea
;
335 this.compositionView
= compositionView
;
336 this.terminal
= terminal
;
337 this.isComposing
= false;
338 this.isSendingComposition
= false;
339 this.compositionPosition
= { start
: null, end
: null };
341 CompositionHelper
.prototype.compositionstart = function () {
342 this.isComposing
= true;
343 this.compositionPosition
.start
= this.textarea
.value
.length
;
344 this.compositionView
.textContent
= '';
345 this.compositionView
.classList
.add('active');
347 CompositionHelper
.prototype.compositionupdate = function (ev
) {
349 this.compositionView
.textContent
= ev
.data
;
350 this.updateCompositionElements();
351 setTimeout(function () {
352 _this
.compositionPosition
.end
= _this
.textarea
.value
.length
;
355 CompositionHelper
.prototype.compositionend = function () {
356 this.finalizeComposition(true);
358 CompositionHelper
.prototype.keydown = function (ev
) {
359 if (this.isComposing
|| this.isSendingComposition
) {
360 if (ev
.keyCode
=== 229) {
363 else if (ev
.keyCode
=== 16 || ev
.keyCode
=== 17 || ev
.keyCode
=== 18) {
367 this.finalizeComposition(false);
370 if (ev
.keyCode
=== 229) {
371 this.handleAnyTextareaChanges();
376 CompositionHelper
.prototype.finalizeComposition = function (waitForPropogation
) {
378 this.compositionView
.classList
.remove('active');
379 this.isComposing
= false;
380 this.clearTextareaPosition();
381 if (!waitForPropogation
) {
382 this.isSendingComposition
= false;
383 var input
= this.textarea
.value
.substring(this.compositionPosition
.start
, this.compositionPosition
.end
);
384 this.terminal
.handler(input
);
387 var currentCompositionPosition_1
= {
388 start
: this.compositionPosition
.start
,
389 end
: this.compositionPosition
.end
,
391 this.isSendingComposition
= true;
392 setTimeout(function () {
393 if (_this
.isSendingComposition
) {
394 _this
.isSendingComposition
= false;
396 if (_this
.isComposing
) {
397 input
= _this
.textarea
.value
.substring(currentCompositionPosition_1
.start
, currentCompositionPosition_1
.end
);
400 input
= _this
.textarea
.value
.substring(currentCompositionPosition_1
.start
);
402 _this
.terminal
.handler(input
);
407 CompositionHelper
.prototype.handleAnyTextareaChanges = function () {
409 var oldValue
= this.textarea
.value
;
410 setTimeout(function () {
411 if (!_this
.isComposing
) {
412 var newValue
= _this
.textarea
.value
;
413 var diff
= newValue
.replace(oldValue
, '');
414 if (diff
.length
> 0) {
415 _this
.terminal
.handler(diff
);
420 CompositionHelper
.prototype.updateCompositionElements = function (dontRecurse
) {
422 if (!this.isComposing
) {
425 var cursor
= this.terminal
.element
.querySelector('.terminal-cursor');
427 var xtermRows
= this.terminal
.element
.querySelector('.xterm-rows');
428 var cursorTop
= xtermRows
.offsetTop
+ cursor
.offsetTop
;
429 this.compositionView
.style
.left
= cursor
.offsetLeft
+ 'px';
430 this.compositionView
.style
.top
= cursorTop
+ 'px';
431 this.compositionView
.style
.height
= cursor
.offsetHeight
+ 'px';
432 this.compositionView
.style
.lineHeight
= cursor
.offsetHeight
+ 'px';
433 var compositionViewBounds
= this.compositionView
.getBoundingClientRect();
434 this.textarea
.style
.left
= cursor
.offsetLeft
+ 'px';
435 this.textarea
.style
.top
= cursorTop
+ 'px';
436 this.textarea
.style
.width
= compositionViewBounds
.width
+ 'px';
437 this.textarea
.style
.height
= compositionViewBounds
.height
+ 'px';
438 this.textarea
.style
.lineHeight
= compositionViewBounds
.height
+ 'px';
441 setTimeout(function () { return _this
.updateCompositionElements(true); }, 0);
445 CompositionHelper
.prototype.clearTextareaPosition = function () {
446 this.textarea
.style
.left
= '';
447 this.textarea
.style
.top
= '';
450 return CompositionHelper
;
452 exports
.CompositionHelper
= CompositionHelper
;
456 },{}],5:[function(require
,module
,exports
){
458 Object
.defineProperty(exports
, "__esModule", { value
: true });
495 })(C0
= exports
.C0
|| (exports
.C0
= {}));
500 },{}],6:[function(require
,module
,exports
){
502 Object
.defineProperty(exports
, "__esModule", { value
: true });
504 var EventEmitter
= (function () {
505 function EventEmitter() {
506 this._events
= this._events
|| {};
508 EventEmitter
.prototype.on = function (type
, listener
) {
509 this._events
[type
] = this._events
[type
] || [];
510 this._events
[type
].push(listener
);
512 EventEmitter
.prototype.off = function (type
, listener
) {
513 if (!this._events
[type
]) {
516 var obj
= this._events
[type
];
519 if (obj
[i
] === listener
|| obj
[i
].listener
=== listener
) {
525 EventEmitter
.prototype.removeAllListeners = function (type
) {
526 if (this._events
[type
]) {
527 delete this._events
[type
];
530 EventEmitter
.prototype.once = function (type
, listener
) {
532 var args
= Array
.prototype.slice
.call(arguments
);
534 return listener
.apply(this, args
);
536 on
.listener
= listener
;
537 return this.on(type
, on
);
539 EventEmitter
.prototype.emit = function (type
) {
541 for (var _i
= 1; _i
< arguments
.length
; _i
++) {
542 args
[_i
- 1] = arguments
[_i
];
544 if (!this._events
[type
]) {
547 var obj
= this._events
[type
];
548 for (var i
= 0; i
< obj
.length
; i
++) {
549 obj
[i
].apply(this, args
);
552 EventEmitter
.prototype.listeners = function (type
) {
553 return this._events
[type
] || [];
557 exports
.EventEmitter
= EventEmitter
;
561 },{}],7:[function(require
,module
,exports
){
563 Object
.defineProperty(exports
, "__esModule", { value
: true });
564 var EscapeSequences_1
= require("./EscapeSequences");
565 var Charsets_1
= require("./Charsets");
566 var InputHandler
= (function () {
567 function InputHandler(_terminal
) {
568 this._terminal
= _terminal
;
570 InputHandler
.prototype.addChar = function (char, code
) {
572 var ch_width
= exports
.wcwidth(code
);
573 if (this._terminal
.charset
&& this._terminal
.charset
[char]) {
574 char = this._terminal
.charset
[char];
576 var row
= this._terminal
.buffer
.y
+ this._terminal
.buffer
.ybase
;
577 if (!ch_width
&& this._terminal
.buffer
.x
) {
578 if (this._terminal
.buffer
.lines
.get(row
)[this._terminal
.buffer
.x
- 1]) {
579 if (!this._terminal
.buffer
.lines
.get(row
)[this._terminal
.buffer
.x
- 1][2]) {
580 if (this._terminal
.buffer
.lines
.get(row
)[this._terminal
.buffer
.x
- 2])
581 this._terminal
.buffer
.lines
.get(row
)[this._terminal
.buffer
.x
- 2][1] += char;
584 this._terminal
.buffer
.lines
.get(row
)[this._terminal
.buffer
.x
- 1][1] += char;
586 this._terminal
.updateRange(this._terminal
.buffer
.y
);
590 if (this._terminal
.buffer
.x
+ ch_width
- 1 >= this._terminal
.cols
) {
591 if (this._terminal
.wraparoundMode
) {
592 this._terminal
.buffer
.x
= 0;
593 this._terminal
.buffer
.y
++;
594 if (this._terminal
.buffer
.y
> this._terminal
.buffer
.scrollBottom
) {
595 this._terminal
.buffer
.y
--;
596 this._terminal
.scroll(true);
599 this._terminal
.buffer
.lines
.get(this._terminal
.buffer
.y
).isWrapped
= true;
607 row
= this._terminal
.buffer
.y
+ this._terminal
.buffer
.ybase
;
608 if (this._terminal
.insertMode
) {
609 for (var moves
= 0; moves
< ch_width
; ++moves
) {
610 var removed
= this._terminal
.buffer
.lines
.get(this._terminal
.buffer
.y
+ this._terminal
.buffer
.ybase
).pop();
612 && this._terminal
.buffer
.lines
.get(row
)[this._terminal
.cols
- 2]
613 && this._terminal
.buffer
.lines
.get(row
)[this._terminal
.cols
- 2][2] === 2) {
614 this._terminal
.buffer
.lines
.get(row
)[this._terminal
.cols
- 2] = [this._terminal
.curAttr
, ' ', 1];
616 this._terminal
.buffer
.lines
.get(row
).splice(this._terminal
.buffer
.x
, 0, [this._terminal
.curAttr
, ' ', 1]);
619 this._terminal
.buffer
.lines
.get(row
)[this._terminal
.buffer
.x
] = [this._terminal
.curAttr
, char, ch_width
];
620 this._terminal
.buffer
.x
++;
621 this._terminal
.updateRange(this._terminal
.buffer
.y
);
622 if (ch_width
=== 2) {
623 this._terminal
.buffer
.lines
.get(row
)[this._terminal
.buffer
.x
] = [this._terminal
.curAttr
, '', 0];
624 this._terminal
.buffer
.x
++;
628 InputHandler
.prototype.bell = function () {
630 if (!this._terminal
.visualBell
) {
633 this._terminal
.element
.style
.borderColor
= 'white';
634 setTimeout(function () { return _this
._terminal
.element
.style
.borderColor
= ''; }, 10);
635 if (this._terminal
.popOnBell
) {
636 this._terminal
.focus();
639 InputHandler
.prototype.lineFeed = function () {
640 if (this._terminal
.convertEol
) {
641 this._terminal
.buffer
.x
= 0;
643 this._terminal
.buffer
.y
++;
644 if (this._terminal
.buffer
.y
> this._terminal
.buffer
.scrollBottom
) {
645 this._terminal
.buffer
.y
--;
646 this._terminal
.scroll();
648 if (this._terminal
.buffer
.x
>= this._terminal
.cols
) {
649 this._terminal
.buffer
.x
--;
651 this._terminal
.emit('lineFeed');
653 InputHandler
.prototype.carriageReturn = function () {
654 this._terminal
.buffer
.x
= 0;
656 InputHandler
.prototype.backspace = function () {
657 if (this._terminal
.buffer
.x
> 0) {
658 this._terminal
.buffer
.x
--;
661 InputHandler
.prototype.tab = function () {
662 this._terminal
.buffer
.x
= this._terminal
.nextStop();
664 InputHandler
.prototype.shiftOut = function () {
665 this._terminal
.setgLevel(1);
667 InputHandler
.prototype.shiftIn = function () {
668 this._terminal
.setgLevel(0);
670 InputHandler
.prototype.insertChars = function (params
) {
671 var param
, row
, j
, ch
;
675 row
= this._terminal
.buffer
.y
+ this._terminal
.buffer
.ybase
;
676 j
= this._terminal
.buffer
.x
;
677 ch
= [this._terminal
.eraseAttr(), ' ', 1];
678 while (param
-- && j
< this._terminal
.cols
) {
679 this._terminal
.buffer
.lines
.get(row
).splice(j
++, 0, ch
);
680 this._terminal
.buffer
.lines
.get(row
).pop();
683 InputHandler
.prototype.cursorUp = function (params
) {
684 var param
= params
[0];
688 this._terminal
.buffer
.y
-= param
;
689 if (this._terminal
.buffer
.y
< 0) {
690 this._terminal
.buffer
.y
= 0;
693 InputHandler
.prototype.cursorDown = function (params
) {
694 var param
= params
[0];
698 this._terminal
.buffer
.y
+= param
;
699 if (this._terminal
.buffer
.y
>= this._terminal
.rows
) {
700 this._terminal
.buffer
.y
= this._terminal
.rows
- 1;
702 if (this._terminal
.buffer
.x
>= this._terminal
.cols
) {
703 this._terminal
.buffer
.x
--;
706 InputHandler
.prototype.cursorForward = function (params
) {
707 var param
= params
[0];
711 this._terminal
.buffer
.x
+= param
;
712 if (this._terminal
.buffer
.x
>= this._terminal
.cols
) {
713 this._terminal
.buffer
.x
= this._terminal
.cols
- 1;
716 InputHandler
.prototype.cursorBackward = function (params
) {
717 var param
= params
[0];
721 if (this._terminal
.buffer
.x
>= this._terminal
.cols
) {
722 this._terminal
.buffer
.x
--;
724 this._terminal
.buffer
.x
-= param
;
725 if (this._terminal
.buffer
.x
< 0) {
726 this._terminal
.buffer
.x
= 0;
729 InputHandler
.prototype.cursorNextLine = function (params
) {
730 var param
= params
[0];
734 this._terminal
.buffer
.y
+= param
;
735 if (this._terminal
.buffer
.y
>= this._terminal
.rows
) {
736 this._terminal
.buffer
.y
= this._terminal
.rows
- 1;
738 this._terminal
.buffer
.x
= 0;
740 InputHandler
.prototype.cursorPrecedingLine = function (params
) {
741 var param
= params
[0];
745 this._terminal
.buffer
.y
-= param
;
746 if (this._terminal
.buffer
.y
< 0) {
747 this._terminal
.buffer
.y
= 0;
749 this._terminal
.buffer
.x
= 0;
751 InputHandler
.prototype.cursorCharAbsolute = function (params
) {
752 var param
= params
[0];
756 this._terminal
.buffer
.x
= param
- 1;
758 InputHandler
.prototype.cursorPosition = function (params
) {
761 if (params
.length
>= 2) {
770 else if (row
>= this._terminal
.rows
) {
771 row
= this._terminal
.rows
- 1;
776 else if (col
>= this._terminal
.cols
) {
777 col
= this._terminal
.cols
- 1;
779 this._terminal
.buffer
.x
= col
;
780 this._terminal
.buffer
.y
= row
;
782 InputHandler
.prototype.cursorForwardTab = function (params
) {
783 var param
= params
[0] || 1;
785 this._terminal
.buffer
.x
= this._terminal
.nextStop();
788 InputHandler
.prototype.eraseInDisplay = function (params
) {
792 this._terminal
.eraseRight(this._terminal
.buffer
.x
, this._terminal
.buffer
.y
);
793 j
= this._terminal
.buffer
.y
+ 1;
794 for (; j
< this._terminal
.rows
; j
++) {
795 this._terminal
.eraseLine(j
);
799 this._terminal
.eraseLeft(this._terminal
.buffer
.x
, this._terminal
.buffer
.y
);
800 j
= this._terminal
.buffer
.y
;
802 this._terminal
.eraseLine(j
);
806 j
= this._terminal
.rows
;
808 this._terminal
.eraseLine(j
);
811 var scrollBackSize
= this._terminal
.buffer
.lines
.length
- this._terminal
.rows
;
812 if (scrollBackSize
> 0) {
813 this._terminal
.buffer
.lines
.trimStart(scrollBackSize
);
814 this._terminal
.buffer
.ybase
= Math
.max(this._terminal
.buffer
.ybase
- scrollBackSize
, 0);
815 this._terminal
.buffer
.ydisp
= Math
.max(this._terminal
.buffer
.ydisp
- scrollBackSize
, 0);
816 this._terminal
.emit('scroll', 0);
821 InputHandler
.prototype.eraseInLine = function (params
) {
824 this._terminal
.eraseRight(this._terminal
.buffer
.x
, this._terminal
.buffer
.y
);
827 this._terminal
.eraseLeft(this._terminal
.buffer
.x
, this._terminal
.buffer
.y
);
830 this._terminal
.eraseLine(this._terminal
.buffer
.y
);
834 InputHandler
.prototype.insertLines = function (params
) {
840 row
= this._terminal
.buffer
.y
+ this._terminal
.buffer
.ybase
;
841 j
= this._terminal
.rows
- 1 - this._terminal
.buffer
.scrollBottom
;
842 j
= this._terminal
.rows
- 1 + this._terminal
.buffer
.ybase
- j
+ 1;
844 if (this._terminal
.buffer
.lines
.length
=== this._terminal
.buffer
.lines
.maxLength
) {
845 this._terminal
.buffer
.lines
.trimStart(1);
846 this._terminal
.buffer
.ybase
--;
847 this._terminal
.buffer
.ydisp
--;
851 this._terminal
.buffer
.lines
.splice(row
, 0, this._terminal
.blankLine(true));
852 this._terminal
.buffer
.lines
.splice(j
, 1);
854 this._terminal
.updateRange(this._terminal
.buffer
.y
);
855 this._terminal
.updateRange(this._terminal
.buffer
.scrollBottom
);
857 InputHandler
.prototype.deleteLines = function (params
) {
863 row
= this._terminal
.buffer
.y
+ this._terminal
.buffer
.ybase
;
864 j
= this._terminal
.rows
- 1 - this._terminal
.buffer
.scrollBottom
;
865 j
= this._terminal
.rows
- 1 + this._terminal
.buffer
.ybase
- j
;
867 if (this._terminal
.buffer
.lines
.length
=== this._terminal
.buffer
.lines
.maxLength
) {
868 this._terminal
.buffer
.lines
.trimStart(1);
869 this._terminal
.buffer
.ybase
-= 1;
870 this._terminal
.buffer
.ydisp
-= 1;
872 this._terminal
.buffer
.lines
.splice(j
+ 1, 0, this._terminal
.blankLine(true));
873 this._terminal
.buffer
.lines
.splice(row
, 1);
875 this._terminal
.updateRange(this._terminal
.buffer
.y
);
876 this._terminal
.updateRange(this._terminal
.buffer
.scrollBottom
);
878 InputHandler
.prototype.deleteChars = function (params
) {
884 row
= this._terminal
.buffer
.y
+ this._terminal
.buffer
.ybase
;
885 ch
= [this._terminal
.eraseAttr(), ' ', 1];
887 this._terminal
.buffer
.lines
.get(row
).splice(this._terminal
.buffer
.x
, 1);
888 this._terminal
.buffer
.lines
.get(row
).push(ch
);
891 InputHandler
.prototype.scrollUp = function (params
) {
892 var param
= params
[0] || 1;
894 this._terminal
.buffer
.lines
.splice(this._terminal
.buffer
.ybase
+ this._terminal
.buffer
.scrollTop
, 1);
895 this._terminal
.buffer
.lines
.splice(this._terminal
.buffer
.ybase
+ this._terminal
.buffer
.scrollBottom
, 0, this._terminal
.blankLine());
897 this._terminal
.updateRange(this._terminal
.buffer
.scrollTop
);
898 this._terminal
.updateRange(this._terminal
.buffer
.scrollBottom
);
900 InputHandler
.prototype.scrollDown = function (params
) {
901 var param
= params
[0] || 1;
903 this._terminal
.buffer
.lines
.splice(this._terminal
.buffer
.ybase
+ this._terminal
.buffer
.scrollBottom
, 1);
904 this._terminal
.buffer
.lines
.splice(this._terminal
.buffer
.ybase
+ this._terminal
.buffer
.scrollTop
, 0, this._terminal
.blankLine());
906 this._terminal
.updateRange(this._terminal
.buffer
.scrollTop
);
907 this._terminal
.updateRange(this._terminal
.buffer
.scrollBottom
);
909 InputHandler
.prototype.eraseChars = function (params
) {
910 var param
, row
, j
, ch
;
915 row
= this._terminal
.buffer
.y
+ this._terminal
.buffer
.ybase
;
916 j
= this._terminal
.buffer
.x
;
917 ch
= [this._terminal
.eraseAttr(), ' ', 1];
918 while (param
-- && j
< this._terminal
.cols
) {
919 this._terminal
.buffer
.lines
.get(row
)[j
++] = ch
;
922 InputHandler
.prototype.cursorBackwardTab = function (params
) {
923 var param
= params
[0] || 1;
925 this._terminal
.buffer
.x
= this._terminal
.prevStop();
928 InputHandler
.prototype.charPosAbsolute = function (params
) {
929 var param
= params
[0];
933 this._terminal
.buffer
.x
= param
- 1;
934 if (this._terminal
.buffer
.x
>= this._terminal
.cols
) {
935 this._terminal
.buffer
.x
= this._terminal
.cols
- 1;
938 InputHandler
.prototype.HPositionRelative = function (params
) {
939 var param
= params
[0];
943 this._terminal
.buffer
.x
+= param
;
944 if (this._terminal
.buffer
.x
>= this._terminal
.cols
) {
945 this._terminal
.buffer
.x
= this._terminal
.cols
- 1;
948 InputHandler
.prototype.repeatPrecedingCharacter = function (params
) {
949 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];
951 line
[this._terminal
.buffer
.x
++] = ch
;
954 InputHandler
.prototype.sendDeviceAttributes = function (params
) {
958 if (!this._terminal
.prefix
) {
959 if (this._terminal
.is('xterm') || this._terminal
.is('rxvt-unicode') || this._terminal
.is('screen')) {
960 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?1;2c');
962 else if (this._terminal
.is('linux')) {
963 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?6c');
966 else if (this._terminal
.prefix
=== '>') {
967 if (this._terminal
.is('xterm')) {
968 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>0;276;0c');
970 else if (this._terminal
.is('rxvt-unicode')) {
971 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>85;95;0c');
973 else if (this._terminal
.is('linux')) {
974 this._terminal
.send(params
[0] + 'c');
976 else if (this._terminal
.is('screen')) {
977 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>83;40003;0c');
981 InputHandler
.prototype.linePosAbsolute = function (params
) {
982 var param
= params
[0];
986 this._terminal
.buffer
.y
= param
- 1;
987 if (this._terminal
.buffer
.y
>= this._terminal
.rows
) {
988 this._terminal
.buffer
.y
= this._terminal
.rows
- 1;
991 InputHandler
.prototype.VPositionRelative = function (params
) {
992 var param
= params
[0];
996 this._terminal
.buffer
.y
+= param
;
997 if (this._terminal
.buffer
.y
>= this._terminal
.rows
) {
998 this._terminal
.buffer
.y
= this._terminal
.rows
- 1;
1000 if (this._terminal
.buffer
.x
>= this._terminal
.cols
) {
1001 this._terminal
.buffer
.x
--;
1004 InputHandler
.prototype.HVPosition = function (params
) {
1009 this._terminal
.buffer
.y
= params
[0] - 1;
1010 if (this._terminal
.buffer
.y
>= this._terminal
.rows
) {
1011 this._terminal
.buffer
.y
= this._terminal
.rows
- 1;
1013 this._terminal
.buffer
.x
= params
[1] - 1;
1014 if (this._terminal
.buffer
.x
>= this._terminal
.cols
) {
1015 this._terminal
.buffer
.x
= this._terminal
.cols
- 1;
1018 InputHandler
.prototype.tabClear = function (params
) {
1019 var param
= params
[0];
1021 delete this._terminal
.buffer
.tabs
[this._terminal
.buffer
.x
];
1023 else if (param
=== 3) {
1024 this._terminal
.buffer
.tabs
= {};
1027 InputHandler
.prototype.setMode = function (params
) {
1028 if (params
.length
> 1) {
1029 for (var i
= 0; i
< params
.length
; i
++) {
1030 this.setMode([params
[i
]]);
1034 if (!this._terminal
.prefix
) {
1035 switch (params
[0]) {
1037 this._terminal
.insertMode
= true;
1043 else if (this._terminal
.prefix
=== '?') {
1044 switch (params
[0]) {
1046 this._terminal
.applicationCursor
= true;
1049 this._terminal
.setgCharset(0, Charsets_1
.DEFAULT_CHARSET
);
1050 this._terminal
.setgCharset(1, Charsets_1
.DEFAULT_CHARSET
);
1051 this._terminal
.setgCharset(2, Charsets_1
.DEFAULT_CHARSET
);
1052 this._terminal
.setgCharset(3, Charsets_1
.DEFAULT_CHARSET
);
1055 this._terminal
.savedCols
= this._terminal
.cols
;
1056 this._terminal
.resize(132, this._terminal
.rows
);
1059 this._terminal
.originMode
= true;
1062 this._terminal
.wraparoundMode
= true;
1067 this._terminal
.log('Serial port requested application keypad.');
1068 this._terminal
.applicationKeypad
= true;
1069 this._terminal
.viewport
.syncScrollArea();
1075 this._terminal
.x10Mouse
= params
[0] === 9;
1076 this._terminal
.vt200Mouse
= params
[0] === 1000;
1077 this._terminal
.normalMouse
= params
[0] > 1000;
1078 this._terminal
.mouseEvents
= true;
1079 this._terminal
.element
.classList
.add('enable-mouse-events');
1080 this._terminal
.selectionManager
.disable();
1081 this._terminal
.log('Binding to mouse events.');
1084 this._terminal
.sendFocus
= true;
1087 this._terminal
.utfMouse
= true;
1090 this._terminal
.sgrMouse
= true;
1093 this._terminal
.urxvtMouse
= true;
1096 this._terminal
.cursorHidden
= false;
1101 this._terminal
.buffers
.activateAltBuffer();
1102 this._terminal
.viewport
.syncScrollArea();
1103 this._terminal
.showCursor();
1108 InputHandler
.prototype.resetMode = function (params
) {
1109 if (params
.length
> 1) {
1110 for (var i
= 0; i
< params
.length
; i
++) {
1111 this.resetMode([params
[i
]]);
1115 if (!this._terminal
.prefix
) {
1116 switch (params
[0]) {
1118 this._terminal
.insertMode
= false;
1124 else if (this._terminal
.prefix
=== '?') {
1125 switch (params
[0]) {
1127 this._terminal
.applicationCursor
= false;
1130 if (this._terminal
.cols
=== 132 && this._terminal
.savedCols
) {
1131 this._terminal
.resize(this._terminal
.savedCols
, this._terminal
.rows
);
1133 delete this._terminal
.savedCols
;
1136 this._terminal
.originMode
= false;
1139 this._terminal
.wraparoundMode
= false;
1144 this._terminal
.log('Switching back to normal keypad.');
1145 this._terminal
.applicationKeypad
= false;
1146 this._terminal
.viewport
.syncScrollArea();
1152 this._terminal
.x10Mouse
= false;
1153 this._terminal
.vt200Mouse
= false;
1154 this._terminal
.normalMouse
= false;
1155 this._terminal
.mouseEvents
= false;
1156 this._terminal
.element
.classList
.remove('enable-mouse-events');
1157 this._terminal
.selectionManager
.enable();
1160 this._terminal
.sendFocus
= false;
1163 this._terminal
.utfMouse
= false;
1166 this._terminal
.sgrMouse
= false;
1169 this._terminal
.urxvtMouse
= false;
1172 this._terminal
.cursorHidden
= true;
1177 this._terminal
.buffers
.activateNormalBuffer();
1178 this._terminal
.selectionManager
.setBuffer(this._terminal
.buffer
.lines
);
1179 this._terminal
.refresh(0, this._terminal
.rows
- 1);
1180 this._terminal
.viewport
.syncScrollArea();
1181 this._terminal
.showCursor();
1186 InputHandler
.prototype.charAttributes = function (params
) {
1187 if (params
.length
=== 1 && params
[0] === 0) {
1188 this._terminal
.curAttr
= this._terminal
.defAttr
;
1191 var l
= params
.length
, i
= 0, flags
= this._terminal
.curAttr
>> 18, fg
= (this._terminal
.curAttr
>> 9) & 0x1ff, bg
= this._terminal
.curAttr
& 0x1ff, p
;
1192 for (; i
< l
; i
++) {
1194 if (p
>= 30 && p
<= 37) {
1197 else if (p
>= 40 && p
<= 47) {
1200 else if (p
>= 90 && p
<= 97) {
1204 else if (p
>= 100 && p
<= 107) {
1209 flags
= this._terminal
.defAttr
>> 18;
1210 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1211 bg
= this._terminal
.defAttr
& 0x1ff;
1228 else if (p
=== 22) {
1231 else if (p
=== 24) {
1234 else if (p
=== 25) {
1237 else if (p
=== 27) {
1240 else if (p
=== 28) {
1243 else if (p
=== 39) {
1244 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1246 else if (p
=== 49) {
1247 bg
= this._terminal
.defAttr
& 0x1ff;
1249 else if (p
=== 38) {
1250 if (params
[i
+ 1] === 2) {
1252 fg
= this._terminal
.matchColor(params
[i
] & 0xff, params
[i
+ 1] & 0xff, params
[i
+ 2] & 0xff);
1257 else if (params
[i
+ 1] === 5) {
1259 p
= params
[i
] & 0xff;
1263 else if (p
=== 48) {
1264 if (params
[i
+ 1] === 2) {
1266 bg
= this._terminal
.matchColor(params
[i
] & 0xff, params
[i
+ 1] & 0xff, params
[i
+ 2] & 0xff);
1271 else if (params
[i
+ 1] === 5) {
1273 p
= params
[i
] & 0xff;
1277 else if (p
=== 100) {
1278 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1279 bg
= this._terminal
.defAttr
& 0x1ff;
1282 this._terminal
.error('Unknown SGR attribute: %d.', p
);
1285 this._terminal
.curAttr
= (flags
<< 18) | (fg
<< 9) | bg
;
1287 InputHandler
.prototype.deviceStatus = function (params
) {
1288 if (!this._terminal
.prefix
) {
1289 switch (params
[0]) {
1291 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[0n');
1294 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '['
1295 + (this._terminal
.buffer
.y
+ 1)
1297 + (this._terminal
.buffer
.x
+ 1)
1302 else if (this._terminal
.prefix
=== '?') {
1303 switch (params
[0]) {
1305 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?'
1306 + (this._terminal
.buffer
.y
+ 1)
1308 + (this._terminal
.buffer
.x
+ 1)
1322 InputHandler
.prototype.softReset = function (params
) {
1323 this._terminal
.cursorHidden
= false;
1324 this._terminal
.insertMode
= false;
1325 this._terminal
.originMode
= false;
1326 this._terminal
.wraparoundMode
= true;
1327 this._terminal
.applicationKeypad
= false;
1328 this._terminal
.viewport
.syncScrollArea();
1329 this._terminal
.applicationCursor
= false;
1330 this._terminal
.buffer
.scrollTop
= 0;
1331 this._terminal
.buffer
.scrollBottom
= this._terminal
.rows
- 1;
1332 this._terminal
.curAttr
= this._terminal
.defAttr
;
1333 this._terminal
.buffer
.x
= this._terminal
.buffer
.y
= 0;
1334 this._terminal
.charset
= null;
1335 this._terminal
.glevel
= 0;
1336 this._terminal
.charsets
= [null];
1338 InputHandler
.prototype.setCursorStyle = function (params
) {
1339 var param
= params
[0] < 1 ? 1 : params
[0];
1343 this._terminal
.setOption('cursorStyle', 'block');
1347 this._terminal
.setOption('cursorStyle', 'underline');
1351 this._terminal
.setOption('cursorStyle', 'bar');
1354 var isBlinking
= param
% 2 === 1;
1355 this._terminal
.setOption('cursorBlink', isBlinking
);
1357 InputHandler
.prototype.setScrollRegion = function (params
) {
1358 if (this._terminal
.prefix
)
1360 this._terminal
.buffer
.scrollTop
= (params
[0] || 1) - 1;
1361 this._terminal
.buffer
.scrollBottom
= (params
[1] && params
[1] <= this._terminal
.rows
? params
[1] : this._terminal
.rows
) - 1;
1362 this._terminal
.buffer
.x
= 0;
1363 this._terminal
.buffer
.y
= 0;
1365 InputHandler
.prototype.saveCursor = function (params
) {
1366 this._terminal
.buffer
.savedX
= this._terminal
.buffer
.x
;
1367 this._terminal
.buffer
.savedY
= this._terminal
.buffer
.y
;
1369 InputHandler
.prototype.restoreCursor = function (params
) {
1370 this._terminal
.buffer
.x
= this._terminal
.buffer
.savedX
|| 0;
1371 this._terminal
.buffer
.y
= this._terminal
.buffer
.savedY
|| 0;
1373 return InputHandler
;
1375 exports
.InputHandler
= InputHandler
;
1376 exports
.wcwidth
= (function (opts
) {
1377 var COMBINING_BMP
= [
1378 [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
1379 [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
1380 [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
1381 [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670],
1382 [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED],
1383 [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A],
1384 [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902],
1385 [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D],
1386 [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981],
1387 [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD],
1388 [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C],
1389 [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D],
1390 [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC],
1391 [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD],
1392 [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C],
1393 [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D],
1394 [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0],
1395 [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48],
1396 [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC],
1397 [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD],
1398 [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D],
1399 [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6],
1400 [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E],
1401 [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC],
1402 [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35],
1403 [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E],
1404 [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97],
1405 [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030],
1406 [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039],
1407 [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F],
1408 [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753],
1409 [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD],
1410 [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD],
1411 [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922],
1412 [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B],
1413 [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34],
1414 [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42],
1415 [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF],
1416 [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063],
1417 [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F],
1418 [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B],
1419 [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F],
1420 [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB],
1422 var COMBINING_HIGH
= [
1423 [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F],
1424 [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169],
1425 [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD],
1426 [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F],
1429 function bisearch(ucs
, data
) {
1431 var max
= data
.length
- 1;
1433 if (ucs
< data
[0][0] || ucs
> data
[max
][1])
1435 while (max
>= min
) {
1436 mid
= (min
+ max
) >> 1;
1437 if (ucs
> data
[mid
][1])
1439 else if (ucs
< data
[mid
][0])
1446 function wcwidthBMP(ucs
) {
1449 if (ucs
< 32 || (ucs
>= 0x7f && ucs
< 0xa0))
1450 return opts
.control
;
1451 if (bisearch(ucs
, COMBINING_BMP
))
1453 if (isWideBMP(ucs
)) {
1458 function isWideBMP(ucs
) {
1459 return (ucs
>= 0x1100 && (ucs
<= 0x115f ||
1462 (ucs
>= 0x2e80 && ucs
<= 0xa4cf && ucs
!== 0x303f) ||
1463 (ucs
>= 0xac00 && ucs
<= 0xd7a3) ||
1464 (ucs
>= 0xf900 && ucs
<= 0xfaff) ||
1465 (ucs
>= 0xfe10 && ucs
<= 0xfe19) ||
1466 (ucs
>= 0xfe30 && ucs
<= 0xfe6f) ||
1467 (ucs
>= 0xff00 && ucs
<= 0xff60) ||
1468 (ucs
>= 0xffe0 && ucs
<= 0xffe6)));
1470 function wcwidthHigh(ucs
) {
1471 if (bisearch(ucs
, COMBINING_HIGH
))
1473 if ((ucs
>= 0x20000 && ucs
<= 0x2fffd) || (ucs
>= 0x30000 && ucs
<= 0x3fffd)) {
1478 var control
= opts
.control
| 0;
1480 function init_table() {
1481 var CODEPOINTS
= 65536;
1484 var CONTAINERSIZE
= CODEPOINTS
* BITWIDTH
/ ITEMSIZE
;
1485 var CODEPOINTS_PER_ITEM
= ITEMSIZE
/ BITWIDTH
;
1486 table
= (typeof Uint32Array
=== 'undefined')
1487 ? new Array(CONTAINERSIZE
)
1488 : new Uint32Array(CONTAINERSIZE
);
1489 for (var i
= 0; i
< CONTAINERSIZE
; ++i
) {
1491 var pos
= CODEPOINTS_PER_ITEM
;
1493 num
= (num
<< 2) | wcwidthBMP(CODEPOINTS_PER_ITEM
* i
+ pos
);
1498 return function (num
) {
1504 var t
= table
|| init_table();
1506 return t
[num
>> 4] >> ((num
& 15) << 1) & 3;
1507 return wcwidthHigh(num
);
1509 })({ nul
: 0, control
: 0 });
1513 },{"./Charsets":3,"./EscapeSequences":5}],8:[function(require
,module
,exports
){
1515 Object
.defineProperty(exports
, "__esModule", { value
: true });
1516 var INVALID_LINK_CLASS
= 'xterm-invalid-link';
1517 var protocolClause
= '(https?:\\/\\/)';
1518 var domainCharacterSet
= '[\\da-z\\.-]+';
1519 var negatedDomainCharacterSet
= '[^\\da-z\\.-]+';
1520 var domainBodyClause
= '(' + domainCharacterSet
+ ')';
1521 var tldClause
= '([a-z\\.]{2,6})';
1522 var ipClause
= '((\\d{1,3}\\.){3}\\d{1,3})';
1523 var localHostClause
= '(localhost)';
1524 var portClause
= '(:\\d{1,5})';
1525 var hostClause
= '((' + domainBodyClause
+ '\\.' + tldClause
+ ')|' + ipClause
+ '|' + localHostClause
+ ')' + portClause
+ '?';
1526 var pathClause
= '(\\/[\\/\\w\\.\\-%~]*)*';
1527 var queryStringHashFragmentCharacterSet
= '[0-9\\w\\[\\]\\(\\)\\/\\?\\!#@$%&\'*+,:;~\\=\\.\\-]*';
1528 var queryStringClause
= '(\\?' + queryStringHashFragmentCharacterSet
+ ')?';
1529 var hashFragmentClause
= '(#' + queryStringHashFragmentCharacterSet
+ ')?';
1530 var negatedPathCharacterSet
= '[^\\/\\w\\.\\-%]+';
1531 var bodyClause
= hostClause
+ pathClause
+ queryStringClause
+ hashFragmentClause
;
1532 var start
= '(?:^|' + negatedDomainCharacterSet
+ ')(';
1533 var end
= ')($|' + negatedPathCharacterSet
+ ')';
1534 var strictUrlRegex
= new RegExp(start
+ protocolClause
+ bodyClause
+ end
);
1535 var HYPERTEXT_LINK_MATCHER_ID
= 0;
1536 var Linkifier
= (function () {
1537 function Linkifier() {
1538 this._nextLinkMatcherId
= HYPERTEXT_LINK_MATCHER_ID
;
1539 this._rowTimeoutIds
= [];
1540 this._linkMatchers
= [];
1541 this.registerLinkMatcher(strictUrlRegex
, null, { matchIndex
: 1 });
1543 Linkifier
.prototype.attachToDom = function (document
, rows
) {
1544 this._document
= document
;
1547 Linkifier
.prototype.linkifyRow = function (rowIndex
) {
1548 if (!this._document
) {
1551 var timeoutId
= this._rowTimeoutIds
[rowIndex
];
1553 clearTimeout(timeoutId
);
1555 this._rowTimeoutIds
[rowIndex
] = setTimeout(this._linkifyRow
.bind(this, rowIndex
), Linkifier
.TIME_BEFORE_LINKIFY
);
1557 Linkifier
.prototype.setHypertextLinkHandler = function (handler
) {
1558 this._linkMatchers
[HYPERTEXT_LINK_MATCHER_ID
].handler
= handler
;
1560 Linkifier
.prototype.setHypertextValidationCallback = function (callback
) {
1561 this._linkMatchers
[HYPERTEXT_LINK_MATCHER_ID
].validationCallback
= callback
;
1563 Linkifier
.prototype.registerLinkMatcher = function (regex
, handler
, options
) {
1564 if (options
=== void 0) { options
= {}; }
1565 if (this._nextLinkMatcherId
!== HYPERTEXT_LINK_MATCHER_ID
&& !handler
) {
1566 throw new Error('handler must be defined');
1569 id
: this._nextLinkMatcherId
++,
1572 matchIndex
: options
.matchIndex
,
1573 validationCallback
: options
.validationCallback
,
1574 priority
: options
.priority
|| 0
1576 this._addLinkMatcherToList(matcher
);
1579 Linkifier
.prototype._addLinkMatcherToList = function (matcher
) {
1580 if (this._linkMatchers
.length
=== 0) {
1581 this._linkMatchers
.push(matcher
);
1584 for (var i
= this._linkMatchers
.length
- 1; i
>= 0; i
--) {
1585 if (matcher
.priority
<= this._linkMatchers
[i
].priority
) {
1586 this._linkMatchers
.splice(i
+ 1, 0, matcher
);
1590 this._linkMatchers
.splice(0, 0, matcher
);
1592 Linkifier
.prototype.deregisterLinkMatcher = function (matcherId
) {
1593 for (var i
= 1; i
< this._linkMatchers
.length
; i
++) {
1594 if (this._linkMatchers
[i
].id
=== matcherId
) {
1595 this._linkMatchers
.splice(i
, 1);
1601 Linkifier
.prototype._linkifyRow = function (rowIndex
) {
1602 var row
= this._rows
[rowIndex
];
1606 var text
= row
.textContent
;
1607 for (var i
= 0; i
< this._linkMatchers
.length
; i
++) {
1608 var matcher
= this._linkMatchers
[i
];
1609 var linkElements
= this._doLinkifyRow(row
, matcher
);
1610 if (linkElements
.length
> 0) {
1611 if (matcher
.validationCallback
) {
1612 var _loop_1 = function (j
) {
1613 var element
= linkElements
[j
];
1614 matcher
.validationCallback(element
.textContent
, element
, function (isValid
) {
1616 element
.classList
.add(INVALID_LINK_CLASS
);
1620 for (var j
= 0; j
< linkElements
.length
; j
++) {
1628 Linkifier
.prototype._doLinkifyRow = function (row
, matcher
) {
1630 var isHttpLinkMatcher
= matcher
.id
=== HYPERTEXT_LINK_MATCHER_ID
;
1631 var nodes
= row
.childNodes
;
1632 var match
= row
.textContent
.match(matcher
.regex
);
1633 if (!match
|| match
.length
=== 0) {
1636 var uri
= match
[typeof matcher
.matchIndex
!== 'number' ? 0 : matcher
.matchIndex
];
1637 var rowStartIndex
= match
.index
+ uri
.length
;
1638 for (var i
= 0; i
< nodes
.length
; i
++) {
1639 var node
= nodes
[i
];
1640 var searchIndex
= node
.textContent
.indexOf(uri
);
1641 if (searchIndex
>= 0) {
1642 var linkElement
= this._createAnchorElement(uri
, matcher
.handler
, isHttpLinkMatcher
);
1643 if (node
.textContent
.length
=== uri
.length
) {
1644 if (node
.nodeType
=== 3) {
1645 this._replaceNode(node
, linkElement
);
1649 if (element
.nodeName
=== 'A') {
1652 element
.innerHTML
= '';
1653 element
.appendChild(linkElement
);
1656 else if (node
.childNodes
.length
> 1) {
1657 for (var j
= 0; j
< node
.childNodes
.length
; j
++) {
1658 var childNode
= node
.childNodes
[j
];
1659 var childSearchIndex
= childNode
.textContent
.indexOf(uri
);
1660 if (childSearchIndex
!== -1) {
1661 this._replaceNodeSubstringWithNode(childNode
, linkElement
, uri
, childSearchIndex
);
1667 var nodesAdded
= this._replaceNodeSubstringWithNode(node
, linkElement
, uri
, searchIndex
);
1670 result
.push(linkElement
);
1671 match
= row
.textContent
.substring(rowStartIndex
).match(matcher
.regex
);
1672 if (!match
|| match
.length
=== 0) {
1675 uri
= match
[typeof matcher
.matchIndex
!== 'number' ? 0 : matcher
.matchIndex
];
1676 rowStartIndex
+= match
.index
+ uri
.length
;
1681 Linkifier
.prototype._createAnchorElement = function (uri
, handler
, isHypertextLinkHandler
) {
1682 var element
= this._document
.createElement('a');
1683 element
.textContent
= uri
;
1684 element
.draggable
= false;
1685 if (isHypertextLinkHandler
) {
1687 element
.target
= '_blank';
1688 element
.addEventListener('click', function (event
) {
1690 return handler(event
, uri
);
1695 element
.addEventListener('click', function (event
) {
1696 if (element
.classList
.contains(INVALID_LINK_CLASS
)) {
1699 return handler(event
, uri
);
1704 Linkifier
.prototype._replaceNode = function (oldNode
) {
1706 for (var _i
= 1; _i
< arguments
.length
; _i
++) {
1707 newNodes
[_i
- 1] = arguments
[_i
];
1709 var parent
= oldNode
.parentNode
;
1710 for (var i
= 0; i
< newNodes
.length
; i
++) {
1711 parent
.insertBefore(newNodes
[i
], oldNode
);
1713 parent
.removeChild(oldNode
);
1715 Linkifier
.prototype._replaceNodeSubstringWithNode = function (targetNode
, newNode
, substring
, substringIndex
) {
1716 if (targetNode
.childNodes
.length
=== 1) {
1717 targetNode
= targetNode
.childNodes
[0];
1719 if (targetNode
.nodeType
!== 3) {
1720 throw new Error('targetNode must be a text node or only contain a single text node');
1722 var fullText
= targetNode
.textContent
;
1723 if (substringIndex
=== 0) {
1724 var rightText_1
= fullText
.substring(substring
.length
);
1725 var rightTextNode_1
= this._document
.createTextNode(rightText_1
);
1726 this._replaceNode(targetNode
, newNode
, rightTextNode_1
);
1729 if (substringIndex
=== targetNode
.textContent
.length
- substring
.length
) {
1730 var leftText_1
= fullText
.substring(0, substringIndex
);
1731 var leftTextNode_1
= this._document
.createTextNode(leftText_1
);
1732 this._replaceNode(targetNode
, leftTextNode_1
, newNode
);
1735 var leftText
= fullText
.substring(0, substringIndex
);
1736 var leftTextNode
= this._document
.createTextNode(leftText
);
1737 var rightText
= fullText
.substring(substringIndex
+ substring
.length
);
1738 var rightTextNode
= this._document
.createTextNode(rightText
);
1739 this._replaceNode(targetNode
, leftTextNode
, newNode
, rightTextNode
);
1744 Linkifier
.TIME_BEFORE_LINKIFY
= 200;
1745 exports
.Linkifier
= Linkifier
;
1749 },{}],9:[function(require
,module
,exports
){
1751 Object
.defineProperty(exports
, "__esModule", { value
: true });
1752 var EscapeSequences_1
= require("./EscapeSequences");
1753 var Charsets_1
= require("./Charsets");
1754 var normalStateHandler
= {};
1755 normalStateHandler
[EscapeSequences_1
.C0
.BEL
] = function (parser
, handler
) { return handler
.bell(); };
1756 normalStateHandler
[EscapeSequences_1
.C0
.LF
] = function (parser
, handler
) { return handler
.lineFeed(); };
1757 normalStateHandler
[EscapeSequences_1
.C0
.VT
] = normalStateHandler
[EscapeSequences_1
.C0
.LF
];
1758 normalStateHandler
[EscapeSequences_1
.C0
.FF
] = normalStateHandler
[EscapeSequences_1
.C0
.LF
];
1759 normalStateHandler
[EscapeSequences_1
.C0
.CR
] = function (parser
, handler
) { return handler
.carriageReturn(); };
1760 normalStateHandler
[EscapeSequences_1
.C0
.BS
] = function (parser
, handler
) { return handler
.backspace(); };
1761 normalStateHandler
[EscapeSequences_1
.C0
.HT
] = function (parser
, handler
) { return handler
.tab(); };
1762 normalStateHandler
[EscapeSequences_1
.C0
.SO
] = function (parser
, handler
) { return handler
.shiftOut(); };
1763 normalStateHandler
[EscapeSequences_1
.C0
.SI
] = function (parser
, handler
) { return handler
.shiftIn(); };
1764 normalStateHandler
[EscapeSequences_1
.C0
.ESC
] = function (parser
, handler
) { return parser
.setState(ParserState
.ESCAPED
); };
1765 var escapedStateHandler
= {};
1766 escapedStateHandler
['['] = function (parser
, terminal
) {
1767 terminal
.params
= [];
1768 terminal
.currentParam
= 0;
1769 parser
.setState(ParserState
.CSI_PARAM
);
1771 escapedStateHandler
[']'] = function (parser
, terminal
) {
1772 terminal
.params
= [];
1773 terminal
.currentParam
= 0;
1774 parser
.setState(ParserState
.OSC
);
1776 escapedStateHandler
['P'] = function (parser
, terminal
) {
1777 terminal
.params
= [];
1778 terminal
.currentParam
= 0;
1779 parser
.setState(ParserState
.DCS
);
1781 escapedStateHandler
['_'] = function (parser
, terminal
) {
1782 parser
.setState(ParserState
.IGNORE
);
1784 escapedStateHandler
['^'] = function (parser
, terminal
) {
1785 parser
.setState(ParserState
.IGNORE
);
1787 escapedStateHandler
['c'] = function (parser
, terminal
) {
1790 escapedStateHandler
['E'] = function (parser
, terminal
) {
1791 terminal
.buffer
.x
= 0;
1793 parser
.setState(ParserState
.NORMAL
);
1795 escapedStateHandler
['D'] = function (parser
, terminal
) {
1797 parser
.setState(ParserState
.NORMAL
);
1799 escapedStateHandler
['M'] = function (parser
, terminal
) {
1800 terminal
.reverseIndex();
1801 parser
.setState(ParserState
.NORMAL
);
1803 escapedStateHandler
['%'] = function (parser
, terminal
) {
1804 terminal
.setgLevel(0);
1805 terminal
.setgCharset(0, Charsets_1
.DEFAULT_CHARSET
);
1806 parser
.setState(ParserState
.NORMAL
);
1807 parser
.skipNextChar();
1809 escapedStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (parser
) { return parser
.setState(ParserState
.NORMAL
); };
1810 var csiParamStateHandler
= {};
1811 csiParamStateHandler
['?'] = function (parser
) { return parser
.setPrefix('?'); };
1812 csiParamStateHandler
['>'] = function (parser
) { return parser
.setPrefix('>'); };
1813 csiParamStateHandler
['!'] = function (parser
) { return parser
.setPrefix('!'); };
1814 csiParamStateHandler
['0'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10); };
1815 csiParamStateHandler
['1'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 1); };
1816 csiParamStateHandler
['2'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 2); };
1817 csiParamStateHandler
['3'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 3); };
1818 csiParamStateHandler
['4'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 4); };
1819 csiParamStateHandler
['5'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 5); };
1820 csiParamStateHandler
['6'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 6); };
1821 csiParamStateHandler
['7'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 7); };
1822 csiParamStateHandler
['8'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 8); };
1823 csiParamStateHandler
['9'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 9); };
1824 csiParamStateHandler
['$'] = function (parser
) { return parser
.setPostfix('$'); };
1825 csiParamStateHandler
['"'] = function (parser
) { return parser
.setPostfix('"'); };
1826 csiParamStateHandler
[' '] = function (parser
) { return parser
.setPostfix(' '); };
1827 csiParamStateHandler
['\''] = function (parser
) { return parser
.setPostfix('\''); };
1828 csiParamStateHandler
[';'] = function (parser
) { return parser
.finalizeParam(); };
1829 csiParamStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (parser
) { return parser
.setState(ParserState
.NORMAL
); };
1830 var csiStateHandler
= {};
1831 csiStateHandler
['@'] = function (handler
, params
, prefix
) { return handler
.insertChars(params
); };
1832 csiStateHandler
['A'] = function (handler
, params
, prefix
) { return handler
.cursorUp(params
); };
1833 csiStateHandler
['B'] = function (handler
, params
, prefix
) { return handler
.cursorDown(params
); };
1834 csiStateHandler
['C'] = function (handler
, params
, prefix
) { return handler
.cursorForward(params
); };
1835 csiStateHandler
['D'] = function (handler
, params
, prefix
) { return handler
.cursorBackward(params
); };
1836 csiStateHandler
['E'] = function (handler
, params
, prefix
) { return handler
.cursorNextLine(params
); };
1837 csiStateHandler
['F'] = function (handler
, params
, prefix
) { return handler
.cursorPrecedingLine(params
); };
1838 csiStateHandler
['G'] = function (handler
, params
, prefix
) { return handler
.cursorCharAbsolute(params
); };
1839 csiStateHandler
['H'] = function (handler
, params
, prefix
) { return handler
.cursorPosition(params
); };
1840 csiStateHandler
['I'] = function (handler
, params
, prefix
) { return handler
.cursorForwardTab(params
); };
1841 csiStateHandler
['J'] = function (handler
, params
, prefix
) { return handler
.eraseInDisplay(params
); };
1842 csiStateHandler
['K'] = function (handler
, params
, prefix
) { return handler
.eraseInLine(params
); };
1843 csiStateHandler
['L'] = function (handler
, params
, prefix
) { return handler
.insertLines(params
); };
1844 csiStateHandler
['M'] = function (handler
, params
, prefix
) { return handler
.deleteLines(params
); };
1845 csiStateHandler
['P'] = function (handler
, params
, prefix
) { return handler
.deleteChars(params
); };
1846 csiStateHandler
['S'] = function (handler
, params
, prefix
) { return handler
.scrollUp(params
); };
1847 csiStateHandler
['T'] = function (handler
, params
, prefix
) {
1848 if (params
.length
< 2 && !prefix
) {
1849 handler
.scrollDown(params
);
1852 csiStateHandler
['X'] = function (handler
, params
, prefix
) { return handler
.eraseChars(params
); };
1853 csiStateHandler
['Z'] = function (handler
, params
, prefix
) { return handler
.cursorBackwardTab(params
); };
1854 csiStateHandler
['`'] = function (handler
, params
, prefix
) { return handler
.charPosAbsolute(params
); };
1855 csiStateHandler
['a'] = function (handler
, params
, prefix
) { return handler
.HPositionRelative(params
); };
1856 csiStateHandler
['b'] = function (handler
, params
, prefix
) { return handler
.repeatPrecedingCharacter(params
); };
1857 csiStateHandler
['c'] = function (handler
, params
, prefix
) { return handler
.sendDeviceAttributes(params
); };
1858 csiStateHandler
['d'] = function (handler
, params
, prefix
) { return handler
.linePosAbsolute(params
); };
1859 csiStateHandler
['e'] = function (handler
, params
, prefix
) { return handler
.VPositionRelative(params
); };
1860 csiStateHandler
['f'] = function (handler
, params
, prefix
) { return handler
.HVPosition(params
); };
1861 csiStateHandler
['g'] = function (handler
, params
, prefix
) { return handler
.tabClear(params
); };
1862 csiStateHandler
['h'] = function (handler
, params
, prefix
) { return handler
.setMode(params
); };
1863 csiStateHandler
['l'] = function (handler
, params
, prefix
) { return handler
.resetMode(params
); };
1864 csiStateHandler
['m'] = function (handler
, params
, prefix
) { return handler
.charAttributes(params
); };
1865 csiStateHandler
['n'] = function (handler
, params
, prefix
) { return handler
.deviceStatus(params
); };
1866 csiStateHandler
['p'] = function (handler
, params
, prefix
) {
1869 handler
.softReset(params
);
1873 csiStateHandler
['q'] = function (handler
, params
, prefix
, postfix
) {
1874 if (postfix
=== ' ') {
1875 handler
.setCursorStyle(params
);
1878 csiStateHandler
['r'] = function (handler
, params
) { return handler
.setScrollRegion(params
); };
1879 csiStateHandler
['s'] = function (handler
, params
) { return handler
.saveCursor(params
); };
1880 csiStateHandler
['u'] = function (handler
, params
) { return handler
.restoreCursor(params
); };
1881 csiStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (handler
, params
, prefix
, postfix
, parser
) { return parser
.setState(ParserState
.NORMAL
); };
1883 (function (ParserState
) {
1884 ParserState
[ParserState
["NORMAL"] = 0] = "NORMAL";
1885 ParserState
[ParserState
["ESCAPED"] = 1] = "ESCAPED";
1886 ParserState
[ParserState
["CSI_PARAM"] = 2] = "CSI_PARAM";
1887 ParserState
[ParserState
["CSI"] = 3] = "CSI";
1888 ParserState
[ParserState
["OSC"] = 4] = "OSC";
1889 ParserState
[ParserState
["CHARSET"] = 5] = "CHARSET";
1890 ParserState
[ParserState
["DCS"] = 6] = "DCS";
1891 ParserState
[ParserState
["IGNORE"] = 7] = "IGNORE";
1892 })(ParserState
|| (ParserState
= {}));
1893 var Parser
= (function () {
1894 function Parser(_inputHandler
, _terminal
) {
1895 this._inputHandler
= _inputHandler
;
1896 this._terminal
= _terminal
;
1897 this._state
= ParserState
.NORMAL
;
1899 Parser
.prototype.parse = function (data
) {
1900 var l
= data
.length
, j
, cs
, ch
, code
, low
;
1901 if (this._terminal
.debug
) {
1902 this._terminal
.log('data: ' + data
);
1905 if (this._terminal
.surrogate_high
) {
1906 data
= this._terminal
.surrogate_high
+ data
;
1907 this._terminal
.surrogate_high
= '';
1909 for (; this._position
< l
; this._position
++) {
1910 ch
= data
[this._position
];
1911 code
= data
.charCodeAt(this._position
);
1912 if (0xD800 <= code
&& code
<= 0xDBFF) {
1913 low
= data
.charCodeAt(this._position
+ 1);
1915 this._terminal
.surrogate_high
= ch
;
1918 code
= ((code
- 0xD800) * 0x400) + (low
- 0xDC00) + 0x10000;
1919 ch
+= data
.charAt(this._position
+ 1);
1921 if (0xDC00 <= code
&& code
<= 0xDFFF)
1923 switch (this._state
) {
1924 case ParserState
.NORMAL
:
1925 if (ch
in normalStateHandler
) {
1926 normalStateHandler
[ch
](this, this._inputHandler
);
1929 this._inputHandler
.addChar(ch
, code
);
1932 case ParserState
.ESCAPED
:
1933 if (ch
in escapedStateHandler
) {
1934 escapedStateHandler
[ch
](this, this._terminal
);
1946 this._terminal
.gcharset
= 0;
1949 this._terminal
.gcharset
= 1;
1952 this._terminal
.gcharset
= 2;
1955 this._terminal
.gcharset
= 3;
1958 this._terminal
.gcharset
= 1;
1961 this._terminal
.gcharset
= 2;
1964 this._state
= ParserState
.CHARSET
;
1967 this._terminal
.gcharset
= 3;
1968 this._state
= ParserState
.CHARSET
;
1976 this._terminal
.setgLevel(2);
1979 this._terminal
.setgLevel(3);
1982 this._terminal
.setgLevel(3);
1985 this._terminal
.setgLevel(2);
1988 this._terminal
.setgLevel(1);
1991 this._inputHandler
.saveCursor();
1992 this._state
= ParserState
.NORMAL
;
1995 this._inputHandler
.restoreCursor();
1996 this._state
= ParserState
.NORMAL
;
1999 this._state
= ParserState
.NORMAL
;
2003 this._terminal
.tabSet();
2004 this._state
= ParserState
.NORMAL
;
2007 this._terminal
.log('Serial port requested application keypad.');
2008 this._terminal
.applicationKeypad
= true;
2009 this._terminal
.viewport
.syncScrollArea();
2010 this._state
= ParserState
.NORMAL
;
2013 this._terminal
.log('Switching back to normal keypad.');
2014 this._terminal
.applicationKeypad
= false;
2015 this._terminal
.viewport
.syncScrollArea();
2016 this._state
= ParserState
.NORMAL
;
2019 this._state
= ParserState
.NORMAL
;
2020 this._terminal
.error('Unknown ESC control: %s.', ch
);
2024 case ParserState
.CHARSET
:
2025 if (ch
in Charsets_1
.CHARSETS
) {
2026 cs
= Charsets_1
.CHARSETS
[ch
];
2028 this.skipNextChar();
2032 cs
= Charsets_1
.DEFAULT_CHARSET
;
2034 this._terminal
.setgCharset(this._terminal
.gcharset
, cs
);
2035 this._terminal
.gcharset
= null;
2036 this._state
= ParserState
.NORMAL
;
2038 case ParserState
.OSC
:
2039 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
2040 if (ch
=== EscapeSequences_1
.C0
.ESC
)
2042 this._terminal
.params
.push(this._terminal
.currentParam
);
2043 switch (this._terminal
.params
[0]) {
2047 if (this._terminal
.params
[1]) {
2048 this._terminal
.title
= this._terminal
.params
[1];
2049 this._terminal
.handleTitle(this._terminal
.title
);
2089 this._terminal
.params
= [];
2090 this._terminal
.currentParam
= 0;
2091 this._state
= ParserState
.NORMAL
;
2094 if (!this._terminal
.params
.length
) {
2095 if (ch
>= '0' && ch
<= '9') {
2096 this._terminal
.currentParam
=
2097 this._terminal
.currentParam
* 10 + ch
.charCodeAt(0) - 48;
2099 else if (ch
=== ';') {
2100 this._terminal
.params
.push(this._terminal
.currentParam
);
2101 this._terminal
.currentParam
= '';
2105 this._terminal
.currentParam
+= ch
;
2109 case ParserState
.CSI_PARAM
:
2110 if (ch
in csiParamStateHandler
) {
2111 csiParamStateHandler
[ch
](this);
2114 this.finalizeParam();
2115 this._state
= ParserState
.CSI
;
2116 case ParserState
.CSI
:
2117 if (ch
in csiStateHandler
) {
2118 if (this._terminal
.debug
) {
2119 this._terminal
.log("CSI " + (this._terminal
.prefix
? this._terminal
.prefix
: '') + " " + (this._terminal
.params
? this._terminal
.params
.join(';') : '') + " " + (this._terminal
.postfix
? this._terminal
.postfix
: '') + " " + ch
);
2121 csiStateHandler
[ch
](this._inputHandler
, this._terminal
.params
, this._terminal
.prefix
, this._terminal
.postfix
, this);
2124 this._terminal
.error('Unknown CSI code: %s.', ch
);
2126 this._state
= ParserState
.NORMAL
;
2127 this._terminal
.prefix
= '';
2128 this._terminal
.postfix
= '';
2130 case ParserState
.DCS
:
2131 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
2132 if (ch
=== EscapeSequences_1
.C0
.ESC
)
2136 switch (this._terminal
.prefix
) {
2140 pt
= this._terminal
.currentParam
;
2151 + (this._terminal
.buffer
.scrollTop
+ 1)
2153 + (this._terminal
.buffer
.scrollBottom
+ 1)
2160 this._terminal
.error('Unknown DCS Pt: %s.', pt
);
2164 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ 'P' + +valid
+ '$r' + pt
+ EscapeSequences_1
.C0
.ESC
+ '\\');
2169 pt
= this._terminal
.currentParam
;
2171 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ 'P' + +valid
+ '+r' + pt
+ EscapeSequences_1
.C0
.ESC
+ '\\');
2174 this._terminal
.error('Unknown DCS prefix: %s.', this._terminal
.prefix
);
2177 this._terminal
.currentParam
= 0;
2178 this._terminal
.prefix
= '';
2179 this._state
= ParserState
.NORMAL
;
2181 else if (!this._terminal
.currentParam
) {
2182 if (!this._terminal
.prefix
&& ch
!== '$' && ch
!== '+') {
2183 this._terminal
.currentParam
= ch
;
2185 else if (this._terminal
.prefix
.length
=== 2) {
2186 this._terminal
.currentParam
= ch
;
2189 this._terminal
.prefix
+= ch
;
2193 this._terminal
.currentParam
+= ch
;
2196 case ParserState
.IGNORE
:
2197 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
2198 if (ch
=== EscapeSequences_1
.C0
.ESC
)
2200 this._state
= ParserState
.NORMAL
;
2207 Parser
.prototype.setState = function (state
) {
2208 this._state
= state
;
2210 Parser
.prototype.setPrefix = function (prefix
) {
2211 this._terminal
.prefix
= prefix
;
2213 Parser
.prototype.setPostfix = function (postfix
) {
2214 this._terminal
.postfix
= postfix
;
2216 Parser
.prototype.setParam = function (param
) {
2217 this._terminal
.currentParam
= param
;
2219 Parser
.prototype.getParam = function () {
2220 return this._terminal
.currentParam
;
2222 Parser
.prototype.finalizeParam = function () {
2223 this._terminal
.params
.push(this._terminal
.currentParam
);
2224 this._terminal
.currentParam
= 0;
2226 Parser
.prototype.skipNextChar = function () {
2231 exports
.Parser
= Parser
;
2235 },{"./Charsets":3,"./EscapeSequences":5}],10:[function(require
,module
,exports
){
2237 Object
.defineProperty(exports
, "__esModule", { value
: true });
2238 var DomElementObjectPool_1
= require("./utils/DomElementObjectPool");
2239 var MAX_REFRESH_FRAME_SKIP
= 5;
2242 FLAGS
[FLAGS
["BOLD"] = 1] = "BOLD";
2243 FLAGS
[FLAGS
["UNDERLINE"] = 2] = "UNDERLINE";
2244 FLAGS
[FLAGS
["BLINK"] = 4] = "BLINK";
2245 FLAGS
[FLAGS
["INVERSE"] = 8] = "INVERSE";
2246 FLAGS
[FLAGS
["INVISIBLE"] = 16] = "INVISIBLE";
2247 })(FLAGS
|| (FLAGS
= {}));
2249 var brokenBold
= null;
2250 var Renderer
= (function () {
2251 function Renderer(_terminal
) {
2252 this._terminal
= _terminal
;
2253 this._refreshRowsQueue
= [];
2254 this._refreshFramesSkipped
= 0;
2255 this._refreshAnimationFrame
= null;
2256 this._spanElementObjectPool
= new DomElementObjectPool_1
.DomElementObjectPool('span');
2257 if (brokenBold
=== null) {
2258 brokenBold
= checkBoldBroken(this._terminal
.element
);
2260 this._spanElementObjectPool
= new DomElementObjectPool_1
.DomElementObjectPool('span');
2262 Renderer
.prototype.queueRefresh = function (start
, end
) {
2263 this._refreshRowsQueue
.push({ start
: start
, end
: end
});
2264 if (!this._refreshAnimationFrame
) {
2265 this._refreshAnimationFrame
= window
.requestAnimationFrame(this._refreshLoop
.bind(this));
2268 Renderer
.prototype._refreshLoop = function () {
2269 var skipFrame
= this._terminal
.writeBuffer
.length
> 0 && this._refreshFramesSkipped
++ <= MAX_REFRESH_FRAME_SKIP
;
2271 this._refreshAnimationFrame
= window
.requestAnimationFrame(this._refreshLoop
.bind(this));
2274 this._refreshFramesSkipped
= 0;
2277 if (this._refreshRowsQueue
.length
> 4) {
2279 end
= this._terminal
.rows
- 1;
2282 start
= this._refreshRowsQueue
[0].start
;
2283 end
= this._refreshRowsQueue
[0].end
;
2284 for (var i
= 1; i
< this._refreshRowsQueue
.length
; i
++) {
2285 if (this._refreshRowsQueue
[i
].start
< start
) {
2286 start
= this._refreshRowsQueue
[i
].start
;
2288 if (this._refreshRowsQueue
[i
].end
> end
) {
2289 end
= this._refreshRowsQueue
[i
].end
;
2293 this._refreshRowsQueue
= [];
2294 this._refreshAnimationFrame
= null;
2295 this._refresh(start
, end
);
2297 Renderer
.prototype._refresh = function (start
, end
) {
2299 if (end
- start
>= this._terminal
.rows
/ 2) {
2300 parent
= this._terminal
.element
.parentNode
;
2302 this._terminal
.element
.removeChild(this._terminal
.rowContainer
);
2305 var width
= this._terminal
.cols
;
2307 if (end
>= this._terminal
.rows
) {
2308 this._terminal
.log('`end` is too large. Most likely a bad CSR.');
2309 end
= this._terminal
.rows
- 1;
2311 for (; y
<= end
; y
++) {
2312 var row
= y
+ this._terminal
.buffer
.ydisp
;
2313 var line
= this._terminal
.buffer
.lines
.get(row
);
2315 if (this._terminal
.buffer
.y
=== y
- (this._terminal
.buffer
.ybase
- this._terminal
.buffer
.ydisp
) &&
2316 this._terminal
.cursorState
&&
2317 !this._terminal
.cursorHidden
) {
2318 x
= this._terminal
.buffer
.x
;
2323 var attr
= this._terminal
.defAttr
;
2324 var documentFragment
= document
.createDocumentFragment();
2326 var currentElement
= void 0;
2327 while (this._terminal
.children
[y
].children
.length
) {
2328 var child
= this._terminal
.children
[y
].children
[0];
2329 this._terminal
.children
[y
].removeChild(child
);
2330 this._spanElementObjectPool
.release(child
);
2332 for (var i
= 0; i
< width
; i
++) {
2333 var data
= line
[i
][0];
2334 var ch
= line
[i
][1];
2335 var ch_width
= line
[i
][2];
2336 var isCursor
= i
=== x
;
2340 if (data
!== attr
|| isCursor
) {
2341 if (attr
!== this._terminal
.defAttr
&& !isCursor
) {
2343 currentElement
.innerHTML
= innerHTML
;
2346 documentFragment
.appendChild(currentElement
);
2347 currentElement
= null;
2349 if (data
!== this._terminal
.defAttr
|| isCursor
) {
2350 if (innerHTML
&& !currentElement
) {
2351 currentElement
= this._spanElementObjectPool
.acquire();
2353 if (currentElement
) {
2355 currentElement
.innerHTML
= innerHTML
;
2358 documentFragment
.appendChild(currentElement
);
2360 currentElement
= this._spanElementObjectPool
.acquire();
2361 var bg
= data
& 0x1ff;
2362 var fg
= (data
>> 9) & 0x1ff;
2363 var flags
= data
>> 18;
2365 currentElement
.classList
.add('reverse-video');
2366 currentElement
.classList
.add('terminal-cursor');
2368 if (flags
& FLAGS
.BOLD
) {
2370 currentElement
.classList
.add('xterm-bold');
2376 if (flags
& FLAGS
.UNDERLINE
) {
2377 currentElement
.classList
.add('xterm-underline');
2379 if (flags
& FLAGS
.BLINK
) {
2380 currentElement
.classList
.add('xterm-blink');
2382 if (flags
& FLAGS
.INVERSE
) {
2386 if ((flags
& 1) && fg
< 8) {
2390 if (flags
& FLAGS
.INVISIBLE
&& !isCursor
) {
2391 currentElement
.classList
.add('xterm-hidden');
2393 if (flags
& FLAGS
.INVERSE
) {
2402 currentElement
.classList
.add("xterm-bg-color-" + bg
);
2405 currentElement
.classList
.add("xterm-color-" + fg
);
2409 if (ch_width
=== 2) {
2410 innerHTML
+= "<span class=\"xterm-wide-char\">" + ch
+ "</span>";
2412 else if (ch
.charCodeAt(0) > 255) {
2413 innerHTML
+= "<span class=\"xterm-normal-char\">" + ch
+ "</span>";
2418 innerHTML
+= '&';
2421 innerHTML
+= '<';
2424 innerHTML
+= '>';
2428 innerHTML
+= ' ';
2436 attr
= isCursor
? -1 : data
;
2438 if (innerHTML
&& !currentElement
) {
2439 currentElement
= this._spanElementObjectPool
.acquire();
2441 if (currentElement
) {
2443 currentElement
.innerHTML
= innerHTML
;
2446 documentFragment
.appendChild(currentElement
);
2447 currentElement
= null;
2449 this._terminal
.children
[y
].appendChild(documentFragment
);
2452 this._terminal
.element
.appendChild(this._terminal
.rowContainer
);
2454 this._terminal
.emit('refresh', { element
: this._terminal
.element
, start
: start
, end
: end
});
2457 Renderer
.prototype.refreshSelection = function (start
, end
) {
2458 while (this._terminal
.selectionContainer
.children
.length
) {
2459 this._terminal
.selectionContainer
.removeChild(this._terminal
.selectionContainer
.children
[0]);
2461 if (!start
|| !end
) {
2464 var viewportStartRow
= start
[1] - this._terminal
.buffer
.ydisp
;
2465 var viewportEndRow
= end
[1] - this._terminal
.buffer
.ydisp
;
2466 var viewportCappedStartRow
= Math
.max(viewportStartRow
, 0);
2467 var viewportCappedEndRow
= Math
.min(viewportEndRow
, this._terminal
.rows
- 1);
2468 if (viewportCappedStartRow
>= this._terminal
.rows
|| viewportCappedEndRow
< 0) {
2471 var documentFragment
= document
.createDocumentFragment();
2472 var startCol
= viewportStartRow
=== viewportCappedStartRow
? start
[0] : 0;
2473 var endCol
= viewportCappedStartRow
=== viewportCappedEndRow
? end
[0] : this._terminal
.cols
;
2474 documentFragment
.appendChild(this._createSelectionElement(viewportCappedStartRow
, startCol
, endCol
));
2475 var middleRowsCount
= viewportCappedEndRow
- viewportCappedStartRow
- 1;
2476 documentFragment
.appendChild(this._createSelectionElement(viewportCappedStartRow
+ 1, 0, this._terminal
.cols
, middleRowsCount
));
2477 if (viewportCappedStartRow
!== viewportCappedEndRow
) {
2478 var endCol_1
= viewportEndRow
=== viewportCappedEndRow
? end
[0] : this._terminal
.cols
;
2479 documentFragment
.appendChild(this._createSelectionElement(viewportCappedEndRow
, 0, endCol_1
));
2481 this._terminal
.selectionContainer
.appendChild(documentFragment
);
2483 Renderer
.prototype._createSelectionElement = function (row
, colStart
, colEnd
, rowCount
) {
2484 if (rowCount
=== void 0) { rowCount
= 1; }
2485 var element
= document
.createElement('div');
2486 element
.style
.height
= rowCount
* this._terminal
.charMeasure
.height
+ "px";
2487 element
.style
.top
= row
* this._terminal
.charMeasure
.height
+ "px";
2488 element
.style
.left
= colStart
* this._terminal
.charMeasure
.width
+ "px";
2489 element
.style
.width
= this._terminal
.charMeasure
.width
* (colEnd
- colStart
) + "px";
2494 exports
.Renderer
= Renderer
;
2495 function checkBoldBroken(terminal
) {
2496 var document
= terminal
.ownerDocument
;
2497 var el
= document
.createElement('span');
2498 el
.innerHTML
= 'hello world';
2499 terminal
.appendChild(el
);
2500 var w1
= el
.offsetWidth
;
2501 var h1
= el
.offsetHeight
;
2502 el
.style
.fontWeight
= 'bold';
2503 var w2
= el
.offsetWidth
;
2504 var h2
= el
.offsetHeight
;
2505 terminal
.removeChild(el
);
2506 return w1
!== w2
|| h1
!== h2
;
2511 },{"./utils/DomElementObjectPool":19}],11:[function(require
,module
,exports
){
2513 var __extends
= (this && this.__extends
) || (function () {
2514 var extendStatics
= Object
.setPrototypeOf
||
2515 ({ __proto__
: [] } instanceof Array
&& function (d
, b
) { d
.__proto__
= b
; }) ||
2516 function (d
, b
) { for (var p
in b
) if (b
.hasOwnProperty(p
)) d
[p
] = b
[p
]; };
2517 return function (d
, b
) {
2518 extendStatics(d
, b
);
2519 function __() { this.constructor = d
; }
2520 d
.prototype = b
=== null ? Object
.create(b
) : (__
.prototype = b
.prototype, new __());
2523 Object
.defineProperty(exports
, "__esModule", { value
: true });
2524 var Mouse
= require("./utils/Mouse");
2525 var Browser
= require("./utils/Browser");
2526 var EventEmitter_1
= require("./EventEmitter");
2527 var SelectionModel_1
= require("./SelectionModel");
2528 var BufferLine_1
= require("./utils/BufferLine");
2529 var DRAG_SCROLL_MAX_THRESHOLD
= 50;
2530 var DRAG_SCROLL_MAX_SPEED
= 15;
2531 var DRAG_SCROLL_INTERVAL
= 50;
2532 var WORD_SEPARATORS
= ' ()[]{}\'"';
2533 var LINE_DATA_CHAR_INDEX
= 1;
2534 var LINE_DATA_WIDTH_INDEX
= 2;
2535 var NON_BREAKING_SPACE_CHAR
= String
.fromCharCode(160);
2536 var ALL_NON_BREAKING_SPACE_REGEX
= new RegExp(NON_BREAKING_SPACE_CHAR
, 'g');
2538 (function (SelectionMode
) {
2539 SelectionMode
[SelectionMode
["NORMAL"] = 0] = "NORMAL";
2540 SelectionMode
[SelectionMode
["WORD"] = 1] = "WORD";
2541 SelectionMode
[SelectionMode
["LINE"] = 2] = "LINE";
2542 })(SelectionMode
|| (SelectionMode
= {}));
2543 var SelectionManager
= (function (_super
) {
2544 __extends(SelectionManager
, _super
);
2545 function SelectionManager(_terminal
, _buffer
, _rowContainer
, _charMeasure
) {
2546 var _this
= _super
.call(this) || this;
2547 _this
._terminal
= _terminal
;
2548 _this
._buffer
= _buffer
;
2549 _this
._rowContainer
= _rowContainer
;
2550 _this
._charMeasure
= _charMeasure
;
2551 _this
._enabled
= true;
2552 _this
._initListeners();
2554 _this
._model
= new SelectionModel_1
.SelectionModel(_terminal
);
2555 _this
._activeSelectionMode
= SelectionMode
.NORMAL
;
2558 SelectionManager
.prototype._initListeners = function () {
2560 this._mouseMoveListener = function (event
) { return _this
._onMouseMove(event
); };
2561 this._mouseUpListener = function (event
) { return _this
._onMouseUp(event
); };
2562 this._rowContainer
.addEventListener('mousedown', function (event
) { return _this
._onMouseDown(event
); });
2563 this._buffer
.on('trim', function (amount
) { return _this
._onTrim(amount
); });
2565 SelectionManager
.prototype.disable = function () {
2566 this.clearSelection();
2567 this._enabled
= false;
2569 SelectionManager
.prototype.enable = function () {
2570 this._enabled
= true;
2572 SelectionManager
.prototype.setBuffer = function (buffer
) {
2573 this._buffer
= buffer
;
2574 this.clearSelection();
2576 Object
.defineProperty(SelectionManager
.prototype, "selectionStart", {
2577 get: function () { return this._model
.finalSelectionStart
; },
2581 Object
.defineProperty(SelectionManager
.prototype, "selectionEnd", {
2582 get: function () { return this._model
.finalSelectionEnd
; },
2586 Object
.defineProperty(SelectionManager
.prototype, "hasSelection", {
2588 var start
= this._model
.finalSelectionStart
;
2589 var end
= this._model
.finalSelectionEnd
;
2590 if (!start
|| !end
) {
2593 return start
[0] !== end
[0] || start
[1] !== end
[1];
2598 Object
.defineProperty(SelectionManager
.prototype, "selectionText", {
2600 var start
= this._model
.finalSelectionStart
;
2601 var end
= this._model
.finalSelectionEnd
;
2602 if (!start
|| !end
) {
2605 var startRowEndCol
= start
[1] === end
[1] ? end
[0] : null;
2607 result
.push(BufferLine_1
.translateBufferLineToString(this._buffer
.get(start
[1]), true, start
[0], startRowEndCol
));
2608 for (var i
= start
[1] + 1; i
<= end
[1] - 1; i
++) {
2609 var bufferLine
= this._buffer
.get(i
);
2610 var lineText
= BufferLine_1
.translateBufferLineToString(bufferLine
, true);
2611 if (bufferLine
.isWrapped
) {
2612 result
[result
.length
- 1] += lineText
;
2615 result
.push(lineText
);
2618 if (start
[1] !== end
[1]) {
2619 var bufferLine
= this._buffer
.get(end
[1]);
2620 var lineText
= BufferLine_1
.translateBufferLineToString(bufferLine
, true, 0, end
[0]);
2621 if (bufferLine
.isWrapped
) {
2622 result
[result
.length
- 1] += lineText
;
2625 result
.push(lineText
);
2628 var formattedResult
= result
.map(function (line
) {
2629 return line
.replace(ALL_NON_BREAKING_SPACE_REGEX
, ' ');
2630 }).join(Browser
.isMSWindows
? '\r\n' : '\n');
2631 return formattedResult
;
2636 SelectionManager
.prototype.clearSelection = function () {
2637 this._model
.clearSelection();
2638 this._removeMouseDownListeners();
2641 SelectionManager
.prototype.refresh = function (isNewSelection
) {
2643 if (!this._refreshAnimationFrame
) {
2644 this._refreshAnimationFrame
= window
.requestAnimationFrame(function () { return _this
._refresh(); });
2646 if (Browser
.isLinux
&& isNewSelection
) {
2647 var selectionText
= this.selectionText
;
2648 if (selectionText
.length
) {
2649 this.emit('newselection', this.selectionText
);
2653 SelectionManager
.prototype._refresh = function () {
2654 this._refreshAnimationFrame
= null;
2655 this.emit('refresh', { start
: this._model
.finalSelectionStart
, end
: this._model
.finalSelectionEnd
});
2657 SelectionManager
.prototype.selectAll = function () {
2658 this._model
.isSelectAllActive
= true;
2661 SelectionManager
.prototype._onTrim = function (amount
) {
2662 var needsRefresh
= this._model
.onTrim(amount
);
2667 SelectionManager
.prototype._getMouseBufferCoords = function (event
) {
2668 var coords
= Mouse
.getCoords(event
, this._rowContainer
, this._charMeasure
, this._terminal
.cols
, this._terminal
.rows
, true);
2674 coords
[1] += this._terminal
.buffer
.ydisp
;
2677 SelectionManager
.prototype._getMouseEventScrollAmount = function (event
) {
2678 var offset
= Mouse
.getCoordsRelativeToElement(event
, this._rowContainer
)[1];
2679 var terminalHeight
= this._terminal
.rows
* this._charMeasure
.height
;
2680 if (offset
>= 0 && offset
<= terminalHeight
) {
2683 if (offset
> terminalHeight
) {
2684 offset
-= terminalHeight
;
2686 offset
= Math
.min(Math
.max(offset
, -DRAG_SCROLL_MAX_THRESHOLD
), DRAG_SCROLL_MAX_THRESHOLD
);
2687 offset
/= DRAG_SCROLL_MAX_THRESHOLD
;
2688 return (offset
/ Math
.abs(offset
)) + Math
.round(offset
* (DRAG_SCROLL_MAX_SPEED
- 1));
2690 SelectionManager
.prototype._onMouseDown = function (event
) {
2691 if (event
.button
=== 2 && this.hasSelection
) {
2692 event
.stopPropagation();
2695 if (event
.button
!== 0) {
2698 if (!this._enabled
) {
2699 var shouldForceSelection
= Browser
.isMac
&& event
.altKey
;
2700 if (!shouldForceSelection
) {
2703 event
.stopPropagation();
2705 event
.preventDefault();
2706 this._dragScrollAmount
= 0;
2707 if (this._enabled
&& event
.shiftKey
) {
2708 this._onIncrementalClick(event
);
2711 if (event
.detail
=== 1) {
2712 this._onSingleClick(event
);
2714 else if (event
.detail
=== 2) {
2715 this._onDoubleClick(event
);
2717 else if (event
.detail
=== 3) {
2718 this._onTripleClick(event
);
2721 this._addMouseDownListeners();
2724 SelectionManager
.prototype._addMouseDownListeners = function () {
2726 this._rowContainer
.ownerDocument
.addEventListener('mousemove', this._mouseMoveListener
);
2727 this._rowContainer
.ownerDocument
.addEventListener('mouseup', this._mouseUpListener
);
2728 this._dragScrollIntervalTimer
= setInterval(function () { return _this
._dragScroll(); }, DRAG_SCROLL_INTERVAL
);
2730 SelectionManager
.prototype._removeMouseDownListeners = function () {
2731 this._rowContainer
.ownerDocument
.removeEventListener('mousemove', this._mouseMoveListener
);
2732 this._rowContainer
.ownerDocument
.removeEventListener('mouseup', this._mouseUpListener
);
2733 clearInterval(this._dragScrollIntervalTimer
);
2734 this._dragScrollIntervalTimer
= null;
2736 SelectionManager
.prototype._onIncrementalClick = function (event
) {
2737 if (this._model
.selectionStart
) {
2738 this._model
.selectionEnd
= this._getMouseBufferCoords(event
);
2741 SelectionManager
.prototype._onSingleClick = function (event
) {
2742 this._model
.selectionStartLength
= 0;
2743 this._model
.isSelectAllActive
= false;
2744 this._activeSelectionMode
= SelectionMode
.NORMAL
;
2745 this._model
.selectionStart
= this._getMouseBufferCoords(event
);
2746 if (!this._model
.selectionStart
) {
2749 this._model
.selectionEnd
= null;
2750 var line
= this._buffer
.get(this._model
.selectionStart
[1]);
2754 var char = line
[this._model
.selectionStart
[0]];
2755 if (char[LINE_DATA_WIDTH_INDEX
] === 0) {
2756 this._model
.selectionStart
[0]++;
2759 SelectionManager
.prototype._onDoubleClick = function (event
) {
2760 var coords
= this._getMouseBufferCoords(event
);
2762 this._activeSelectionMode
= SelectionMode
.WORD
;
2763 this._selectWordAt(coords
);
2766 SelectionManager
.prototype._onTripleClick = function (event
) {
2767 var coords
= this._getMouseBufferCoords(event
);
2769 this._activeSelectionMode
= SelectionMode
.LINE
;
2770 this._selectLineAt(coords
[1]);
2773 SelectionManager
.prototype._onMouseMove = function (event
) {
2774 var previousSelectionEnd
= this._model
.selectionEnd
? [this._model
.selectionEnd
[0], this._model
.selectionEnd
[1]] : null;
2775 this._model
.selectionEnd
= this._getMouseBufferCoords(event
);
2776 if (!this._model
.selectionEnd
) {
2780 if (this._activeSelectionMode
=== SelectionMode
.LINE
) {
2781 if (this._model
.selectionEnd
[1] < this._model
.selectionStart
[1]) {
2782 this._model
.selectionEnd
[0] = 0;
2785 this._model
.selectionEnd
[0] = this._terminal
.cols
;
2788 else if (this._activeSelectionMode
=== SelectionMode
.WORD
) {
2789 this._selectToWordAt(this._model
.selectionEnd
);
2791 this._dragScrollAmount
= this._getMouseEventScrollAmount(event
);
2792 if (this._dragScrollAmount
> 0) {
2793 this._model
.selectionEnd
[0] = this._terminal
.cols
- 1;
2795 else if (this._dragScrollAmount
< 0) {
2796 this._model
.selectionEnd
[0] = 0;
2798 if (this._model
.selectionEnd
[1] < this._buffer
.length
) {
2799 var char = this._buffer
.get(this._model
.selectionEnd
[1])[this._model
.selectionEnd
[0]];
2800 if (char && char[2] === 0) {
2801 this._model
.selectionEnd
[0]++;
2804 if (!previousSelectionEnd
||
2805 previousSelectionEnd
[0] !== this._model
.selectionEnd
[0] ||
2806 previousSelectionEnd
[1] !== this._model
.selectionEnd
[1]) {
2810 SelectionManager
.prototype._dragScroll = function () {
2811 if (this._dragScrollAmount
) {
2812 this._terminal
.scrollDisp(this._dragScrollAmount
, false);
2813 if (this._dragScrollAmount
> 0) {
2814 this._model
.selectionEnd
= [this._terminal
.cols
- 1, this._terminal
.buffer
.ydisp
+ this._terminal
.rows
];
2817 this._model
.selectionEnd
= [0, this._terminal
.buffer
.ydisp
];
2822 SelectionManager
.prototype._onMouseUp = function (event
) {
2823 this._removeMouseDownListeners();
2825 SelectionManager
.prototype._convertViewportColToCharacterIndex = function (bufferLine
, coords
) {
2826 var charIndex
= coords
[0];
2827 for (var i
= 0; coords
[0] >= i
; i
++) {
2828 var char = bufferLine
[i
];
2829 if (char[LINE_DATA_WIDTH_INDEX
] === 0) {
2835 SelectionManager
.prototype.setSelection = function (col
, row
, length
) {
2836 this._model
.clearSelection();
2837 this._removeMouseDownListeners();
2838 this._model
.selectionStart
= [col
, row
];
2839 this._model
.selectionStartLength
= length
;
2842 SelectionManager
.prototype._getWordAt = function (coords
) {
2843 var bufferLine
= this._buffer
.get(coords
[1]);
2847 var line
= BufferLine_1
.translateBufferLineToString(bufferLine
, false);
2848 var endIndex
= this._convertViewportColToCharacterIndex(bufferLine
, coords
);
2849 var startIndex
= endIndex
;
2850 var charOffset
= coords
[0] - startIndex
;
2851 var leftWideCharCount
= 0;
2852 var rightWideCharCount
= 0;
2853 if (line
.charAt(startIndex
) === ' ') {
2854 while (startIndex
> 0 && line
.charAt(startIndex
- 1) === ' ') {
2857 while (endIndex
< line
.length
&& line
.charAt(endIndex
+ 1) === ' ') {
2862 var startCol
= coords
[0];
2863 var endCol
= coords
[0];
2864 if (bufferLine
[startCol
][LINE_DATA_WIDTH_INDEX
] === 0) {
2865 leftWideCharCount
++;
2868 if (bufferLine
[endCol
][LINE_DATA_WIDTH_INDEX
] === 2) {
2869 rightWideCharCount
++;
2872 while (startIndex
> 0 && !this._isCharWordSeparator(line
.charAt(startIndex
- 1))) {
2873 if (bufferLine
[startCol
- 1][LINE_DATA_WIDTH_INDEX
] === 0) {
2874 leftWideCharCount
++;
2880 while (endIndex
+ 1 < line
.length
&& !this._isCharWordSeparator(line
.charAt(endIndex
+ 1))) {
2881 if (bufferLine
[endCol
+ 1][LINE_DATA_WIDTH_INDEX
] === 2) {
2882 rightWideCharCount
++;
2889 var start
= startIndex
+ charOffset
- leftWideCharCount
;
2890 var length
= Math
.min(endIndex
- startIndex
+ leftWideCharCount
+ rightWideCharCount
+ 1, this._terminal
.cols
);
2891 return { start
: start
, length
: length
};
2893 SelectionManager
.prototype._selectWordAt = function (coords
) {
2894 var wordPosition
= this._getWordAt(coords
);
2896 this._model
.selectionStart
= [wordPosition
.start
, coords
[1]];
2897 this._model
.selectionStartLength
= wordPosition
.length
;
2900 SelectionManager
.prototype._selectToWordAt = function (coords
) {
2901 var wordPosition
= this._getWordAt(coords
);
2903 this._model
.selectionEnd
= [this._model
.areSelectionValuesReversed() ? wordPosition
.start
: (wordPosition
.start
+ wordPosition
.length
), coords
[1]];
2906 SelectionManager
.prototype._isCharWordSeparator = function (char) {
2907 return WORD_SEPARATORS
.indexOf(char) >= 0;
2909 SelectionManager
.prototype._selectLineAt = function (line
) {
2910 this._model
.selectionStart
= [0, line
];
2911 this._model
.selectionStartLength
= this._terminal
.cols
;
2913 return SelectionManager
;
2914 }(EventEmitter_1
.EventEmitter
));
2915 exports
.SelectionManager
= SelectionManager
;
2919 },{"./EventEmitter":6,"./SelectionModel":12,"./utils/Browser":15,"./utils/BufferLine":16,"./utils/Mouse":21}],12:[function(require
,module
,exports
){
2921 Object
.defineProperty(exports
, "__esModule", { value
: true });
2922 var SelectionModel
= (function () {
2923 function SelectionModel(_terminal
) {
2924 this._terminal
= _terminal
;
2925 this.clearSelection();
2927 SelectionModel
.prototype.clearSelection = function () {
2928 this.selectionStart
= null;
2929 this.selectionEnd
= null;
2930 this.isSelectAllActive
= false;
2931 this.selectionStartLength
= 0;
2933 Object
.defineProperty(SelectionModel
.prototype, "finalSelectionStart", {
2935 if (this.isSelectAllActive
) {
2938 if (!this.selectionEnd
|| !this.selectionStart
) {
2939 return this.selectionStart
;
2941 return this.areSelectionValuesReversed() ? this.selectionEnd
: this.selectionStart
;
2946 Object
.defineProperty(SelectionModel
.prototype, "finalSelectionEnd", {
2948 if (this.isSelectAllActive
) {
2949 return [this._terminal
.cols
, this._terminal
.buffer
.ybase
+ this._terminal
.rows
- 1];
2951 if (!this.selectionStart
) {
2954 if (!this.selectionEnd
|| this.areSelectionValuesReversed()) {
2955 return [this.selectionStart
[0] + this.selectionStartLength
, this.selectionStart
[1]];
2957 if (this.selectionStartLength
) {
2958 if (this.selectionEnd
[1] === this.selectionStart
[1]) {
2959 return [Math
.max(this.selectionStart
[0] + this.selectionStartLength
, this.selectionEnd
[0]), this.selectionEnd
[1]];
2962 return this.selectionEnd
;
2967 SelectionModel
.prototype.areSelectionValuesReversed = function () {
2968 var start
= this.selectionStart
;
2969 var end
= this.selectionEnd
;
2970 return start
[1] > end
[1] || (start
[1] === end
[1] && start
[0] > end
[0]);
2972 SelectionModel
.prototype.onTrim = function (amount
) {
2973 if (this.selectionStart
) {
2974 this.selectionStart
[1] -= amount
;
2976 if (this.selectionEnd
) {
2977 this.selectionEnd
[1] -= amount
;
2979 if (this.selectionEnd
&& this.selectionEnd
[1] < 0) {
2980 this.clearSelection();
2983 if (this.selectionStart
&& this.selectionStart
[1] < 0) {
2984 this.selectionStart
[1] = 0;
2988 return SelectionModel
;
2990 exports
.SelectionModel
= SelectionModel
;
2994 },{}],13:[function(require
,module
,exports
){
2996 Object
.defineProperty(exports
, "__esModule", { value
: true });
2997 var Viewport
= (function () {
2998 function Viewport(terminal
, viewportElement
, scrollArea
, charMeasure
) {
3000 this.terminal
= terminal
;
3001 this.viewportElement
= viewportElement
;
3002 this.scrollArea
= scrollArea
;
3003 this.charMeasure
= charMeasure
;
3004 this.currentRowHeight
= 0;
3005 this.lastRecordedBufferLength
= 0;
3006 this.lastRecordedViewportHeight
= 0;
3007 this.terminal
.on('scroll', this.syncScrollArea
.bind(this));
3008 this.terminal
.on('resize', this.syncScrollArea
.bind(this));
3009 this.viewportElement
.addEventListener('scroll', this.onScroll
.bind(this));
3010 setTimeout(function () { return _this
.syncScrollArea(); }, 0);
3012 Viewport
.prototype.refresh = function () {
3013 if (this.charMeasure
.height
> 0) {
3014 var rowHeightChanged
= this.charMeasure
.height
!== this.currentRowHeight
;
3015 if (rowHeightChanged
) {
3016 this.currentRowHeight
= this.charMeasure
.height
;
3017 this.viewportElement
.style
.lineHeight
= this.charMeasure
.height
+ 'px';
3018 this.terminal
.rowContainer
.style
.lineHeight
= this.charMeasure
.height
+ 'px';
3020 var viewportHeightChanged
= this.lastRecordedViewportHeight
!== this.terminal
.rows
;
3021 if (rowHeightChanged
|| viewportHeightChanged
) {
3022 this.lastRecordedViewportHeight
= this.terminal
.rows
;
3023 this.viewportElement
.style
.height
= this.charMeasure
.height
* this.terminal
.rows
+ 'px';
3024 this.terminal
.selectionContainer
.style
.height
= this.viewportElement
.style
.height
;
3026 this.scrollArea
.style
.height
= (this.charMeasure
.height
* this.lastRecordedBufferLength
) + 'px';
3029 Viewport
.prototype.syncScrollArea = function () {
3030 if (this.lastRecordedBufferLength
!== this.terminal
.buffer
.lines
.length
) {
3031 this.lastRecordedBufferLength
= this.terminal
.buffer
.lines
.length
;
3034 else if (this.lastRecordedViewportHeight
!== this.terminal
.rows
) {
3038 if (this.charMeasure
.height
!== this.currentRowHeight
) {
3042 var scrollTop
= this.terminal
.buffer
.ydisp
* this.currentRowHeight
;
3043 if (this.viewportElement
.scrollTop
!== scrollTop
) {
3044 this.viewportElement
.scrollTop
= scrollTop
;
3047 Viewport
.prototype.onScroll = function (ev
) {
3048 var newRow
= Math
.round(this.viewportElement
.scrollTop
/ this.currentRowHeight
);
3049 var diff
= newRow
- this.terminal
.buffer
.ydisp
;
3050 this.terminal
.scrollDisp(diff
, true);
3052 Viewport
.prototype.onWheel = function (ev
) {
3053 if (ev
.deltaY
=== 0) {
3057 if (ev
.deltaMode
=== WheelEvent
.DOM_DELTA_LINE
) {
3058 multiplier
= this.currentRowHeight
;
3060 else if (ev
.deltaMode
=== WheelEvent
.DOM_DELTA_PAGE
) {
3061 multiplier
= this.currentRowHeight
* this.terminal
.rows
;
3063 this.viewportElement
.scrollTop
+= ev
.deltaY
* multiplier
;
3064 ev
.preventDefault();
3067 Viewport
.prototype.onTouchStart = function (ev
) {
3068 this.lastTouchY
= ev
.touches
[0].pageY
;
3071 Viewport
.prototype.onTouchMove = function (ev
) {
3072 var deltaY
= this.lastTouchY
- ev
.touches
[0].pageY
;
3073 this.lastTouchY
= ev
.touches
[0].pageY
;
3077 this.viewportElement
.scrollTop
+= deltaY
;
3078 ev
.preventDefault();
3083 exports
.Viewport
= Viewport
;
3087 },{}],14:[function(require
,module
,exports
){
3089 Object
.defineProperty(exports
, "__esModule", { value
: true });
3090 function prepareTextForTerminal(text
, isMSWindows
) {
3092 return text
.replace(/\r?\n/g, '\r');
3096 exports
.prepareTextForTerminal
= prepareTextForTerminal
;
3097 function copyHandler(ev
, term
, selectionManager
) {
3098 if (term
.browser
.isMSIE
) {
3099 window
.clipboardData
.setData('Text', selectionManager
.selectionText
);
3102 ev
.clipboardData
.setData('text/plain', selectionManager
.selectionText
);
3104 ev
.preventDefault();
3106 exports
.copyHandler
= copyHandler
;
3107 function pasteHandler(ev
, term
) {
3108 ev
.stopPropagation();
3110 var dispatchPaste = function (text
) {
3111 text
= prepareTextForTerminal(text
, term
.browser
.isMSWindows
);
3113 term
.textarea
.value
= '';
3114 term
.emit('paste', text
);
3115 return term
.cancel(ev
);
3117 if (term
.browser
.isMSIE
) {
3118 if (window
.clipboardData
) {
3119 text
= window
.clipboardData
.getData('Text');
3120 dispatchPaste(text
);
3124 if (ev
.clipboardData
) {
3125 text
= ev
.clipboardData
.getData('text/plain');
3126 dispatchPaste(text
);
3130 exports
.pasteHandler
= pasteHandler
;
3131 function moveTextAreaUnderMouseCursor(ev
, textarea
) {
3132 textarea
.style
.position
= 'fixed';
3133 textarea
.style
.width
= '20px';
3134 textarea
.style
.height
= '20px';
3135 textarea
.style
.left
= (ev
.clientX
- 10) + 'px';
3136 textarea
.style
.top
= (ev
.clientY
- 10) + 'px';
3137 textarea
.style
.zIndex
= '1000';
3139 setTimeout(function () {
3140 textarea
.style
.position
= null;
3141 textarea
.style
.width
= null;
3142 textarea
.style
.height
= null;
3143 textarea
.style
.left
= null;
3144 textarea
.style
.top
= null;
3145 textarea
.style
.zIndex
= null;
3148 exports
.moveTextAreaUnderMouseCursor
= moveTextAreaUnderMouseCursor
;
3149 function rightClickHandler(ev
, textarea
, selectionManager
) {
3150 moveTextAreaUnderMouseCursor(ev
, textarea
);
3151 textarea
.value
= selectionManager
.selectionText
;
3154 exports
.rightClickHandler
= rightClickHandler
;
3158 },{}],15:[function(require
,module
,exports
){
3160 Object
.defineProperty(exports
, "__esModule", { value
: true });
3161 var Generic_1
= require("./Generic");
3162 var isNode
= (typeof navigator
=== 'undefined') ? true : false;
3163 var userAgent
= (isNode
) ? 'node' : navigator
.userAgent
;
3164 var platform
= (isNode
) ? 'node' : navigator
.platform
;
3165 exports
.isFirefox
= !!~userAgent
.indexOf('Firefox');
3166 exports
.isMSIE
= !!~userAgent
.indexOf('MSIE') || !!~userAgent
.indexOf('Trident');
3167 exports
.isMac
= Generic_1
.contains(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], platform
);
3168 exports
.isIpad
= platform
=== 'iPad';
3169 exports
.isIphone
= platform
=== 'iPhone';
3170 exports
.isMSWindows
= Generic_1
.contains(['Windows', 'Win16', 'Win32', 'WinCE'], platform
);
3171 exports
.isLinux
= platform
.indexOf('Linux') >= 0;
3175 },{"./Generic":20}],16:[function(require
,module
,exports
){
3177 Object
.defineProperty(exports
, "__esModule", { value
: true });
3178 var LINE_DATA_CHAR_INDEX
= 1;
3179 var LINE_DATA_WIDTH_INDEX
= 2;
3180 function translateBufferLineToString(line
, trimRight
, startCol
, endCol
) {
3181 if (startCol
=== void 0) { startCol
= 0; }
3182 if (endCol
=== void 0) { endCol
= null; }
3183 var lineString
= '';
3184 var widthAdjustedStartCol
= startCol
;
3185 var widthAdjustedEndCol
= endCol
;
3186 for (var i
= 0; i
< line
.length
; i
++) {
3188 lineString
+= char[LINE_DATA_CHAR_INDEX
];
3189 if (char[LINE_DATA_WIDTH_INDEX
] === 0) {
3190 if (startCol
>= i
) {
3191 widthAdjustedStartCol
--;
3194 widthAdjustedEndCol
--;
3198 var finalEndCol
= widthAdjustedEndCol
|| line
.length
;
3200 var rightWhitespaceIndex
= lineString
.search(/\s+$/);
3201 if (rightWhitespaceIndex
!== -1) {
3202 finalEndCol
= Math
.min(finalEndCol
, rightWhitespaceIndex
);
3204 if (finalEndCol
<= widthAdjustedStartCol
) {
3208 return lineString
.substring(widthAdjustedStartCol
, finalEndCol
);
3210 exports
.translateBufferLineToString
= translateBufferLineToString
;
3214 },{}],17:[function(require
,module
,exports
){
3216 var __extends
= (this && this.__extends
) || (function () {
3217 var extendStatics
= Object
.setPrototypeOf
||
3218 ({ __proto__
: [] } instanceof Array
&& function (d
, b
) { d
.__proto__
= b
; }) ||
3219 function (d
, b
) { for (var p
in b
) if (b
.hasOwnProperty(p
)) d
[p
] = b
[p
]; };
3220 return function (d
, b
) {
3221 extendStatics(d
, b
);
3222 function __() { this.constructor = d
; }
3223 d
.prototype = b
=== null ? Object
.create(b
) : (__
.prototype = b
.prototype, new __());
3226 Object
.defineProperty(exports
, "__esModule", { value
: true });
3227 var EventEmitter_js_1
= require("../EventEmitter.js");
3228 var CharMeasure
= (function (_super
) {
3229 __extends(CharMeasure
, _super
);
3230 function CharMeasure(document
, parentElement
) {
3231 var _this
= _super
.call(this) || this;
3232 _this
._document
= document
;
3233 _this
._parentElement
= parentElement
;
3236 Object
.defineProperty(CharMeasure
.prototype, "width", {
3243 Object
.defineProperty(CharMeasure
.prototype, "height", {
3245 return this._height
;
3250 CharMeasure
.prototype.measure = function () {
3252 if (!this._measureElement
) {
3253 this._measureElement
= this._document
.createElement('span');
3254 this._measureElement
.style
.position
= 'absolute';
3255 this._measureElement
.style
.top
= '0';
3256 this._measureElement
.style
.left
= '-9999em';
3257 this._measureElement
.textContent
= 'W';
3258 this._measureElement
.setAttribute('aria-hidden', 'true');
3259 this._parentElement
.appendChild(this._measureElement
);
3260 setTimeout(function () { return _this
._doMeasure(); }, 0);
3266 CharMeasure
.prototype._doMeasure = function () {
3267 var geometry
= this._measureElement
.getBoundingClientRect();
3268 if (geometry
.width
=== 0 || geometry
.height
=== 0) {
3271 if (this._width
!== geometry
.width
|| this._height
!== geometry
.height
) {
3272 this._width
= geometry
.width
;
3273 this._height
= geometry
.height
;
3274 this.emit('charsizechanged');
3278 }(EventEmitter_js_1
.EventEmitter
));
3279 exports
.CharMeasure
= CharMeasure
;
3283 },{"../EventEmitter.js":6}],18:[function(require
,module
,exports
){
3285 var __extends
= (this && this.__extends
) || (function () {
3286 var extendStatics
= Object
.setPrototypeOf
||
3287 ({ __proto__
: [] } instanceof Array
&& function (d
, b
) { d
.__proto__
= b
; }) ||
3288 function (d
, b
) { for (var p
in b
) if (b
.hasOwnProperty(p
)) d
[p
] = b
[p
]; };
3289 return function (d
, b
) {
3290 extendStatics(d
, b
);
3291 function __() { this.constructor = d
; }
3292 d
.prototype = b
=== null ? Object
.create(b
) : (__
.prototype = b
.prototype, new __());
3295 Object
.defineProperty(exports
, "__esModule", { value
: true });
3296 var EventEmitter_1
= require("../EventEmitter");
3297 var CircularList
= (function (_super
) {
3298 __extends(CircularList
, _super
);
3299 function CircularList(maxLength
) {
3300 var _this
= _super
.call(this) || this;
3301 _this
._array
= new Array(maxLength
);
3302 _this
._startIndex
= 0;
3306 Object
.defineProperty(CircularList
.prototype, "maxLength", {
3308 return this._array
.length
;
3310 set: function (newMaxLength
) {
3311 var newArray
= new Array(newMaxLength
);
3312 for (var i
= 0; i
< Math
.min(newMaxLength
, this.length
); i
++) {
3313 newArray
[i
] = this._array
[this._getCyclicIndex(i
)];
3315 this._array
= newArray
;
3316 this._startIndex
= 0;
3321 Object
.defineProperty(CircularList
.prototype, "length", {
3323 return this._length
;
3325 set: function (newLength
) {
3326 if (newLength
> this._length
) {
3327 for (var i
= this._length
; i
< newLength
; i
++) {
3328 this._array
[i
] = undefined;
3331 this._length
= newLength
;
3336 Object
.defineProperty(CircularList
.prototype, "forEach", {
3339 return function (callbackfn
) {
3341 var length
= _this
.length
;
3342 for (var i_1
= 0; i_1
< length
; i_1
++) {
3343 callbackfn(_this
.get(i_1
), i_1
);
3350 CircularList
.prototype.get = function (index
) {
3351 return this._array
[this._getCyclicIndex(index
)];
3353 CircularList
.prototype.set = function (index
, value
) {
3354 this._array
[this._getCyclicIndex(index
)] = value
;
3356 CircularList
.prototype.push = function (value
) {
3357 this._array
[this._getCyclicIndex(this._length
)] = value
;
3358 if (this._length
=== this.maxLength
) {
3360 if (this._startIndex
=== this.maxLength
) {
3361 this._startIndex
= 0;
3363 this.emit('trim', 1);
3369 CircularList
.prototype.pop = function () {
3370 return this._array
[this._getCyclicIndex(this._length
-- - 1)];
3372 CircularList
.prototype.splice = function (start
, deleteCount
) {
3374 for (var _i
= 2; _i
< arguments
.length
; _i
++) {
3375 items
[_i
- 2] = arguments
[_i
];
3378 for (var i
= start
; i
< this._length
- deleteCount
; i
++) {
3379 this._array
[this._getCyclicIndex(i
)] = this._array
[this._getCyclicIndex(i
+ deleteCount
)];
3381 this._length
-= deleteCount
;
3383 if (items
&& items
.length
) {
3384 for (var i
= this._length
- 1; i
>= start
; i
--) {
3385 this._array
[this._getCyclicIndex(i
+ items
.length
)] = this._array
[this._getCyclicIndex(i
)];
3387 for (var i
= 0; i
< items
.length
; i
++) {
3388 this._array
[this._getCyclicIndex(start
+ i
)] = items
[i
];
3390 if (this._length
+ items
.length
> this.maxLength
) {
3391 var countToTrim
= (this._length
+ items
.length
) - this.maxLength
;
3392 this._startIndex
+= countToTrim
;
3393 this._length
= this.maxLength
;
3394 this.emit('trim', countToTrim
);
3397 this._length
+= items
.length
;
3401 CircularList
.prototype.trimStart = function (count
) {
3402 if (count
> this._length
) {
3403 count
= this._length
;
3405 this._startIndex
+= count
;
3406 this._length
-= count
;
3407 this.emit('trim', count
);
3409 CircularList
.prototype.shiftElements = function (start
, count
, offset
) {
3413 if (start
< 0 || start
>= this._length
) {
3414 throw new Error('start argument out of range');
3416 if (start
+ offset
< 0) {
3417 throw new Error('Cannot shift elements in list beyond index 0');
3420 for (var i
= count
- 1; i
>= 0; i
--) {
3421 this.set(start
+ i
+ offset
, this.get(start
+ i
));
3423 var expandListBy
= (start
+ count
+ offset
) - this._length
;
3424 if (expandListBy
> 0) {
3425 this._length
+= expandListBy
;
3426 while (this._length
> this.maxLength
) {
3429 this.emit('trim', 1);
3434 for (var i
= 0; i
< count
; i
++) {
3435 this.set(start
+ i
+ offset
, this.get(start
+ i
));
3439 CircularList
.prototype._getCyclicIndex = function (index
) {
3440 return (this._startIndex
+ index
) % this.maxLength
;
3442 return CircularList
;
3443 }(EventEmitter_1
.EventEmitter
));
3444 exports
.CircularList
= CircularList
;
3448 },{"../EventEmitter":6}],19:[function(require
,module
,exports
){
3450 Object
.defineProperty(exports
, "__esModule", { value
: true });
3451 var DomElementObjectPool
= (function () {
3452 function DomElementObjectPool(type
) {
3458 DomElementObjectPool
.prototype.acquire = function () {
3460 if (this._pool
.length
=== 0) {
3461 element
= this._createNew();
3464 element
= this._pool
.pop();
3466 this._inUse
[element
.getAttribute(DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
)] = element
;
3469 DomElementObjectPool
.prototype.release = function (element
) {
3470 if (!this._inUse
[element
.getAttribute(DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
)]) {
3471 throw new Error('Could not release an element not yet acquired');
3473 delete this._inUse
[element
.getAttribute(DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
)];
3474 this._cleanElement(element
);
3475 this._pool
.push(element
);
3477 DomElementObjectPool
.prototype._createNew = function () {
3478 var element
= document
.createElement(this._type
);
3479 var id
= DomElementObjectPool
._objectCount
++;
3480 element
.setAttribute(DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
, id
.toString(10));
3483 DomElementObjectPool
.prototype._cleanElement = function (element
) {
3484 element
.className
= '';
3485 element
.innerHTML
= '';
3487 return DomElementObjectPool
;
3489 DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
= 'data-obj-id';
3490 DomElementObjectPool
._objectCount
= 0;
3491 exports
.DomElementObjectPool
= DomElementObjectPool
;
3495 },{}],20:[function(require
,module
,exports
){
3497 Object
.defineProperty(exports
, "__esModule", { value
: true });
3498 function contains(arr
, el
) {
3499 return arr
.indexOf(el
) >= 0;
3501 exports
.contains
= contains
;
3506 },{}],21:[function(require
,module
,exports
){
3508 Object
.defineProperty(exports
, "__esModule", { value
: true });
3509 function getCoordsRelativeToElement(event
, element
) {
3510 if (event
.pageX
== null) {
3513 var x
= event
.pageX
;
3514 var y
= event
.pageY
;
3515 while (element
&& element
!== self
.document
.documentElement
) {
3516 x
-= element
.offsetLeft
;
3517 y
-= element
.offsetTop
;
3518 element
= 'offsetParent' in element
? element
.offsetParent
: element
.parentElement
;
3522 exports
.getCoordsRelativeToElement
= getCoordsRelativeToElement
;
3523 function getCoords(event
, rowContainer
, charMeasure
, colCount
, rowCount
, isSelection
) {
3524 if (!charMeasure
.width
|| !charMeasure
.height
) {
3527 var coords
= getCoordsRelativeToElement(event
, rowContainer
);
3531 coords
[0] = Math
.ceil((coords
[0] + (isSelection
? charMeasure
.width
/ 2 : 0)) / charMeasure
.width
);
3532 coords
[1] = Math
.ceil(coords
[1] / charMeasure
.height
);
3533 coords
[0] = Math
.min(Math
.max(coords
[0], 1), colCount
+ 1);
3534 coords
[1] = Math
.min(Math
.max(coords
[1], 1), rowCount
+ 1);
3537 exports
.getCoords
= getCoords
;
3538 function getRawByteCoords(event
, rowContainer
, charMeasure
, colCount
, rowCount
) {
3539 var coords
= getCoords(event
, rowContainer
, charMeasure
, colCount
, rowCount
);
3544 return { x
: x
, y
: y
};
3546 exports
.getRawByteCoords
= getRawByteCoords
;
3550 },{}],22:[function(require
,module
,exports
){
3552 Object
.defineProperty(exports
, "__esModule", { value
: true });
3553 var BufferSet_1
= require("./BufferSet");
3554 var CompositionHelper_1
= require("./CompositionHelper");
3555 var EventEmitter_1
= require("./EventEmitter");
3556 var Viewport_1
= require("./Viewport");
3557 var Clipboard_1
= require("./handlers/Clipboard");
3558 var EscapeSequences_1
= require("./EscapeSequences");
3559 var InputHandler_1
= require("./InputHandler");
3560 var Parser_1
= require("./Parser");
3561 var Renderer_1
= require("./Renderer");
3562 var Linkifier_1
= require("./Linkifier");
3563 var SelectionManager_1
= require("./SelectionManager");
3564 var CharMeasure_1
= require("./utils/CharMeasure");
3565 var Browser
= require("./utils/Browser");
3566 var Mouse_1
= require("./utils/Mouse");
3567 var BufferLine_1
= require("./utils/BufferLine");
3568 var document
= (typeof window
!= 'undefined') ? window
.document
: null;
3569 var WRITE_BUFFER_PAUSE_THRESHOLD
= 5;
3570 var WRITE_BATCH_SIZE
= 300;
3571 var CURSOR_BLINK_INTERVAL
= 600;
3572 function Terminal(options
) {
3574 if (!(this instanceof Terminal
)) {
3575 return new Terminal(arguments
[0], arguments
[1], arguments
[2]);
3577 self
.browser
= Browser
;
3578 self
.cancel
= Terminal
.cancel
;
3579 EventEmitter_1
.EventEmitter
.call(this);
3580 if (typeof options
=== 'number') {
3584 handler
: arguments
[2]
3587 options
= options
|| {};
3588 Object
.keys(Terminal
.defaults
).forEach(function (key
) {
3589 if (options
[key
] == null) {
3590 options
[key
] = Terminal
.options
[key
];
3591 if (Terminal
[key
] !== Terminal
.defaults
[key
]) {
3592 options
[key
] = Terminal
[key
];
3595 self
[key
] = options
[key
];
3597 if (options
.colors
.length
=== 8) {
3598 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(8));
3600 else if (options
.colors
.length
=== 16) {
3601 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16));
3603 else if (options
.colors
.length
=== 10) {
3604 options
.colors
= options
.colors
.slice(0, -2).concat(Terminal
._colors
.slice(8, -2), options
.colors
.slice(-2));
3606 else if (options
.colors
.length
=== 18) {
3607 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16, -2), options
.colors
.slice(-2));
3609 this.colors
= options
.colors
;
3610 this.options
= options
;
3611 this.parent
= options
.body
|| options
.parent
|| (document
? document
.getElementsByTagName('body')[0] : null);
3612 this.cols
= options
.cols
|| options
.geometry
[0];
3613 this.rows
= options
.rows
|| options
.geometry
[1];
3614 this.geometry
= [this.cols
, this.rows
];
3615 if (options
.handler
) {
3616 this.on('data', options
.handler
);
3618 this.cursorState
= 0;
3619 this.cursorHidden
= false;
3622 this.customKeyEventHandler
= null;
3623 this.cursorBlinkInterval
= null;
3624 this.applicationKeypad
= false;
3625 this.applicationCursor
= false;
3626 this.originMode
= false;
3627 this.insertMode
= false;
3628 this.wraparoundMode
= true;
3629 this.charset
= null;
3630 this.gcharset
= null;
3632 this.charsets
= [null];
3650 this.readable
= true;
3651 this.writable
= true;
3652 this.defAttr
= (0 << 18) | (257 << 9) | (256 << 0);
3653 this.curAttr
= this.defAttr
;
3655 this.currentParam
= 0;
3658 this.inputHandler
= new InputHandler_1
.InputHandler(this);
3659 this.parser
= new Parser_1
.Parser(this.inputHandler
, this);
3660 this.renderer
= this.renderer
|| null;
3661 this.selectionManager
= this.selectionManager
|| null;
3662 this.linkifier
= this.linkifier
|| new Linkifier_1
.Linkifier();
3663 this.writeBuffer
= [];
3664 this.writeInProgress
= false;
3665 this.xoffSentToCatchUp
= false;
3666 this.writeStopped
= false;
3667 this.surrogate_high
= '';
3668 this.buffers
= new BufferSet_1
.BufferSet(this);
3669 this.buffer
= this.buffers
.active
;
3670 this.buffers
.on('activate', function (buffer
) {
3671 this._terminal
.buffer
= buffer
;
3673 if (this.selectionManager
) {
3674 this.selectionManager
.setBuffer(this.buffer
.lines
);
3677 this.userScrolling
= false;
3679 inherits(Terminal
, EventEmitter_1
.EventEmitter
);
3680 Terminal
.prototype.eraseAttr = function () {
3681 return (this.defAttr
& ~0x1ff) | (this.curAttr
& 0x1ff);
3683 Terminal
.tangoColors
= [
3701 Terminal
.colors
= (function () {
3702 var colors
= Terminal
.tangoColors
.slice(), r
= [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff], i
;
3704 for (; i
< 216; i
++) {
3705 out(r
[(i
/ 36) % 6 | 0], r
[(i
/ 6) % 6 | 0], r
[i
% 6]);
3708 for (; i
< 24; i
++) {
3712 function out(r
, g
, b
) {
3713 colors
.push('#' + hex(r
) + hex(g
) + hex(b
));
3717 return c
.length
< 2 ? '0' + c
: c
;
3721 Terminal
._colors
= Terminal
.colors
.slice();
3722 Terminal
.vcolors
= (function () {
3723 var out
= [], colors
= Terminal
.colors
, i
= 0, color
;
3724 for (; i
< 256; i
++) {
3725 color
= parseInt(colors
[i
].substring(1), 16);
3727 (color
>> 16) & 0xff,
3728 (color
>> 8) & 0xff,
3734 Terminal
.defaults
= {
3735 colors
: Terminal
.colors
,
3741 cursorStyle
: 'block',
3747 cancelEvents
: false,
3748 disableStdin
: false,
3749 useFlowControl
: false,
3752 Terminal
.options
= {};
3753 Terminal
.focus
= null;
3754 each(keys(Terminal
.defaults
), function (key
) {
3755 Terminal
[key
] = Terminal
.defaults
[key
];
3756 Terminal
.options
[key
] = Terminal
.defaults
[key
];
3758 Terminal
.prototype.focus = function () {
3759 return this.textarea
.focus();
3761 Terminal
.prototype.getOption = function (key
) {
3762 if (!(key
in Terminal
.defaults
)) {
3763 throw new Error('No option with key "' + key
+ '"');
3765 if (typeof this.options
[key
] !== 'undefined') {
3766 return this.options
[key
];
3770 Terminal
.prototype.setOption = function (key
, value
) {
3771 if (!(key
in Terminal
.defaults
)) {
3772 throw new Error('No option with key "' + key
+ '"');
3776 if (value
< this.rows
) {
3777 var msg
= 'Setting the scrollback value less than the number of rows ';
3778 msg
+= "(" + this.rows
+ ") is not allowed.";
3782 if (this.options
[key
] !== value
) {
3783 if (this.buffer
.lines
.length
> value
) {
3784 var amountToTrim
= this.buffer
.lines
.length
- value
;
3785 var needsRefresh
= (this.buffer
.ydisp
- amountToTrim
< 0);
3786 this.buffer
.lines
.trimStart(amountToTrim
);
3787 this.buffer
.ybase
= Math
.max(this.buffer
.ybase
- amountToTrim
, 0);
3788 this.buffer
.ydisp
= Math
.max(this.buffer
.ydisp
- amountToTrim
, 0);
3790 this.refresh(0, this.rows
- 1);
3793 this.buffer
.lines
.maxLength
= value
;
3794 this.viewport
.syncScrollArea();
3799 this.options
[key
] = value
;
3802 this.setCursorBlinking(value
);
3805 this.element
.classList
.toggle("xterm-cursor-style-block", value
=== 'block');
3806 this.element
.classList
.toggle("xterm-cursor-style-underline", value
=== 'underline');
3807 this.element
.classList
.toggle("xterm-cursor-style-bar", value
=== 'bar');
3809 case 'tabStopWidth':
3814 Terminal
.prototype.restartCursorBlinking = function () {
3815 this.setCursorBlinking(this.options
.cursorBlink
);
3817 Terminal
.prototype.setCursorBlinking = function (enabled
) {
3818 this.element
.classList
.toggle('xterm-cursor-blink', enabled
);
3819 this.clearCursorBlinkingInterval();
3822 this.cursorBlinkInterval
= setInterval(function () {
3823 self
.element
.classList
.toggle('xterm-cursor-blink-on');
3824 }, CURSOR_BLINK_INTERVAL
);
3827 Terminal
.prototype.clearCursorBlinkingInterval = function () {
3828 this.element
.classList
.remove('xterm-cursor-blink-on');
3829 if (this.cursorBlinkInterval
) {
3830 clearInterval(this.cursorBlinkInterval
);
3831 this.cursorBlinkInterval
= null;
3834 Terminal
.bindFocus = function (term
) {
3835 on(term
.textarea
, 'focus', function (ev
) {
3836 if (term
.sendFocus
) {
3837 term
.send(EscapeSequences_1
.C0
.ESC
+ '[I');
3839 term
.element
.classList
.add('focus');
3841 term
.restartCursorBlinking
.apply(term
);
3842 Terminal
.focus
= term
;
3843 term
.emit('focus', { terminal
: term
});
3846 Terminal
.prototype.blur = function () {
3847 return this.textarea
.blur();
3849 Terminal
.bindBlur = function (term
) {
3850 on(term
.textarea
, 'blur', function (ev
) {
3851 term
.refresh(term
.buffer
.y
, term
.buffer
.y
);
3852 if (term
.sendFocus
) {
3853 term
.send(EscapeSequences_1
.C0
.ESC
+ '[O');
3855 term
.element
.classList
.remove('focus');
3856 term
.clearCursorBlinkingInterval
.apply(term
);
3857 Terminal
.focus
= null;
3858 term
.emit('blur', { terminal
: term
});
3861 Terminal
.prototype.initGlobal = function () {
3864 Terminal
.bindKeys(this);
3865 Terminal
.bindFocus(this);
3866 Terminal
.bindBlur(this);
3867 on(this.element
, 'copy', function (event
) {
3868 if (!term
.hasSelection()) {
3871 Clipboard_1
.copyHandler(event
, term
, _this
.selectionManager
);
3873 var pasteHandlerWrapper = function (event
) { return Clipboard_1
.pasteHandler(event
, term
); };
3874 on(this.textarea
, 'paste', pasteHandlerWrapper
);
3875 on(this.element
, 'paste', pasteHandlerWrapper
);
3876 if (term
.browser
.isFirefox
) {
3877 on(this.element
, 'mousedown', function (event
) {
3878 if (event
.button
== 2) {
3879 Clipboard_1
.rightClickHandler(event
, _this
.textarea
, _this
.selectionManager
);
3884 on(this.element
, 'contextmenu', function (event
) {
3885 Clipboard_1
.rightClickHandler(event
, _this
.textarea
, _this
.selectionManager
);
3888 if (term
.browser
.isLinux
) {
3889 on(this.element
, 'auxclick', function (event
) {
3890 if (event
.button
=== 1) {
3891 Clipboard_1
.moveTextAreaUnderMouseCursor(event
, _this
.textarea
, _this
.selectionManager
);
3896 Terminal
.bindKeys = function (term
) {
3897 on(term
.element
, 'keydown', function (ev
) {
3898 if (document
.activeElement
!= this) {
3903 on(term
.element
, 'keypress', function (ev
) {
3904 if (document
.activeElement
!= this) {
3909 on(term
.element
, 'keyup', function (ev
) {
3910 if (!wasMondifierKeyOnlyEvent(ev
)) {
3914 on(term
.textarea
, 'keydown', function (ev
) {
3917 on(term
.textarea
, 'keypress', function (ev
) {
3921 on(term
.textarea
, 'compositionstart', term
.compositionHelper
.compositionstart
.bind(term
.compositionHelper
));
3922 on(term
.textarea
, 'compositionupdate', term
.compositionHelper
.compositionupdate
.bind(term
.compositionHelper
));
3923 on(term
.textarea
, 'compositionend', term
.compositionHelper
.compositionend
.bind(term
.compositionHelper
));
3924 term
.on('refresh', term
.compositionHelper
.updateCompositionElements
.bind(term
.compositionHelper
));
3925 term
.on('refresh', function (data
) {
3926 term
.queueLinkification(data
.start
, data
.end
);
3929 Terminal
.prototype.insertRow = function (row
) {
3930 if (typeof row
!= 'object') {
3931 row
= document
.createElement('div');
3933 this.rowContainer
.appendChild(row
);
3934 this.children
.push(row
);
3937 Terminal
.prototype.open = function (parent
, focus
) {
3939 var self
= this, i
= 0, div
;
3940 this.parent
= parent
|| this.parent
;
3942 throw new Error('Terminal requires a parent element.');
3944 this.context
= this.parent
.ownerDocument
.defaultView
;
3945 this.document
= this.parent
.ownerDocument
;
3946 this.body
= this.document
.getElementsByTagName('body')[0];
3947 this.element
= this.document
.createElement('div');
3948 this.element
.classList
.add('terminal');
3949 this.element
.classList
.add('xterm');
3950 this.element
.classList
.add('xterm-theme-' + this.theme
);
3951 this.element
.classList
.add("xterm-cursor-style-" + this.options
.cursorStyle
);
3952 this.setCursorBlinking(this.options
.cursorBlink
);
3953 this.element
.setAttribute('tabindex', 0);
3954 this.viewportElement
= document
.createElement('div');
3955 this.viewportElement
.classList
.add('xterm-viewport');
3956 this.element
.appendChild(this.viewportElement
);
3957 this.viewportScrollArea
= document
.createElement('div');
3958 this.viewportScrollArea
.classList
.add('xterm-scroll-area');
3959 this.viewportElement
.appendChild(this.viewportScrollArea
);
3960 this.selectionContainer
= document
.createElement('div');
3961 this.selectionContainer
.classList
.add('xterm-selection');
3962 this.element
.appendChild(this.selectionContainer
);
3963 this.rowContainer
= document
.createElement('div');
3964 this.rowContainer
.classList
.add('xterm-rows');
3965 this.element
.appendChild(this.rowContainer
);
3967 this.linkifier
.attachToDom(document
, this.children
);
3968 this.helperContainer
= document
.createElement('div');
3969 this.helperContainer
.classList
.add('xterm-helpers');
3970 this.element
.appendChild(this.helperContainer
);
3971 this.textarea
= document
.createElement('textarea');
3972 this.textarea
.classList
.add('xterm-helper-textarea');
3973 this.textarea
.setAttribute('autocorrect', 'off');
3974 this.textarea
.setAttribute('autocapitalize', 'off');
3975 this.textarea
.setAttribute('spellcheck', 'false');
3976 this.textarea
.tabIndex
= 0;
3977 this.textarea
.addEventListener('focus', function () {
3978 self
.emit('focus', { terminal
: self
});
3980 this.textarea
.addEventListener('blur', function () {
3981 self
.emit('blur', { terminal
: self
});
3983 this.helperContainer
.appendChild(this.textarea
);
3984 this.compositionView
= document
.createElement('div');
3985 this.compositionView
.classList
.add('composition-view');
3986 this.compositionHelper
= new CompositionHelper_1
.CompositionHelper(this.textarea
, this.compositionView
, this);
3987 this.helperContainer
.appendChild(this.compositionView
);
3988 this.charSizeStyleElement
= document
.createElement('style');
3989 this.helperContainer
.appendChild(this.charSizeStyleElement
);
3990 for (; i
< this.rows
; i
++) {
3993 this.parent
.appendChild(this.element
);
3994 this.charMeasure
= new CharMeasure_1
.CharMeasure(document
, this.helperContainer
);
3995 this.charMeasure
.on('charsizechanged', function () {
3996 self
.updateCharSizeStyles();
3998 this.charMeasure
.measure();
3999 this.viewport
= new Viewport_1
.Viewport(this, this.viewportElement
, this.viewportScrollArea
, this.charMeasure
);
4000 this.renderer
= new Renderer_1
.Renderer(this);
4001 this.selectionManager
= new SelectionManager_1
.SelectionManager(this, this.buffer
.lines
, this.rowContainer
, this.charMeasure
);
4002 this.selectionManager
.on('refresh', function (data
) {
4003 _this
.renderer
.refreshSelection(data
.start
, data
.end
);
4005 this.selectionManager
.on('newselection', function (text
) {
4006 _this
.textarea
.value
= text
;
4007 _this
.textarea
.focus();
4008 _this
.textarea
.select();
4010 this.on('scroll', function () { return _this
.selectionManager
.refresh(); });
4011 this.viewportElement
.addEventListener('scroll', function () { return _this
.selectionManager
.refresh(); });
4012 this.refresh(0, this.rows
- 1);
4014 if (typeof focus
== 'undefined') {
4015 var message
= 'You did not pass the `focus` argument in `Terminal.prototype.open()`.\n';
4016 message
+= 'The `focus` argument now defaults to `true` but starting with xterm.js 3.0 ';
4017 message
+= 'it will default to `false`.';
4018 console
.warn(message
);
4027 Terminal
.loadAddon = function (addon
, callback
) {
4028 if (typeof exports
=== 'object' && typeof module
=== 'object') {
4029 return require('./addons/' + addon
+ '/' + addon
);
4031 else if (typeof define
== 'function') {
4032 return require(['./addons/' + addon
+ '/' + addon
], callback
);
4035 console
.error('Cannot load a module without a CommonJS or RequireJS environment.');
4039 Terminal
.prototype.updateCharSizeStyles = function () {
4040 this.charSizeStyleElement
.textContent
=
4041 ".xterm-wide-char{width:" + this.charMeasure
.width
* 2 + "px;}" +
4042 (".xterm-normal-char{width:" + this.charMeasure
.width
+ "px;}") +
4043 (".xterm-rows > div{height:" + this.charMeasure
.height
+ "px;}");
4045 Terminal
.prototype.bindMouse = function () {
4046 var el
= this.element
, self
= this, pressed
= 32;
4047 function sendButton(ev
) {
4049 button
= getButton(ev
);
4050 pos
= Mouse_1
.getRawByteCoords(ev
, self
.rowContainer
, self
.charMeasure
, self
.cols
, self
.rows
);
4053 sendEvent(button
, pos
);
4054 switch (ev
.overrideType
|| ev
.type
) {
4065 function sendMove(ev
) {
4066 var button
= pressed
, pos
;
4067 pos
= Mouse_1
.getRawByteCoords(ev
, self
.rowContainer
, self
.charMeasure
, self
.cols
, self
.rows
);
4071 sendEvent(button
, pos
);
4073 function encode(data
, ch
) {
4074 if (!self
.utfMouse
) {
4076 return data
.push(0);
4083 return data
.push(0);
4090 data
.push(0xC0 | (ch
>> 6));
4091 data
.push(0x80 | (ch
& 0x3F));
4095 function sendEvent(button
, pos
) {
4096 if (self
.vt300Mouse
) {
4100 var data
= EscapeSequences_1
.C0
.ESC
+ '[24';
4103 else if (button
=== 1)
4105 else if (button
=== 2)
4107 else if (button
=== 3)
4111 data
+= '~[' + pos
.x
+ ',' + pos
.y
+ ']\r';
4115 if (self
.decLocator
) {
4121 else if (button
=== 1)
4123 else if (button
=== 2)
4125 else if (button
=== 3)
4127 self
.send(EscapeSequences_1
.C0
.ESC
+ '['
4130 + (button
=== 3 ? 4 : 0)
4140 if (self
.urxvtMouse
) {
4145 self
.send(EscapeSequences_1
.C0
.ESC
+ '[' + button
+ ';' + pos
.x
+ ';' + pos
.y
+ 'M');
4148 if (self
.sgrMouse
) {
4151 self
.send(EscapeSequences_1
.C0
.ESC
+ '[<'
4152 + (((button
& 3) === 3 ? button
& ~3 : button
) - 32)
4157 + ((button
& 3) === 3 ? 'm' : 'M'));
4161 encode(data
, button
);
4162 encode(data
, pos
.x
);
4163 encode(data
, pos
.y
);
4164 self
.send(EscapeSequences_1
.C0
.ESC
+ '[M' + String
.fromCharCode
.apply(String
, data
));
4166 function getButton(ev
) {
4167 var button
, shift
, meta
, ctrl
, mod
;
4168 switch (ev
.overrideType
|| ev
.type
) {
4170 button
= ev
.button
!= null
4175 if (self
.browser
.isMSIE
) {
4176 button
= button
=== 1 ? 0 : button
=== 4 ? 1 : button
;
4182 case 'DOMMouseScroll':
4183 button
= ev
.detail
< 0
4188 button
= ev
.wheelDeltaY
> 0
4193 shift
= ev
.shiftKey
? 4 : 0;
4194 meta
= ev
.metaKey
? 8 : 0;
4195 ctrl
= ev
.ctrlKey
? 16 : 0;
4196 mod
= shift
| meta
| ctrl
;
4197 if (self
.vt200Mouse
) {
4200 else if (!self
.normalMouse
) {
4203 button
= (32 + (mod
<< 2)) + button
;
4206 on(el
, 'mousedown', function (ev
) {
4207 ev
.preventDefault();
4209 if (!self
.mouseEvents
)
4212 if (self
.vt200Mouse
) {
4213 ev
.overrideType
= 'mouseup';
4215 return self
.cancel(ev
);
4217 if (self
.normalMouse
)
4218 on(self
.document
, 'mousemove', sendMove
);
4219 if (!self
.x10Mouse
) {
4220 on(self
.document
, 'mouseup', function up(ev
) {
4222 if (self
.normalMouse
)
4223 off(self
.document
, 'mousemove', sendMove
);
4224 off(self
.document
, 'mouseup', up
);
4225 return self
.cancel(ev
);
4228 return self
.cancel(ev
);
4230 on(el
, 'wheel', function (ev
) {
4231 if (!self
.mouseEvents
)
4238 return self
.cancel(ev
);
4240 on(el
, 'wheel', function (ev
) {
4241 if (self
.mouseEvents
)
4243 self
.viewport
.onWheel(ev
);
4244 return self
.cancel(ev
);
4246 on(el
, 'touchstart', function (ev
) {
4247 if (self
.mouseEvents
)
4249 self
.viewport
.onTouchStart(ev
);
4250 return self
.cancel(ev
);
4252 on(el
, 'touchmove', function (ev
) {
4253 if (self
.mouseEvents
)
4255 self
.viewport
.onTouchMove(ev
);
4256 return self
.cancel(ev
);
4259 Terminal
.prototype.destroy = function () {
4260 this.readable
= false;
4261 this.writable
= false;
4263 this.handler = function () { };
4264 this.write = function () { };
4265 if (this.element
&& this.element
.parentNode
) {
4266 this.element
.parentNode
.removeChild(this.element
);
4269 Terminal
.prototype.refresh = function (start
, end
) {
4270 if (this.renderer
) {
4271 this.renderer
.queueRefresh(start
, end
);
4274 Terminal
.prototype.queueLinkification = function (start
, end
) {
4275 if (this.linkifier
) {
4276 for (var i
= start
; i
<= end
; i
++) {
4277 this.linkifier
.linkifyRow(i
);
4281 Terminal
.prototype.showCursor = function () {
4282 if (!this.cursorState
) {
4283 this.cursorState
= 1;
4284 this.refresh(this.buffer
.y
, this.buffer
.y
);
4287 Terminal
.prototype.scroll = function (isWrapped
) {
4289 if (this.buffer
.lines
.length
=== this.buffer
.lines
.maxLength
) {
4290 this.buffer
.lines
.trimStart(1);
4291 this.buffer
.ybase
--;
4292 if (this.buffer
.ydisp
!== 0) {
4293 this.buffer
.ydisp
--;
4296 this.buffer
.ybase
++;
4297 if (!this.userScrolling
) {
4298 this.buffer
.ydisp
= this.buffer
.ybase
;
4300 row
= this.buffer
.ybase
+ this.rows
- 1;
4301 row
-= this.rows
- 1 - this.buffer
.scrollBottom
;
4302 if (row
=== this.buffer
.lines
.length
) {
4303 this.buffer
.lines
.push(this.blankLine(undefined, isWrapped
));
4306 this.buffer
.lines
.splice(row
, 0, this.blankLine(undefined, isWrapped
));
4308 if (this.buffer
.scrollTop
!== 0) {
4309 if (this.buffer
.ybase
!== 0) {
4310 this.buffer
.ybase
--;
4311 if (!this.userScrolling
) {
4312 this.buffer
.ydisp
= this.buffer
.ybase
;
4315 this.buffer
.lines
.splice(this.buffer
.ybase
+ this.buffer
.scrollTop
, 1);
4317 this.updateRange(this.buffer
.scrollTop
);
4318 this.updateRange(this.buffer
.scrollBottom
);
4319 this.emit('scroll', this.buffer
.ydisp
);
4321 Terminal
.prototype.scrollDisp = function (disp
, suppressScrollEvent
) {
4323 if (this.buffer
.ydisp
=== 0) {
4326 this.userScrolling
= true;
4328 else if (disp
+ this.buffer
.ydisp
>= this.buffer
.ybase
) {
4329 this.userScrolling
= false;
4331 var oldYdisp
= this.buffer
.ydisp
;
4332 this.buffer
.ydisp
= Math
.max(Math
.min(this.buffer
.ydisp
+ disp
, this.buffer
.ybase
), 0);
4333 if (oldYdisp
=== this.buffer
.ydisp
) {
4336 if (!suppressScrollEvent
) {
4337 this.emit('scroll', this.buffer
.ydisp
);
4339 this.refresh(0, this.rows
- 1);
4341 Terminal
.prototype.scrollPages = function (pageCount
) {
4342 this.scrollDisp(pageCount
* (this.rows
- 1));
4344 Terminal
.prototype.scrollToTop = function () {
4345 this.scrollDisp(-this.buffer
.ydisp
);
4347 Terminal
.prototype.scrollToBottom = function () {
4348 this.scrollDisp(this.buffer
.ybase
- this.buffer
.ydisp
);
4350 Terminal
.prototype.write = function (data
) {
4351 this.writeBuffer
.push(data
);
4352 if (this.options
.useFlowControl
&& !this.xoffSentToCatchUp
&& this.writeBuffer
.length
>= WRITE_BUFFER_PAUSE_THRESHOLD
) {
4353 this.send(EscapeSequences_1
.C0
.DC3
);
4354 this.xoffSentToCatchUp
= true;
4356 if (!this.writeInProgress
&& this.writeBuffer
.length
> 0) {
4357 this.writeInProgress
= true;
4359 setTimeout(function () {
4364 Terminal
.prototype.innerWrite = function () {
4365 var writeBatch
= this.writeBuffer
.splice(0, WRITE_BATCH_SIZE
);
4366 while (writeBatch
.length
> 0) {
4367 var data
= writeBatch
.shift();
4368 var l
= data
.length
, i
= 0, j
, cs
, ch
, code
, low
, ch_width
, row
;
4369 if (this.xoffSentToCatchUp
&& writeBatch
.length
=== 0 && this.writeBuffer
.length
=== 0) {
4370 this.send(EscapeSequences_1
.C0
.DC1
);
4371 this.xoffSentToCatchUp
= false;
4373 this.refreshStart
= this.buffer
.y
;
4374 this.refreshEnd
= this.buffer
.y
;
4375 var state
= this.parser
.parse(data
);
4376 this.parser
.setState(state
);
4377 this.updateRange(this.buffer
.y
);
4378 this.refresh(this.refreshStart
, this.refreshEnd
);
4380 if (this.writeBuffer
.length
> 0) {
4382 setTimeout(function () {
4387 this.writeInProgress
= false;
4390 Terminal
.prototype.writeln = function (data
) {
4391 this.write(data
+ '\r\n');
4393 Terminal
.prototype.attachCustomKeydownHandler = function (customKeydownHandler
) {
4394 var message
= 'attachCustomKeydownHandler() is DEPRECATED and will be removed soon. Please use attachCustomKeyEventHandler() instead.';
4395 console
.warn(message
);
4396 this.attachCustomKeyEventHandler(customKeydownHandler
);
4398 Terminal
.prototype.attachCustomKeyEventHandler = function (customKeyEventHandler
) {
4399 this.customKeyEventHandler
= customKeyEventHandler
;
4401 Terminal
.prototype.setHypertextLinkHandler = function (handler
) {
4402 if (!this.linkifier
) {
4403 throw new Error('Cannot attach a hypertext link handler before Terminal.open is called');
4405 this.linkifier
.setHypertextLinkHandler(handler
);
4406 this.refresh(0, this.rows
- 1);
4408 Terminal
.prototype.setHypertextValidationCallback = function (callback
) {
4409 if (!this.linkifier
) {
4410 throw new Error('Cannot attach a hypertext validation callback before Terminal.open is called');
4412 this.linkifier
.setHypertextValidationCallback(callback
);
4413 this.refresh(0, this.rows
- 1);
4415 Terminal
.prototype.registerLinkMatcher = function (regex
, handler
, options
) {
4416 if (this.linkifier
) {
4417 var matcherId
= this.linkifier
.registerLinkMatcher(regex
, handler
, options
);
4418 this.refresh(0, this.rows
- 1);
4422 Terminal
.prototype.deregisterLinkMatcher = function (matcherId
) {
4423 if (this.linkifier
) {
4424 if (this.linkifier
.deregisterLinkMatcher(matcherId
)) {
4425 this.refresh(0, this.rows
- 1);
4429 Terminal
.prototype.hasSelection = function () {
4430 return this.selectionManager
? this.selectionManager
.hasSelection
: false;
4432 Terminal
.prototype.getSelection = function () {
4433 return this.selectionManager
? this.selectionManager
.selectionText
: '';
4435 Terminal
.prototype.clearSelection = function () {
4436 if (this.selectionManager
) {
4437 this.selectionManager
.clearSelection();
4440 Terminal
.prototype.selectAll = function () {
4441 if (this.selectionManager
) {
4442 this.selectionManager
.selectAll();
4445 Terminal
.prototype.keyDown = function (ev
) {
4446 if (this.customKeyEventHandler
&& this.customKeyEventHandler(ev
) === false) {
4449 this.restartCursorBlinking();
4450 if (!this.compositionHelper
.keydown
.bind(this.compositionHelper
)(ev
)) {
4451 if (this.buffer
.ybase
!== this.buffer
.ydisp
) {
4452 this.scrollToBottom();
4457 var result
= this.evaluateKeyEscapeSequence(ev
);
4458 if (result
.key
=== EscapeSequences_1
.C0
.DC3
) {
4459 this.writeStopped
= true;
4461 else if (result
.key
=== EscapeSequences_1
.C0
.DC1
) {
4462 this.writeStopped
= false;
4464 if (result
.scrollDisp
) {
4465 this.scrollDisp(result
.scrollDisp
);
4466 return this.cancel(ev
, true);
4468 if (isThirdLevelShift(this, ev
)) {
4471 if (result
.cancel
) {
4472 this.cancel(ev
, true);
4477 this.emit('keydown', ev
);
4478 this.emit('key', result
.key
, ev
);
4480 this.handler(result
.key
);
4481 return this.cancel(ev
, true);
4483 Terminal
.prototype.evaluateKeyEscapeSequence = function (ev
) {
4487 scrollDisp
: undefined
4489 var modifiers
= ev
.shiftKey
<< 0 | ev
.altKey
<< 1 | ev
.ctrlKey
<< 2 | ev
.metaKey
<< 3;
4490 switch (ev
.keyCode
) {
4493 result
.key
= EscapeSequences_1
.C0
.BS
;
4496 result
.key
= EscapeSequences_1
.C0
.DEL
;
4500 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[Z';
4503 result
.key
= EscapeSequences_1
.C0
.HT
;
4504 result
.cancel
= true;
4507 result
.key
= EscapeSequences_1
.C0
.CR
;
4508 result
.cancel
= true;
4511 result
.key
= EscapeSequences_1
.C0
.ESC
;
4512 result
.cancel
= true;
4516 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'D';
4517 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3D') {
4518 result
.key
= (this.browser
.isMac
) ? EscapeSequences_1
.C0
.ESC
+ 'b' : EscapeSequences_1
.C0
.ESC
+ '[1;5D';
4521 else if (this.applicationCursor
) {
4522 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OD';
4525 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[D';
4530 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'C';
4531 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3C') {
4532 result
.key
= (this.browser
.isMac
) ? EscapeSequences_1
.C0
.ESC
+ 'f' : EscapeSequences_1
.C0
.ESC
+ '[1;5C';
4535 else if (this.applicationCursor
) {
4536 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OC';
4539 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[C';
4544 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'A';
4545 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3A') {
4546 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;5A';
4549 else if (this.applicationCursor
) {
4550 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OA';
4553 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[A';
4558 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'B';
4559 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3B') {
4560 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;5B';
4563 else if (this.applicationCursor
) {
4564 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OB';
4567 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[B';
4571 if (!ev
.shiftKey
&& !ev
.ctrlKey
) {
4572 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[2~';
4577 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[3;' + (modifiers
+ 1) + '~';
4580 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[3~';
4585 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'H';
4586 else if (this.applicationCursor
)
4587 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OH';
4589 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[H';
4593 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'F';
4594 else if (this.applicationCursor
)
4595 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OF';
4597 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[F';
4601 result
.scrollDisp
= -(this.rows
- 1);
4604 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[5~';
4609 result
.scrollDisp
= this.rows
- 1;
4612 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[6~';
4617 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'P';
4620 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OP';
4625 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'Q';
4628 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OQ';
4633 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'R';
4636 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OR';
4641 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'S';
4644 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OS';
4649 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[15;' + (modifiers
+ 1) + '~';
4652 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[15~';
4657 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[17;' + (modifiers
+ 1) + '~';
4660 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[17~';
4665 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[18;' + (modifiers
+ 1) + '~';
4668 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[18~';
4673 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[19;' + (modifiers
+ 1) + '~';
4676 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[19~';
4681 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[20;' + (modifiers
+ 1) + '~';
4684 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[20~';
4689 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[21;' + (modifiers
+ 1) + '~';
4692 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[21~';
4697 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[23;' + (modifiers
+ 1) + '~';
4700 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[23~';
4705 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[24;' + (modifiers
+ 1) + '~';
4708 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[24~';
4712 if (ev
.ctrlKey
&& !ev
.shiftKey
&& !ev
.altKey
&& !ev
.metaKey
) {
4713 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
4714 result
.key
= String
.fromCharCode(ev
.keyCode
- 64);
4716 else if (ev
.keyCode
=== 32) {
4717 result
.key
= String
.fromCharCode(0);
4719 else if (ev
.keyCode
>= 51 && ev
.keyCode
<= 55) {
4720 result
.key
= String
.fromCharCode(ev
.keyCode
- 51 + 27);
4722 else if (ev
.keyCode
=== 56) {
4723 result
.key
= String
.fromCharCode(127);
4725 else if (ev
.keyCode
=== 219) {
4726 result
.key
= String
.fromCharCode(27);
4728 else if (ev
.keyCode
=== 220) {
4729 result
.key
= String
.fromCharCode(28);
4731 else if (ev
.keyCode
=== 221) {
4732 result
.key
= String
.fromCharCode(29);
4735 else if (!this.browser
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) {
4736 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
4737 result
.key
= EscapeSequences_1
.C0
.ESC
+ String
.fromCharCode(ev
.keyCode
+ 32);
4739 else if (ev
.keyCode
=== 192) {
4740 result
.key
= EscapeSequences_1
.C0
.ESC
+ '`';
4742 else if (ev
.keyCode
>= 48 && ev
.keyCode
<= 57) {
4743 result
.key
= EscapeSequences_1
.C0
.ESC
+ (ev
.keyCode
- 48);
4746 else if (this.browser
.isMac
&& !ev
.altKey
&& !ev
.ctrlKey
&& ev
.metaKey
) {
4747 if (ev
.keyCode
=== 65) {
4755 Terminal
.prototype.setgLevel = function (g
) {
4757 this.charset
= this.charsets
[g
];
4759 Terminal
.prototype.setgCharset = function (g
, charset
) {
4760 this.charsets
[g
] = charset
;
4761 if (this.glevel
=== g
) {
4762 this.charset
= charset
;
4765 Terminal
.prototype.keyPress = function (ev
) {
4767 if (this.customKeyEventHandler
&& this.customKeyEventHandler(ev
) === false) {
4774 else if (ev
.which
== null) {
4777 else if (ev
.which
!== 0 && ev
.charCode
!== 0) {
4783 if (!key
|| ((ev
.altKey
|| ev
.ctrlKey
|| ev
.metaKey
) && !isThirdLevelShift(this, ev
))) {
4786 key
= String
.fromCharCode(key
);
4787 this.emit('keypress', key
, ev
);
4788 this.emit('key', key
, ev
);
4793 Terminal
.prototype.send = function (data
) {
4796 setTimeout(function () {
4797 self
.handler(self
.queue
);
4803 Terminal
.prototype.bell = function () {
4804 if (!this.visualBell
)
4807 this.element
.style
.borderColor
= 'white';
4808 setTimeout(function () {
4809 self
.element
.style
.borderColor
= '';
4814 Terminal
.prototype.log = function () {
4817 if (!this.context
.console
|| !this.context
.console
.log
)
4819 var args
= Array
.prototype.slice
.call(arguments
);
4820 this.context
.console
.log
.apply(this.context
.console
, args
);
4822 Terminal
.prototype.error = function () {
4825 if (!this.context
.console
|| !this.context
.console
.error
)
4827 var args
= Array
.prototype.slice
.call(arguments
);
4828 this.context
.console
.error
.apply(this.context
.console
, args
);
4830 Terminal
.prototype.resize = function (x
, y
) {
4831 if (isNaN(x
) || isNaN(y
)) {
4834 if (y
> this.getOption('scrollback')) {
4835 this.setOption('scrollback', y
);
4837 var line
, el
, i
, j
, ch
, addToY
;
4838 if (x
=== this.cols
&& y
=== this.rows
) {
4839 if (!this.charMeasure
.width
|| !this.charMeasure
.height
) {
4840 this.charMeasure
.measure();
4848 this.buffers
.resize(x
, y
);
4849 while (this.children
.length
< y
) {
4852 while (this.children
.length
> y
) {
4853 el
= this.children
.shift();
4856 el
.parentNode
.removeChild(el
);
4860 this.setupStops(this.cols
);
4861 this.charMeasure
.measure();
4862 this.refresh(0, this.rows
- 1);
4863 this.geometry
= [this.cols
, this.rows
];
4864 this.emit('resize', { terminal
: this, cols
: x
, rows
: y
});
4866 Terminal
.prototype.updateRange = function (y
) {
4867 if (y
< this.refreshStart
)
4868 this.refreshStart
= y
;
4869 if (y
> this.refreshEnd
)
4870 this.refreshEnd
= y
;
4872 Terminal
.prototype.maxRange = function () {
4873 this.refreshStart
= 0;
4874 this.refreshEnd
= this.rows
- 1;
4876 Terminal
.prototype.setupStops = function (i
) {
4878 if (!this.buffer
.tabs
[i
]) {
4879 i
= this.prevStop(i
);
4883 this.buffer
.tabs
= {};
4886 for (; i
< this.cols
; i
+= this.getOption('tabStopWidth')) {
4887 this.buffer
.tabs
[i
] = true;
4890 Terminal
.prototype.prevStop = function (x
) {
4893 while (!this.buffer
.tabs
[--x
] && x
> 0)
4895 return x
>= this.cols
4899 Terminal
.prototype.nextStop = function (x
) {
4902 while (!this.buffer
.tabs
[++x
] && x
< this.cols
)
4904 return x
>= this.cols
4908 Terminal
.prototype.eraseRight = function (x
, y
) {
4909 var line
= this.buffer
.lines
.get(this.buffer
.ybase
+ y
);
4913 var ch
= [this.eraseAttr(), ' ', 1];
4914 for (; x
< this.cols
; x
++) {
4917 this.updateRange(y
);
4919 Terminal
.prototype.eraseLeft = function (x
, y
) {
4920 var line
= this.buffer
.lines
.get(this.buffer
.ybase
+ y
);
4924 var ch
= [this.eraseAttr(), ' ', 1];
4929 this.updateRange(y
);
4931 Terminal
.prototype.clear = function () {
4932 if (this.buffer
.ybase
=== 0 && this.buffer
.y
=== 0) {
4935 this.buffer
.lines
.set(0, this.buffer
.lines
.get(this.buffer
.ybase
+ this.buffer
.y
));
4936 this.buffer
.lines
.length
= 1;
4937 this.buffer
.ydisp
= 0;
4938 this.buffer
.ybase
= 0;
4940 for (var i
= 1; i
< this.rows
; i
++) {
4941 this.buffer
.lines
.push(this.blankLine());
4943 this.refresh(0, this.rows
- 1);
4944 this.emit('scroll', this.buffer
.ydisp
);
4946 Terminal
.prototype.eraseLine = function (y
) {
4947 this.eraseRight(0, y
);
4949 Terminal
.prototype.blankLine = function (cur
, isWrapped
) {
4953 var ch
= [attr
, ' ', 1], line
= [], i
= 0;
4955 line
.isWrapped
= isWrapped
;
4957 for (; i
< this.cols
; i
++) {
4962 Terminal
.prototype.ch = function (cur
) {
4964 ? [this.eraseAttr(), ' ', 1]
4965 : [this.defAttr
, ' ', 1];
4967 Terminal
.prototype.is = function (term
) {
4968 var name
= this.termName
;
4969 return (name
+ '').indexOf(term
) === 0;
4971 Terminal
.prototype.handler = function (data
) {
4972 if (this.options
.disableStdin
) {
4975 if (this.selectionManager
&& this.selectionManager
.hasSelection
) {
4976 this.selectionManager
.clearSelection();
4978 if (this.buffer
.ybase
!== this.buffer
.ydisp
) {
4979 this.scrollToBottom();
4981 this.emit('data', data
);
4983 Terminal
.prototype.handleTitle = function (title
) {
4984 this.emit('title', title
);
4986 Terminal
.prototype.index = function () {
4988 if (this.buffer
.y
> this.buffer
.scrollBottom
) {
4992 if (this.buffer
.x
>= this.cols
) {
4996 Terminal
.prototype.reverseIndex = function () {
4998 if (this.buffer
.y
=== this.buffer
.scrollTop
) {
4999 this.buffer
.lines
.shiftElements(this.buffer
.y
+ this.buffer
.ybase
, this.rows
- 1, 1);
5000 this.buffer
.lines
.set(this.buffer
.y
+ this.buffer
.ybase
, this.blankLine(true));
5001 this.updateRange(this.buffer
.scrollTop
);
5002 this.updateRange(this.buffer
.scrollBottom
);
5008 Terminal
.prototype.reset = function () {
5009 this.options
.rows
= this.rows
;
5010 this.options
.cols
= this.cols
;
5011 var customKeyEventHandler
= this.customKeyEventHandler
;
5012 var cursorBlinkInterval
= this.cursorBlinkInterval
;
5013 var inputHandler
= this.inputHandler
;
5014 Terminal
.call(this, this.options
);
5015 this.customKeyEventHandler
= customKeyEventHandler
;
5016 this.cursorBlinkInterval
= cursorBlinkInterval
;
5017 this.inputHandler
= inputHandler
;
5018 this.refresh(0, this.rows
- 1);
5019 this.viewport
.syncScrollArea();
5021 Terminal
.prototype.tabSet = function () {
5022 this.buffer
.tabs
[this.buffer
.x
] = true;
5024 function on(el
, type
, handler
, capture
) {
5025 if (!Array
.isArray(el
)) {
5028 el
.forEach(function (element
) {
5029 element
.addEventListener(type
, handler
, capture
|| false);
5032 function off(el
, type
, handler
, capture
) {
5033 el
.removeEventListener(type
, handler
, capture
|| false);
5035 function cancel(ev
, force
) {
5036 if (!this.cancelEvents
&& !force
) {
5039 ev
.preventDefault();
5040 ev
.stopPropagation();
5043 function inherits(child
, parent
) {
5045 this.constructor = child
;
5047 f
.prototype = parent
.prototype;
5048 child
.prototype = new f
;
5050 function indexOf(obj
, el
) {
5058 function isThirdLevelShift(term
, ev
) {
5059 var thirdLevelKey
= (term
.browser
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) ||
5060 (term
.browser
.isMSWindows
&& ev
.altKey
&& ev
.ctrlKey
&& !ev
.metaKey
);
5061 if (ev
.type
== 'keypress') {
5062 return thirdLevelKey
;
5064 return thirdLevelKey
&& (!ev
.keyCode
|| ev
.keyCode
> 47);
5066 Terminal
.prototype.matchColor
= matchColor
;
5067 function matchColor(r1
, g1
, b1
) {
5068 var hash
= (r1
<< 16) | (g1
<< 8) | b1
;
5069 if (matchColor
._cache
[hash
] != null) {
5070 return matchColor
._cache
[hash
];
5072 var ldiff
= Infinity
, li
= -1, i
= 0, c
, r2
, g2
, b2
, diff
;
5073 for (; i
< Terminal
.vcolors
.length
; i
++) {
5074 c
= Terminal
.vcolors
[i
];
5078 diff
= matchColor
.distance(r1
, g1
, b1
, r2
, g2
, b2
);
5088 return matchColor
._cache
[hash
] = li
;
5090 matchColor
._cache
= {};
5091 matchColor
.distance = function (r1
, g1
, b1
, r2
, g2
, b2
) {
5092 return Math
.pow(30 * (r1
- r2
), 2)
5093 + Math
.pow(59 * (g1
- g2
), 2)
5094 + Math
.pow(11 * (b1
- b2
), 2);
5096 function each(obj
, iter
, con
) {
5098 return obj
.forEach(iter
, con
);
5099 for (var i
= 0; i
< obj
.length
; i
++) {
5100 iter
.call(con
, obj
[i
], i
, obj
);
5103 function wasMondifierKeyOnlyEvent(ev
) {
5104 return ev
.keyCode
=== 16 ||
5105 ev
.keyCode
=== 17 ||
5108 function keys(obj
) {
5110 return Object
.keys(obj
);
5113 if (Object
.prototype.hasOwnProperty
.call(obj
, key
)) {
5119 Terminal
.translateBufferLineToString
= BufferLine_1
.translateBufferLineToString
;
5120 Terminal
.EventEmitter
= EventEmitter_1
.EventEmitter
;
5121 Terminal
.inherits
= inherits
;
5124 Terminal
.cancel
= cancel
;
5125 module
.exports
= Terminal
;
5129 },{"./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)
5131 //# sourceMappingURL=xterm.js.map