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