]>
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(_dereq_,module,exports){ | |
2 | 'use strict'; | |
3 | ||
4 | Object.defineProperty(exports, "__esModule", { | |
5 | value: true | |
6 | }); | |
7 | /** | |
8 | * xterm.js: xterm, in the browser | |
9 | * Copyright (c) 2014-2016, SourceLair Private Company (www.sourcelair.com (MIT License) | |
10 | */ | |
11 | ||
12 | /** | |
13 | * Encapsulates the logic for handling compositionstart, compositionupdate and compositionend | |
14 | * events, displaying the in-progress composition to the UI and forwarding the final composition | |
15 | * to the handler. | |
16 | * @param {HTMLTextAreaElement} textarea The textarea that xterm uses for input. | |
17 | * @param {HTMLElement} compositionView The element to display the in-progress composition in. | |
18 | * @param {Terminal} terminal The Terminal to forward the finished composition to. | |
19 | */ | |
20 | function CompositionHelper(textarea, compositionView, terminal) { | |
21 | this.textarea = textarea; | |
22 | this.compositionView = compositionView; | |
23 | this.terminal = terminal; | |
24 | ||
25 | // Whether input composition is currently happening, eg. via a mobile keyboard, speech input | |
26 | // or IME. This variable determines whether the compositionText should be displayed on the UI. | |
27 | this.isComposing = false; | |
28 | ||
29 | // The input currently being composed, eg. via a mobile keyboard, speech input or IME. | |
30 | this.compositionText = null; | |
31 | ||
32 | // The position within the input textarea's value of the current composition. | |
33 | this.compositionPosition = { start: null, end: null }; | |
34 | ||
35 | // Whether a composition is in the process of being sent, setting this to false will cancel | |
36 | // any in-progress composition. | |
37 | this.isSendingComposition = false; | |
38 | } | |
39 | ||
40 | /** | |
41 | * Handles the compositionstart event, activating the composition view. | |
42 | */ | |
43 | CompositionHelper.prototype.compositionstart = function () { | |
44 | this.isComposing = true; | |
45 | this.compositionPosition.start = this.textarea.value.length; | |
46 | this.compositionView.textContent = ''; | |
47 | this.compositionView.classList.add('active'); | |
48 | }; | |
49 | ||
50 | /** | |
51 | * Handles the compositionupdate event, updating the composition view. | |
52 | * @param {CompositionEvent} ev The event. | |
53 | */ | |
54 | CompositionHelper.prototype.compositionupdate = function (ev) { | |
55 | this.compositionView.textContent = ev.data; | |
56 | this.updateCompositionElements(); | |
57 | var self = this; | |
58 | setTimeout(function () { | |
59 | self.compositionPosition.end = self.textarea.value.length; | |
60 | }, 0); | |
61 | }; | |
62 | ||
63 | /** | |
64 | * Handles the compositionend event, hiding the composition view and sending the composition to | |
65 | * the handler. | |
66 | */ | |
67 | CompositionHelper.prototype.compositionend = function () { | |
68 | this.finalizeComposition(true); | |
69 | }; | |
70 | ||
71 | /** | |
72 | * Handles the keydown event, routing any necessary events to the CompositionHelper functions. | |
73 | * @return Whether the Terminal should continue processing the keydown event. | |
74 | */ | |
75 | CompositionHelper.prototype.keydown = function (ev) { | |
76 | if (this.isComposing || this.isSendingComposition) { | |
77 | if (ev.keyCode === 229) { | |
78 | // Continue composing if the keyCode is the "composition character" | |
79 | return false; | |
80 | } else if (ev.keyCode === 16 || ev.keyCode === 17 || ev.keyCode === 18) { | |
81 | // Continue composing if the keyCode is a modifier key | |
82 | return false; | |
83 | } else { | |
84 | // Finish composition immediately. This is mainly here for the case where enter is | |
85 | // pressed and the handler needs to be triggered before the command is executed. | |
86 | this.finalizeComposition(false); | |
87 | } | |
88 | } | |
89 | ||
90 | if (ev.keyCode === 229) { | |
91 | // If the "composition character" is used but gets to this point it means a non-composition | |
92 | // character (eg. numbers and punctuation) was pressed when the IME was active. | |
93 | this.handleAnyTextareaChanges(); | |
94 | return false; | |
95 | } | |
96 | ||
97 | return true; | |
98 | }; | |
99 | ||
100 | /** | |
101 | * Finalizes the composition, resuming regular input actions. This is called when a composition | |
102 | * is ending. | |
103 | * @param {boolean} waitForPropogation Whether to wait for events to propogate before sending | |
104 | * the input. This should be false if a non-composition keystroke is entered before the | |
105 | * compositionend event is triggered, such as enter, so that the composition is send before | |
106 | * the command is executed. | |
107 | */ | |
108 | CompositionHelper.prototype.finalizeComposition = function (waitForPropogation) { | |
109 | this.compositionView.classList.remove('active'); | |
110 | this.isComposing = false; | |
111 | this.clearTextareaPosition(); | |
112 | ||
113 | if (!waitForPropogation) { | |
114 | // Cancel any delayed composition send requests and send the input immediately. | |
115 | this.isSendingComposition = false; | |
116 | var input = this.textarea.value.substring(this.compositionPosition.start, this.compositionPosition.end); | |
117 | this.terminal.handler(input); | |
118 | } else { | |
119 | // Make a deep copy of the composition position here as a new compositionstart event may | |
120 | // fire before the setTimeout executes. | |
121 | var currentCompositionPosition = { | |
122 | start: this.compositionPosition.start, | |
123 | end: this.compositionPosition.end | |
124 | }; | |
125 | ||
126 | // Since composition* events happen before the changes take place in the textarea on most | |
127 | // browsers, use a setTimeout with 0ms time to allow the native compositionend event to | |
128 | // complete. This ensures the correct character is retrieved, this solution was used | |
129 | // because: | |
130 | // - The compositionend event's data property is unreliable, at least on Chromium | |
131 | // - The last compositionupdate event's data property does not always accurately describe | |
132 | // the character, a counter example being Korean where an ending consonsant can move to | |
133 | // the following character if the following input is a vowel. | |
134 | var self = this; | |
135 | this.isSendingComposition = true; | |
136 | setTimeout(function () { | |
137 | // Ensure that the input has not already been sent | |
138 | if (self.isSendingComposition) { | |
139 | self.isSendingComposition = false; | |
140 | var input; | |
141 | if (self.isComposing) { | |
142 | // Use the end position to get the string if a new composition has started. | |
143 | input = self.textarea.value.substring(currentCompositionPosition.start, currentCompositionPosition.end); | |
144 | } else { | |
145 | // Don't use the end position here in order to pick up any characters after the | |
146 | // composition has finished, for example when typing a non-composition character | |
147 | // (eg. 2) after a composition character. | |
148 | input = self.textarea.value.substring(currentCompositionPosition.start); | |
149 | } | |
150 | self.terminal.handler(input); | |
151 | } | |
152 | }, 0); | |
153 | } | |
154 | }; | |
155 | ||
156 | /** | |
157 | * Apply any changes made to the textarea after the current event chain is allowed to complete. | |
158 | * This should be called when not currently composing but a keydown event with the "composition | |
159 | * character" (229) is triggered, in order to allow non-composition text to be entered when an | |
160 | * IME is active. | |
161 | */ | |
162 | CompositionHelper.prototype.handleAnyTextareaChanges = function () { | |
163 | var oldValue = this.textarea.value; | |
164 | var self = this; | |
165 | setTimeout(function () { | |
166 | // Ignore if a composition has started since the timeout | |
167 | if (!self.isComposing) { | |
168 | var newValue = self.textarea.value; | |
169 | var diff = newValue.replace(oldValue, ''); | |
170 | if (diff.length > 0) { | |
171 | self.terminal.handler(diff); | |
172 | } | |
173 | } | |
174 | }, 0); | |
175 | }; | |
176 | ||
177 | /** | |
178 | * Positions the composition view on top of the cursor and the textarea just below it (so the | |
179 | * IME helper dialog is positioned correctly). | |
180 | */ | |
181 | CompositionHelper.prototype.updateCompositionElements = function (dontRecurse) { | |
182 | if (!this.isComposing) { | |
183 | return; | |
184 | } | |
185 | var cursor = this.terminal.element.querySelector('.terminal-cursor'); | |
186 | if (cursor) { | |
187 | // Take .xterm-rows offsetTop into account as well in case it's positioned absolutely within | |
188 | // the .xterm element. | |
189 | var xtermRows = this.terminal.element.querySelector('.xterm-rows'); | |
190 | var cursorTop = xtermRows.offsetTop + cursor.offsetTop; | |
191 | ||
192 | this.compositionView.style.left = cursor.offsetLeft + 'px'; | |
193 | this.compositionView.style.top = cursorTop + 'px'; | |
194 | this.compositionView.style.height = cursor.offsetHeight + 'px'; | |
195 | this.compositionView.style.lineHeight = cursor.offsetHeight + 'px'; | |
196 | // Sync the textarea to the exact position of the composition view so the IME knows where the | |
197 | // text is. | |
198 | var compositionViewBounds = this.compositionView.getBoundingClientRect(); | |
199 | this.textarea.style.left = cursor.offsetLeft + 'px'; | |
200 | this.textarea.style.top = cursorTop + 'px'; | |
201 | this.textarea.style.width = compositionViewBounds.width + 'px'; | |
202 | this.textarea.style.height = compositionViewBounds.height + 'px'; | |
203 | this.textarea.style.lineHeight = compositionViewBounds.height + 'px'; | |
204 | } | |
205 | if (!dontRecurse) { | |
206 | setTimeout(this.updateCompositionElements.bind(this, true), 0); | |
207 | } | |
208 | }; | |
209 | ||
210 | /** | |
211 | * Clears the textarea's position so that the cursor does not blink on IE. | |
212 | * @private | |
213 | */ | |
214 | CompositionHelper.prototype.clearTextareaPosition = function () { | |
215 | this.textarea.style.left = ''; | |
216 | this.textarea.style.top = ''; | |
217 | }; | |
218 | ||
219 | exports.CompositionHelper = CompositionHelper; | |
220 | ||
221 | },{}],2:[function(_dereq_,module,exports){ | |
222 | "use strict"; | |
223 | ||
224 | Object.defineProperty(exports, "__esModule", { | |
225 | value: true | |
226 | }); | |
227 | /** | |
228 | * xterm.js: xterm, in the browser | |
229 | * Copyright (c) 2014-2016, SourceLair Private Company (www.sourcelair.com (MIT License) | |
230 | */ | |
231 | ||
232 | function EventEmitter() { | |
233 | this._events = this._events || {}; | |
234 | } | |
235 | ||
236 | EventEmitter.prototype.addListener = function (type, listener) { | |
237 | this._events[type] = this._events[type] || []; | |
238 | this._events[type].push(listener); | |
239 | }; | |
240 | ||
241 | EventEmitter.prototype.on = EventEmitter.prototype.addListener; | |
242 | ||
243 | EventEmitter.prototype.removeListener = function (type, listener) { | |
244 | if (!this._events[type]) return; | |
245 | ||
246 | var obj = this._events[type], | |
247 | i = obj.length; | |
248 | ||
249 | while (i--) { | |
250 | if (obj[i] === listener || obj[i].listener === listener) { | |
251 | obj.splice(i, 1); | |
252 | return; | |
253 | } | |
254 | } | |
255 | }; | |
256 | ||
257 | EventEmitter.prototype.off = EventEmitter.prototype.removeListener; | |
258 | ||
259 | EventEmitter.prototype.removeAllListeners = function (type) { | |
260 | if (this._events[type]) delete this._events[type]; | |
261 | }; | |
262 | ||
263 | EventEmitter.prototype.once = function (type, listener) { | |
264 | var self = this; | |
265 | function on() { | |
266 | var args = Array.prototype.slice.call(arguments); | |
267 | this.removeListener(type, on); | |
268 | return listener.apply(this, args); | |
269 | } | |
270 | on.listener = listener; | |
271 | return this.on(type, on); | |
272 | }; | |
273 | ||
274 | EventEmitter.prototype.emit = function (type) { | |
275 | if (!this._events[type]) return; | |
276 | ||
277 | var args = Array.prototype.slice.call(arguments, 1), | |
278 | obj = this._events[type], | |
279 | l = obj.length, | |
280 | i = 0; | |
281 | ||
282 | for (; i < l; i++) { | |
283 | obj[i].apply(this, args); | |
284 | } | |
285 | }; | |
286 | ||
287 | EventEmitter.prototype.listeners = function (type) { | |
288 | return this._events[type] = this._events[type] || []; | |
289 | }; | |
290 | ||
291 | exports.EventEmitter = EventEmitter; | |
292 | ||
293 | },{}],3:[function(_dereq_,module,exports){ | |
294 | 'use strict'; | |
295 | ||
296 | Object.defineProperty(exports, "__esModule", { | |
297 | value: true | |
298 | }); | |
299 | /** | |
300 | * xterm.js: xterm, in the browser | |
301 | * Copyright (c) 2014-2016, SourceLair Private Company (www.sourcelair.com (MIT License) | |
302 | */ | |
303 | ||
304 | /** | |
305 | * Represents the viewport of a terminal, the visible area within the larger buffer of output. | |
306 | * Logic for the virtual scroll bar is included in this object. | |
307 | * @param {Terminal} terminal The Terminal object. | |
308 | * @param {HTMLElement} viewportElement The DOM element acting as the viewport | |
309 | * @param {HTMLElement} charMeasureElement A DOM element used to measure the character size of | |
310 | * the terminal. | |
311 | */ | |
312 | function Viewport(terminal, viewportElement, scrollArea, charMeasureElement) { | |
313 | this.terminal = terminal; | |
314 | this.viewportElement = viewportElement; | |
315 | this.scrollArea = scrollArea; | |
316 | this.charMeasureElement = charMeasureElement; | |
317 | this.currentRowHeight = 0; | |
318 | this.lastRecordedBufferLength = 0; | |
319 | this.lastRecordedViewportHeight = 0; | |
320 | ||
321 | this.terminal.on('scroll', this.syncScrollArea.bind(this)); | |
322 | this.terminal.on('resize', this.syncScrollArea.bind(this)); | |
323 | this.viewportElement.addEventListener('scroll', this.onScroll.bind(this)); | |
324 | ||
325 | this.syncScrollArea(); | |
326 | } | |
327 | ||
328 | /** | |
329 | * Refreshes row height, setting line-height, viewport height and scroll area height if | |
330 | * necessary. | |
331 | * @param {number|undefined} charSize A character size measurement bounding rect object, if it | |
332 | * doesn't exist it will be created. | |
333 | */ | |
334 | Viewport.prototype.refresh = function (charSize) { | |
335 | var size = charSize || this.charMeasureElement.getBoundingClientRect(); | |
336 | if (size.height > 0) { | |
337 | var rowHeightChanged = size.height !== this.currentRowHeight; | |
338 | if (rowHeightChanged) { | |
339 | this.currentRowHeight = size.height; | |
340 | this.viewportElement.style.lineHeight = size.height + 'px'; | |
341 | this.terminal.rowContainer.style.lineHeight = size.height + 'px'; | |
342 | } | |
343 | var viewportHeightChanged = this.lastRecordedViewportHeight !== this.terminal.rows; | |
344 | if (rowHeightChanged || viewportHeightChanged) { | |
345 | this.lastRecordedViewportHeight = this.terminal.rows; | |
346 | this.viewportElement.style.height = size.height * this.terminal.rows + 'px'; | |
347 | } | |
348 | this.scrollArea.style.height = size.height * this.lastRecordedBufferLength + 'px'; | |
349 | } | |
350 | }; | |
351 | ||
352 | /** | |
353 | * Updates dimensions and synchronizes the scroll area if necessary. | |
354 | */ | |
355 | Viewport.prototype.syncScrollArea = function () { | |
356 | if (this.lastRecordedBufferLength !== this.terminal.lines.length) { | |
357 | // If buffer height changed | |
358 | this.lastRecordedBufferLength = this.terminal.lines.length; | |
359 | this.refresh(); | |
360 | } else if (this.lastRecordedViewportHeight !== this.terminal.rows) { | |
361 | // If viewport height changed | |
362 | this.refresh(); | |
363 | } else { | |
364 | // If size has changed, refresh viewport | |
365 | var size = this.charMeasureElement.getBoundingClientRect(); | |
366 | if (size.height !== this.currentRowHeight) { | |
367 | this.refresh(size); | |
368 | } | |
369 | } | |
370 | ||
371 | // Sync scrollTop | |
372 | var scrollTop = this.terminal.ydisp * this.currentRowHeight; | |
373 | if (this.viewportElement.scrollTop !== scrollTop) { | |
374 | this.viewportElement.scrollTop = scrollTop; | |
375 | } | |
376 | }; | |
377 | ||
378 | /** | |
379 | * Handles scroll events on the viewport, calculating the new viewport and requesting the | |
380 | * terminal to scroll to it. | |
381 | * @param {Event} ev The scroll event. | |
382 | */ | |
383 | Viewport.prototype.onScroll = function (ev) { | |
384 | var newRow = Math.round(this.viewportElement.scrollTop / this.currentRowHeight); | |
385 | var diff = newRow - this.terminal.ydisp; | |
386 | this.terminal.scrollDisp(diff, true); | |
387 | }; | |
388 | ||
389 | /** | |
390 | * Handles mouse wheel events by adjusting the viewport's scrollTop and delegating the actual | |
391 | * scrolling to `onScroll`, this event needs to be attached manually by the consumer of | |
392 | * `Viewport`. | |
393 | * @param {WheelEvent} ev The mouse wheel event. | |
394 | */ | |
395 | Viewport.prototype.onWheel = function (ev) { | |
396 | if (ev.deltaY === 0) { | |
397 | // Do nothing if it's not a vertical scroll event | |
398 | return; | |
399 | } | |
400 | // Fallback to WheelEvent.DOM_DELTA_PIXEL | |
401 | var multiplier = 1; | |
402 | if (ev.deltaMode === WheelEvent.DOM_DELTA_LINE) { | |
403 | multiplier = this.currentRowHeight; | |
404 | } else if (ev.deltaMode === WheelEvent.DOM_DELTA_PAGE) { | |
405 | multiplier = this.currentRowHeight * this.terminal.rows; | |
406 | } | |
407 | this.viewportElement.scrollTop += ev.deltaY * multiplier; | |
408 | // Prevent the page from scrolling when the terminal scrolls | |
409 | ev.preventDefault(); | |
410 | }; | |
411 | ||
412 | exports.Viewport = Viewport; | |
413 | ||
414 | },{}],4:[function(_dereq_,module,exports){ | |
415 | 'use strict'; | |
416 | ||
417 | Object.defineProperty(exports, "__esModule", { | |
418 | value: true | |
419 | }); | |
420 | /** | |
421 | * xterm.js: xterm, in the browser | |
422 | * Copyright (c) 2016, SourceLair Private Company <www.sourcelair.com> (MIT License) | |
423 | */ | |
424 | ||
425 | /** | |
426 | * Clipboard handler module. This module contains methods for handling all | |
427 | * clipboard-related events appropriately in the terminal. | |
428 | * @module xterm/handlers/Clipboard | |
429 | */ | |
430 | ||
431 | /** | |
432 | * Prepares text copied from terminal selection, to be saved in the clipboard by: | |
433 | * 1. stripping all trailing white spaces | |
434 | * 2. converting all non-breaking spaces to regular spaces | |
435 | * @param {string} text The copied text that needs processing for storing in clipboard | |
436 | * @returns {string} | |
437 | */ | |
438 | function prepareTextForClipboard(text) { | |
439 | var space = String.fromCharCode(32), | |
440 | nonBreakingSpace = String.fromCharCode(160), | |
441 | allNonBreakingSpaces = new RegExp(nonBreakingSpace, 'g'), | |
442 | processedText = text.split('\n').map(function (line) { | |
443 | // Strip all trailing white spaces and convert all non-breaking spaces | |
444 | // to regular spaces. | |
445 | var processedLine = line.replace(/\s+$/g, '').replace(allNonBreakingSpaces, space); | |
446 | ||
447 | return processedLine; | |
448 | }).join('\n'); | |
449 | ||
450 | return processedText; | |
451 | } | |
452 | ||
453 | /** | |
454 | * Binds copy functionality to the given terminal. | |
455 | * @param {ClipboardEvent} ev The original copy event to be handled | |
456 | */ | |
457 | function copyHandler(ev, term) { | |
458 | var copiedText = window.getSelection().toString(), | |
459 | text = prepareTextForClipboard(copiedText); | |
460 | ||
461 | if (term.browser.isMSIE) { | |
462 | window.clipboardData.setData('Text', text); | |
463 | } else { | |
464 | ev.clipboardData.setData('text/plain', text); | |
465 | } | |
466 | ||
467 | ev.preventDefault(); // Prevent or the original text will be copied. | |
468 | } | |
469 | ||
470 | /** | |
471 | * Redirect the clipboard's data to the terminal's input handler. | |
472 | * @param {ClipboardEvent} ev The original paste event to be handled | |
473 | * @param {Terminal} term The terminal on which to apply the handled paste event | |
474 | */ | |
475 | function pasteHandler(ev, term) { | |
476 | ev.stopPropagation(); | |
477 | ||
478 | var dispatchPaste = function dispatchPaste(text) { | |
479 | term.handler(text); | |
480 | term.textarea.value = ''; | |
481 | return term.cancel(ev); | |
482 | }; | |
483 | ||
484 | if (term.browser.isMSIE) { | |
485 | if (window.clipboardData) { | |
486 | var text = window.clipboardData.getData('Text'); | |
487 | dispatchPaste(text); | |
488 | } | |
489 | } else { | |
490 | if (ev.clipboardData) { | |
491 | var text = ev.clipboardData.getData('text/plain'); | |
492 | dispatchPaste(text); | |
493 | } | |
494 | } | |
495 | } | |
496 | ||
497 | /** | |
498 | * Bind to right-click event and allow right-click copy and paste. | |
499 | * | |
500 | * **Logic** | |
501 | * If text is selected and right-click happens on selected text, then | |
502 | * do nothing to allow seamless copying. | |
503 | * If no text is selected or right-click is outside of the selection | |
504 | * area, then bring the terminal's input below the cursor, in order to | |
505 | * trigger the event on the textarea and allow-right click paste, without | |
506 | * caring about disappearing selection. | |
507 | * @param {ClipboardEvent} ev The original paste event to be handled | |
508 | * @param {Terminal} term The terminal on which to apply the handled paste event | |
509 | */ | |
510 | function rightClickHandler(ev, term) { | |
511 | var s = document.getSelection(), | |
512 | selectedText = prepareTextForClipboard(s.toString()), | |
513 | clickIsOnSelection = false; | |
514 | ||
515 | if (s.rangeCount) { | |
516 | var r = s.getRangeAt(0), | |
517 | cr = r.getClientRects(), | |
518 | x = ev.clientX, | |
519 | y = ev.clientY, | |
520 | i, | |
521 | rect; | |
522 | ||
523 | for (i = 0; i < cr.length; i++) { | |
524 | rect = cr[i]; | |
525 | clickIsOnSelection = x > rect.left && x < rect.right && y > rect.top && y < rect.bottom; | |
526 | ||
527 | if (clickIsOnSelection) { | |
528 | break; | |
529 | } | |
530 | } | |
531 | // If we clicked on selection and selection is not a single space, | |
532 | // then mark the right click as copy-only. We check for the single | |
533 | // space selection, as this can happen when clicking on an | |
534 | // and there is not much pointing in copying a single space. | |
535 | if (selectedText.match(/^\s$/) || !selectedText.length) { | |
536 | clickIsOnSelection = false; | |
537 | } | |
538 | } | |
539 | ||
540 | // Bring textarea at the cursor position | |
541 | if (!clickIsOnSelection) { | |
542 | term.textarea.style.position = 'fixed'; | |
543 | term.textarea.style.width = '20px'; | |
544 | term.textarea.style.height = '20px'; | |
545 | term.textarea.style.left = x - 10 + 'px'; | |
546 | term.textarea.style.top = y - 10 + 'px'; | |
547 | term.textarea.style.zIndex = 1000; | |
548 | term.textarea.focus(); | |
549 | ||
550 | // Reset the terminal textarea's styling | |
551 | setTimeout(function () { | |
552 | term.textarea.style.position = null; | |
553 | term.textarea.style.width = null; | |
554 | term.textarea.style.height = null; | |
555 | term.textarea.style.left = null; | |
556 | term.textarea.style.top = null; | |
557 | term.textarea.style.zIndex = null; | |
558 | }, 4); | |
559 | } | |
560 | } | |
561 | ||
562 | exports.prepareTextForClipboard = prepareTextForClipboard; | |
563 | exports.copyHandler = copyHandler; | |
564 | exports.pasteHandler = pasteHandler; | |
565 | exports.rightClickHandler = rightClickHandler; | |
566 | ||
567 | },{}],5:[function(_dereq_,module,exports){ | |
568 | 'use strict'; | |
569 | ||
570 | Object.defineProperty(exports, "__esModule", { | |
571 | value: true | |
572 | }); | |
573 | exports.isMSWindows = exports.isIphone = exports.isIpad = exports.isMac = exports.isMSIE = exports.isFirefox = undefined; | |
574 | ||
575 | var _Generic = _dereq_('./Generic.js'); | |
576 | ||
577 | var isNode = typeof navigator == 'undefined' ? true : false; /** | |
578 | * xterm.js: xterm, in the browser | |
579 | * Copyright (c) 2016, SourceLair Private Company <www.sourcelair.com> (MIT License) | |
580 | */ | |
581 | ||
582 | /** | |
583 | * Browser utilities module. This module contains attributes and methods to help with | |
584 | * identifying the current browser and platform. | |
585 | * @module xterm/utils/Browser | |
586 | */ | |
587 | ||
588 | var userAgent = isNode ? 'node' : navigator.userAgent; | |
589 | var platform = isNode ? 'node' : navigator.platform; | |
590 | ||
591 | var isFirefox = exports.isFirefox = !!~userAgent.indexOf('Firefox'); | |
592 | var isMSIE = exports.isMSIE = !!~userAgent.indexOf('MSIE') || !!~userAgent.indexOf('Trident'); | |
593 | ||
594 | // Find the users platform. We use this to interpret the meta key | |
595 | // and ISO third level shifts. | |
596 | // http://stackoverflow.com/q/19877924/577598 | |
597 | var isMac = exports.isMac = (0, _Generic.contains)(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], platform); | |
598 | var isIpad = exports.isIpad = platform === 'iPad'; | |
599 | var isIphone = exports.isIphone = platform === 'iPhone'; | |
600 | var isMSWindows = exports.isMSWindows = (0, _Generic.contains)(['Windows', 'Win16', 'Win32', 'WinCE'], platform); | |
601 | ||
602 | },{"./Generic.js":6}],6:[function(_dereq_,module,exports){ | |
603 | "use strict"; | |
604 | ||
605 | Object.defineProperty(exports, "__esModule", { | |
606 | value: true | |
607 | }); | |
608 | /** | |
609 | * xterm.js: xterm, in the browser | |
610 | * Copyright (c) 2016, SourceLair Private Company <www.sourcelair.com> (MIT License) | |
611 | */ | |
612 | ||
613 | /** | |
614 | * Generic utilities module. This module contains generic methods that can be helpful at | |
615 | * different parts of the code base. | |
616 | * @module xterm/utils/Generic | |
617 | */ | |
618 | ||
619 | /** | |
620 | * Return if the given array contains the given element | |
621 | * @param {Array} array The array to search for the given element. | |
622 | * @param {Object} el The element to look for into the array | |
623 | */ | |
624 | var contains = exports.contains = function contains(arr, el) { | |
625 | return arr.indexOf(el) >= 0; | |
626 | }; | |
627 | ||
628 | },{}],7:[function(_dereq_,module,exports){ | |
629 | 'use strict';var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj;}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};/** | |
630 | * xterm.js: xterm, in the browser | |
631 | * Copyright (c) 2014-2014, SourceLair Private Company <www.sourcelair.com> (MIT License) | |
632 | * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License) | |
633 | * https://github.com/chjj/term.js | |
634 | * | |
635 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
636 | * of this software and associated documentation files (the "Software"), to deal | |
637 | * in the Software without restriction, including without limitation the rights | |
638 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
639 | * copies of the Software, and to permit persons to whom the Software is | |
640 | * furnished to do so, subject to the following conditions: | |
641 | * | |
642 | * The above copyright notice and this permission notice shall be included in | |
643 | * all copies or substantial portions of the Software. | |
644 | * | |
645 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
646 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
647 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
648 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
649 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
650 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
651 | * THE SOFTWARE. | |
652 | * | |
653 | * Originally forked from (with the author's permission): | |
654 | * Fabrice Bellard's javascript vt100 for jslinux: | |
655 | * http://bellard.org/jslinux/ | |
656 | * Copyright (c) 2011 Fabrice Bellard | |
657 | * The original design remains. The terminal itself | |
658 | * has been extended to include xterm CSI codes, among | |
659 | * other features. | |
660 | */var _CompositionHelper=_dereq_('./CompositionHelper.js');var _EventEmitter=_dereq_('./EventEmitter.js');var _Viewport=_dereq_('./Viewport.js');var _Clipboard=_dereq_('./handlers/Clipboard.js');var _Browser=_dereq_('./utils/Browser');var Browser=_interopRequireWildcard(_Browser);function _interopRequireWildcard(obj){if(obj&&obj.__esModule){return obj;}else{var newObj={};if(obj!=null){for(var key in obj){if(Object.prototype.hasOwnProperty.call(obj,key))newObj[key]=obj[key];}}newObj.default=obj;return newObj;}}/** | |
661 | * Terminal Emulation References: | |
662 | * http://vt100.net/ | |
663 | * http://invisible-island.net/xterm/ctlseqs/ctlseqs.txt | |
664 | * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html | |
665 | * http://invisible-island.net/vttest/ | |
666 | * http://www.inwap.com/pdp10/ansicode.txt | |
667 | * http://linux.die.net/man/4/console_codes | |
668 | * http://linux.die.net/man/7/urxvt | |
669 | */// Let it work inside Node.js for automated testing purposes. | |
670 | var document=typeof window!='undefined'?window.document:null;/** | |
671 | * States | |
672 | */var normal=0,escaped=1,csi=2,osc=3,charset=4,dcs=5,ignore=6;/** | |
673 | * Terminal | |
674 | *//** | |
675 | * Creates a new `Terminal` object. | |
676 | * | |
677 | * @param {object} options An object containing a set of options, the available options are: | |
678 | * - `cursorBlink` (boolean): Whether the terminal cursor blinks | |
679 | * - `cols` (number): The number of columns of the terminal (horizontal size) | |
680 | * - `rows` (number): The number of rows of the terminal (vertical size) | |
681 | * | |
682 | * @public | |
683 | * @class Xterm Xterm | |
684 | * @alias module:xterm/src/xterm | |
685 | */function Terminal(options){var self=this;if(!(this instanceof Terminal)){return new Terminal(arguments[0],arguments[1],arguments[2]);}self.browser=Browser;self.cancel=Terminal.cancel;_EventEmitter.EventEmitter.call(this);if(typeof options==='number'){options={cols:arguments[0],rows:arguments[1],handler:arguments[2]};}options=options||{};Object.keys(Terminal.defaults).forEach(function(key){if(options[key]==null){options[key]=Terminal.options[key];if(Terminal[key]!==Terminal.defaults[key]){options[key]=Terminal[key];}}self[key]=options[key];});if(options.colors.length===8){options.colors=options.colors.concat(Terminal._colors.slice(8));}else if(options.colors.length===16){options.colors=options.colors.concat(Terminal._colors.slice(16));}else if(options.colors.length===10){options.colors=options.colors.slice(0,-2).concat(Terminal._colors.slice(8,-2),options.colors.slice(-2));}else if(options.colors.length===18){options.colors=options.colors.concat(Terminal._colors.slice(16,-2),options.colors.slice(-2));}this.colors=options.colors;this.options=options;// this.context = options.context || window; | |
686 | // this.document = options.document || document; | |
687 | this.parent=options.body||options.parent||(document?document.getElementsByTagName('body')[0]:null);this.cols=options.cols||options.geometry[0];this.rows=options.rows||options.geometry[1];this.geometry=[this.cols,this.rows];if(options.handler){this.on('data',options.handler);}/** | |
688 | * The scroll position of the y cursor, ie. ybase + y = the y position within the entire | |
689 | * buffer | |
690 | */this.ybase=0;/** | |
691 | * The scroll position of the viewport | |
692 | */this.ydisp=0;/** | |
693 | * The cursor's x position after ybase | |
694 | */this.x=0;/** | |
695 | * The cursor's y position after ybase | |
696 | */this.y=0;/** | |
697 | * Used to debounce the refresh function | |
698 | */this.isRefreshing=false;/** | |
699 | * Whether there is a full terminal refresh queued | |
700 | */this.cursorState=0;this.cursorHidden=false;this.convertEol;this.state=0;this.queue='';this.scrollTop=0;this.scrollBottom=this.rows-1;this.customKeydownHandler=null;// modes | |
701 | this.applicationKeypad=false;this.applicationCursor=false;this.originMode=false;this.insertMode=false;this.wraparoundMode=true;// defaults: xterm - true, vt100 - false | |
702 | this.normal=null;// charset | |
703 | this.charset=null;this.gcharset=null;this.glevel=0;this.charsets=[null];// mouse properties | |
704 | this.decLocator;this.x10Mouse;this.vt200Mouse;this.vt300Mouse;this.normalMouse;this.mouseEvents;this.sendFocus;this.utfMouse;this.sgrMouse;this.urxvtMouse;// misc | |
705 | this.element;this.children;this.refreshStart;this.refreshEnd;this.savedX;this.savedY;this.savedCols;// stream | |
706 | this.readable=true;this.writable=true;this.defAttr=0<<18|257<<9|256<<0;this.curAttr=this.defAttr;this.params=[];this.currentParam=0;this.prefix='';this.postfix='';// leftover surrogate high from previous write invocation | |
707 | this.surrogate_high='';/** | |
708 | * An array of all lines in the entire buffer, including the prompt. The lines are array of | |
709 | * characters which are 2-length arrays where [0] is an attribute and [1] is the character. | |
710 | */this.lines=[];var i=this.rows;while(i--){this.lines.push(this.blankLine());}this.tabs;this.setupStops();// Store if user went browsing history in scrollback | |
711 | this.userScrolling=false;}inherits(Terminal,_EventEmitter.EventEmitter);/** | |
712 | * back_color_erase feature for xterm. | |
713 | */Terminal.prototype.eraseAttr=function(){// if (this.is('screen')) return this.defAttr; | |
714 | return this.defAttr&~0x1ff|this.curAttr&0x1ff;};/** | |
715 | * Colors | |
716 | */// Colors 0-15 | |
717 | Terminal.tangoColors=[// dark: | |
718 | '#2e3436','#cc0000','#4e9a06','#c4a000','#3465a4','#75507b','#06989a','#d3d7cf',// bright: | |
719 | '#555753','#ef2929','#8ae234','#fce94f','#729fcf','#ad7fa8','#34e2e2','#eeeeec'];// Colors 0-15 + 16-255 | |
720 | // Much thanks to TooTallNate for writing this. | |
721 | Terminal.colors=function(){var colors=Terminal.tangoColors.slice(),r=[0x00,0x5f,0x87,0xaf,0xd7,0xff],i;// 16-231 | |
722 | i=0;for(;i<216;i++){out(r[i/36%6|0],r[i/6%6|0],r[i%6]);}// 232-255 (grey) | |
723 | i=0;for(;i<24;i++){r=8+i*10;out(r,r,r);}function out(r,g,b){colors.push('#'+hex(r)+hex(g)+hex(b));}function hex(c){c=c.toString(16);return c.length<2?'0'+c:c;}return colors;}();Terminal._colors=Terminal.colors.slice();Terminal.vcolors=function(){var out=[],colors=Terminal.colors,i=0,color;for(;i<256;i++){color=parseInt(colors[i].substring(1),16);out.push([color>>16&0xff,color>>8&0xff,color&0xff]);}return out;}();/** | |
724 | * Options | |
725 | */Terminal.defaults={colors:Terminal.colors,theme:'default',convertEol:false,termName:'xterm',geometry:[80,24],cursorBlink:false,visualBell:false,popOnBell:false,scrollback:1000,screenKeys:false,debug:false,cancelEvents:false// programFeatures: false, | |
726 | // focusKeys: false, | |
727 | };Terminal.options={};Terminal.focus=null;each(keys(Terminal.defaults),function(key){Terminal[key]=Terminal.defaults[key];Terminal.options[key]=Terminal.defaults[key];});/** | |
728 | * Focus the terminal. Delegates focus handling to the terminal's DOM element. | |
729 | */Terminal.prototype.focus=function(){return this.textarea.focus();};/** | |
730 | * Retrieves an option's value from the terminal. | |
731 | * @param {string} key The option key. | |
732 | */Terminal.prototype.getOption=function(key,value){if(!(key in Terminal.defaults)){throw new Error('No option with key "'+key+'"');}if(typeof this.options[key]!=='undefined'){return this.options[key];}return this[key];};/** | |
733 | * Sets an option on the terminal. | |
734 | * @param {string} key The option key. | |
735 | * @param {string} value The option value. | |
736 | */Terminal.prototype.setOption=function(key,value){if(!(key in Terminal.defaults)){throw new Error('No option with key "'+key+'"');}this[key]=value;this.options[key]=value;};/** | |
737 | * Binds the desired focus behavior on a given terminal object. | |
738 | * | |
739 | * @static | |
740 | */Terminal.bindFocus=function(term){on(term.textarea,'focus',function(ev){if(term.sendFocus){term.send('\x1b[I');}term.element.classList.add('focus');term.showCursor();Terminal.focus=term;term.emit('focus',{terminal:term});});};/** | |
741 | * Blur the terminal. Delegates blur handling to the terminal's DOM element. | |
742 | */Terminal.prototype.blur=function(){return this.textarea.blur();};/** | |
743 | * Binds the desired blur behavior on a given terminal object. | |
744 | * | |
745 | * @static | |
746 | */Terminal.bindBlur=function(term){on(term.textarea,'blur',function(ev){term.refresh(term.y,term.y);if(term.sendFocus){term.send('\x1b[O');}term.element.classList.remove('focus');Terminal.focus=null;term.emit('blur',{terminal:term});});};/** | |
747 | * Initialize default behavior | |
748 | */Terminal.prototype.initGlobal=function(){var term=this;Terminal.bindKeys(this);Terminal.bindFocus(this);Terminal.bindBlur(this);// Bind clipboard functionality | |
749 | on(this.element,'copy',function(ev){_Clipboard.copyHandler.call(this,ev,term);});on(this.textarea,'paste',function(ev){_Clipboard.pasteHandler.call(this,ev,term);});function rightClickHandlerWrapper(ev){_Clipboard.rightClickHandler.call(this,ev,term);}if(term.browser.isFirefox){on(this.element,'mousedown',function(ev){if(ev.button==2){rightClickHandlerWrapper(ev);}});}else{on(this.element,'contextmenu',rightClickHandlerWrapper);}};/** | |
750 | * Apply key handling to the terminal | |
751 | */Terminal.bindKeys=function(term){on(term.element,'keydown',function(ev){if(document.activeElement!=this){return;}term.keyDown(ev);},true);on(term.element,'keypress',function(ev){if(document.activeElement!=this){return;}term.keyPress(ev);},true);on(term.element,'keyup',term.focus.bind(term));on(term.textarea,'keydown',function(ev){term.keyDown(ev);},true);on(term.textarea,'keypress',function(ev){term.keyPress(ev);// Truncate the textarea's value, since it is not needed | |
752 | this.value='';},true);on(term.textarea,'compositionstart',term.compositionHelper.compositionstart.bind(term.compositionHelper));on(term.textarea,'compositionupdate',term.compositionHelper.compositionupdate.bind(term.compositionHelper));on(term.textarea,'compositionend',term.compositionHelper.compositionend.bind(term.compositionHelper));term.on('refresh',term.compositionHelper.updateCompositionElements.bind(term.compositionHelper));};/** | |
753 | * Insert the given row to the terminal or produce a new one | |
754 | * if no row argument is passed. Return the inserted row. | |
755 | * @param {HTMLElement} row (optional) The row to append to the terminal. | |
756 | */Terminal.prototype.insertRow=function(row){if((typeof row==='undefined'?'undefined':_typeof(row))!='object'){row=document.createElement('div');}this.rowContainer.appendChild(row);this.children.push(row);return row;};/** | |
757 | * Opens the terminal within an element. | |
758 | * | |
759 | * @param {HTMLElement} parent The element to create the terminal within. | |
760 | */Terminal.prototype.open=function(parent){var self=this,i=0,div;this.parent=parent||this.parent;if(!this.parent){throw new Error('Terminal requires a parent element.');}// Grab global elements | |
761 | this.context=this.parent.ownerDocument.defaultView;this.document=this.parent.ownerDocument;this.body=this.document.getElementsByTagName('body')[0];//Create main element container | |
762 | this.element=this.document.createElement('div');this.element.classList.add('terminal');this.element.classList.add('xterm');this.element.classList.add('xterm-theme-'+this.theme);this.element.style.height;this.element.setAttribute('tabindex',0);this.viewportElement=document.createElement('div');this.viewportElement.classList.add('xterm-viewport');this.element.appendChild(this.viewportElement);this.viewportScrollArea=document.createElement('div');this.viewportScrollArea.classList.add('xterm-scroll-area');this.viewportElement.appendChild(this.viewportScrollArea);// Create the container that will hold the lines of the terminal and then | |
763 | // produce the lines the lines. | |
764 | this.rowContainer=document.createElement('div');this.rowContainer.classList.add('xterm-rows');this.element.appendChild(this.rowContainer);this.children=[];// Create the container that will hold helpers like the textarea for | |
765 | // capturing DOM Events. Then produce the helpers. | |
766 | this.helperContainer=document.createElement('div');this.helperContainer.classList.add('xterm-helpers');// TODO: This should probably be inserted once it's filled to prevent an additional layout | |
767 | this.element.appendChild(this.helperContainer);this.textarea=document.createElement('textarea');this.textarea.classList.add('xterm-helper-textarea');this.textarea.setAttribute('autocorrect','off');this.textarea.setAttribute('autocapitalize','off');this.textarea.setAttribute('spellcheck','false');this.textarea.tabIndex=0;this.textarea.addEventListener('focus',function(){self.emit('focus',{terminal:self});});this.textarea.addEventListener('blur',function(){self.emit('blur',{terminal:self});});this.helperContainer.appendChild(this.textarea);this.compositionView=document.createElement('div');this.compositionView.classList.add('composition-view');this.compositionHelper=new _CompositionHelper.CompositionHelper(this.textarea,this.compositionView,this);this.helperContainer.appendChild(this.compositionView);this.charMeasureElement=document.createElement('div');this.charMeasureElement.classList.add('xterm-char-measure-element');this.charMeasureElement.innerHTML='W';this.helperContainer.appendChild(this.charMeasureElement);for(;i<this.rows;i++){this.insertRow();}this.parent.appendChild(this.element);this.viewport=new _Viewport.Viewport(this,this.viewportElement,this.viewportScrollArea,this.charMeasureElement);// Draw the screen. | |
768 | this.refresh(0,this.rows-1);// Initialize global actions that | |
769 | // need to be taken on the document. | |
770 | this.initGlobal();// Ensure there is a Terminal.focus. | |
771 | this.focus();on(this.element,'click',function(){var selection=document.getSelection(),collapsed=selection.isCollapsed,isRange=typeof collapsed=='boolean'?!collapsed:selection.type=='Range';if(!isRange){self.focus();}});// Listen for mouse events and translate | |
772 | // them into terminal mouse protocols. | |
773 | this.bindMouse();// Figure out whether boldness affects | |
774 | // the character width of monospace fonts. | |
775 | if(Terminal.brokenBold==null){Terminal.brokenBold=isBoldBroken(this.document);}this.emit('open');};/** | |
776 | * Attempts to load an add-on using CommonJS or RequireJS (whichever is available). | |
777 | * @param {string} addon The name of the addon to load | |
778 | * @static | |
779 | */Terminal.loadAddon=function(addon,callback){if((typeof exports==='undefined'?'undefined':_typeof(exports))==='object'&&(typeof module==='undefined'?'undefined':_typeof(module))==='object'){// CommonJS | |
780 | return _dereq_('../addons/'+addon);}else if(typeof define=='function'){// RequireJS | |
781 | return _dereq_(['../addons/'+addon+'/'+addon],callback);}else{console.error('Cannot load a module without a CommonJS or RequireJS environment.');return false;}};/** | |
782 | * XTerm mouse events | |
783 | * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking | |
784 | * To better understand these | |
785 | * the xterm code is very helpful: | |
786 | * Relevant files: | |
787 | * button.c, charproc.c, misc.c | |
788 | * Relevant functions in xterm/button.c: | |
789 | * BtnCode, EmitButtonCode, EditorButton, SendMousePosition | |
790 | */Terminal.prototype.bindMouse=function(){var el=this.element,self=this,pressed=32;// mouseup, mousedown, wheel | |
791 | // left click: ^[[M 3<^[[M#3< | |
792 | // wheel up: ^[[M`3> | |
793 | function sendButton(ev){var button,pos;// get the xterm-style button | |
794 | button=getButton(ev);// get mouse coordinates | |
795 | pos=getCoords(ev);if(!pos)return;sendEvent(button,pos);switch(ev.overrideType||ev.type){case'mousedown':pressed=button;break;case'mouseup':// keep it at the left | |
796 | // button, just in case. | |
797 | pressed=32;break;case'wheel':// nothing. don't | |
798 | // interfere with | |
799 | // `pressed`. | |
800 | break;}}// motion example of a left click: | |
801 | // ^[[M 3<^[[M@4<^[[M@5<^[[M@6<^[[M@7<^[[M#7< | |
802 | function sendMove(ev){var button=pressed,pos;pos=getCoords(ev);if(!pos)return;// buttons marked as motions | |
803 | // are incremented by 32 | |
804 | button+=32;sendEvent(button,pos);}// encode button and | |
805 | // position to characters | |
806 | function encode(data,ch){if(!self.utfMouse){if(ch===255)return data.push(0);if(ch>127)ch=127;data.push(ch);}else{if(ch===2047)return data.push(0);if(ch<127){data.push(ch);}else{if(ch>2047)ch=2047;data.push(0xC0|ch>>6);data.push(0x80|ch&0x3F);}}}// send a mouse event: | |
807 | // regular/utf8: ^[[M Cb Cx Cy | |
808 | // urxvt: ^[[ Cb ; Cx ; Cy M | |
809 | // sgr: ^[[ Cb ; Cx ; Cy M/m | |
810 | // vt300: ^[[ 24(1/3/5)~ [ Cx , Cy ] \r | |
811 | // locator: CSI P e ; P b ; P r ; P c ; P p & w | |
812 | function sendEvent(button,pos){// self.emit('mouse', { | |
813 | // x: pos.x - 32, | |
814 | // y: pos.x - 32, | |
815 | // button: button | |
816 | // }); | |
817 | if(self.vt300Mouse){// NOTE: Unstable. | |
818 | // http://www.vt100.net/docs/vt3xx-gp/chapter15.html | |
819 | button&=3;pos.x-=32;pos.y-=32;var data='\x1b[24';if(button===0)data+='1';else if(button===1)data+='3';else if(button===2)data+='5';else if(button===3)return;else data+='0';data+='~['+pos.x+','+pos.y+']\r';self.send(data);return;}if(self.decLocator){// NOTE: Unstable. | |
820 | button&=3;pos.x-=32;pos.y-=32;if(button===0)button=2;else if(button===1)button=4;else if(button===2)button=6;else if(button===3)button=3;self.send('\x1b['+button+';'+(button===3?4:0)+';'+pos.y+';'+pos.x+';'+(pos.page||0)+'&w');return;}if(self.urxvtMouse){pos.x-=32;pos.y-=32;pos.x++;pos.y++;self.send('\x1b['+button+';'+pos.x+';'+pos.y+'M');return;}if(self.sgrMouse){pos.x-=32;pos.y-=32;self.send('\x1b[<'+((button&3)===3?button&~3:button)+';'+pos.x+';'+pos.y+((button&3)===3?'m':'M'));return;}var data=[];encode(data,button);encode(data,pos.x);encode(data,pos.y);self.send('\x1b[M'+String.fromCharCode.apply(String,data));}function getButton(ev){var button,shift,meta,ctrl,mod;// two low bits: | |
821 | // 0 = left | |
822 | // 1 = middle | |
823 | // 2 = right | |
824 | // 3 = release | |
825 | // wheel up/down: | |
826 | // 1, and 2 - with 64 added | |
827 | switch(ev.overrideType||ev.type){case'mousedown':button=ev.button!=null?+ev.button:ev.which!=null?ev.which-1:null;if(self.browser.isMSIE){button=button===1?0:button===4?1:button;}break;case'mouseup':button=3;break;case'DOMMouseScroll':button=ev.detail<0?64:65;break;case'wheel':button=ev.wheelDeltaY>0?64:65;break;}// next three bits are the modifiers: | |
828 | // 4 = shift, 8 = meta, 16 = control | |
829 | shift=ev.shiftKey?4:0;meta=ev.metaKey?8:0;ctrl=ev.ctrlKey?16:0;mod=shift|meta|ctrl;// no mods | |
830 | if(self.vt200Mouse){// ctrl only | |
831 | mod&=ctrl;}else if(!self.normalMouse){mod=0;}// increment to SP | |
832 | button=32+(mod<<2)+button;return button;}// mouse coordinates measured in cols/rows | |
833 | function getCoords(ev){var x,y,w,h,el;// ignore browsers without pageX for now | |
834 | if(ev.pageX==null)return;x=ev.pageX;y=ev.pageY;el=self.element;// should probably check offsetParent | |
835 | // but this is more portable | |
836 | while(el&&el!==self.document.documentElement){x-=el.offsetLeft;y-=el.offsetTop;el='offsetParent'in el?el.offsetParent:el.parentNode;}// convert to cols/rows | |
837 | w=self.element.clientWidth;h=self.element.clientHeight;x=Math.ceil(x/w*self.cols);y=Math.ceil(y/h*self.rows);// be sure to avoid sending | |
838 | // bad positions to the program | |
839 | if(x<0)x=0;if(x>self.cols)x=self.cols;if(y<0)y=0;if(y>self.rows)y=self.rows;// xterm sends raw bytes and | |
840 | // starts at 32 (SP) for each. | |
841 | x+=32;y+=32;return{x:x,y:y,type:'wheel'};}on(el,'mousedown',function(ev){if(!self.mouseEvents)return;// send the button | |
842 | sendButton(ev);// ensure focus | |
843 | self.focus();// fix for odd bug | |
844 | //if (self.vt200Mouse && !self.normalMouse) { | |
845 | if(self.vt200Mouse){ev.overrideType='mouseup';sendButton(ev);return self.cancel(ev);}// bind events | |
846 | if(self.normalMouse)on(self.document,'mousemove',sendMove);// x10 compatibility mode can't send button releases | |
847 | if(!self.x10Mouse){on(self.document,'mouseup',function up(ev){sendButton(ev);if(self.normalMouse)off(self.document,'mousemove',sendMove);off(self.document,'mouseup',up);return self.cancel(ev);});}return self.cancel(ev);});//if (self.normalMouse) { | |
848 | // on(self.document, 'mousemove', sendMove); | |
849 | //} | |
850 | on(el,'wheel',function(ev){if(!self.mouseEvents)return;if(self.x10Mouse||self.vt300Mouse||self.decLocator)return;sendButton(ev);return self.cancel(ev);});// allow wheel scrolling in | |
851 | // the shell for example | |
852 | on(el,'wheel',function(ev){if(self.mouseEvents)return;self.viewport.onWheel(ev);return self.cancel(ev);});};/** | |
853 | * Destroys the terminal. | |
854 | */Terminal.prototype.destroy=function(){this.readable=false;this.writable=false;this._events={};this.handler=function(){};this.write=function(){};if(this.element.parentNode){this.element.parentNode.removeChild(this.element);}//this.emit('close'); | |
855 | };/** | |
856 | * Flags used to render terminal text properly | |
857 | */Terminal.flags={BOLD:1,UNDERLINE:2,BLINK:4,INVERSE:8,INVISIBLE:16};/** | |
858 | * Refreshes (re-renders) terminal content within two rows (inclusive) | |
859 | * | |
860 | * Rendering Engine: | |
861 | * | |
862 | * In the screen buffer, each character is stored as a an array with a character | |
863 | * and a 32-bit integer: | |
864 | * - First value: a utf-16 character. | |
865 | * - Second value: | |
866 | * - Next 9 bits: background color (0-511). | |
867 | * - Next 9 bits: foreground color (0-511). | |
868 | * - Next 14 bits: a mask for misc. flags: | |
869 | * - 1=bold | |
870 | * - 2=underline | |
871 | * - 4=blink | |
872 | * - 8=inverse | |
873 | * - 16=invisible | |
874 | * | |
875 | * @param {number} start The row to start from (between 0 and terminal's height terminal - 1) | |
876 | * @param {number} end The row to end at (between fromRow and terminal's height terminal - 1) | |
877 | * @param {boolean} queue Whether the refresh should ran right now or be queued | |
878 | */Terminal.prototype.refresh=function(start,end,queue){var self=this;// queue defaults to true | |
879 | queue=typeof queue=='undefined'?true:queue;/** | |
880 | * The refresh queue allows refresh to execute only approximately 30 times a second. For | |
881 | * commands that pass a significant amount of output to the write function, this prevents the | |
882 | * terminal from maxing out the CPU and making the UI unresponsive. While commands can still | |
883 | * run beyond what they do on the terminal, it is far better with a debounce in place as | |
884 | * every single terminal manipulation does not need to be constructed in the DOM. | |
885 | * | |
886 | * A side-effect of this is that it makes ^C to interrupt a process seem more responsive. | |
887 | */if(queue){// If refresh should be queued, order the refresh and return. | |
888 | if(this._refreshIsQueued){// If a refresh has already been queued, just order a full refresh next | |
889 | this._fullRefreshNext=true;}else{setTimeout(function(){self.refresh(start,end,false);},34);this._refreshIsQueued=true;}return;}// If refresh should be run right now (not be queued), release the lock | |
890 | this._refreshIsQueued=false;// If multiple refreshes were requested, make a full refresh. | |
891 | if(this._fullRefreshNext){start=0;end=this.rows-1;this._fullRefreshNext=false;// reset lock | |
892 | }var x,y,i,line,out,ch,ch_width,width,data,attr,bg,fg,flags,row,parent,focused=document.activeElement;// If this is a big refresh, remove the terminal rows from the DOM for faster calculations | |
893 | if(end-start>=this.rows/2){parent=this.element.parentNode;if(parent){this.element.removeChild(this.rowContainer);}}width=this.cols;y=start;if(end>=this.rows.length){this.log('`end` is too large. Most likely a bad CSR.');end=this.rows.length-1;}for(;y<=end;y++){row=y+this.ydisp;line=this.lines[row];out='';if(this.y===y-(this.ybase-this.ydisp)&&this.cursorState&&!this.cursorHidden){x=this.x;}else{x=-1;}attr=this.defAttr;i=0;for(;i<width;i++){data=line[i][0];ch=line[i][1];ch_width=line[i][2];if(!ch_width)continue;if(i===x)data=-1;if(data!==attr){if(attr!==this.defAttr){out+='</span>';}if(data!==this.defAttr){if(data===-1){out+='<span class="reverse-video terminal-cursor';if(this.cursorBlink){out+=' blinking';}out+='">';}else{var classNames=[];bg=data&0x1ff;fg=data>>9&0x1ff;flags=data>>18;if(flags&Terminal.flags.BOLD){if(!Terminal.brokenBold){classNames.push('xterm-bold');}// See: XTerm*boldColors | |
894 | if(fg<8)fg+=8;}if(flags&Terminal.flags.UNDERLINE){classNames.push('xterm-underline');}if(flags&Terminal.flags.BLINK){classNames.push('xterm-blink');}// If inverse flag is on, then swap the foreground and background variables. | |
895 | if(flags&Terminal.flags.INVERSE){/* One-line variable swap in JavaScript: http://stackoverflow.com/a/16201730 */bg=[fg,fg=bg][0];// Should inverse just be before the | |
896 | // above boldColors effect instead? | |
897 | if(flags&1&&fg<8)fg+=8;}if(flags&Terminal.flags.INVISIBLE){classNames.push('xterm-hidden');}/** | |
898 | * Weird situation: Invert flag used black foreground and white background results | |
899 | * in invalid background color, positioned at the 256 index of the 256 terminal | |
900 | * color map. Pin the colors manually in such a case. | |
901 | * | |
902 | * Source: https://github.com/sourcelair/xterm.js/issues/57 | |
903 | */if(flags&Terminal.flags.INVERSE){if(bg==257){bg=15;}if(fg==256){fg=0;}}if(bg<256){classNames.push('xterm-bg-color-'+bg);}if(fg<256){classNames.push('xterm-color-'+fg);}out+='<span';if(classNames.length){out+=' class="'+classNames.join(' ')+'"';}out+='>';}}}switch(ch){case'&':out+='&';break;case'<':out+='<';break;case'>':out+='>';break;default:if(ch<=' '){out+=' ';}else{out+=ch;}break;}attr=data;}if(attr!==this.defAttr){out+='</span>';}this.children[y].innerHTML=out;}if(parent){this.element.appendChild(this.rowContainer);}this.emit('refresh',{element:this.element,start:start,end:end});};/** | |
904 | * Display the cursor element | |
905 | */Terminal.prototype.showCursor=function(){if(!this.cursorState){this.cursorState=1;this.refresh(this.y,this.y);}};/** | |
906 | * Scroll the terminal | |
907 | */Terminal.prototype.scroll=function(){var row;if(++this.ybase===this.scrollback){this.ybase=this.ybase/2|0;this.lines=this.lines.slice(-(this.ybase+this.rows)+1);}if(!this.userScrolling){this.ydisp=this.ybase;}// last line | |
908 | row=this.ybase+this.rows-1;// subtract the bottom scroll region | |
909 | row-=this.rows-1-this.scrollBottom;if(row===this.lines.length){// potential optimization: | |
910 | // pushing is faster than splicing | |
911 | // when they amount to the same | |
912 | // behavior. | |
913 | this.lines.push(this.blankLine());}else{// add our new line | |
914 | this.lines.splice(row,0,this.blankLine());}if(this.scrollTop!==0){if(this.ybase!==0){this.ybase--;if(!this.userScrolling){this.ydisp=this.ybase;}}this.lines.splice(this.ybase+this.scrollTop,1);}// this.maxRange(); | |
915 | this.updateRange(this.scrollTop);this.updateRange(this.scrollBottom);this.emit('scroll',this.ydisp);};/** | |
916 | * Scroll the display of the terminal | |
917 | * @param {number} disp The number of lines to scroll down (negatives scroll up). | |
918 | * @param {boolean} suppressScrollEvent Don't emit the scroll event as scrollDisp. This is used | |
919 | * to avoid unwanted events being handled by the veiwport when the event was triggered from the | |
920 | * viewport originally. | |
921 | */Terminal.prototype.scrollDisp=function(disp,suppressScrollEvent){if(disp<0){this.userScrolling=true;}else if(disp+this.ydisp>=this.ybase){this.userScrolling=false;}this.ydisp+=disp;if(this.ydisp>this.ybase){this.ydisp=this.ybase;}else if(this.ydisp<0){this.ydisp=0;}if(!suppressScrollEvent){this.emit('scroll',this.ydisp);}this.refresh(0,this.rows-1);};/** | |
922 | * Scroll the display of the terminal by a number of pages. | |
923 | * @param {number} pageCount The number of pages to scroll (negative scrolls up). | |
924 | */Terminal.prototype.scrollPages=function(pageCount){this.scrollDisp(pageCount*(this.rows-1));};/** | |
925 | * Scrolls the display of the terminal to the top. | |
926 | */Terminal.prototype.scrollToTop=function(){this.scrollDisp(-this.ydisp);};/** | |
927 | * Scrolls the display of the terminal to the bottom. | |
928 | */Terminal.prototype.scrollToBottom=function(){this.scrollDisp(this.ybase-this.ydisp);};/** | |
929 | * Writes text to the terminal. | |
930 | * @param {string} text The text to write to the terminal. | |
931 | */Terminal.prototype.write=function(data){var l=data.length,i=0,j,cs,ch,code,low,ch_width,row;this.refreshStart=this.y;this.refreshEnd=this.y;// apply leftover surrogate high from last write | |
932 | if(this.surrogate_high){data=this.surrogate_high+data;this.surrogate_high='';}for(;i<l;i++){ch=data[i];// FIXME: higher chars than 0xa0 are not allowed in escape sequences | |
933 | // --> maybe move to default | |
934 | code=data.charCodeAt(i);if(0xD800<=code&&code<=0xDBFF){// we got a surrogate high | |
935 | // get surrogate low (next 2 bytes) | |
936 | low=data.charCodeAt(i+1);if(isNaN(low)){// end of data stream, save surrogate high | |
937 | this.surrogate_high=ch;continue;}code=(code-0xD800)*0x400+(low-0xDC00)+0x10000;ch+=data.charAt(i+1);}// surrogate low - already handled above | |
938 | if(0xDC00<=code&&code<=0xDFFF)continue;switch(this.state){case normal:switch(ch){case'\x07':this.bell();break;// '\n', '\v', '\f' | |
939 | case'\n':case'\x0b':case'\x0c':if(this.convertEol){this.x=0;}this.y++;if(this.y>this.scrollBottom){this.y--;this.scroll();}break;// '\r' | |
940 | case'\r':this.x=0;break;// '\b' | |
941 | case'\x08':if(this.x>0){this.x--;}break;// '\t' | |
942 | case'\t':this.x=this.nextStop();break;// shift out | |
943 | case'\x0e':this.setgLevel(1);break;// shift in | |
944 | case'\x0f':this.setgLevel(0);break;// '\e' | |
945 | case'\x1b':this.state=escaped;break;default:// ' ' | |
946 | // calculate print space | |
947 | // expensive call, therefore we save width in line buffer | |
948 | ch_width=wcwidth(code);if(ch>=' '){if(this.charset&&this.charset[ch]){ch=this.charset[ch];}row=this.y+this.ybase;// insert combining char in last cell | |
949 | // FIXME: needs handling after cursor jumps | |
950 | if(!ch_width&&this.x){// dont overflow left | |
951 | if(this.lines[row][this.x-1]){if(!this.lines[row][this.x-1][2]){// found empty cell after fullwidth, need to go 2 cells back | |
952 | if(this.lines[row][this.x-2])this.lines[row][this.x-2][1]+=ch;}else{this.lines[row][this.x-1][1]+=ch;}this.updateRange(this.y);}break;}// goto next line if ch would overflow | |
953 | // TODO: needs a global min terminal width of 2 | |
954 | if(this.x+ch_width-1>=this.cols){// autowrap - DECAWM | |
955 | if(this.wraparoundMode){this.x=0;this.y++;if(this.y>this.scrollBottom){this.y--;this.scroll();}}else{this.x=this.cols-1;if(ch_width===2)// FIXME: check for xterm behavior | |
956 | continue;}}row=this.y+this.ybase;// insert mode: move characters to right | |
957 | if(this.insertMode){// do this twice for a fullwidth char | |
958 | for(var moves=0;moves<ch_width;++moves){// remove last cell, if it's width is 0 | |
959 | // we have to adjust the second last cell as well | |
960 | var removed=this.lines[this.y+this.ybase].pop();if(removed[2]===0&&this.lines[row][this.cols-2]&&this.lines[row][this.cols-2][2]===2)this.lines[row][this.cols-2]=[this.curAttr,' ',1];// insert empty cell at cursor | |
961 | this.lines[row].splice(this.x,0,[this.curAttr,' ',1]);}}this.lines[row][this.x]=[this.curAttr,ch,ch_width];this.x++;this.updateRange(this.y);// fullwidth char - set next cell width to zero and advance cursor | |
962 | if(ch_width===2){this.lines[row][this.x]=[this.curAttr,'',0];this.x++;}}break;}break;case escaped:switch(ch){// ESC [ Control Sequence Introducer ( CSI is 0x9b). | |
963 | case'[':this.params=[];this.currentParam=0;this.state=csi;break;// ESC ] Operating System Command ( OSC is 0x9d). | |
964 | case']':this.params=[];this.currentParam=0;this.state=osc;break;// ESC P Device Control String ( DCS is 0x90). | |
965 | case'P':this.params=[];this.currentParam=0;this.state=dcs;break;// ESC _ Application Program Command ( APC is 0x9f). | |
966 | case'_':this.state=ignore;break;// ESC ^ Privacy Message ( PM is 0x9e). | |
967 | case'^':this.state=ignore;break;// ESC c Full Reset (RIS). | |
968 | case'c':this.reset();break;// ESC E Next Line ( NEL is 0x85). | |
969 | // ESC D Index ( IND is 0x84). | |
970 | case'E':this.x=0;;case'D':this.index();break;// ESC M Reverse Index ( RI is 0x8d). | |
971 | case'M':this.reverseIndex();break;// ESC % Select default/utf-8 character set. | |
972 | // @ = default, G = utf-8 | |
973 | case'%'://this.charset = null; | |
974 | this.setgLevel(0);this.setgCharset(0,Terminal.charsets.US);this.state=normal;i++;break;// ESC (,),*,+,-,. Designate G0-G2 Character Set. | |
975 | case'(':// <-- this seems to get all the attention | |
976 | case')':case'*':case'+':case'-':case'.':switch(ch){case'(':this.gcharset=0;break;case')':this.gcharset=1;break;case'*':this.gcharset=2;break;case'+':this.gcharset=3;break;case'-':this.gcharset=1;break;case'.':this.gcharset=2;break;}this.state=charset;break;// Designate G3 Character Set (VT300). | |
977 | // A = ISO Latin-1 Supplemental. | |
978 | // Not implemented. | |
979 | case'/':this.gcharset=3;this.state=charset;i--;break;// ESC N | |
980 | // Single Shift Select of G2 Character Set | |
981 | // ( SS2 is 0x8e). This affects next character only. | |
982 | case'N':break;// ESC O | |
983 | // Single Shift Select of G3 Character Set | |
984 | // ( SS3 is 0x8f). This affects next character only. | |
985 | case'O':break;// ESC n | |
986 | // Invoke the G2 Character Set as GL (LS2). | |
987 | case'n':this.setgLevel(2);break;// ESC o | |
988 | // Invoke the G3 Character Set as GL (LS3). | |
989 | case'o':this.setgLevel(3);break;// ESC | | |
990 | // Invoke the G3 Character Set as GR (LS3R). | |
991 | case'|':this.setgLevel(3);break;// ESC } | |
992 | // Invoke the G2 Character Set as GR (LS2R). | |
993 | case'}':this.setgLevel(2);break;// ESC ~ | |
994 | // Invoke the G1 Character Set as GR (LS1R). | |
995 | case'~':this.setgLevel(1);break;// ESC 7 Save Cursor (DECSC). | |
996 | case'7':this.saveCursor();this.state=normal;break;// ESC 8 Restore Cursor (DECRC). | |
997 | case'8':this.restoreCursor();this.state=normal;break;// ESC # 3 DEC line height/width | |
998 | case'#':this.state=normal;i++;break;// ESC H Tab Set (HTS is 0x88). | |
999 | case'H':this.tabSet();break;// ESC = Application Keypad (DECKPAM). | |
1000 | case'=':this.log('Serial port requested application keypad.');this.applicationKeypad=true;this.viewport.syncScrollArea();this.state=normal;break;// ESC > Normal Keypad (DECKPNM). | |
1001 | case'>':this.log('Switching back to normal keypad.');this.applicationKeypad=false;this.viewport.syncScrollArea();this.state=normal;break;default:this.state=normal;this.error('Unknown ESC control: %s.',ch);break;}break;case charset:switch(ch){case'0':// DEC Special Character and Line Drawing Set. | |
1002 | cs=Terminal.charsets.SCLD;break;case'A':// UK | |
1003 | cs=Terminal.charsets.UK;break;case'B':// United States (USASCII). | |
1004 | cs=Terminal.charsets.US;break;case'4':// Dutch | |
1005 | cs=Terminal.charsets.Dutch;break;case'C':// Finnish | |
1006 | case'5':cs=Terminal.charsets.Finnish;break;case'R':// French | |
1007 | cs=Terminal.charsets.French;break;case'Q':// FrenchCanadian | |
1008 | cs=Terminal.charsets.FrenchCanadian;break;case'K':// German | |
1009 | cs=Terminal.charsets.German;break;case'Y':// Italian | |
1010 | cs=Terminal.charsets.Italian;break;case'E':// NorwegianDanish | |
1011 | case'6':cs=Terminal.charsets.NorwegianDanish;break;case'Z':// Spanish | |
1012 | cs=Terminal.charsets.Spanish;break;case'H':// Swedish | |
1013 | case'7':cs=Terminal.charsets.Swedish;break;case'=':// Swiss | |
1014 | cs=Terminal.charsets.Swiss;break;case'/':// ISOLatin (actually /A) | |
1015 | cs=Terminal.charsets.ISOLatin;i++;break;default:// Default | |
1016 | cs=Terminal.charsets.US;break;}this.setgCharset(this.gcharset,cs);this.gcharset=null;this.state=normal;break;case osc:// OSC Ps ; Pt ST | |
1017 | // OSC Ps ; Pt BEL | |
1018 | // Set Text Parameters. | |
1019 | if(ch==='\x1b'||ch==='\x07'){if(ch==='\x1b')i++;this.params.push(this.currentParam);switch(this.params[0]){case 0:case 1:case 2:if(this.params[1]){this.title=this.params[1];this.handleTitle(this.title);}break;case 3:// set X property | |
1020 | break;case 4:case 5:// change dynamic colors | |
1021 | break;case 10:case 11:case 12:case 13:case 14:case 15:case 16:case 17:case 18:case 19:// change dynamic ui colors | |
1022 | break;case 46:// change log file | |
1023 | break;case 50:// dynamic font | |
1024 | break;case 51:// emacs shell | |
1025 | break;case 52:// manipulate selection data | |
1026 | break;case 104:case 105:case 110:case 111:case 112:case 113:case 114:case 115:case 116:case 117:case 118:// reset colors | |
1027 | break;}this.params=[];this.currentParam=0;this.state=normal;}else{if(!this.params.length){if(ch>='0'&&ch<='9'){this.currentParam=this.currentParam*10+ch.charCodeAt(0)-48;}else if(ch===';'){this.params.push(this.currentParam);this.currentParam='';}}else{this.currentParam+=ch;}}break;case csi:// '?', '>', '!' | |
1028 | if(ch==='?'||ch==='>'||ch==='!'){this.prefix=ch;break;}// 0 - 9 | |
1029 | if(ch>='0'&&ch<='9'){this.currentParam=this.currentParam*10+ch.charCodeAt(0)-48;break;}// '$', '"', ' ', '\'' | |
1030 | if(ch==='$'||ch==='"'||ch===' '||ch==='\''){this.postfix=ch;break;}this.params.push(this.currentParam);this.currentParam=0;// ';' | |
1031 | if(ch===';')break;this.state=normal;switch(ch){// CSI Ps A | |
1032 | // Cursor Up Ps Times (default = 1) (CUU). | |
1033 | case'A':this.cursorUp(this.params);break;// CSI Ps B | |
1034 | // Cursor Down Ps Times (default = 1) (CUD). | |
1035 | case'B':this.cursorDown(this.params);break;// CSI Ps C | |
1036 | // Cursor Forward Ps Times (default = 1) (CUF). | |
1037 | case'C':this.cursorForward(this.params);break;// CSI Ps D | |
1038 | // Cursor Backward Ps Times (default = 1) (CUB). | |
1039 | case'D':this.cursorBackward(this.params);break;// CSI Ps ; Ps H | |
1040 | // Cursor Position [row;column] (default = [1,1]) (CUP). | |
1041 | case'H':this.cursorPos(this.params);break;// CSI Ps J Erase in Display (ED). | |
1042 | case'J':this.eraseInDisplay(this.params);break;// CSI Ps K Erase in Line (EL). | |
1043 | case'K':this.eraseInLine(this.params);break;// CSI Pm m Character Attributes (SGR). | |
1044 | case'm':if(!this.prefix){this.charAttributes(this.params);}break;// CSI Ps n Device Status Report (DSR). | |
1045 | case'n':if(!this.prefix){this.deviceStatus(this.params);}break;/** | |
1046 | * Additions | |
1047 | */// CSI Ps @ | |
1048 | // Insert Ps (Blank) Character(s) (default = 1) (ICH). | |
1049 | case'@':this.insertChars(this.params);break;// CSI Ps E | |
1050 | // Cursor Next Line Ps Times (default = 1) (CNL). | |
1051 | case'E':this.cursorNextLine(this.params);break;// CSI Ps F | |
1052 | // Cursor Preceding Line Ps Times (default = 1) (CNL). | |
1053 | case'F':this.cursorPrecedingLine(this.params);break;// CSI Ps G | |
1054 | // Cursor Character Absolute [column] (default = [row,1]) (CHA). | |
1055 | case'G':this.cursorCharAbsolute(this.params);break;// CSI Ps L | |
1056 | // Insert Ps Line(s) (default = 1) (IL). | |
1057 | case'L':this.insertLines(this.params);break;// CSI Ps M | |
1058 | // Delete Ps Line(s) (default = 1) (DL). | |
1059 | case'M':this.deleteLines(this.params);break;// CSI Ps P | |
1060 | // Delete Ps Character(s) (default = 1) (DCH). | |
1061 | case'P':this.deleteChars(this.params);break;// CSI Ps X | |
1062 | // Erase Ps Character(s) (default = 1) (ECH). | |
1063 | case'X':this.eraseChars(this.params);break;// CSI Pm ` Character Position Absolute | |
1064 | // [column] (default = [row,1]) (HPA). | |
1065 | case'`':this.charPosAbsolute(this.params);break;// 141 61 a * HPR - | |
1066 | // Horizontal Position Relative | |
1067 | case'a':this.HPositionRelative(this.params);break;// CSI P s c | |
1068 | // Send Device Attributes (Primary DA). | |
1069 | // CSI > P s c | |
1070 | // Send Device Attributes (Secondary DA) | |
1071 | case'c':this.sendDeviceAttributes(this.params);break;// CSI Pm d | |
1072 | // Line Position Absolute [row] (default = [1,column]) (VPA). | |
1073 | case'd':this.linePosAbsolute(this.params);break;// 145 65 e * VPR - Vertical Position Relative | |
1074 | case'e':this.VPositionRelative(this.params);break;// CSI Ps ; Ps f | |
1075 | // Horizontal and Vertical Position [row;column] (default = | |
1076 | // [1,1]) (HVP). | |
1077 | case'f':this.HVPosition(this.params);break;// CSI Pm h Set Mode (SM). | |
1078 | // CSI ? Pm h - mouse escape codes, cursor escape codes | |
1079 | case'h':this.setMode(this.params);break;// CSI Pm l Reset Mode (RM). | |
1080 | // CSI ? Pm l | |
1081 | case'l':this.resetMode(this.params);break;// CSI Ps ; Ps r | |
1082 | // Set Scrolling Region [top;bottom] (default = full size of win- | |
1083 | // dow) (DECSTBM). | |
1084 | // CSI ? Pm r | |
1085 | case'r':this.setScrollRegion(this.params);break;// CSI s | |
1086 | // Save cursor (ANSI.SYS). | |
1087 | case's':this.saveCursor(this.params);break;// CSI u | |
1088 | // Restore cursor (ANSI.SYS). | |
1089 | case'u':this.restoreCursor(this.params);break;/** | |
1090 | * Lesser Used | |
1091 | */// CSI Ps I | |
1092 | // Cursor Forward Tabulation Ps tab stops (default = 1) (CHT). | |
1093 | case'I':this.cursorForwardTab(this.params);break;// CSI Ps S Scroll up Ps lines (default = 1) (SU). | |
1094 | case'S':this.scrollUp(this.params);break;// CSI Ps T Scroll down Ps lines (default = 1) (SD). | |
1095 | // CSI Ps ; Ps ; Ps ; Ps ; Ps T | |
1096 | // CSI > Ps; Ps T | |
1097 | case'T':// if (this.prefix === '>') { | |
1098 | // this.resetTitleModes(this.params); | |
1099 | // break; | |
1100 | // } | |
1101 | // if (this.params.length > 2) { | |
1102 | // this.initMouseTracking(this.params); | |
1103 | // break; | |
1104 | // } | |
1105 | if(this.params.length<2&&!this.prefix){this.scrollDown(this.params);}break;// CSI Ps Z | |
1106 | // Cursor Backward Tabulation Ps tab stops (default = 1) (CBT). | |
1107 | case'Z':this.cursorBackwardTab(this.params);break;// CSI Ps b Repeat the preceding graphic character Ps times (REP). | |
1108 | case'b':this.repeatPrecedingCharacter(this.params);break;// CSI Ps g Tab Clear (TBC). | |
1109 | case'g':this.tabClear(this.params);break;// CSI Pm i Media Copy (MC). | |
1110 | // CSI ? Pm i | |
1111 | // case 'i': | |
1112 | // this.mediaCopy(this.params); | |
1113 | // break; | |
1114 | // CSI Pm m Character Attributes (SGR). | |
1115 | // CSI > Ps; Ps m | |
1116 | // case 'm': // duplicate | |
1117 | // if (this.prefix === '>') { | |
1118 | // this.setResources(this.params); | |
1119 | // } else { | |
1120 | // this.charAttributes(this.params); | |
1121 | // } | |
1122 | // break; | |
1123 | // CSI Ps n Device Status Report (DSR). | |
1124 | // CSI > Ps n | |
1125 | // case 'n': // duplicate | |
1126 | // if (this.prefix === '>') { | |
1127 | // this.disableModifiers(this.params); | |
1128 | // } else { | |
1129 | // this.deviceStatus(this.params); | |
1130 | // } | |
1131 | // break; | |
1132 | // CSI > Ps p Set pointer mode. | |
1133 | // CSI ! p Soft terminal reset (DECSTR). | |
1134 | // CSI Ps$ p | |
1135 | // Request ANSI mode (DECRQM). | |
1136 | // CSI ? Ps$ p | |
1137 | // Request DEC private mode (DECRQM). | |
1138 | // CSI Ps ; Ps " p | |
1139 | case'p':switch(this.prefix){// case '>': | |
1140 | // this.setPointerMode(this.params); | |
1141 | // break; | |
1142 | case'!':this.softReset(this.params);break;// case '?': | |
1143 | // if (this.postfix === '$') { | |
1144 | // this.requestPrivateMode(this.params); | |
1145 | // } | |
1146 | // break; | |
1147 | // default: | |
1148 | // if (this.postfix === '"') { | |
1149 | // this.setConformanceLevel(this.params); | |
1150 | // } else if (this.postfix === '$') { | |
1151 | // this.requestAnsiMode(this.params); | |
1152 | // } | |
1153 | // break; | |
1154 | }break;// CSI Ps q Load LEDs (DECLL). | |
1155 | // CSI Ps SP q | |
1156 | // CSI Ps " q | |
1157 | // case 'q': | |
1158 | // if (this.postfix === ' ') { | |
1159 | // this.setCursorStyle(this.params); | |
1160 | // break; | |
1161 | // } | |
1162 | // if (this.postfix === '"') { | |
1163 | // this.setCharProtectionAttr(this.params); | |
1164 | // break; | |
1165 | // } | |
1166 | // this.loadLEDs(this.params); | |
1167 | // break; | |
1168 | // CSI Ps ; Ps r | |
1169 | // Set Scrolling Region [top;bottom] (default = full size of win- | |
1170 | // dow) (DECSTBM). | |
1171 | // CSI ? Pm r | |
1172 | // CSI Pt; Pl; Pb; Pr; Ps$ r | |
1173 | // case 'r': // duplicate | |
1174 | // if (this.prefix === '?') { | |
1175 | // this.restorePrivateValues(this.params); | |
1176 | // } else if (this.postfix === '$') { | |
1177 | // this.setAttrInRectangle(this.params); | |
1178 | // } else { | |
1179 | // this.setScrollRegion(this.params); | |
1180 | // } | |
1181 | // break; | |
1182 | // CSI s Save cursor (ANSI.SYS). | |
1183 | // CSI ? Pm s | |
1184 | // case 's': // duplicate | |
1185 | // if (this.prefix === '?') { | |
1186 | // this.savePrivateValues(this.params); | |
1187 | // } else { | |
1188 | // this.saveCursor(this.params); | |
1189 | // } | |
1190 | // break; | |
1191 | // CSI Ps ; Ps ; Ps t | |
1192 | // CSI Pt; Pl; Pb; Pr; Ps$ t | |
1193 | // CSI > Ps; Ps t | |
1194 | // CSI Ps SP t | |
1195 | // case 't': | |
1196 | // if (this.postfix === '$') { | |
1197 | // this.reverseAttrInRectangle(this.params); | |
1198 | // } else if (this.postfix === ' ') { | |
1199 | // this.setWarningBellVolume(this.params); | |
1200 | // } else { | |
1201 | // if (this.prefix === '>') { | |
1202 | // this.setTitleModeFeature(this.params); | |
1203 | // } else { | |
1204 | // this.manipulateWindow(this.params); | |
1205 | // } | |
1206 | // } | |
1207 | // break; | |
1208 | // CSI u Restore cursor (ANSI.SYS). | |
1209 | // CSI Ps SP u | |
1210 | // case 'u': // duplicate | |
1211 | // if (this.postfix === ' ') { | |
1212 | // this.setMarginBellVolume(this.params); | |
1213 | // } else { | |
1214 | // this.restoreCursor(this.params); | |
1215 | // } | |
1216 | // break; | |
1217 | // CSI Pt; Pl; Pb; Pr; Pp; Pt; Pl; Pp$ v | |
1218 | // case 'v': | |
1219 | // if (this.postfix === '$') { | |
1220 | // this.copyRectagle(this.params); | |
1221 | // } | |
1222 | // break; | |
1223 | // CSI Pt ; Pl ; Pb ; Pr ' w | |
1224 | // case 'w': | |
1225 | // if (this.postfix === '\'') { | |
1226 | // this.enableFilterRectangle(this.params); | |
1227 | // } | |
1228 | // break; | |
1229 | // CSI Ps x Request Terminal Parameters (DECREQTPARM). | |
1230 | // CSI Ps x Select Attribute Change Extent (DECSACE). | |
1231 | // CSI Pc; Pt; Pl; Pb; Pr$ x | |
1232 | // case 'x': | |
1233 | // if (this.postfix === '$') { | |
1234 | // this.fillRectangle(this.params); | |
1235 | // } else { | |
1236 | // this.requestParameters(this.params); | |
1237 | // //this.__(this.params); | |
1238 | // } | |
1239 | // break; | |
1240 | // CSI Ps ; Pu ' z | |
1241 | // CSI Pt; Pl; Pb; Pr$ z | |
1242 | // case 'z': | |
1243 | // if (this.postfix === '\'') { | |
1244 | // this.enableLocatorReporting(this.params); | |
1245 | // } else if (this.postfix === '$') { | |
1246 | // this.eraseRectangle(this.params); | |
1247 | // } | |
1248 | // break; | |
1249 | // CSI Pm ' { | |
1250 | // CSI Pt; Pl; Pb; Pr$ { | |
1251 | // case '{': | |
1252 | // if (this.postfix === '\'') { | |
1253 | // this.setLocatorEvents(this.params); | |
1254 | // } else if (this.postfix === '$') { | |
1255 | // this.selectiveEraseRectangle(this.params); | |
1256 | // } | |
1257 | // break; | |
1258 | // CSI Ps ' | | |
1259 | // case '|': | |
1260 | // if (this.postfix === '\'') { | |
1261 | // this.requestLocatorPosition(this.params); | |
1262 | // } | |
1263 | // break; | |
1264 | // CSI P m SP } | |
1265 | // Insert P s Column(s) (default = 1) (DECIC), VT420 and up. | |
1266 | // case '}': | |
1267 | // if (this.postfix === ' ') { | |
1268 | // this.insertColumns(this.params); | |
1269 | // } | |
1270 | // break; | |
1271 | // CSI P m SP ~ | |
1272 | // Delete P s Column(s) (default = 1) (DECDC), VT420 and up | |
1273 | // case '~': | |
1274 | // if (this.postfix === ' ') { | |
1275 | // this.deleteColumns(this.params); | |
1276 | // } | |
1277 | // break; | |
1278 | default:this.error('Unknown CSI code: %s.',ch);break;}this.prefix='';this.postfix='';break;case dcs:if(ch==='\x1b'||ch==='\x07'){if(ch==='\x1b')i++;switch(this.prefix){// User-Defined Keys (DECUDK). | |
1279 | case'':break;// Request Status String (DECRQSS). | |
1280 | // test: echo -e '\eP$q"p\e\\' | |
1281 | case'$q':var pt=this.currentParam,valid=false;switch(pt){// DECSCA | |
1282 | case'"q':pt='0"q';break;// DECSCL | |
1283 | case'"p':pt='61"p';break;// DECSTBM | |
1284 | case'r':pt=''+(this.scrollTop+1)+';'+(this.scrollBottom+1)+'r';break;// SGR | |
1285 | case'm':pt='0m';break;default:this.error('Unknown DCS Pt: %s.',pt);pt='';break;}this.send('\x1bP'+ +valid+'$r'+pt+'\x1b\\');break;// Set Termcap/Terminfo Data (xterm, experimental). | |
1286 | case'+p':break;// Request Termcap/Terminfo String (xterm, experimental) | |
1287 | // Regular xterm does not even respond to this sequence. | |
1288 | // This can cause a small glitch in vim. | |
1289 | // test: echo -ne '\eP+q6b64\e\\' | |
1290 | case'+q':var pt=this.currentParam,valid=false;this.send('\x1bP'+ +valid+'+r'+pt+'\x1b\\');break;default:this.error('Unknown DCS prefix: %s.',this.prefix);break;}this.currentParam=0;this.prefix='';this.state=normal;}else if(!this.currentParam){if(!this.prefix&&ch!=='$'&&ch!=='+'){this.currentParam=ch;}else if(this.prefix.length===2){this.currentParam=ch;}else{this.prefix+=ch;}}else{this.currentParam+=ch;}break;case ignore:// For PM and APC. | |
1291 | if(ch==='\x1b'||ch==='\x07'){if(ch==='\x1b')i++;this.state=normal;}break;}}this.updateRange(this.y);this.refresh(this.refreshStart,this.refreshEnd);};/** | |
1292 | * Writes text to the terminal, followed by a break line character (\n). | |
1293 | * @param {string} text The text to write to the terminal. | |
1294 | */Terminal.prototype.writeln=function(data){this.write(data+'\r\n');};/** | |
1295 | * Attaches a custom keydown handler which is run before keys are processed, giving consumers of | |
1296 | * xterm.js ultimate control as to what keys should be processed by the terminal and what keys | |
1297 | * should not. | |
1298 | * @param {function} customKeydownHandler The custom KeyboardEvent handler to attach. This is a | |
1299 | * function that takes a KeyboardEvent, allowing consumers to stop propogation and/or prevent | |
1300 | * the default action. The function returns whether the event should be processed by xterm.js. | |
1301 | */Terminal.prototype.attachCustomKeydownHandler=function(customKeydownHandler){this.customKeydownHandler=customKeydownHandler;};/** | |
1302 | * Handle a keydown event | |
1303 | * Key Resources: | |
1304 | * - https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent | |
1305 | * @param {KeyboardEvent} ev The keydown event to be handled. | |
1306 | */Terminal.prototype.keyDown=function(ev){// Scroll down to prompt, whenever the user presses a key. | |
1307 | if(this.ybase!==this.ydisp){this.scrollToBottom();}if(this.customKeydownHandler&&this.customKeydownHandler(ev)===false){return false;}if(!this.compositionHelper.keydown.bind(this.compositionHelper)(ev)){return false;}var self=this;var result=this.evaluateKeyEscapeSequence(ev);if(result.scrollDisp){this.scrollDisp(result.scrollDisp);return this.cancel(ev,true);}if(isThirdLevelShift(this,ev)){return true;}if(result.cancel){// The event is canceled at the end already, is this necessary? | |
1308 | this.cancel(ev,true);}if(!result.key){return true;}this.emit('keydown',ev);this.emit('key',result.key,ev);this.showCursor();this.handler(result.key);return this.cancel(ev,true);};/** | |
1309 | * Returns an object that determines how a KeyboardEvent should be handled. The key of the | |
1310 | * returned value is the new key code to pass to the PTY. | |
1311 | * | |
1312 | * Reference: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html | |
1313 | * @param {KeyboardEvent} ev The keyboard event to be translated to key escape sequence. | |
1314 | */Terminal.prototype.evaluateKeyEscapeSequence=function(ev){var result={// Whether to cancel event propogation (NOTE: this may not be needed since the event is | |
1315 | // canceled at the end of keyDown | |
1316 | cancel:false,// The new key even to emit | |
1317 | key:undefined,// The number of characters to scroll, if this is defined it will cancel the event | |
1318 | scrollDisp:undefined};var modifiers=ev.shiftKey<<0|ev.altKey<<1|ev.ctrlKey<<2|ev.metaKey<<3;switch(ev.keyCode){case 8:// backspace | |
1319 | if(ev.shiftKey){result.key='\x08';// ^H | |
1320 | break;}result.key='\x7f';// ^? | |
1321 | break;case 9:// tab | |
1322 | if(ev.shiftKey){result.key='\x1b[Z';break;}result.key='\t';result.cancel=true;break;case 13:// return/enter | |
1323 | result.key='\r';result.cancel=true;break;case 27:// escape | |
1324 | result.key='\x1b';result.cancel=true;break;case 37:// left-arrow | |
1325 | if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'D';// HACK: Make Alt + left-arrow behave like Ctrl + left-arrow: move one word backwards | |
1326 | // http://unix.stackexchange.com/a/108106 | |
1327 | if(result.key=='\x1b[1;3D'){result.key='\x1b[1;5D';}}else if(this.applicationCursor){result.key='\x1bOD';}else{result.key='\x1b[D';}break;case 39:// right-arrow | |
1328 | if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'C';// HACK: Make Alt + right-arrow behave like Ctrl + right-arrow: move one word forward | |
1329 | // http://unix.stackexchange.com/a/108106 | |
1330 | if(result.key=='\x1b[1;3C'){result.key='\x1b[1;5C';}}else if(this.applicationCursor){result.key='\x1bOC';}else{result.key='\x1b[C';}break;case 38:// up-arrow | |
1331 | if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'A';// HACK: Make Alt + up-arrow behave like Ctrl + up-arrow | |
1332 | // http://unix.stackexchange.com/a/108106 | |
1333 | if(result.key=='\x1b[1;3A'){result.key='\x1b[1;5A';}}else if(this.applicationCursor){result.key='\x1bOA';}else{result.key='\x1b[A';}break;case 40:// down-arrow | |
1334 | if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'B';// HACK: Make Alt + down-arrow behave like Ctrl + down-arrow | |
1335 | // http://unix.stackexchange.com/a/108106 | |
1336 | if(result.key=='\x1b[1;3B'){result.key='\x1b[1;5B';}}else if(this.applicationCursor){result.key='\x1bOB';}else{result.key='\x1b[B';}break;case 45:// insert | |
1337 | if(!ev.shiftKey&&!ev.ctrlKey){// <Ctrl> or <Shift> + <Insert> are used to | |
1338 | // copy-paste on some systems. | |
1339 | result.key='\x1b[2~';}break;case 46:// delete | |
1340 | if(modifiers){result.key='\x1b[3;'+(modifiers+1)+'~';}else{result.key='\x1b[3~';}break;case 36:// home | |
1341 | if(modifiers)result.key='\x1b[1;'+(modifiers+1)+'H';else if(this.applicationCursor)result.key='\x1bOH';else result.key='\x1b[H';break;case 35:// end | |
1342 | if(modifiers)result.key='\x1b[1;'+(modifiers+1)+'F';else if(this.applicationCursor)result.key='\x1bOF';else result.key='\x1b[F';break;case 33:// page up | |
1343 | if(ev.shiftKey){result.scrollDisp=-(this.rows-1);}else{result.key='\x1b[5~';}break;case 34:// page down | |
1344 | if(ev.shiftKey){result.scrollDisp=this.rows-1;}else{result.key='\x1b[6~';}break;case 112:// F1-F12 | |
1345 | if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'P';}else{result.key='\x1bOP';}break;case 113:if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'Q';}else{result.key='\x1bOQ';}break;case 114:if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'R';}else{result.key='\x1bOR';}break;case 115:if(modifiers){result.key='\x1b[1;'+(modifiers+1)+'S';}else{result.key='\x1bOS';}break;case 116:if(modifiers){result.key='\x1b[15;'+(modifiers+1)+'~';}else{result.key='\x1b[15~';}break;case 117:if(modifiers){result.key='\x1b[17;'+(modifiers+1)+'~';}else{result.key='\x1b[17~';}break;case 118:if(modifiers){result.key='\x1b[18;'+(modifiers+1)+'~';}else{result.key='\x1b[18~';}break;case 119:if(modifiers){result.key='\x1b[19;'+(modifiers+1)+'~';}else{result.key='\x1b[19~';}break;case 120:if(modifiers){result.key='\x1b[20;'+(modifiers+1)+'~';}else{result.key='\x1b[20~';}break;case 121:if(modifiers){result.key='\x1b[21;'+(modifiers+1)+'~';}else{result.key='\x1b[21~';}break;case 122:if(modifiers){result.key='\x1b[23;'+(modifiers+1)+'~';}else{result.key='\x1b[23~';}break;case 123:if(modifiers){result.key='\x1b[24;'+(modifiers+1)+'~';}else{result.key='\x1b[24~';}break;default:// a-z and space | |
1346 | if(ev.ctrlKey&&!ev.shiftKey&&!ev.altKey&&!ev.metaKey){if(ev.keyCode>=65&&ev.keyCode<=90){result.key=String.fromCharCode(ev.keyCode-64);}else if(ev.keyCode===32){// NUL | |
1347 | result.key=String.fromCharCode(0);}else if(ev.keyCode>=51&&ev.keyCode<=55){// escape, file sep, group sep, record sep, unit sep | |
1348 | result.key=String.fromCharCode(ev.keyCode-51+27);}else if(ev.keyCode===56){// delete | |
1349 | result.key=String.fromCharCode(127);}else if(ev.keyCode===219){// ^[ - escape | |
1350 | result.key=String.fromCharCode(27);}else if(ev.keyCode===221){// ^] - group sep | |
1351 | result.key=String.fromCharCode(29);}}else if(!this.browser.isMac&&ev.altKey&&!ev.ctrlKey&&!ev.metaKey){// On Mac this is a third level shift. Use <Esc> instead. | |
1352 | if(ev.keyCode>=65&&ev.keyCode<=90){result.key='\x1b'+String.fromCharCode(ev.keyCode+32);}else if(ev.keyCode===192){result.key='\x1b`';}else if(ev.keyCode>=48&&ev.keyCode<=57){result.key='\x1b'+(ev.keyCode-48);}}break;}return result;};/** | |
1353 | * Set the G level of the terminal | |
1354 | * @param g | |
1355 | */Terminal.prototype.setgLevel=function(g){this.glevel=g;this.charset=this.charsets[g];};/** | |
1356 | * Set the charset for the given G level of the terminal | |
1357 | * @param g | |
1358 | * @param charset | |
1359 | */Terminal.prototype.setgCharset=function(g,charset){this.charsets[g]=charset;if(this.glevel===g){this.charset=charset;}};/** | |
1360 | * Handle a keypress event. | |
1361 | * Key Resources: | |
1362 | * - https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent | |
1363 | * @param {KeyboardEvent} ev The keypress event to be handled. | |
1364 | */Terminal.prototype.keyPress=function(ev){var key;this.cancel(ev);if(ev.charCode){key=ev.charCode;}else if(ev.which==null){key=ev.keyCode;}else if(ev.which!==0&&ev.charCode!==0){key=ev.which;}else{return false;}if(!key||(ev.altKey||ev.ctrlKey||ev.metaKey)&&!isThirdLevelShift(this,ev)){return false;}key=String.fromCharCode(key);this.emit('keypress',key,ev);this.emit('key',key,ev);this.showCursor();this.handler(key);return false;};/** | |
1365 | * Send data for handling to the terminal | |
1366 | * @param {string} data | |
1367 | */Terminal.prototype.send=function(data){var self=this;if(!this.queue){setTimeout(function(){self.handler(self.queue);self.queue='';},1);}this.queue+=data;};/** | |
1368 | * Ring the bell. | |
1369 | * Note: We could do sweet things with webaudio here | |
1370 | */Terminal.prototype.bell=function(){if(!this.visualBell)return;var self=this;this.element.style.borderColor='white';setTimeout(function(){self.element.style.borderColor='';},10);if(this.popOnBell)this.focus();};/** | |
1371 | * Log the current state to the console. | |
1372 | */Terminal.prototype.log=function(){if(!this.debug)return;if(!this.context.console||!this.context.console.log)return;var args=Array.prototype.slice.call(arguments);this.context.console.log.apply(this.context.console,args);};/** | |
1373 | * Log the current state as error to the console. | |
1374 | */Terminal.prototype.error=function(){if(!this.debug)return;if(!this.context.console||!this.context.console.error)return;var args=Array.prototype.slice.call(arguments);this.context.console.error.apply(this.context.console,args);};/** | |
1375 | * Resizes the terminal. | |
1376 | * | |
1377 | * @param {number} x The number of columns to resize to. | |
1378 | * @param {number} y The number of rows to resize to. | |
1379 | */Terminal.prototype.resize=function(x,y){var line,el,i,j,ch,addToY;if(x===this.cols&&y===this.rows){return;}if(x<1)x=1;if(y<1)y=1;// resize cols | |
1380 | j=this.cols;if(j<x){ch=[this.defAttr,' ',1];// does xterm use the default attr? | |
1381 | i=this.lines.length;while(i--){while(this.lines[i].length<x){this.lines[i].push(ch);}}}else{// (j > x) | |
1382 | i=this.lines.length;while(i--){while(this.lines[i].length>x){this.lines[i].pop();}}}this.setupStops(j);this.cols=x;// resize rows | |
1383 | j=this.rows;addToY=0;if(j<y){el=this.element;while(j++<y){// y is rows, not this.y | |
1384 | if(this.lines.length<y+this.ybase){if(this.ybase>0&&this.lines.length<=this.ybase+this.y+addToY+1){// There is room above the buffer and there are no empty elements below the line, | |
1385 | // scroll up | |
1386 | this.ybase--;addToY++;if(this.ydisp>0){// Viewport is at the top of the buffer, must increase downwards | |
1387 | this.ydisp--;}}else{// Add a blank line if there is no buffer left at the top to scroll to, or if there | |
1388 | // are blank lines after the cursor | |
1389 | this.lines.push(this.blankLine());}}if(this.children.length<y){this.insertRow();}}}else{// (j > y) | |
1390 | while(j-->y){if(this.lines.length>y+this.ybase){if(this.lines.length>this.ybase+this.y+1){// The line is a blank line below the cursor, remove it | |
1391 | this.lines.pop();}else{// The line is the cursor, scroll down | |
1392 | this.ybase++;this.ydisp++;}}if(this.children.length>y){el=this.children.shift();if(!el)continue;el.parentNode.removeChild(el);}}}this.rows=y;// Make sure that the cursor stays on screen | |
1393 | if(this.y>=y){this.y=y-1;}if(addToY){this.y+=addToY;}if(this.x>=x){this.x=x-1;}this.scrollTop=0;this.scrollBottom=y-1;this.refresh(0,this.rows-1);this.normal=null;this.geometry=[this.cols,this.rows];this.emit('resize',{terminal:this,cols:x,rows:y});};/** | |
1394 | * Updates the range of rows to refresh | |
1395 | * @param {number} y The number of rows to refresh next. | |
1396 | */Terminal.prototype.updateRange=function(y){if(y<this.refreshStart)this.refreshStart=y;if(y>this.refreshEnd)this.refreshEnd=y;// if (y > this.refreshEnd) { | |
1397 | // this.refreshEnd = y; | |
1398 | // if (y > this.rows - 1) { | |
1399 | // this.refreshEnd = this.rows - 1; | |
1400 | // } | |
1401 | // } | |
1402 | };/** | |
1403 | * Set the range of refreshing to the maximum value | |
1404 | */Terminal.prototype.maxRange=function(){this.refreshStart=0;this.refreshEnd=this.rows-1;};/** | |
1405 | * Setup the tab stops. | |
1406 | * @param {number} i | |
1407 | */Terminal.prototype.setupStops=function(i){if(i!=null){if(!this.tabs[i]){i=this.prevStop(i);}}else{this.tabs={};i=0;}for(;i<this.cols;i+=8){this.tabs[i]=true;}};/** | |
1408 | * Move the cursor to the previous tab stop from the given position (default is current). | |
1409 | * @param {number} x The position to move the cursor to the previous tab stop. | |
1410 | */Terminal.prototype.prevStop=function(x){if(x==null)x=this.x;while(!this.tabs[--x]&&x>0){}return x>=this.cols?this.cols-1:x<0?0:x;};/** | |
1411 | * Move the cursor one tab stop forward from the given position (default is current). | |
1412 | * @param {number} x The position to move the cursor one tab stop forward. | |
1413 | */Terminal.prototype.nextStop=function(x){if(x==null)x=this.x;while(!this.tabs[++x]&&x<this.cols){}return x>=this.cols?this.cols-1:x<0?0:x;};/** | |
1414 | * Erase in the identified line everything from "x" to the end of the line (right). | |
1415 | * @param {number} x The column from which to start erasing to the end of the line. | |
1416 | * @param {number} y The line in which to operate. | |
1417 | */Terminal.prototype.eraseRight=function(x,y){var line=this.lines[this.ybase+y],ch=[this.eraseAttr(),' ',1];// xterm | |
1418 | for(;x<this.cols;x++){line[x]=ch;}this.updateRange(y);};/** | |
1419 | * Erase in the identified line everything from "x" to the start of the line (left). | |
1420 | * @param {number} x The column from which to start erasing to the start of the line. | |
1421 | * @param {number} y The line in which to operate. | |
1422 | */Terminal.prototype.eraseLeft=function(x,y){var line=this.lines[this.ybase+y],ch=[this.eraseAttr(),' ',1];// xterm | |
1423 | x++;while(x--){line[x]=ch;}this.updateRange(y);};/** | |
1424 | * Clears the entire buffer, making the prompt line the new first line. | |
1425 | */Terminal.prototype.clear=function(){if(this.ybase===0&&this.y===0){// Don't clear if it's already clear | |
1426 | return;}this.lines=[this.lines[this.ybase+this.y]];this.ydisp=0;this.ybase=0;this.y=0;for(var i=1;i<this.rows;i++){this.lines.push(this.blankLine());}this.refresh(0,this.rows-1);this.emit('scroll',this.ydisp);};/** | |
1427 | * Erase all content in the given line | |
1428 | * @param {number} y The line to erase all of its contents. | |
1429 | */Terminal.prototype.eraseLine=function(y){this.eraseRight(0,y);};/** | |
1430 | * Return the data array of a blank line/ | |
1431 | * @param {number} cur First bunch of data for each "blank" character. | |
1432 | */Terminal.prototype.blankLine=function(cur){var attr=cur?this.eraseAttr():this.defAttr;var ch=[attr,' ',1]// width defaults to 1 halfwidth character | |
1433 | ,line=[],i=0;for(;i<this.cols;i++){line[i]=ch;}return line;};/** | |
1434 | * If cur return the back color xterm feature attribute. Else return defAttr. | |
1435 | * @param {object} cur | |
1436 | */Terminal.prototype.ch=function(cur){return cur?[this.eraseAttr(),' ',1]:[this.defAttr,' ',1];};/** | |
1437 | * Evaluate if the current erminal is the given argument. | |
1438 | * @param {object} term The terminal to evaluate | |
1439 | */Terminal.prototype.is=function(term){var name=this.termName;return(name+'').indexOf(term)===0;};/** | |
1440 | * Emit the 'data' event and populate the given data. | |
1441 | * @param {string} data The data to populate in the event. | |
1442 | */Terminal.prototype.handler=function(data){this.emit('data',data);};/** | |
1443 | * Emit the 'title' event and populate the given title. | |
1444 | * @param {string} title The title to populate in the event. | |
1445 | */Terminal.prototype.handleTitle=function(title){this.emit('title',title);};/** | |
1446 | * ESC | |
1447 | *//** | |
1448 | * ESC D Index (IND is 0x84). | |
1449 | */Terminal.prototype.index=function(){this.y++;if(this.y>this.scrollBottom){this.y--;this.scroll();}this.state=normal;};/** | |
1450 | * ESC M Reverse Index (RI is 0x8d). | |
1451 | */Terminal.prototype.reverseIndex=function(){var j;this.y--;if(this.y<this.scrollTop){this.y++;// possibly move the code below to term.reverseScroll(); | |
1452 | // test: echo -ne '\e[1;1H\e[44m\eM\e[0m' | |
1453 | // blankLine(true) is xterm/linux behavior | |
1454 | this.lines.splice(this.y+this.ybase,0,this.blankLine(true));j=this.rows-1-this.scrollBottom;this.lines.splice(this.rows-1+this.ybase-j+1,1);// this.maxRange(); | |
1455 | this.updateRange(this.scrollTop);this.updateRange(this.scrollBottom);}this.state=normal;};/** | |
1456 | * ESC c Full Reset (RIS). | |
1457 | */Terminal.prototype.reset=function(){this.options.rows=this.rows;this.options.cols=this.cols;var customKeydownHandler=this.customKeydownHandler;Terminal.call(this,this.options);this.customKeydownHandler=customKeydownHandler;this.refresh(0,this.rows-1);this.viewport.syncScrollArea();};/** | |
1458 | * ESC H Tab Set (HTS is 0x88). | |
1459 | */Terminal.prototype.tabSet=function(){this.tabs[this.x]=true;this.state=normal;};/** | |
1460 | * CSI | |
1461 | *//** | |
1462 | * CSI Ps A | |
1463 | * Cursor Up Ps Times (default = 1) (CUU). | |
1464 | */Terminal.prototype.cursorUp=function(params){var param=params[0];if(param<1)param=1;this.y-=param;if(this.y<0)this.y=0;};/** | |
1465 | * CSI Ps B | |
1466 | * Cursor Down Ps Times (default = 1) (CUD). | |
1467 | */Terminal.prototype.cursorDown=function(params){var param=params[0];if(param<1)param=1;this.y+=param;if(this.y>=this.rows){this.y=this.rows-1;}};/** | |
1468 | * CSI Ps C | |
1469 | * Cursor Forward Ps Times (default = 1) (CUF). | |
1470 | */Terminal.prototype.cursorForward=function(params){var param=params[0];if(param<1)param=1;this.x+=param;if(this.x>=this.cols){this.x=this.cols-1;}};/** | |
1471 | * CSI Ps D | |
1472 | * Cursor Backward Ps Times (default = 1) (CUB). | |
1473 | */Terminal.prototype.cursorBackward=function(params){var param=params[0];if(param<1)param=1;this.x-=param;if(this.x<0)this.x=0;};/** | |
1474 | * CSI Ps ; Ps H | |
1475 | * Cursor Position [row;column] (default = [1,1]) (CUP). | |
1476 | */Terminal.prototype.cursorPos=function(params){var row,col;row=params[0]-1;if(params.length>=2){col=params[1]-1;}else{col=0;}if(row<0){row=0;}else if(row>=this.rows){row=this.rows-1;}if(col<0){col=0;}else if(col>=this.cols){col=this.cols-1;}this.x=col;this.y=row;};/** | |
1477 | * CSI Ps J Erase in Display (ED). | |
1478 | * Ps = 0 -> Erase Below (default). | |
1479 | * Ps = 1 -> Erase Above. | |
1480 | * Ps = 2 -> Erase All. | |
1481 | * Ps = 3 -> Erase Saved Lines (xterm). | |
1482 | * CSI ? Ps J | |
1483 | * Erase in Display (DECSED). | |
1484 | * Ps = 0 -> Selective Erase Below (default). | |
1485 | * Ps = 1 -> Selective Erase Above. | |
1486 | * Ps = 2 -> Selective Erase All. | |
1487 | */Terminal.prototype.eraseInDisplay=function(params){var j;switch(params[0]){case 0:this.eraseRight(this.x,this.y);j=this.y+1;for(;j<this.rows;j++){this.eraseLine(j);}break;case 1:this.eraseLeft(this.x,this.y);j=this.y;while(j--){this.eraseLine(j);}break;case 2:j=this.rows;while(j--){this.eraseLine(j);}break;case 3:;// no saved lines | |
1488 | break;}};/** | |
1489 | * CSI Ps K Erase in Line (EL). | |
1490 | * Ps = 0 -> Erase to Right (default). | |
1491 | * Ps = 1 -> Erase to Left. | |
1492 | * Ps = 2 -> Erase All. | |
1493 | * CSI ? Ps K | |
1494 | * Erase in Line (DECSEL). | |
1495 | * Ps = 0 -> Selective Erase to Right (default). | |
1496 | * Ps = 1 -> Selective Erase to Left. | |
1497 | * Ps = 2 -> Selective Erase All. | |
1498 | */Terminal.prototype.eraseInLine=function(params){switch(params[0]){case 0:this.eraseRight(this.x,this.y);break;case 1:this.eraseLeft(this.x,this.y);break;case 2:this.eraseLine(this.y);break;}};/** | |
1499 | * CSI Pm m Character Attributes (SGR). | |
1500 | * Ps = 0 -> Normal (default). | |
1501 | * Ps = 1 -> Bold. | |
1502 | * Ps = 4 -> Underlined. | |
1503 | * Ps = 5 -> Blink (appears as Bold). | |
1504 | * Ps = 7 -> Inverse. | |
1505 | * Ps = 8 -> Invisible, i.e., hidden (VT300). | |
1506 | * Ps = 2 2 -> Normal (neither bold nor faint). | |
1507 | * Ps = 2 4 -> Not underlined. | |
1508 | * Ps = 2 5 -> Steady (not blinking). | |
1509 | * Ps = 2 7 -> Positive (not inverse). | |
1510 | * Ps = 2 8 -> Visible, i.e., not hidden (VT300). | |
1511 | * Ps = 3 0 -> Set foreground color to Black. | |
1512 | * Ps = 3 1 -> Set foreground color to Red. | |
1513 | * Ps = 3 2 -> Set foreground color to Green. | |
1514 | * Ps = 3 3 -> Set foreground color to Yellow. | |
1515 | * Ps = 3 4 -> Set foreground color to Blue. | |
1516 | * Ps = 3 5 -> Set foreground color to Magenta. | |
1517 | * Ps = 3 6 -> Set foreground color to Cyan. | |
1518 | * Ps = 3 7 -> Set foreground color to White. | |
1519 | * Ps = 3 9 -> Set foreground color to default (original). | |
1520 | * Ps = 4 0 -> Set background color to Black. | |
1521 | * Ps = 4 1 -> Set background color to Red. | |
1522 | * Ps = 4 2 -> Set background color to Green. | |
1523 | * Ps = 4 3 -> Set background color to Yellow. | |
1524 | * Ps = 4 4 -> Set background color to Blue. | |
1525 | * Ps = 4 5 -> Set background color to Magenta. | |
1526 | * Ps = 4 6 -> Set background color to Cyan. | |
1527 | * Ps = 4 7 -> Set background color to White. | |
1528 | * Ps = 4 9 -> Set background color to default (original). | |
1529 | * | |
1530 | * If 16-color support is compiled, the following apply. Assume | |
1531 | * that xterm's resources are set so that the ISO color codes are | |
1532 | * the first 8 of a set of 16. Then the aixterm colors are the | |
1533 | * bright versions of the ISO colors: | |
1534 | * Ps = 9 0 -> Set foreground color to Black. | |
1535 | * Ps = 9 1 -> Set foreground color to Red. | |
1536 | * Ps = 9 2 -> Set foreground color to Green. | |
1537 | * Ps = 9 3 -> Set foreground color to Yellow. | |
1538 | * Ps = 9 4 -> Set foreground color to Blue. | |
1539 | * Ps = 9 5 -> Set foreground color to Magenta. | |
1540 | * Ps = 9 6 -> Set foreground color to Cyan. | |
1541 | * Ps = 9 7 -> Set foreground color to White. | |
1542 | * Ps = 1 0 0 -> Set background color to Black. | |
1543 | * Ps = 1 0 1 -> Set background color to Red. | |
1544 | * Ps = 1 0 2 -> Set background color to Green. | |
1545 | * Ps = 1 0 3 -> Set background color to Yellow. | |
1546 | * Ps = 1 0 4 -> Set background color to Blue. | |
1547 | * Ps = 1 0 5 -> Set background color to Magenta. | |
1548 | * Ps = 1 0 6 -> Set background color to Cyan. | |
1549 | * Ps = 1 0 7 -> Set background color to White. | |
1550 | * | |
1551 | * If xterm is compiled with the 16-color support disabled, it | |
1552 | * supports the following, from rxvt: | |
1553 | * Ps = 1 0 0 -> Set foreground and background color to | |
1554 | * default. | |
1555 | * | |
1556 | * If 88- or 256-color support is compiled, the following apply. | |
1557 | * Ps = 3 8 ; 5 ; Ps -> Set foreground color to the second | |
1558 | * Ps. | |
1559 | * Ps = 4 8 ; 5 ; Ps -> Set background color to the second | |
1560 | * Ps. | |
1561 | */Terminal.prototype.charAttributes=function(params){// Optimize a single SGR0. | |
1562 | if(params.length===1&¶ms[0]===0){this.curAttr=this.defAttr;return;}var l=params.length,i=0,flags=this.curAttr>>18,fg=this.curAttr>>9&0x1ff,bg=this.curAttr&0x1ff,p;for(;i<l;i++){p=params[i];if(p>=30&&p<=37){// fg color 8 | |
1563 | fg=p-30;}else if(p>=40&&p<=47){// bg color 8 | |
1564 | bg=p-40;}else if(p>=90&&p<=97){// fg color 16 | |
1565 | p+=8;fg=p-90;}else if(p>=100&&p<=107){// bg color 16 | |
1566 | p+=8;bg=p-100;}else if(p===0){// default | |
1567 | flags=this.defAttr>>18;fg=this.defAttr>>9&0x1ff;bg=this.defAttr&0x1ff;// flags = 0; | |
1568 | // fg = 0x1ff; | |
1569 | // bg = 0x1ff; | |
1570 | }else if(p===1){// bold text | |
1571 | flags|=1;}else if(p===4){// underlined text | |
1572 | flags|=2;}else if(p===5){// blink | |
1573 | flags|=4;}else if(p===7){// inverse and positive | |
1574 | // test with: echo -e '\e[31m\e[42mhello\e[7mworld\e[27mhi\e[m' | |
1575 | flags|=8;}else if(p===8){// invisible | |
1576 | flags|=16;}else if(p===22){// not bold | |
1577 | flags&=~1;}else if(p===24){// not underlined | |
1578 | flags&=~2;}else if(p===25){// not blink | |
1579 | flags&=~4;}else if(p===27){// not inverse | |
1580 | flags&=~8;}else if(p===28){// not invisible | |
1581 | flags&=~16;}else if(p===39){// reset fg | |
1582 | fg=this.defAttr>>9&0x1ff;}else if(p===49){// reset bg | |
1583 | bg=this.defAttr&0x1ff;}else if(p===38){// fg color 256 | |
1584 | if(params[i+1]===2){i+=2;fg=matchColor(params[i]&0xff,params[i+1]&0xff,params[i+2]&0xff);if(fg===-1)fg=0x1ff;i+=2;}else if(params[i+1]===5){i+=2;p=params[i]&0xff;fg=p;}}else if(p===48){// bg color 256 | |
1585 | if(params[i+1]===2){i+=2;bg=matchColor(params[i]&0xff,params[i+1]&0xff,params[i+2]&0xff);if(bg===-1)bg=0x1ff;i+=2;}else if(params[i+1]===5){i+=2;p=params[i]&0xff;bg=p;}}else if(p===100){// reset fg/bg | |
1586 | fg=this.defAttr>>9&0x1ff;bg=this.defAttr&0x1ff;}else{this.error('Unknown SGR attribute: %d.',p);}}this.curAttr=flags<<18|fg<<9|bg;};/** | |
1587 | * CSI Ps n Device Status Report (DSR). | |
1588 | * Ps = 5 -> Status Report. Result (``OK'') is | |
1589 | * CSI 0 n | |
1590 | * Ps = 6 -> Report Cursor Position (CPR) [row;column]. | |
1591 | * Result is | |
1592 | * CSI r ; c R | |
1593 | * CSI ? Ps n | |
1594 | * Device Status Report (DSR, DEC-specific). | |
1595 | * Ps = 6 -> Report Cursor Position (CPR) [row;column] as CSI | |
1596 | * ? r ; c R (assumes page is zero). | |
1597 | * Ps = 1 5 -> Report Printer status as CSI ? 1 0 n (ready). | |
1598 | * or CSI ? 1 1 n (not ready). | |
1599 | * Ps = 2 5 -> Report UDK status as CSI ? 2 0 n (unlocked) | |
1600 | * or CSI ? 2 1 n (locked). | |
1601 | * Ps = 2 6 -> Report Keyboard status as | |
1602 | * CSI ? 2 7 ; 1 ; 0 ; 0 n (North American). | |
1603 | * The last two parameters apply to VT400 & up, and denote key- | |
1604 | * board ready and LK01 respectively. | |
1605 | * Ps = 5 3 -> Report Locator status as | |
1606 | * CSI ? 5 3 n Locator available, if compiled-in, or | |
1607 | * CSI ? 5 0 n No Locator, if not. | |
1608 | */Terminal.prototype.deviceStatus=function(params){if(!this.prefix){switch(params[0]){case 5:// status report | |
1609 | this.send('\x1b[0n');break;case 6:// cursor position | |
1610 | this.send('\x1b['+(this.y+1)+';'+(this.x+1)+'R');break;}}else if(this.prefix==='?'){// modern xterm doesnt seem to | |
1611 | // respond to any of these except ?6, 6, and 5 | |
1612 | switch(params[0]){case 6:// cursor position | |
1613 | this.send('\x1b[?'+(this.y+1)+';'+(this.x+1)+'R');break;case 15:// no printer | |
1614 | // this.send('\x1b[?11n'); | |
1615 | break;case 25:// dont support user defined keys | |
1616 | // this.send('\x1b[?21n'); | |
1617 | break;case 26:// north american keyboard | |
1618 | // this.send('\x1b[?27;1;0;0n'); | |
1619 | break;case 53:// no dec locator/mouse | |
1620 | // this.send('\x1b[?50n'); | |
1621 | break;}}};/** | |
1622 | * Additions | |
1623 | *//** | |
1624 | * CSI Ps @ | |
1625 | * Insert Ps (Blank) Character(s) (default = 1) (ICH). | |
1626 | */Terminal.prototype.insertChars=function(params){var param,row,j,ch;param=params[0];if(param<1)param=1;row=this.y+this.ybase;j=this.x;ch=[this.eraseAttr(),' ',1];// xterm | |
1627 | while(param--&&j<this.cols){this.lines[row].splice(j++,0,ch);this.lines[row].pop();}};/** | |
1628 | * CSI Ps E | |
1629 | * Cursor Next Line Ps Times (default = 1) (CNL). | |
1630 | * same as CSI Ps B ? | |
1631 | */Terminal.prototype.cursorNextLine=function(params){var param=params[0];if(param<1)param=1;this.y+=param;if(this.y>=this.rows){this.y=this.rows-1;}this.x=0;};/** | |
1632 | * CSI Ps F | |
1633 | * Cursor Preceding Line Ps Times (default = 1) (CNL). | |
1634 | * reuse CSI Ps A ? | |
1635 | */Terminal.prototype.cursorPrecedingLine=function(params){var param=params[0];if(param<1)param=1;this.y-=param;if(this.y<0)this.y=0;this.x=0;};/** | |
1636 | * CSI Ps G | |
1637 | * Cursor Character Absolute [column] (default = [row,1]) (CHA). | |
1638 | */Terminal.prototype.cursorCharAbsolute=function(params){var param=params[0];if(param<1)param=1;this.x=param-1;};/** | |
1639 | * CSI Ps L | |
1640 | * Insert Ps Line(s) (default = 1) (IL). | |
1641 | */Terminal.prototype.insertLines=function(params){var param,row,j;param=params[0];if(param<1)param=1;row=this.y+this.ybase;j=this.rows-1-this.scrollBottom;j=this.rows-1+this.ybase-j+1;while(param--){// test: echo -e '\e[44m\e[1L\e[0m' | |
1642 | // blankLine(true) - xterm/linux behavior | |
1643 | this.lines.splice(row,0,this.blankLine(true));this.lines.splice(j,1);}// this.maxRange(); | |
1644 | this.updateRange(this.y);this.updateRange(this.scrollBottom);};/** | |
1645 | * CSI Ps M | |
1646 | * Delete Ps Line(s) (default = 1) (DL). | |
1647 | */Terminal.prototype.deleteLines=function(params){var param,row,j;param=params[0];if(param<1)param=1;row=this.y+this.ybase;j=this.rows-1-this.scrollBottom;j=this.rows-1+this.ybase-j;while(param--){// test: echo -e '\e[44m\e[1M\e[0m' | |
1648 | // blankLine(true) - xterm/linux behavior | |
1649 | this.lines.splice(j+1,0,this.blankLine(true));this.lines.splice(row,1);}// this.maxRange(); | |
1650 | this.updateRange(this.y);this.updateRange(this.scrollBottom);};/** | |
1651 | * CSI Ps P | |
1652 | * Delete Ps Character(s) (default = 1) (DCH). | |
1653 | */Terminal.prototype.deleteChars=function(params){var param,row,ch;param=params[0];if(param<1)param=1;row=this.y+this.ybase;ch=[this.eraseAttr(),' ',1];// xterm | |
1654 | while(param--){this.lines[row].splice(this.x,1);this.lines[row].push(ch);}};/** | |
1655 | * CSI Ps X | |
1656 | * Erase Ps Character(s) (default = 1) (ECH). | |
1657 | */Terminal.prototype.eraseChars=function(params){var param,row,j,ch;param=params[0];if(param<1)param=1;row=this.y+this.ybase;j=this.x;ch=[this.eraseAttr(),' ',1];// xterm | |
1658 | while(param--&&j<this.cols){this.lines[row][j++]=ch;}};/** | |
1659 | * CSI Pm ` Character Position Absolute | |
1660 | * [column] (default = [row,1]) (HPA). | |
1661 | */Terminal.prototype.charPosAbsolute=function(params){var param=params[0];if(param<1)param=1;this.x=param-1;if(this.x>=this.cols){this.x=this.cols-1;}};/** | |
1662 | * 141 61 a * HPR - | |
1663 | * Horizontal Position Relative | |
1664 | * reuse CSI Ps C ? | |
1665 | */Terminal.prototype.HPositionRelative=function(params){var param=params[0];if(param<1)param=1;this.x+=param;if(this.x>=this.cols){this.x=this.cols-1;}};/** | |
1666 | * CSI Ps c Send Device Attributes (Primary DA). | |
1667 | * Ps = 0 or omitted -> request attributes from terminal. The | |
1668 | * response depends on the decTerminalID resource setting. | |
1669 | * -> CSI ? 1 ; 2 c (``VT100 with Advanced Video Option'') | |
1670 | * -> CSI ? 1 ; 0 c (``VT101 with No Options'') | |
1671 | * -> CSI ? 6 c (``VT102'') | |
1672 | * -> CSI ? 6 0 ; 1 ; 2 ; 6 ; 8 ; 9 ; 1 5 ; c (``VT220'') | |
1673 | * The VT100-style response parameters do not mean anything by | |
1674 | * themselves. VT220 parameters do, telling the host what fea- | |
1675 | * tures the terminal supports: | |
1676 | * Ps = 1 -> 132-columns. | |
1677 | * Ps = 2 -> Printer. | |
1678 | * Ps = 6 -> Selective erase. | |
1679 | * Ps = 8 -> User-defined keys. | |
1680 | * Ps = 9 -> National replacement character sets. | |
1681 | * Ps = 1 5 -> Technical characters. | |
1682 | * Ps = 2 2 -> ANSI color, e.g., VT525. | |
1683 | * Ps = 2 9 -> ANSI text locator (i.e., DEC Locator mode). | |
1684 | * CSI > Ps c | |
1685 | * Send Device Attributes (Secondary DA). | |
1686 | * Ps = 0 or omitted -> request the terminal's identification | |
1687 | * code. The response depends on the decTerminalID resource set- | |
1688 | * ting. It should apply only to VT220 and up, but xterm extends | |
1689 | * this to VT100. | |
1690 | * -> CSI > Pp ; Pv ; Pc c | |
1691 | * where Pp denotes the terminal type | |
1692 | * Pp = 0 -> ``VT100''. | |
1693 | * Pp = 1 -> ``VT220''. | |
1694 | * and Pv is the firmware version (for xterm, this was originally | |
1695 | * the XFree86 patch number, starting with 95). In a DEC termi- | |
1696 | * nal, Pc indicates the ROM cartridge registration number and is | |
1697 | * always zero. | |
1698 | * More information: | |
1699 | * xterm/charproc.c - line 2012, for more information. | |
1700 | * vim responds with ^[[?0c or ^[[?1c after the terminal's response (?) | |
1701 | */Terminal.prototype.sendDeviceAttributes=function(params){if(params[0]>0)return;if(!this.prefix){if(this.is('xterm')||this.is('rxvt-unicode')||this.is('screen')){this.send('\x1b[?1;2c');}else if(this.is('linux')){this.send('\x1b[?6c');}}else if(this.prefix==='>'){// xterm and urxvt | |
1702 | // seem to spit this | |
1703 | // out around ~370 times (?). | |
1704 | if(this.is('xterm')){this.send('\x1b[>0;276;0c');}else if(this.is('rxvt-unicode')){this.send('\x1b[>85;95;0c');}else if(this.is('linux')){// not supported by linux console. | |
1705 | // linux console echoes parameters. | |
1706 | this.send(params[0]+'c');}else if(this.is('screen')){this.send('\x1b[>83;40003;0c');}}};/** | |
1707 | * CSI Pm d | |
1708 | * Line Position Absolute [row] (default = [1,column]) (VPA). | |
1709 | */Terminal.prototype.linePosAbsolute=function(params){var param=params[0];if(param<1)param=1;this.y=param-1;if(this.y>=this.rows){this.y=this.rows-1;}};/** | |
1710 | * 145 65 e * VPR - Vertical Position Relative | |
1711 | * reuse CSI Ps B ? | |
1712 | */Terminal.prototype.VPositionRelative=function(params){var param=params[0];if(param<1)param=1;this.y+=param;if(this.y>=this.rows){this.y=this.rows-1;}};/** | |
1713 | * CSI Ps ; Ps f | |
1714 | * Horizontal and Vertical Position [row;column] (default = | |
1715 | * [1,1]) (HVP). | |
1716 | */Terminal.prototype.HVPosition=function(params){if(params[0]<1)params[0]=1;if(params[1]<1)params[1]=1;this.y=params[0]-1;if(this.y>=this.rows){this.y=this.rows-1;}this.x=params[1]-1;if(this.x>=this.cols){this.x=this.cols-1;}};/** | |
1717 | * CSI Pm h Set Mode (SM). | |
1718 | * Ps = 2 -> Keyboard Action Mode (AM). | |
1719 | * Ps = 4 -> Insert Mode (IRM). | |
1720 | * Ps = 1 2 -> Send/receive (SRM). | |
1721 | * Ps = 2 0 -> Automatic Newline (LNM). | |
1722 | * CSI ? Pm h | |
1723 | * DEC Private Mode Set (DECSET). | |
1724 | * Ps = 1 -> Application Cursor Keys (DECCKM). | |
1725 | * Ps = 2 -> Designate USASCII for character sets G0-G3 | |
1726 | * (DECANM), and set VT100 mode. | |
1727 | * Ps = 3 -> 132 Column Mode (DECCOLM). | |
1728 | * Ps = 4 -> Smooth (Slow) Scroll (DECSCLM). | |
1729 | * Ps = 5 -> Reverse Video (DECSCNM). | |
1730 | * Ps = 6 -> Origin Mode (DECOM). | |
1731 | * Ps = 7 -> Wraparound Mode (DECAWM). | |
1732 | * Ps = 8 -> Auto-repeat Keys (DECARM). | |
1733 | * Ps = 9 -> Send Mouse X & Y on button press. See the sec- | |
1734 | * tion Mouse Tracking. | |
1735 | * Ps = 1 0 -> Show toolbar (rxvt). | |
1736 | * Ps = 1 2 -> Start Blinking Cursor (att610). | |
1737 | * Ps = 1 8 -> Print form feed (DECPFF). | |
1738 | * Ps = 1 9 -> Set print extent to full screen (DECPEX). | |
1739 | * Ps = 2 5 -> Show Cursor (DECTCEM). | |
1740 | * Ps = 3 0 -> Show scrollbar (rxvt). | |
1741 | * Ps = 3 5 -> Enable font-shifting functions (rxvt). | |
1742 | * Ps = 3 8 -> Enter Tektronix Mode (DECTEK). | |
1743 | * Ps = 4 0 -> Allow 80 -> 132 Mode. | |
1744 | * Ps = 4 1 -> more(1) fix (see curses resource). | |
1745 | * Ps = 4 2 -> Enable Nation Replacement Character sets (DECN- | |
1746 | * RCM). | |
1747 | * Ps = 4 4 -> Turn On Margin Bell. | |
1748 | * Ps = 4 5 -> Reverse-wraparound Mode. | |
1749 | * Ps = 4 6 -> Start Logging. This is normally disabled by a | |
1750 | * compile-time option. | |
1751 | * Ps = 4 7 -> Use Alternate Screen Buffer. (This may be dis- | |
1752 | * abled by the titeInhibit resource). | |
1753 | * Ps = 6 6 -> Application keypad (DECNKM). | |
1754 | * Ps = 6 7 -> Backarrow key sends backspace (DECBKM). | |
1755 | * Ps = 1 0 0 0 -> Send Mouse X & Y on button press and | |
1756 | * release. See the section Mouse Tracking. | |
1757 | * Ps = 1 0 0 1 -> Use Hilite Mouse Tracking. | |
1758 | * Ps = 1 0 0 2 -> Use Cell Motion Mouse Tracking. | |
1759 | * Ps = 1 0 0 3 -> Use All Motion Mouse Tracking. | |
1760 | * Ps = 1 0 0 4 -> Send FocusIn/FocusOut events. | |
1761 | * Ps = 1 0 0 5 -> Enable Extended Mouse Mode. | |
1762 | * Ps = 1 0 1 0 -> Scroll to bottom on tty output (rxvt). | |
1763 | * Ps = 1 0 1 1 -> Scroll to bottom on key press (rxvt). | |
1764 | * Ps = 1 0 3 4 -> Interpret "meta" key, sets eighth bit. | |
1765 | * (enables the eightBitInput resource). | |
1766 | * Ps = 1 0 3 5 -> Enable special modifiers for Alt and Num- | |
1767 | * Lock keys. (This enables the numLock resource). | |
1768 | * Ps = 1 0 3 6 -> Send ESC when Meta modifies a key. (This | |
1769 | * enables the metaSendsEscape resource). | |
1770 | * Ps = 1 0 3 7 -> Send DEL from the editing-keypad Delete | |
1771 | * key. | |
1772 | * Ps = 1 0 3 9 -> Send ESC when Alt modifies a key. (This | |
1773 | * enables the altSendsEscape resource). | |
1774 | * Ps = 1 0 4 0 -> Keep selection even if not highlighted. | |
1775 | * (This enables the keepSelection resource). | |
1776 | * Ps = 1 0 4 1 -> Use the CLIPBOARD selection. (This enables | |
1777 | * the selectToClipboard resource). | |
1778 | * Ps = 1 0 4 2 -> Enable Urgency window manager hint when | |
1779 | * Control-G is received. (This enables the bellIsUrgent | |
1780 | * resource). | |
1781 | * Ps = 1 0 4 3 -> Enable raising of the window when Control-G | |
1782 | * is received. (enables the popOnBell resource). | |
1783 | * Ps = 1 0 4 7 -> Use Alternate Screen Buffer. (This may be | |
1784 | * disabled by the titeInhibit resource). | |
1785 | * Ps = 1 0 4 8 -> Save cursor as in DECSC. (This may be dis- | |
1786 | * abled by the titeInhibit resource). | |
1787 | * Ps = 1 0 4 9 -> Save cursor as in DECSC and use Alternate | |
1788 | * Screen Buffer, clearing it first. (This may be disabled by | |
1789 | * the titeInhibit resource). This combines the effects of the 1 | |
1790 | * 0 4 7 and 1 0 4 8 modes. Use this with terminfo-based | |
1791 | * applications rather than the 4 7 mode. | |
1792 | * Ps = 1 0 5 0 -> Set terminfo/termcap function-key mode. | |
1793 | * Ps = 1 0 5 1 -> Set Sun function-key mode. | |
1794 | * Ps = 1 0 5 2 -> Set HP function-key mode. | |
1795 | * Ps = 1 0 5 3 -> Set SCO function-key mode. | |
1796 | * Ps = 1 0 6 0 -> Set legacy keyboard emulation (X11R6). | |
1797 | * Ps = 1 0 6 1 -> Set VT220 keyboard emulation. | |
1798 | * Ps = 2 0 0 4 -> Set bracketed paste mode. | |
1799 | * Modes: | |
1800 | * http: *vt100.net/docs/vt220-rm/chapter4.html | |
1801 | */Terminal.prototype.setMode=function(params){if((typeof params==='undefined'?'undefined':_typeof(params))==='object'){var l=params.length,i=0;for(;i<l;i++){this.setMode(params[i]);}return;}if(!this.prefix){switch(params){case 4:this.insertMode=true;break;case 20://this.convertEol = true; | |
1802 | break;}}else if(this.prefix==='?'){switch(params){case 1:this.applicationCursor=true;break;case 2:this.setgCharset(0,Terminal.charsets.US);this.setgCharset(1,Terminal.charsets.US);this.setgCharset(2,Terminal.charsets.US);this.setgCharset(3,Terminal.charsets.US);// set VT100 mode here | |
1803 | break;case 3:// 132 col mode | |
1804 | this.savedCols=this.cols;this.resize(132,this.rows);break;case 6:this.originMode=true;break;case 7:this.wraparoundMode=true;break;case 12:// this.cursorBlink = true; | |
1805 | break;case 66:this.log('Serial port requested application keypad.');this.applicationKeypad=true;this.viewport.syncScrollArea();break;case 9:// X10 Mouse | |
1806 | // no release, no motion, no wheel, no modifiers. | |
1807 | case 1000:// vt200 mouse | |
1808 | // no motion. | |
1809 | // no modifiers, except control on the wheel. | |
1810 | case 1002:// button event mouse | |
1811 | case 1003:// any event mouse | |
1812 | // any event - sends motion events, | |
1813 | // even if there is no button held down. | |
1814 | this.x10Mouse=params===9;this.vt200Mouse=params===1000;this.normalMouse=params>1000;this.mouseEvents=true;this.element.style.cursor='default';this.log('Binding to mouse events.');break;case 1004:// send focusin/focusout events | |
1815 | // focusin: ^[[I | |
1816 | // focusout: ^[[O | |
1817 | this.sendFocus=true;break;case 1005:// utf8 ext mode mouse | |
1818 | this.utfMouse=true;// for wide terminals | |
1819 | // simply encodes large values as utf8 characters | |
1820 | break;case 1006:// sgr ext mode mouse | |
1821 | this.sgrMouse=true;// for wide terminals | |
1822 | // does not add 32 to fields | |
1823 | // press: ^[[<b;x;yM | |
1824 | // release: ^[[<b;x;ym | |
1825 | break;case 1015:// urxvt ext mode mouse | |
1826 | this.urxvtMouse=true;// for wide terminals | |
1827 | // numbers for fields | |
1828 | // press: ^[[b;x;yM | |
1829 | // motion: ^[[b;x;yT | |
1830 | break;case 25:// show cursor | |
1831 | this.cursorHidden=false;break;case 1049:// alt screen buffer cursor | |
1832 | //this.saveCursor(); | |
1833 | ;// FALL-THROUGH | |
1834 | case 47:// alt screen buffer | |
1835 | case 1047:// alt screen buffer | |
1836 | if(!this.normal){var normal={lines:this.lines,ybase:this.ybase,ydisp:this.ydisp,x:this.x,y:this.y,scrollTop:this.scrollTop,scrollBottom:this.scrollBottom,tabs:this.tabs// XXX save charset(s) here? | |
1837 | // charset: this.charset, | |
1838 | // glevel: this.glevel, | |
1839 | // charsets: this.charsets | |
1840 | };this.reset();this.normal=normal;this.showCursor();}break;}}};/** | |
1841 | * CSI Pm l Reset Mode (RM). | |
1842 | * Ps = 2 -> Keyboard Action Mode (AM). | |
1843 | * Ps = 4 -> Replace Mode (IRM). | |
1844 | * Ps = 1 2 -> Send/receive (SRM). | |
1845 | * Ps = 2 0 -> Normal Linefeed (LNM). | |
1846 | * CSI ? Pm l | |
1847 | * DEC Private Mode Reset (DECRST). | |
1848 | * Ps = 1 -> Normal Cursor Keys (DECCKM). | |
1849 | * Ps = 2 -> Designate VT52 mode (DECANM). | |
1850 | * Ps = 3 -> 80 Column Mode (DECCOLM). | |
1851 | * Ps = 4 -> Jump (Fast) Scroll (DECSCLM). | |
1852 | * Ps = 5 -> Normal Video (DECSCNM). | |
1853 | * Ps = 6 -> Normal Cursor Mode (DECOM). | |
1854 | * Ps = 7 -> No Wraparound Mode (DECAWM). | |
1855 | * Ps = 8 -> No Auto-repeat Keys (DECARM). | |
1856 | * Ps = 9 -> Don't send Mouse X & Y on button press. | |
1857 | * Ps = 1 0 -> Hide toolbar (rxvt). | |
1858 | * Ps = 1 2 -> Stop Blinking Cursor (att610). | |
1859 | * Ps = 1 8 -> Don't print form feed (DECPFF). | |
1860 | * Ps = 1 9 -> Limit print to scrolling region (DECPEX). | |
1861 | * Ps = 2 5 -> Hide Cursor (DECTCEM). | |
1862 | * Ps = 3 0 -> Don't show scrollbar (rxvt). | |
1863 | * Ps = 3 5 -> Disable font-shifting functions (rxvt). | |
1864 | * Ps = 4 0 -> Disallow 80 -> 132 Mode. | |
1865 | * Ps = 4 1 -> No more(1) fix (see curses resource). | |
1866 | * Ps = 4 2 -> Disable Nation Replacement Character sets (DEC- | |
1867 | * NRCM). | |
1868 | * Ps = 4 4 -> Turn Off Margin Bell. | |
1869 | * Ps = 4 5 -> No Reverse-wraparound Mode. | |
1870 | * Ps = 4 6 -> Stop Logging. (This is normally disabled by a | |
1871 | * compile-time option). | |
1872 | * Ps = 4 7 -> Use Normal Screen Buffer. | |
1873 | * Ps = 6 6 -> Numeric keypad (DECNKM). | |
1874 | * Ps = 6 7 -> Backarrow key sends delete (DECBKM). | |
1875 | * Ps = 1 0 0 0 -> Don't send Mouse X & Y on button press and | |
1876 | * release. See the section Mouse Tracking. | |
1877 | * Ps = 1 0 0 1 -> Don't use Hilite Mouse Tracking. | |
1878 | * Ps = 1 0 0 2 -> Don't use Cell Motion Mouse Tracking. | |
1879 | * Ps = 1 0 0 3 -> Don't use All Motion Mouse Tracking. | |
1880 | * Ps = 1 0 0 4 -> Don't send FocusIn/FocusOut events. | |
1881 | * Ps = 1 0 0 5 -> Disable Extended Mouse Mode. | |
1882 | * Ps = 1 0 1 0 -> Don't scroll to bottom on tty output | |
1883 | * (rxvt). | |
1884 | * Ps = 1 0 1 1 -> Don't scroll to bottom on key press (rxvt). | |
1885 | * Ps = 1 0 3 4 -> Don't interpret "meta" key. (This disables | |
1886 | * the eightBitInput resource). | |
1887 | * Ps = 1 0 3 5 -> Disable special modifiers for Alt and Num- | |
1888 | * Lock keys. (This disables the numLock resource). | |
1889 | * Ps = 1 0 3 6 -> Don't send ESC when Meta modifies a key. | |
1890 | * (This disables the metaSendsEscape resource). | |
1891 | * Ps = 1 0 3 7 -> Send VT220 Remove from the editing-keypad | |
1892 | * Delete key. | |
1893 | * Ps = 1 0 3 9 -> Don't send ESC when Alt modifies a key. | |
1894 | * (This disables the altSendsEscape resource). | |
1895 | * Ps = 1 0 4 0 -> Do not keep selection when not highlighted. | |
1896 | * (This disables the keepSelection resource). | |
1897 | * Ps = 1 0 4 1 -> Use the PRIMARY selection. (This disables | |
1898 | * the selectToClipboard resource). | |
1899 | * Ps = 1 0 4 2 -> Disable Urgency window manager hint when | |
1900 | * Control-G is received. (This disables the bellIsUrgent | |
1901 | * resource). | |
1902 | * Ps = 1 0 4 3 -> Disable raising of the window when Control- | |
1903 | * G is received. (This disables the popOnBell resource). | |
1904 | * Ps = 1 0 4 7 -> Use Normal Screen Buffer, clearing screen | |
1905 | * first if in the Alternate Screen. (This may be disabled by | |
1906 | * the titeInhibit resource). | |
1907 | * Ps = 1 0 4 8 -> Restore cursor as in DECRC. (This may be | |
1908 | * disabled by the titeInhibit resource). | |
1909 | * Ps = 1 0 4 9 -> Use Normal Screen Buffer and restore cursor | |
1910 | * as in DECRC. (This may be disabled by the titeInhibit | |
1911 | * resource). This combines the effects of the 1 0 4 7 and 1 0 | |
1912 | * 4 8 modes. Use this with terminfo-based applications rather | |
1913 | * than the 4 7 mode. | |
1914 | * Ps = 1 0 5 0 -> Reset terminfo/termcap function-key mode. | |
1915 | * Ps = 1 0 5 1 -> Reset Sun function-key mode. | |
1916 | * Ps = 1 0 5 2 -> Reset HP function-key mode. | |
1917 | * Ps = 1 0 5 3 -> Reset SCO function-key mode. | |
1918 | * Ps = 1 0 6 0 -> Reset legacy keyboard emulation (X11R6). | |
1919 | * Ps = 1 0 6 1 -> Reset keyboard emulation to Sun/PC style. | |
1920 | * Ps = 2 0 0 4 -> Reset bracketed paste mode. | |
1921 | */Terminal.prototype.resetMode=function(params){if((typeof params==='undefined'?'undefined':_typeof(params))==='object'){var l=params.length,i=0;for(;i<l;i++){this.resetMode(params[i]);}return;}if(!this.prefix){switch(params){case 4:this.insertMode=false;break;case 20://this.convertEol = false; | |
1922 | break;}}else if(this.prefix==='?'){switch(params){case 1:this.applicationCursor=false;break;case 3:if(this.cols===132&&this.savedCols){this.resize(this.savedCols,this.rows);}delete this.savedCols;break;case 6:this.originMode=false;break;case 7:this.wraparoundMode=false;break;case 12:// this.cursorBlink = false; | |
1923 | break;case 66:this.log('Switching back to normal keypad.');this.applicationKeypad=false;this.viewport.syncScrollArea();break;case 9:// X10 Mouse | |
1924 | case 1000:// vt200 mouse | |
1925 | case 1002:// button event mouse | |
1926 | case 1003:// any event mouse | |
1927 | this.x10Mouse=false;this.vt200Mouse=false;this.normalMouse=false;this.mouseEvents=false;this.element.style.cursor='';break;case 1004:// send focusin/focusout events | |
1928 | this.sendFocus=false;break;case 1005:// utf8 ext mode mouse | |
1929 | this.utfMouse=false;break;case 1006:// sgr ext mode mouse | |
1930 | this.sgrMouse=false;break;case 1015:// urxvt ext mode mouse | |
1931 | this.urxvtMouse=false;break;case 25:// hide cursor | |
1932 | this.cursorHidden=true;break;case 1049:// alt screen buffer cursor | |
1933 | ;// FALL-THROUGH | |
1934 | case 47:// normal screen buffer | |
1935 | case 1047:// normal screen buffer - clearing it first | |
1936 | if(this.normal){this.lines=this.normal.lines;this.ybase=this.normal.ybase;this.ydisp=this.normal.ydisp;this.x=this.normal.x;this.y=this.normal.y;this.scrollTop=this.normal.scrollTop;this.scrollBottom=this.normal.scrollBottom;this.tabs=this.normal.tabs;this.normal=null;// if (params === 1049) { | |
1937 | // this.x = this.savedX; | |
1938 | // this.y = this.savedY; | |
1939 | // } | |
1940 | this.refresh(0,this.rows-1);this.showCursor();}break;}}};/** | |
1941 | * CSI Ps ; Ps r | |
1942 | * Set Scrolling Region [top;bottom] (default = full size of win- | |
1943 | * dow) (DECSTBM). | |
1944 | * CSI ? Pm r | |
1945 | */Terminal.prototype.setScrollRegion=function(params){if(this.prefix)return;this.scrollTop=(params[0]||1)-1;this.scrollBottom=(params[1]||this.rows)-1;this.x=0;this.y=0;};/** | |
1946 | * CSI s | |
1947 | * Save cursor (ANSI.SYS). | |
1948 | */Terminal.prototype.saveCursor=function(params){this.savedX=this.x;this.savedY=this.y;};/** | |
1949 | * CSI u | |
1950 | * Restore cursor (ANSI.SYS). | |
1951 | */Terminal.prototype.restoreCursor=function(params){this.x=this.savedX||0;this.y=this.savedY||0;};/** | |
1952 | * Lesser Used | |
1953 | *//** | |
1954 | * CSI Ps I | |
1955 | * Cursor Forward Tabulation Ps tab stops (default = 1) (CHT). | |
1956 | */Terminal.prototype.cursorForwardTab=function(params){var param=params[0]||1;while(param--){this.x=this.nextStop();}};/** | |
1957 | * CSI Ps S Scroll up Ps lines (default = 1) (SU). | |
1958 | */Terminal.prototype.scrollUp=function(params){var param=params[0]||1;while(param--){this.lines.splice(this.ybase+this.scrollTop,1);this.lines.splice(this.ybase+this.scrollBottom,0,this.blankLine());}// this.maxRange(); | |
1959 | this.updateRange(this.scrollTop);this.updateRange(this.scrollBottom);};/** | |
1960 | * CSI Ps T Scroll down Ps lines (default = 1) (SD). | |
1961 | */Terminal.prototype.scrollDown=function(params){var param=params[0]||1;while(param--){this.lines.splice(this.ybase+this.scrollBottom,1);this.lines.splice(this.ybase+this.scrollTop,0,this.blankLine());}// this.maxRange(); | |
1962 | this.updateRange(this.scrollTop);this.updateRange(this.scrollBottom);};/** | |
1963 | * CSI Ps ; Ps ; Ps ; Ps ; Ps T | |
1964 | * Initiate highlight mouse tracking. Parameters are | |
1965 | * [func;startx;starty;firstrow;lastrow]. See the section Mouse | |
1966 | * Tracking. | |
1967 | */Terminal.prototype.initMouseTracking=function(params){// Relevant: DECSET 1001 | |
1968 | };/** | |
1969 | * CSI > Ps; Ps T | |
1970 | * Reset one or more features of the title modes to the default | |
1971 | * value. Normally, "reset" disables the feature. It is possi- | |
1972 | * ble to disable the ability to reset features by compiling a | |
1973 | * different default for the title modes into xterm. | |
1974 | * Ps = 0 -> Do not set window/icon labels using hexadecimal. | |
1975 | * Ps = 1 -> Do not query window/icon labels using hexadeci- | |
1976 | * mal. | |
1977 | * Ps = 2 -> Do not set window/icon labels using UTF-8. | |
1978 | * Ps = 3 -> Do not query window/icon labels using UTF-8. | |
1979 | * (See discussion of "Title Modes"). | |
1980 | */Terminal.prototype.resetTitleModes=function(params){;};/** | |
1981 | * CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT). | |
1982 | */Terminal.prototype.cursorBackwardTab=function(params){var param=params[0]||1;while(param--){this.x=this.prevStop();}};/** | |
1983 | * CSI Ps b Repeat the preceding graphic character Ps times (REP). | |
1984 | */Terminal.prototype.repeatPrecedingCharacter=function(params){var param=params[0]||1,line=this.lines[this.ybase+this.y],ch=line[this.x-1]||[this.defAttr,' ',1];while(param--){line[this.x++]=ch;}};/** | |
1985 | * CSI Ps g Tab Clear (TBC). | |
1986 | * Ps = 0 -> Clear Current Column (default). | |
1987 | * Ps = 3 -> Clear All. | |
1988 | * Potentially: | |
1989 | * Ps = 2 -> Clear Stops on Line. | |
1990 | * http://vt100.net/annarbor/aaa-ug/section6.html | |
1991 | */Terminal.prototype.tabClear=function(params){var param=params[0];if(param<=0){delete this.tabs[this.x];}else if(param===3){this.tabs={};}};/** | |
1992 | * CSI Pm i Media Copy (MC). | |
1993 | * Ps = 0 -> Print screen (default). | |
1994 | * Ps = 4 -> Turn off printer controller mode. | |
1995 | * Ps = 5 -> Turn on printer controller mode. | |
1996 | * CSI ? Pm i | |
1997 | * Media Copy (MC, DEC-specific). | |
1998 | * Ps = 1 -> Print line containing cursor. | |
1999 | * Ps = 4 -> Turn off autoprint mode. | |
2000 | * Ps = 5 -> Turn on autoprint mode. | |
2001 | * Ps = 1 0 -> Print composed display, ignores DECPEX. | |
2002 | * Ps = 1 1 -> Print all pages. | |
2003 | */Terminal.prototype.mediaCopy=function(params){;};/** | |
2004 | * CSI > Ps; Ps m | |
2005 | * Set or reset resource-values used by xterm to decide whether | |
2006 | * to construct escape sequences holding information about the | |
2007 | * modifiers pressed with a given key. The first parameter iden- | |
2008 | * tifies the resource to set/reset. The second parameter is the | |
2009 | * value to assign to the resource. If the second parameter is | |
2010 | * omitted, the resource is reset to its initial value. | |
2011 | * Ps = 1 -> modifyCursorKeys. | |
2012 | * Ps = 2 -> modifyFunctionKeys. | |
2013 | * Ps = 4 -> modifyOtherKeys. | |
2014 | * If no parameters are given, all resources are reset to their | |
2015 | * initial values. | |
2016 | */Terminal.prototype.setResources=function(params){;};/** | |
2017 | * CSI > Ps n | |
2018 | * Disable modifiers which may be enabled via the CSI > Ps; Ps m | |
2019 | * sequence. This corresponds to a resource value of "-1", which | |
2020 | * cannot be set with the other sequence. The parameter identi- | |
2021 | * fies the resource to be disabled: | |
2022 | * Ps = 1 -> modifyCursorKeys. | |
2023 | * Ps = 2 -> modifyFunctionKeys. | |
2024 | * Ps = 4 -> modifyOtherKeys. | |
2025 | * If the parameter is omitted, modifyFunctionKeys is disabled. | |
2026 | * When modifyFunctionKeys is disabled, xterm uses the modifier | |
2027 | * keys to make an extended sequence of functions rather than | |
2028 | * adding a parameter to each function key to denote the modi- | |
2029 | * fiers. | |
2030 | */Terminal.prototype.disableModifiers=function(params){;};/** | |
2031 | * CSI > Ps p | |
2032 | * Set resource value pointerMode. This is used by xterm to | |
2033 | * decide whether to hide the pointer cursor as the user types. | |
2034 | * Valid values for the parameter: | |
2035 | * Ps = 0 -> never hide the pointer. | |
2036 | * Ps = 1 -> hide if the mouse tracking mode is not enabled. | |
2037 | * Ps = 2 -> always hide the pointer. If no parameter is | |
2038 | * given, xterm uses the default, which is 1 . | |
2039 | */Terminal.prototype.setPointerMode=function(params){;};/** | |
2040 | * CSI ! p Soft terminal reset (DECSTR). | |
2041 | * http://vt100.net/docs/vt220-rm/table4-10.html | |
2042 | */Terminal.prototype.softReset=function(params){this.cursorHidden=false;this.insertMode=false;this.originMode=false;this.wraparoundMode=false;// autowrap | |
2043 | this.applicationKeypad=false;// ? | |
2044 | this.viewport.syncScrollArea();this.applicationCursor=false;this.scrollTop=0;this.scrollBottom=this.rows-1;this.curAttr=this.defAttr;this.x=this.y=0;// ? | |
2045 | this.charset=null;this.glevel=0;// ?? | |
2046 | this.charsets=[null];// ?? | |
2047 | };/** | |
2048 | * CSI Ps$ p | |
2049 | * Request ANSI mode (DECRQM). For VT300 and up, reply is | |
2050 | * CSI Ps; Pm$ y | |
2051 | * where Ps is the mode number as in RM, and Pm is the mode | |
2052 | * value: | |
2053 | * 0 - not recognized | |
2054 | * 1 - set | |
2055 | * 2 - reset | |
2056 | * 3 - permanently set | |
2057 | * 4 - permanently reset | |
2058 | */Terminal.prototype.requestAnsiMode=function(params){;};/** | |
2059 | * CSI ? Ps$ p | |
2060 | * Request DEC private mode (DECRQM). For VT300 and up, reply is | |
2061 | * CSI ? Ps; Pm$ p | |
2062 | * where Ps is the mode number as in DECSET, Pm is the mode value | |
2063 | * as in the ANSI DECRQM. | |
2064 | */Terminal.prototype.requestPrivateMode=function(params){;};/** | |
2065 | * CSI Ps ; Ps " p | |
2066 | * Set conformance level (DECSCL). Valid values for the first | |
2067 | * parameter: | |
2068 | * Ps = 6 1 -> VT100. | |
2069 | * Ps = 6 2 -> VT200. | |
2070 | * Ps = 6 3 -> VT300. | |
2071 | * Valid values for the second parameter: | |
2072 | * Ps = 0 -> 8-bit controls. | |
2073 | * Ps = 1 -> 7-bit controls (always set for VT100). | |
2074 | * Ps = 2 -> 8-bit controls. | |
2075 | */Terminal.prototype.setConformanceLevel=function(params){;};/** | |
2076 | * CSI Ps q Load LEDs (DECLL). | |
2077 | * Ps = 0 -> Clear all LEDS (default). | |
2078 | * Ps = 1 -> Light Num Lock. | |
2079 | * Ps = 2 -> Light Caps Lock. | |
2080 | * Ps = 3 -> Light Scroll Lock. | |
2081 | * Ps = 2 1 -> Extinguish Num Lock. | |
2082 | * Ps = 2 2 -> Extinguish Caps Lock. | |
2083 | * Ps = 2 3 -> Extinguish Scroll Lock. | |
2084 | */Terminal.prototype.loadLEDs=function(params){;};/** | |
2085 | * CSI Ps SP q | |
2086 | * Set cursor style (DECSCUSR, VT520). | |
2087 | * Ps = 0 -> blinking block. | |
2088 | * Ps = 1 -> blinking block (default). | |
2089 | * Ps = 2 -> steady block. | |
2090 | * Ps = 3 -> blinking underline. | |
2091 | * Ps = 4 -> steady underline. | |
2092 | */Terminal.prototype.setCursorStyle=function(params){;};/** | |
2093 | * CSI Ps " q | |
2094 | * Select character protection attribute (DECSCA). Valid values | |
2095 | * for the parameter: | |
2096 | * Ps = 0 -> DECSED and DECSEL can erase (default). | |
2097 | * Ps = 1 -> DECSED and DECSEL cannot erase. | |
2098 | * Ps = 2 -> DECSED and DECSEL can erase. | |
2099 | */Terminal.prototype.setCharProtectionAttr=function(params){;};/** | |
2100 | * CSI ? Pm r | |
2101 | * Restore DEC Private Mode Values. The value of Ps previously | |
2102 | * saved is restored. Ps values are the same as for DECSET. | |
2103 | */Terminal.prototype.restorePrivateValues=function(params){;};/** | |
2104 | * CSI Pt; Pl; Pb; Pr; Ps$ r | |
2105 | * Change Attributes in Rectangular Area (DECCARA), VT400 and up. | |
2106 | * Pt; Pl; Pb; Pr denotes the rectangle. | |
2107 | * Ps denotes the SGR attributes to change: 0, 1, 4, 5, 7. | |
2108 | * NOTE: xterm doesn't enable this code by default. | |
2109 | */Terminal.prototype.setAttrInRectangle=function(params){var t=params[0],l=params[1],b=params[2],r=params[3],attr=params[4];var line,i;for(;t<b+1;t++){line=this.lines[this.ybase+t];for(i=l;i<r;i++){line[i]=[attr,line[i][1]];}}// this.maxRange(); | |
2110 | this.updateRange(params[0]);this.updateRange(params[2]);};/** | |
2111 | * CSI Pc; Pt; Pl; Pb; Pr$ x | |
2112 | * Fill Rectangular Area (DECFRA), VT420 and up. | |
2113 | * Pc is the character to use. | |
2114 | * Pt; Pl; Pb; Pr denotes the rectangle. | |
2115 | * NOTE: xterm doesn't enable this code by default. | |
2116 | */Terminal.prototype.fillRectangle=function(params){var ch=params[0],t=params[1],l=params[2],b=params[3],r=params[4];var line,i;for(;t<b+1;t++){line=this.lines[this.ybase+t];for(i=l;i<r;i++){line[i]=[line[i][0],String.fromCharCode(ch)];}}// this.maxRange(); | |
2117 | this.updateRange(params[1]);this.updateRange(params[3]);};/** | |
2118 | * CSI Ps ; Pu ' z | |
2119 | * Enable Locator Reporting (DECELR). | |
2120 | * Valid values for the first parameter: | |
2121 | * Ps = 0 -> Locator disabled (default). | |
2122 | * Ps = 1 -> Locator enabled. | |
2123 | * Ps = 2 -> Locator enabled for one report, then disabled. | |
2124 | * The second parameter specifies the coordinate unit for locator | |
2125 | * reports. | |
2126 | * Valid values for the second parameter: | |
2127 | * Pu = 0 <- or omitted -> default to character cells. | |
2128 | * Pu = 1 <- device physical pixels. | |
2129 | * Pu = 2 <- character cells. | |
2130 | */Terminal.prototype.enableLocatorReporting=function(params){var val=params[0]>0;//this.mouseEvents = val; | |
2131 | //this.decLocator = val; | |
2132 | };/** | |
2133 | * CSI Pt; Pl; Pb; Pr$ z | |
2134 | * Erase Rectangular Area (DECERA), VT400 and up. | |
2135 | * Pt; Pl; Pb; Pr denotes the rectangle. | |
2136 | * NOTE: xterm doesn't enable this code by default. | |
2137 | */Terminal.prototype.eraseRectangle=function(params){var t=params[0],l=params[1],b=params[2],r=params[3];var line,i,ch;ch=[this.eraseAttr(),' ',1];// xterm? | |
2138 | for(;t<b+1;t++){line=this.lines[this.ybase+t];for(i=l;i<r;i++){line[i]=ch;}}// this.maxRange(); | |
2139 | this.updateRange(params[0]);this.updateRange(params[2]);};/** | |
2140 | * CSI P m SP } | |
2141 | * Insert P s Column(s) (default = 1) (DECIC), VT420 and up. | |
2142 | * NOTE: xterm doesn't enable this code by default. | |
2143 | */Terminal.prototype.insertColumns=function(){var param=params[0],l=this.ybase+this.rows,ch=[this.eraseAttr(),' ',1]// xterm? | |
2144 | ,i;while(param--){for(i=this.ybase;i<l;i++){this.lines[i].splice(this.x+1,0,ch);this.lines[i].pop();}}this.maxRange();};/** | |
2145 | * CSI P m SP ~ | |
2146 | * Delete P s Column(s) (default = 1) (DECDC), VT420 and up | |
2147 | * NOTE: xterm doesn't enable this code by default. | |
2148 | */Terminal.prototype.deleteColumns=function(){var param=params[0],l=this.ybase+this.rows,ch=[this.eraseAttr(),' ',1]// xterm? | |
2149 | ,i;while(param--){for(i=this.ybase;i<l;i++){this.lines[i].splice(this.x,1);this.lines[i].push(ch);}}this.maxRange();};/** | |
2150 | * Character Sets | |
2151 | */Terminal.charsets={};// DEC Special Character and Line Drawing Set. | |
2152 | // http://vt100.net/docs/vt102-ug/table5-13.html | |
2153 | // A lot of curses apps use this if they see TERM=xterm. | |
2154 | // testing: echo -e '\e(0a\e(B' | |
2155 | // The xterm output sometimes seems to conflict with the | |
2156 | // reference above. xterm seems in line with the reference | |
2157 | // when running vttest however. | |
2158 | // The table below now uses xterm's output from vttest. | |
2159 | Terminal.charsets.SCLD={// (0 | |
2160 | '`':'\u25C6',// '◆' | |
2161 | 'a':'\u2592',// '▒' | |
2162 | 'b':'\t',// '\t' | |
2163 | 'c':'\f',// '\f' | |
2164 | 'd':'\r',// '\r' | |
2165 | 'e':'\n',// '\n' | |
2166 | 'f':'\xB0',// '°' | |
2167 | 'g':'\xB1',// '±' | |
2168 | 'h':'\u2424',// '\u2424' (NL) | |
2169 | 'i':'\x0B',// '\v' | |
2170 | 'j':'\u2518',// '┘' | |
2171 | 'k':'\u2510',// '┐' | |
2172 | 'l':'\u250C',// '┌' | |
2173 | 'm':'\u2514',// '└' | |
2174 | 'n':'\u253C',// '┼' | |
2175 | 'o':'\u23BA',// '⎺' | |
2176 | 'p':'\u23BB',// '⎻' | |
2177 | 'q':'\u2500',// '─' | |
2178 | 'r':'\u23BC',// '⎼' | |
2179 | 's':'\u23BD',// '⎽' | |
2180 | 't':'\u251C',// '├' | |
2181 | 'u':'\u2524',// '┤' | |
2182 | 'v':'\u2534',// '┴' | |
2183 | 'w':'\u252C',// '┬' | |
2184 | 'x':'\u2502',// '│' | |
2185 | 'y':'\u2264',// '≤' | |
2186 | 'z':'\u2265',// '≥' | |
2187 | '{':'\u03C0',// 'π' | |
2188 | '|':'\u2260',// '≠' | |
2189 | '}':'\xA3',// '£' | |
2190 | '~':'\xB7'// '·' | |
2191 | };Terminal.charsets.UK=null;// (A | |
2192 | Terminal.charsets.US=null;// (B (USASCII) | |
2193 | Terminal.charsets.Dutch=null;// (4 | |
2194 | Terminal.charsets.Finnish=null;// (C or (5 | |
2195 | Terminal.charsets.French=null;// (R | |
2196 | Terminal.charsets.FrenchCanadian=null;// (Q | |
2197 | Terminal.charsets.German=null;// (K | |
2198 | Terminal.charsets.Italian=null;// (Y | |
2199 | Terminal.charsets.NorwegianDanish=null;// (E or (6 | |
2200 | Terminal.charsets.Spanish=null;// (Z | |
2201 | Terminal.charsets.Swedish=null;// (H or (7 | |
2202 | Terminal.charsets.Swiss=null;// (= | |
2203 | Terminal.charsets.ISOLatin=null;// /A | |
2204 | /** | |
2205 | * Helpers | |
2206 | */function on(el,type,handler,capture){if(!Array.isArray(el)){el=[el];}el.forEach(function(element){element.addEventListener(type,handler,capture||false);});}function off(el,type,handler,capture){el.removeEventListener(type,handler,capture||false);}function cancel(ev,force){if(!this.cancelEvents&&!force){return;}ev.preventDefault();ev.stopPropagation();return false;}function inherits(child,parent){function f(){this.constructor=child;}f.prototype=parent.prototype;child.prototype=new f();}// if bold is broken, we can't | |
2207 | // use it in the terminal. | |
2208 | function isBoldBroken(document){var body=document.getElementsByTagName('body')[0];var el=document.createElement('span');el.innerHTML='hello world';body.appendChild(el);var w1=el.scrollWidth;el.style.fontWeight='bold';var w2=el.scrollWidth;body.removeChild(el);return w1!==w2;}function indexOf(obj,el){var i=obj.length;while(i--){if(obj[i]===el)return i;}return-1;}function isThirdLevelShift(term,ev){var thirdLevelKey=term.browser.isMac&&ev.altKey&&!ev.ctrlKey&&!ev.metaKey||term.browser.isMSWindows&&ev.altKey&&ev.ctrlKey&&!ev.metaKey;if(ev.type=='keypress'){return thirdLevelKey;}// Don't invoke for arrows, pageDown, home, backspace, etc. (on non-keypress events) | |
2209 | return thirdLevelKey&&(!ev.keyCode||ev.keyCode>47);}function matchColor(r1,g1,b1){var hash=r1<<16|g1<<8|b1;if(matchColor._cache[hash]!=null){return matchColor._cache[hash];}var ldiff=Infinity,li=-1,i=0,c,r2,g2,b2,diff;for(;i<Terminal.vcolors.length;i++){c=Terminal.vcolors[i];r2=c[0];g2=c[1];b2=c[2];diff=matchColor.distance(r1,g1,b1,r2,g2,b2);if(diff===0){li=i;break;}if(diff<ldiff){ldiff=diff;li=i;}}return matchColor._cache[hash]=li;}matchColor._cache={};// http://stackoverflow.com/questions/1633828 | |
2210 | matchColor.distance=function(r1,g1,b1,r2,g2,b2){return Math.pow(30*(r1-r2),2)+Math.pow(59*(g1-g2),2)+Math.pow(11*(b1-b2),2);};function each(obj,iter,con){if(obj.forEach)return obj.forEach(iter,con);for(var i=0;i<obj.length;i++){iter.call(con,obj[i],i,obj);}}function keys(obj){if(Object.keys)return Object.keys(obj);var key,keys=[];for(key in obj){if(Object.prototype.hasOwnProperty.call(obj,key)){keys.push(key);}}return keys;}var wcwidth=function(opts){// extracted from https://www.cl.cam.ac.uk/%7Emgk25/ucs/wcwidth.c | |
2211 | // combining characters | |
2212 | var COMBINING=[[0x0300,0x036F],[0x0483,0x0486],[0x0488,0x0489],[0x0591,0x05BD],[0x05BF,0x05BF],[0x05C1,0x05C2],[0x05C4,0x05C5],[0x05C7,0x05C7],[0x0600,0x0603],[0x0610,0x0615],[0x064B,0x065E],[0x0670,0x0670],[0x06D6,0x06E4],[0x06E7,0x06E8],[0x06EA,0x06ED],[0x070F,0x070F],[0x0711,0x0711],[0x0730,0x074A],[0x07A6,0x07B0],[0x07EB,0x07F3],[0x0901,0x0902],[0x093C,0x093C],[0x0941,0x0948],[0x094D,0x094D],[0x0951,0x0954],[0x0962,0x0963],[0x0981,0x0981],[0x09BC,0x09BC],[0x09C1,0x09C4],[0x09CD,0x09CD],[0x09E2,0x09E3],[0x0A01,0x0A02],[0x0A3C,0x0A3C],[0x0A41,0x0A42],[0x0A47,0x0A48],[0x0A4B,0x0A4D],[0x0A70,0x0A71],[0x0A81,0x0A82],[0x0ABC,0x0ABC],[0x0AC1,0x0AC5],[0x0AC7,0x0AC8],[0x0ACD,0x0ACD],[0x0AE2,0x0AE3],[0x0B01,0x0B01],[0x0B3C,0x0B3C],[0x0B3F,0x0B3F],[0x0B41,0x0B43],[0x0B4D,0x0B4D],[0x0B56,0x0B56],[0x0B82,0x0B82],[0x0BC0,0x0BC0],[0x0BCD,0x0BCD],[0x0C3E,0x0C40],[0x0C46,0x0C48],[0x0C4A,0x0C4D],[0x0C55,0x0C56],[0x0CBC,0x0CBC],[0x0CBF,0x0CBF],[0x0CC6,0x0CC6],[0x0CCC,0x0CCD],[0x0CE2,0x0CE3],[0x0D41,0x0D43],[0x0D4D,0x0D4D],[0x0DCA,0x0DCA],[0x0DD2,0x0DD4],[0x0DD6,0x0DD6],[0x0E31,0x0E31],[0x0E34,0x0E3A],[0x0E47,0x0E4E],[0x0EB1,0x0EB1],[0x0EB4,0x0EB9],[0x0EBB,0x0EBC],[0x0EC8,0x0ECD],[0x0F18,0x0F19],[0x0F35,0x0F35],[0x0F37,0x0F37],[0x0F39,0x0F39],[0x0F71,0x0F7E],[0x0F80,0x0F84],[0x0F86,0x0F87],[0x0F90,0x0F97],[0x0F99,0x0FBC],[0x0FC6,0x0FC6],[0x102D,0x1030],[0x1032,0x1032],[0x1036,0x1037],[0x1039,0x1039],[0x1058,0x1059],[0x1160,0x11FF],[0x135F,0x135F],[0x1712,0x1714],[0x1732,0x1734],[0x1752,0x1753],[0x1772,0x1773],[0x17B4,0x17B5],[0x17B7,0x17BD],[0x17C6,0x17C6],[0x17C9,0x17D3],[0x17DD,0x17DD],[0x180B,0x180D],[0x18A9,0x18A9],[0x1920,0x1922],[0x1927,0x1928],[0x1932,0x1932],[0x1939,0x193B],[0x1A17,0x1A18],[0x1B00,0x1B03],[0x1B34,0x1B34],[0x1B36,0x1B3A],[0x1B3C,0x1B3C],[0x1B42,0x1B42],[0x1B6B,0x1B73],[0x1DC0,0x1DCA],[0x1DFE,0x1DFF],[0x200B,0x200F],[0x202A,0x202E],[0x2060,0x2063],[0x206A,0x206F],[0x20D0,0x20EF],[0x302A,0x302F],[0x3099,0x309A],[0xA806,0xA806],[0xA80B,0xA80B],[0xA825,0xA826],[0xFB1E,0xFB1E],[0xFE00,0xFE0F],[0xFE20,0xFE23],[0xFEFF,0xFEFF],[0xFFF9,0xFFFB],[0x10A01,0x10A03],[0x10A05,0x10A06],[0x10A0C,0x10A0F],[0x10A38,0x10A3A],[0x10A3F,0x10A3F],[0x1D167,0x1D169],[0x1D173,0x1D182],[0x1D185,0x1D18B],[0x1D1AA,0x1D1AD],[0x1D242,0x1D244],[0xE0001,0xE0001],[0xE0020,0xE007F],[0xE0100,0xE01EF]];// binary search | |
2213 | function bisearch(ucs){var min=0;var max=COMBINING.length-1;var mid;if(ucs<COMBINING[0][0]||ucs>COMBINING[max][1])return false;while(max>=min){mid=Math.floor((min+max)/2);if(ucs>COMBINING[mid][1])min=mid+1;else if(ucs<COMBINING[mid][0])max=mid-1;else return true;}return false;}function wcwidth(ucs){// test for 8-bit control characters | |
2214 | if(ucs===0)return opts.nul;if(ucs<32||ucs>=0x7f&&ucs<0xa0)return opts.control;// binary search in table of non-spacing characters | |
2215 | if(bisearch(ucs))return 0;// if we arrive here, ucs is not a combining or C0/C1 control character | |
2216 | return 1+(ucs>=0x1100&&(ucs<=0x115f||// Hangul Jamo init. consonants | |
2217 | ucs==0x2329||ucs==0x232a||ucs>=0x2e80&&ucs<=0xa4cf&&ucs!=0x303f||// CJK..Yi | |
2218 | ucs>=0xac00&&ucs<=0xd7a3||// Hangul Syllables | |
2219 | ucs>=0xf900&&ucs<=0xfaff||// CJK Compat Ideographs | |
2220 | ucs>=0xfe10&&ucs<=0xfe19||// Vertical forms | |
2221 | ucs>=0xfe30&&ucs<=0xfe6f||// CJK Compat Forms | |
2222 | ucs>=0xff00&&ucs<=0xff60||// Fullwidth Forms | |
2223 | ucs>=0xffe0&&ucs<=0xffe6||ucs>=0x20000&&ucs<=0x2fffd||ucs>=0x30000&&ucs<=0x3fffd));}return wcwidth;}({nul:0,control:0});// configurable options | |
2224 | /** | |
2225 | * Expose | |
2226 | */Terminal.EventEmitter=_EventEmitter.EventEmitter;Terminal.CompositionHelper=_CompositionHelper.CompositionHelper;Terminal.Viewport=_Viewport.Viewport;Terminal.inherits=inherits;/** | |
2227 | * Adds an event listener to the terminal. | |
2228 | * | |
2229 | * @param {string} event The name of the event. TODO: Document all event types | |
2230 | * @param {function} callback The function to call when the event is triggered. | |
2231 | */Terminal.on=on;Terminal.off=off;Terminal.cancel=cancel;module.exports=Terminal; | |
2232 | ||
2233 | },{"./CompositionHelper.js":1,"./EventEmitter.js":2,"./Viewport.js":3,"./handlers/Clipboard.js":4,"./utils/Browser":5}]},{},[7])(7) | |
2234 | }); | |
2235 | //# sourceMappingURL=xterm.js.map |