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