]>
Commit | Line | Data |
---|---|---|
cd70d298 | 1 | (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Terminal = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ |
5ce522a4 | 2 | /** |
cd70d298 | 3 | * @license MIT |
5ce522a4 | 4 | */ |
cd70d298 | 5 | "use strict"; |
5ce522a4 PK |
6 | /** |
7 | * Encapsulates the logic for handling compositionstart, compositionupdate and compositionend | |
8 | * events, displaying the in-progress composition to the UI and forwarding the final composition | |
9 | * to the handler. | |
5ce522a4 | 10 | */ |
cd70d298 PK |
11 | var CompositionHelper = (function () { |
12 | /** | |
13 | * Creates a new CompositionHelper. | |
14 | * @param textarea The textarea that xterm uses for input. | |
15 | * @param compositionView The element to display the in-progress composition in. | |
16 | * @param terminal The Terminal to forward the finished composition to. | |
17 | */ | |
18 | function CompositionHelper(textarea, compositionView, terminal) { | |
19 | this.textarea = textarea; | |
20 | this.compositionView = compositionView; | |
21 | this.terminal = terminal; | |
22 | this.isComposing = false; | |
23 | this.isSendingComposition = false; | |
24 | this.compositionPosition = { start: null, end: null }; | |
25 | } | |
26 | ; | |
27 | /** | |
28 | * Handles the compositionstart event, activating the composition view. | |
29 | */ | |
30 | CompositionHelper.prototype.compositionstart = function () { | |
31 | this.isComposing = true; | |
32 | this.compositionPosition.start = this.textarea.value.length; | |
33 | this.compositionView.textContent = ''; | |
34 | this.compositionView.classList.add('active'); | |
5ce522a4 | 35 | }; |
cd70d298 PK |
36 | /** |
37 | * Handles the compositionupdate event, updating the composition view. | |
38 | * @param {CompositionEvent} ev The event. | |
39 | */ | |
40 | CompositionHelper.prototype.compositionupdate = function (ev) { | |
41 | this.compositionView.textContent = ev.data; | |
42 | this.updateCompositionElements(); | |
43 | var self = this; | |
44 | setTimeout(function () { | |
45 | self.compositionPosition.end = self.textarea.value.length; | |
46 | }, 0); | |
47 | }; | |
48 | /** | |
49 | * Handles the compositionend event, hiding the composition view and sending the composition to | |
50 | * the handler. | |
51 | */ | |
52 | CompositionHelper.prototype.compositionend = function () { | |
53 | this.finalizeComposition(true); | |
54 | }; | |
55 | /** | |
56 | * Handles the keydown event, routing any necessary events to the CompositionHelper functions. | |
57 | * @param ev The keydown event. | |
58 | * @return Whether the Terminal should continue processing the keydown event. | |
59 | */ | |
60 | CompositionHelper.prototype.keydown = function (ev) { | |
61 | if (this.isComposing || this.isSendingComposition) { | |
62 | if (ev.keyCode === 229) { | |
63 | // Continue composing if the keyCode is the "composition character" | |
64 | return false; | |
65 | } | |
66 | else if (ev.keyCode === 16 || ev.keyCode === 17 || ev.keyCode === 18) { | |
67 | // Continue composing if the keyCode is a modifier key | |
68 | return false; | |
69 | } | |
70 | else { | |
71 | // Finish composition immediately. This is mainly here for the case where enter is | |
72 | // pressed and the handler needs to be triggered before the command is executed. | |
73 | this.finalizeComposition(false); | |
74 | } | |
75 | } | |
76 | if (ev.keyCode === 229) { | |
77 | // If the "composition character" is used but gets to this point it means a non-composition | |
78 | // character (eg. numbers and punctuation) was pressed when the IME was active. | |
79 | this.handleAnyTextareaChanges(); | |
80 | return false; | |
81 | } | |
82 | return true; | |
83 | }; | |
84 | /** | |
85 | * Finalizes the composition, resuming regular input actions. This is called when a composition | |
86 | * is ending. | |
87 | * @param waitForPropogation Whether to wait for events to propogate before sending | |
88 | * the input. This should be false if a non-composition keystroke is entered before the | |
89 | * compositionend event is triggered, such as enter, so that the composition is send before | |
90 | * the command is executed. | |
91 | */ | |
92 | CompositionHelper.prototype.finalizeComposition = function (waitForPropogation) { | |
93 | this.compositionView.classList.remove('active'); | |
94 | this.isComposing = false; | |
95 | this.clearTextareaPosition(); | |
96 | if (!waitForPropogation) { | |
97 | // Cancel any delayed composition send requests and send the input immediately. | |
98 | this.isSendingComposition = false; | |
99 | var input = this.textarea.value.substring(this.compositionPosition.start, this.compositionPosition.end); | |
100 | this.terminal.handler(input); | |
101 | } | |
102 | else { | |
103 | // Make a deep copy of the composition position here as a new compositionstart event may | |
104 | // fire before the setTimeout executes. | |
105 | var currentCompositionPosition = { | |
106 | start: this.compositionPosition.start, | |
107 | end: this.compositionPosition.end, | |
108 | }; | |
109 | // Since composition* events happen before the changes take place in the textarea on most | |
110 | // browsers, use a setTimeout with 0ms time to allow the native compositionend event to | |
111 | // complete. This ensures the correct character is retrieved, this solution was used | |
112 | // because: | |
113 | // - The compositionend event's data property is unreliable, at least on Chromium | |
114 | // - The last compositionupdate event's data property does not always accurately describe | |
115 | // the character, a counter example being Korean where an ending consonsant can move to | |
116 | // the following character if the following input is a vowel. | |
117 | var self = this; | |
118 | this.isSendingComposition = true; | |
119 | setTimeout(function () { | |
120 | // Ensure that the input has not already been sent | |
121 | if (self.isSendingComposition) { | |
122 | self.isSendingComposition = false; | |
123 | var input; | |
124 | if (self.isComposing) { | |
125 | // Use the end position to get the string if a new composition has started. | |
126 | input = self.textarea.value.substring(currentCompositionPosition.start, currentCompositionPosition.end); | |
127 | } | |
128 | else { | |
129 | // Don't use the end position here in order to pick up any characters after the | |
130 | // composition has finished, for example when typing a non-composition character | |
131 | // (eg. 2) after a composition character. | |
132 | input = self.textarea.value.substring(currentCompositionPosition.start); | |
133 | } | |
134 | self.terminal.handler(input); | |
135 | } | |
136 | }, 0); | |
137 | } | |
138 | }; | |
139 | /** | |
140 | * Apply any changes made to the textarea after the current event chain is allowed to complete. | |
141 | * This should be called when not currently composing but a keydown event with the "composition | |
142 | * character" (229) is triggered, in order to allow non-composition text to be entered when an | |
143 | * IME is active. | |
144 | */ | |
145 | CompositionHelper.prototype.handleAnyTextareaChanges = function () { | |
146 | var oldValue = this.textarea.value; | |
147 | var self = this; | |
148 | setTimeout(function () { | |
149 | // Ignore if a composition has started since the timeout | |
150 | if (!self.isComposing) { | |
151 | var newValue = self.textarea.value; | |
152 | var diff = newValue.replace(oldValue, ''); | |
153 | if (diff.length > 0) { | |
154 | self.terminal.handler(diff); | |
155 | } | |
156 | } | |
157 | }, 0); | |
158 | }; | |
159 | /** | |
160 | * Positions the composition view on top of the cursor and the textarea just below it (so the | |
161 | * IME helper dialog is positioned correctly). | |
162 | * @param dontRecurse Whether to use setTimeout to recursively trigger another update, this is | |
163 | * necessary as the IME events across browsers are not consistently triggered. | |
164 | */ | |
165 | CompositionHelper.prototype.updateCompositionElements = function (dontRecurse) { | |
166 | if (!this.isComposing) { | |
167 | return; | |
168 | } | |
169 | var cursor = this.terminal.element.querySelector('.terminal-cursor'); | |
170 | if (cursor) { | |
171 | // Take .xterm-rows offsetTop into account as well in case it's positioned absolutely within | |
172 | // the .xterm element. | |
173 | var xtermRows = this.terminal.element.querySelector('.xterm-rows'); | |
174 | var cursorTop = xtermRows.offsetTop + cursor.offsetTop; | |
175 | this.compositionView.style.left = cursor.offsetLeft + 'px'; | |
176 | this.compositionView.style.top = cursorTop + 'px'; | |
177 | this.compositionView.style.height = cursor.offsetHeight + 'px'; | |
178 | this.compositionView.style.lineHeight = cursor.offsetHeight + 'px'; | |
179 | // Sync the textarea to the exact position of the composition view so the IME knows where the | |
180 | // text is. | |
181 | var compositionViewBounds = this.compositionView.getBoundingClientRect(); | |
182 | this.textarea.style.left = cursor.offsetLeft + 'px'; | |
183 | this.textarea.style.top = cursorTop + 'px'; | |
184 | this.textarea.style.width = compositionViewBounds.width + 'px'; | |
185 | this.textarea.style.height = compositionViewBounds.height + 'px'; | |
186 | this.textarea.style.lineHeight = compositionViewBounds.height + 'px'; | |
187 | } | |
188 | if (!dontRecurse) { | |
189 | setTimeout(this.updateCompositionElements.bind(this, true), 0); | |
190 | } | |
191 | }; | |
192 | ; | |
193 | /** | |
194 | * Clears the textarea's position so that the cursor does not blink on IE. | |
195 | * @private | |
196 | */ | |
197 | CompositionHelper.prototype.clearTextareaPosition = function () { | |
198 | this.textarea.style.left = ''; | |
199 | this.textarea.style.top = ''; | |
200 | }; | |
201 | ; | |
202 | return CompositionHelper; | |
203 | }()); | |
5ce522a4 PK |
204 | exports.CompositionHelper = CompositionHelper; |
205 | ||
cd70d298 | 206 | },{}],2:[function(require,module,exports){ |
5ce522a4 | 207 | /** |
cd70d298 | 208 | * @license MIT |
5ce522a4 | 209 | */ |
cd70d298 | 210 | "use strict"; |
5ce522a4 | 211 | function EventEmitter() { |
cd70d298 | 212 | this._events = this._events || {}; |
5ce522a4 | 213 | } |
cd70d298 | 214 | exports.EventEmitter = EventEmitter; |
5ce522a4 | 215 | EventEmitter.prototype.addListener = function (type, listener) { |
cd70d298 PK |
216 | this._events[type] = this._events[type] || []; |
217 | this._events[type].push(listener); | |
5ce522a4 | 218 | }; |
5ce522a4 | 219 | EventEmitter.prototype.on = EventEmitter.prototype.addListener; |
5ce522a4 | 220 | EventEmitter.prototype.removeListener = function (type, listener) { |
cd70d298 PK |
221 | if (!this._events[type]) |
222 | return; | |
223 | var obj = this._events[type], i = obj.length; | |
224 | while (i--) { | |
225 | if (obj[i] === listener || obj[i].listener === listener) { | |
226 | obj.splice(i, 1); | |
227 | return; | |
228 | } | |
5ce522a4 | 229 | } |
5ce522a4 | 230 | }; |
5ce522a4 | 231 | EventEmitter.prototype.off = EventEmitter.prototype.removeListener; |
5ce522a4 | 232 | EventEmitter.prototype.removeAllListeners = function (type) { |
cd70d298 PK |
233 | if (this._events[type]) |
234 | delete this._events[type]; | |
5ce522a4 | 235 | }; |
5ce522a4 | 236 | EventEmitter.prototype.once = function (type, listener) { |
cd70d298 PK |
237 | var self = this; |
238 | function on() { | |
239 | var args = Array.prototype.slice.call(arguments); | |
240 | this.removeListener(type, on); | |
241 | return listener.apply(this, args); | |
242 | } | |
243 | on.listener = listener; | |
244 | return this.on(type, on); | |
5ce522a4 | 245 | }; |
5ce522a4 | 246 | EventEmitter.prototype.emit = function (type) { |
cd70d298 PK |
247 | if (!this._events[type]) |
248 | return; | |
249 | var args = Array.prototype.slice.call(arguments, 1), obj = this._events[type], l = obj.length, i = 0; | |
250 | for (; i < l; i++) { | |
251 | obj[i].apply(this, args); | |
252 | } | |
5ce522a4 | 253 | }; |
5ce522a4 | 254 | EventEmitter.prototype.listeners = function (type) { |
cd70d298 | 255 | return this._events[type] = this._events[type] || []; |
5ce522a4 PK |
256 | }; |
257 | ||
cd70d298 | 258 | },{}],3:[function(require,module,exports){ |
5ce522a4 | 259 | /** |
cd70d298 | 260 | * @license MIT |
5ce522a4 | 261 | */ |
cd70d298 | 262 | "use strict"; |
5ce522a4 PK |
263 | /** |
264 | * Represents the viewport of a terminal, the visible area within the larger buffer of output. | |
265 | * Logic for the virtual scroll bar is included in this object. | |
5ce522a4 | 266 | */ |
cd70d298 PK |
267 | var Viewport = (function () { |
268 | /** | |
269 | * Creates a new Viewport. | |
270 | * @param terminal The terminal this viewport belongs to. | |
271 | * @param viewportElement The DOM element acting as the viewport. | |
272 | * @param scrollArea The DOM element acting as the scroll area. | |
273 | * @param charMeasureElement A DOM element used to measure the character size of. the terminal. | |
274 | */ | |
275 | function Viewport(terminal, viewportElement, scrollArea, charMeasureElement) { | |
276 | this.terminal = terminal; | |
277 | this.viewportElement = viewportElement; | |
278 | this.scrollArea = scrollArea; | |
279 | this.charMeasureElement = charMeasureElement; | |
280 | this.currentRowHeight = 0; | |
281 | this.lastRecordedBufferLength = 0; | |
282 | this.lastRecordedViewportHeight = 0; | |
283 | this.terminal.on('scroll', this.syncScrollArea.bind(this)); | |
284 | this.terminal.on('resize', this.syncScrollArea.bind(this)); | |
285 | this.viewportElement.addEventListener('scroll', this.onScroll.bind(this)); | |
286 | this.syncScrollArea(); | |
5ce522a4 | 287 | } |
cd70d298 PK |
288 | /** |
289 | * Refreshes row height, setting line-height, viewport height and scroll area height if | |
290 | * necessary. | |
291 | * @param charSize A character size measurement bounding rect object, if it doesn't exist it will | |
292 | * be created. | |
293 | */ | |
294 | Viewport.prototype.refresh = function (charSize) { | |
295 | var size = charSize || this.charMeasureElement.getBoundingClientRect(); | |
296 | if (size.height > 0) { | |
297 | var rowHeightChanged = size.height !== this.currentRowHeight; | |
298 | if (rowHeightChanged) { | |
299 | this.currentRowHeight = size.height; | |
300 | this.viewportElement.style.lineHeight = size.height + 'px'; | |
301 | this.terminal.rowContainer.style.lineHeight = size.height + 'px'; | |
302 | } | |
303 | var viewportHeightChanged = this.lastRecordedViewportHeight !== this.terminal.rows; | |
304 | if (rowHeightChanged || viewportHeightChanged) { | |
305 | this.lastRecordedViewportHeight = this.terminal.rows; | |
306 | this.viewportElement.style.height = size.height * this.terminal.rows + 'px'; | |
307 | } | |
308 | this.scrollArea.style.height = (size.height * this.lastRecordedBufferLength) + 'px'; | |
309 | } | |
310 | }; | |
311 | /** | |
312 | * Updates dimensions and synchronizes the scroll area if necessary. | |
313 | */ | |
314 | Viewport.prototype.syncScrollArea = function () { | |
315 | if (this.lastRecordedBufferLength !== this.terminal.lines.length) { | |
316 | // If buffer height changed | |
317 | this.lastRecordedBufferLength = this.terminal.lines.length; | |
318 | this.refresh(); | |
319 | } | |
320 | else if (this.lastRecordedViewportHeight !== this.terminal.rows) { | |
321 | // If viewport height changed | |
322 | this.refresh(); | |
323 | } | |
324 | else { | |
325 | // If size has changed, refresh viewport | |
326 | var size = this.charMeasureElement.getBoundingClientRect(); | |
327 | if (size.height !== this.currentRowHeight) { | |
328 | this.refresh(size); | |
329 | } | |
330 | } | |
331 | // Sync scrollTop | |
332 | var scrollTop = this.terminal.ydisp * this.currentRowHeight; | |
333 | if (this.viewportElement.scrollTop !== scrollTop) { | |
334 | this.viewportElement.scrollTop = scrollTop; | |
335 | } | |
336 | }; | |
337 | /** | |
338 | * Handles scroll events on the viewport, calculating the new viewport and requesting the | |
339 | * terminal to scroll to it. | |
340 | * @param ev The scroll event. | |
341 | */ | |
342 | Viewport.prototype.onScroll = function (ev) { | |
343 | var newRow = Math.round(this.viewportElement.scrollTop / this.currentRowHeight); | |
344 | var diff = newRow - this.terminal.ydisp; | |
345 | this.terminal.scrollDisp(diff, true); | |
346 | }; | |
347 | /** | |
348 | * Handles mouse wheel events by adjusting the viewport's scrollTop and delegating the actual | |
349 | * scrolling to `onScroll`, this event needs to be attached manually by the consumer of | |
350 | * `Viewport`. | |
351 | * @param ev The mouse wheel event. | |
352 | */ | |
353 | Viewport.prototype.onWheel = function (ev) { | |
354 | if (ev.deltaY === 0) { | |
355 | // Do nothing if it's not a vertical scroll event | |
356 | return; | |
357 | } | |
358 | // Fallback to WheelEvent.DOM_DELTA_PIXEL | |
359 | var multiplier = 1; | |
360 | if (ev.deltaMode === WheelEvent.DOM_DELTA_LINE) { | |
361 | multiplier = this.currentRowHeight; | |
362 | } | |
363 | else if (ev.deltaMode === WheelEvent.DOM_DELTA_PAGE) { | |
364 | multiplier = this.currentRowHeight * this.terminal.rows; | |
365 | } | |
366 | this.viewportElement.scrollTop += ev.deltaY * multiplier; | |
367 | // Prevent the page from scrolling when the terminal scrolls | |
368 | ev.preventDefault(); | |
369 | }; | |
370 | ; | |
371 | return Viewport; | |
372 | }()); | |
5ce522a4 PK |
373 | exports.Viewport = Viewport; |
374 | ||
cd70d298 | 375 | },{}],4:[function(require,module,exports){ |
5ce522a4 | 376 | /** |
cd70d298 PK |
377 | * Clipboard handler module: exports methods for handling all clipboard-related events in the |
378 | * terminal. | |
5ce522a4 | 379 | * @module xterm/handlers/Clipboard |
cd70d298 | 380 | * @license MIT |
5ce522a4 | 381 | */ |
cd70d298 | 382 | "use strict"; |
5ce522a4 PK |
383 | /** |
384 | * Prepares text copied from terminal selection, to be saved in the clipboard by: | |
385 | * 1. stripping all trailing white spaces | |
386 | * 2. converting all non-breaking spaces to regular spaces | |
387 | * @param {string} text The copied text that needs processing for storing in clipboard | |
388 | * @returns {string} | |
389 | */ | |
390 | function prepareTextForClipboard(text) { | |
cd70d298 PK |
391 | var space = String.fromCharCode(32), nonBreakingSpace = String.fromCharCode(160), allNonBreakingSpaces = new RegExp(nonBreakingSpace, 'g'), processedText = text.split('\n').map(function (line) { |
392 | // Strip all trailing white spaces and convert all non-breaking spaces | |
393 | // to regular spaces. | |
394 | var processedLine = line.replace(/\s+$/g, '').replace(allNonBreakingSpaces, space); | |
395 | return processedLine; | |
396 | }).join('\n'); | |
397 | return processedText; | |
5ce522a4 | 398 | } |
cd70d298 | 399 | exports.prepareTextForClipboard = prepareTextForClipboard; |
5ce522a4 PK |
400 | /** |
401 | * Binds copy functionality to the given terminal. | |
402 | * @param {ClipboardEvent} ev The original copy event to be handled | |
403 | */ | |
521d7dbd | 404 | function copyHandler(ev, term) { |
cd70d298 PK |
405 | // We cast `window` to `any` type, because TypeScript has not declared the `clipboardData` |
406 | // property that we use below for Internet Explorer. | |
407 | var copiedText = window.getSelection().toString(), text = prepareTextForClipboard(copiedText); | |
408 | if (term.browser.isMSIE) { | |
409 | window.clipboardData.setData('Text', text); | |
410 | } | |
411 | else { | |
412 | ev.clipboardData.setData('text/plain', text); | |
413 | } | |
414 | ev.preventDefault(); // Prevent or the original text will be copied. | |
5ce522a4 | 415 | } |
cd70d298 | 416 | exports.copyHandler = copyHandler; |
5ce522a4 PK |
417 | /** |
418 | * Redirect the clipboard's data to the terminal's input handler. | |
419 | * @param {ClipboardEvent} ev The original paste event to be handled | |
420 | * @param {Terminal} term The terminal on which to apply the handled paste event | |
421 | */ | |
422 | function pasteHandler(ev, term) { | |
cd70d298 PK |
423 | ev.stopPropagation(); |
424 | var text; | |
425 | var dispatchPaste = function (text) { | |
426 | term.handler(text); | |
427 | term.textarea.value = ''; | |
428 | return term.cancel(ev); | |
429 | }; | |
430 | if (term.browser.isMSIE) { | |
431 | if (window.clipboardData) { | |
432 | text = window.clipboardData.getData('Text'); | |
433 | dispatchPaste(text); | |
434 | } | |
521d7dbd | 435 | } |
cd70d298 PK |
436 | else { |
437 | if (ev.clipboardData) { | |
438 | text = ev.clipboardData.getData('text/plain'); | |
439 | dispatchPaste(text); | |
440 | } | |
521d7dbd | 441 | } |
5ce522a4 | 442 | } |
cd70d298 | 443 | exports.pasteHandler = pasteHandler; |
5ce522a4 PK |
444 | /** |
445 | * Bind to right-click event and allow right-click copy and paste. | |
446 | * | |
447 | * **Logic** | |
448 | * If text is selected and right-click happens on selected text, then | |
449 | * do nothing to allow seamless copying. | |
450 | * If no text is selected or right-click is outside of the selection | |
451 | * area, then bring the terminal's input below the cursor, in order to | |
452 | * trigger the event on the textarea and allow-right click paste, without | |
453 | * caring about disappearing selection. | |
454 | * @param {ClipboardEvent} ev The original paste event to be handled | |
455 | * @param {Terminal} term The terminal on which to apply the handled paste event | |
456 | */ | |
457 | function rightClickHandler(ev, term) { | |
cd70d298 PK |
458 | var s = document.getSelection(), selectedText = prepareTextForClipboard(s.toString()), clickIsOnSelection = false, x = ev.clientX, y = ev.clientY; |
459 | if (s.rangeCount) { | |
460 | var r = s.getRangeAt(0), cr = r.getClientRects(), i = void 0, rect = void 0; | |
461 | for (i = 0; i < cr.length; i++) { | |
462 | rect = cr[i]; | |
463 | clickIsOnSelection = ((x > rect.left) && (x < rect.right) && | |
464 | (y > rect.top) && (y < rect.bottom)); | |
465 | if (clickIsOnSelection) { | |
466 | break; | |
467 | } | |
468 | } | |
469 | // If we clicked on selection and selection is not a single space, | |
470 | // then mark the right click as copy-only. We check for the single | |
471 | // space selection, as this can happen when clicking on an | |
472 | // and there is not much pointing in copying a single space. | |
473 | if (selectedText.match(/^\s$/) || !selectedText.length) { | |
474 | clickIsOnSelection = false; | |
475 | } | |
476 | } | |
477 | // Bring textarea at the cursor position | |
478 | if (!clickIsOnSelection) { | |
479 | term.textarea.style.position = 'fixed'; | |
480 | term.textarea.style.width = '20px'; | |
481 | term.textarea.style.height = '20px'; | |
482 | term.textarea.style.left = (x - 10) + 'px'; | |
483 | term.textarea.style.top = (y - 10) + 'px'; | |
484 | term.textarea.style.zIndex = '1000'; | |
485 | term.textarea.focus(); | |
486 | // Reset the terminal textarea's styling | |
487 | setTimeout(function () { | |
488 | term.textarea.style.position = null; | |
489 | term.textarea.style.width = null; | |
490 | term.textarea.style.height = null; | |
491 | term.textarea.style.left = null; | |
492 | term.textarea.style.top = null; | |
493 | term.textarea.style.zIndex = null; | |
494 | }, 4); | |
495 | } | |
5ce522a4 | 496 | } |
5ce522a4 PK |
497 | exports.rightClickHandler = rightClickHandler; |
498 | ||
cd70d298 | 499 | },{}],5:[function(require,module,exports){ |
521d7dbd | 500 | /** |
cd70d298 | 501 | * Attributes and methods to help with identifying the current browser and platform. |
521d7dbd | 502 | * @module xterm/utils/Browser |
cd70d298 | 503 | * @license MIT |
521d7dbd | 504 | */ |
cd70d298 PK |
505 | "use strict"; |
506 | var Generic_js_1 = require('./Generic.js'); | |
507 | var isNode = (typeof navigator == 'undefined') ? true : false; | |
508 | var userAgent = (isNode) ? 'node' : navigator.userAgent; | |
509 | var platform = (isNode) ? 'node' : navigator.platform; | |
510 | exports.isFirefox = !!~userAgent.indexOf('Firefox'); | |
511 | exports.isMSIE = !!~userAgent.indexOf('MSIE') || !!~userAgent.indexOf('Trident'); | |
521d7dbd PK |
512 | // Find the users platform. We use this to interpret the meta key |
513 | // and ISO third level shifts. | |
514 | // http://stackoverflow.com/q/19877924/577598 | |
cd70d298 PK |
515 | exports.isMac = Generic_js_1.contains(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], platform); |
516 | exports.isIpad = platform === 'iPad'; | |
517 | exports.isIphone = platform === 'iPhone'; | |
518 | exports.isMSWindows = Generic_js_1.contains(['Windows', 'Win16', 'Win32', 'WinCE'], platform); | |
521d7dbd | 519 | |
cd70d298 | 520 | },{"./Generic.js":6}],6:[function(require,module,exports){ |
521d7dbd | 521 | /** |
cd70d298 | 522 | * Generic utilities module with methods that can be helpful at different parts of the code base. |
521d7dbd | 523 | * @module xterm/utils/Generic |
cd70d298 | 524 | * @license MIT |
521d7dbd | 525 | */ |
cd70d298 | 526 | "use strict"; |
521d7dbd PK |
527 | /** |
528 | * Return if the given array contains the given element | |
529 | * @param {Array} array The array to search for the given element. | |
530 | * @param {Object} el The element to look for into the array | |
531 | */ | |
cd70d298 PK |
532 | exports.contains = function (arr, el) { |
533 | return arr.indexOf(el) >= 0; | |
521d7dbd PK |
534 | }; |
535 | ||
cd70d298 PK |
536 | },{}],7:[function(require,module,exports){ |
537 | /** | |
5ce522a4 | 538 | * xterm.js: xterm, in the browser |
5ce522a4 PK |
539 | * Originally forked from (with the author's permission): |
540 | * Fabrice Bellard's javascript vt100 for jslinux: | |
541 | * http://bellard.org/jslinux/ | |
542 | * Copyright (c) 2011 Fabrice Bellard | |
543 | * The original design remains. The terminal itself | |
544 | * has been extended to include xterm CSI codes, among | |
545 | * other features. | |
cd70d298 PK |
546 | * @license MIT |
547 | */ | |
548 | "use strict"; | |
549 | var CompositionHelper_js_1 = require('./CompositionHelper.js'); | |
550 | var EventEmitter_js_1 = require('./EventEmitter.js'); | |
551 | var Viewport_js_1 = require('./Viewport.js'); | |
552 | var Clipboard_js_1 = require('./handlers/Clipboard.js'); | |
553 | var Browser = require('./utils/Browser'); | |
554 | /** | |
5ce522a4 PK |
555 | * Terminal Emulation References: |
556 | * http://vt100.net/ | |
557 | * http://invisible-island.net/xterm/ctlseqs/ctlseqs.txt | |
558 | * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html | |
559 | * http://invisible-island.net/vttest/ | |
560 | * http://www.inwap.com/pdp10/ansicode.txt | |
561 | * http://linux.die.net/man/4/console_codes | |
562 | * http://linux.die.net/man/7/urxvt | |
cd70d298 PK |
563 | */ |
564 | // Let it work inside Node.js for automated testing purposes. | |
565 | var document = (typeof window != 'undefined') ? window.document : null; | |
566 | /** | |
5ce522a4 | 567 | * States |
cd70d298 PK |
568 | */ |
569 | var normal = 0, escaped = 1, csi = 2, osc = 3, charset = 4, dcs = 5, ignore = 6; | |
570 | /** | |
5ce522a4 | 571 | * Terminal |
cd70d298 PK |
572 | */ |
573 | /** | |
5ce522a4 PK |
574 | * Creates a new `Terminal` object. |
575 | * | |
576 | * @param {object} options An object containing a set of options, the available options are: | |
521d7dbd PK |
577 | * - `cursorBlink` (boolean): Whether the terminal cursor blinks |
578 | * - `cols` (number): The number of columns of the terminal (horizontal size) | |
579 | * - `rows` (number): The number of rows of the terminal (vertical size) | |
5ce522a4 PK |
580 | * |
581 | * @public | |
582 | * @class Xterm Xterm | |
583 | * @alias module:xterm/src/xterm | |
cd70d298 PK |
584 | */ |
585 | function Terminal(options) { | |
586 | var self = this; | |
587 | if (!(this instanceof Terminal)) { | |
588 | return new Terminal(arguments[0], arguments[1], arguments[2]); | |
589 | } | |
590 | self.browser = Browser; | |
591 | self.cancel = Terminal.cancel; | |
592 | EventEmitter_js_1.EventEmitter.call(this); | |
593 | if (typeof options === 'number') { | |
594 | options = { | |
595 | cols: arguments[0], | |
596 | rows: arguments[1], | |
597 | handler: arguments[2] | |
598 | }; | |
599 | } | |
600 | options = options || {}; | |
601 | Object.keys(Terminal.defaults).forEach(function (key) { | |
602 | if (options[key] == null) { | |
603 | options[key] = Terminal.options[key]; | |
604 | if (Terminal[key] !== Terminal.defaults[key]) { | |
605 | options[key] = Terminal[key]; | |
606 | } | |
607 | } | |
608 | self[key] = options[key]; | |
609 | }); | |
610 | if (options.colors.length === 8) { | |
611 | options.colors = options.colors.concat(Terminal._colors.slice(8)); | |
612 | } | |
613 | else if (options.colors.length === 16) { | |
614 | options.colors = options.colors.concat(Terminal._colors.slice(16)); | |
615 | } | |
616 | else if (options.colors.length === 10) { | |
617 | options.colors = options.colors.slice(0, -2).concat(Terminal._colors.slice(8, -2), options.colors.slice(-2)); | |
618 | } | |
619 | else if (options.colors.length === 18) { | |
620 | options.colors = options.colors.concat(Terminal._colors.slice(16, -2), options.colors.slice(-2)); | |
621 | } | |
622 | this.colors = options.colors; | |
623 | this.options = options; | |
624 | // this.context = options.context || window; | |
625 | // this.document = options.document || document; | |
626 | this.parent = options.body || options.parent || (document ? document.getElementsByTagName('body')[0] : null); | |
627 | this.cols = options.cols || options.geometry[0]; | |
628 | this.rows = options.rows || options.geometry[1]; | |
629 | this.geometry = [this.cols, this.rows]; | |
630 | if (options.handler) { | |
631 | this.on('data', options.handler); | |
632 | } | |
633 | /** | |
634 | * The scroll position of the y cursor, ie. ybase + y = the y position within the entire | |
635 | * buffer | |
636 | */ | |
637 | this.ybase = 0; | |
638 | /** | |
639 | * The scroll position of the viewport | |
640 | */ | |
641 | this.ydisp = 0; | |
642 | /** | |
643 | * The cursor's x position after ybase | |
644 | */ | |
645 | this.x = 0; | |
646 | /** | |
647 | * The cursor's y position after ybase | |
648 | */ | |
649 | this.y = 0; | |
650 | /** | |
651 | * Used to debounce the refresh function | |
652 | */ | |
653 | this.isRefreshing = false; | |
654 | /** | |
655 | * Whether there is a full terminal refresh queued | |
656 | */ | |
657 | this.cursorState = 0; | |
658 | this.cursorHidden = false; | |
659 | this.convertEol; | |
660 | this.state = 0; | |
661 | this.queue = ''; | |
662 | this.scrollTop = 0; | |
663 | this.scrollBottom = this.rows - 1; | |
664 | this.customKeydownHandler = null; | |
665 | // modes | |
666 | this.applicationKeypad = false; | |
667 | this.applicationCursor = false; | |
668 | this.originMode = false; | |
669 | this.insertMode = false; | |
670 | this.wraparoundMode = true; // defaults: xterm - true, vt100 - false | |
671 | this.normal = null; | |
672 | // charset | |
673 | this.charset = null; | |
674 | this.gcharset = null; | |
675 | this.glevel = 0; | |
676 | this.charsets = [null]; | |
677 | // mouse properties | |
678 | this.decLocator; | |
679 | this.x10Mouse; | |
680 | this.vt200Mouse; | |
681 | this.vt300Mouse; | |
682 | this.normalMouse; | |
683 | this.mouseEvents; | |
684 | this.sendFocus; | |
685 | this.utfMouse; | |
686 | this.sgrMouse; | |
687 | this.urxvtMouse; | |
688 | // misc | |
689 | this.element; | |
690 | this.children; | |
691 | this.refreshStart; | |
692 | this.refreshEnd; | |
693 | this.savedX; | |
694 | this.savedY; | |
695 | this.savedCols; | |
696 | // stream | |
697 | this.readable = true; | |
698 | this.writable = true; | |
699 | this.defAttr = (0 << 18) | (257 << 9) | (256 << 0); | |
700 | this.curAttr = this.defAttr; | |
701 | this.params = []; | |
702 | this.currentParam = 0; | |
703 | this.prefix = ''; | |
704 | this.postfix = ''; | |
705 | // leftover surrogate high from previous write invocation | |
706 | this.surrogate_high = ''; | |
707 | /** | |
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 | */ | |
711 | this.lines = []; | |
712 | var i = this.rows; | |
713 | while (i--) { | |
714 | this.lines.push(this.blankLine()); | |
715 | } | |
716 | this.tabs; | |
717 | this.setupStops(); | |
718 | // Store if user went browsing history in scrollback | |
719 | this.userScrolling = false; | |
720 | } | |
721 | inherits(Terminal, EventEmitter_js_1.EventEmitter); | |
722 | /** | |
5ce522a4 | 723 | * back_color_erase feature for xterm. |
cd70d298 PK |
724 | */ |
725 | Terminal.prototype.eraseAttr = function () { | |
726 | // if (this.is('screen')) return this.defAttr; | |
727 | return (this.defAttr & ~0x1ff) | (this.curAttr & 0x1ff); | |
728 | }; | |
729 | /** | |
5ce522a4 | 730 | * Colors |
cd70d298 PK |
731 | */ |
732 | // Colors 0-15 | |
733 | Terminal.tangoColors = [ | |
734 | // dark: | |
735 | '#2e3436', | |
736 | '#cc0000', | |
737 | '#4e9a06', | |
738 | '#c4a000', | |
739 | '#3465a4', | |
740 | '#75507b', | |
741 | '#06989a', | |
742 | '#d3d7cf', | |
743 | // bright: | |
744 | '#555753', | |
745 | '#ef2929', | |
746 | '#8ae234', | |
747 | '#fce94f', | |
748 | '#729fcf', | |
749 | '#ad7fa8', | |
750 | '#34e2e2', | |
751 | '#eeeeec' | |
752 | ]; | |
753 | // Colors 0-15 + 16-255 | |
5ce522a4 | 754 | // Much thanks to TooTallNate for writing this. |
cd70d298 PK |
755 | Terminal.colors = (function () { |
756 | var colors = Terminal.tangoColors.slice(), r = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff], i; | |
757 | // 16-231 | |
758 | i = 0; | |
759 | for (; i < 216; i++) { | |
760 | out(r[(i / 36) % 6 | 0], r[(i / 6) % 6 | 0], r[i % 6]); | |
761 | } | |
762 | // 232-255 (grey) | |
763 | i = 0; | |
764 | for (; i < 24; i++) { | |
765 | r = 8 + i * 10; | |
766 | out(r, r, r); | |
767 | } | |
768 | function out(r, g, b) { | |
769 | colors.push('#' + hex(r) + hex(g) + hex(b)); | |
770 | } | |
771 | function hex(c) { | |
772 | c = c.toString(16); | |
773 | return c.length < 2 ? '0' + c : c; | |
774 | } | |
775 | return colors; | |
776 | })(); | |
777 | Terminal._colors = Terminal.colors.slice(); | |
778 | Terminal.vcolors = (function () { | |
779 | var out = [], colors = Terminal.colors, i = 0, color; | |
780 | for (; i < 256; i++) { | |
781 | color = parseInt(colors[i].substring(1), 16); | |
782 | out.push([ | |
783 | (color >> 16) & 0xff, | |
784 | (color >> 8) & 0xff, | |
785 | color & 0xff | |
786 | ]); | |
787 | } | |
788 | return out; | |
789 | })(); | |
790 | /** | |
5ce522a4 | 791 | * Options |
cd70d298 PK |
792 | */ |
793 | Terminal.defaults = { | |
794 | colors: Terminal.colors, | |
795 | theme: 'default', | |
796 | convertEol: false, | |
797 | termName: 'xterm', | |
798 | geometry: [80, 24], | |
799 | cursorBlink: false, | |
800 | visualBell: false, | |
801 | popOnBell: false, | |
802 | scrollback: 1000, | |
803 | screenKeys: false, | |
804 | debug: false, | |
805 | cancelEvents: false | |
806 | }; | |
807 | Terminal.options = {}; | |
808 | Terminal.focus = null; | |
809 | each(keys(Terminal.defaults), function (key) { | |
810 | Terminal[key] = Terminal.defaults[key]; | |
811 | Terminal.options[key] = Terminal.defaults[key]; | |
812 | }); | |
813 | /** | |
5ce522a4 | 814 | * Focus the terminal. Delegates focus handling to the terminal's DOM element. |
cd70d298 PK |
815 | */ |
816 | Terminal.prototype.focus = function () { | |
817 | return this.textarea.focus(); | |
818 | }; | |
819 | /** | |
5ce522a4 PK |
820 | * Retrieves an option's value from the terminal. |
821 | * @param {string} key The option key. | |
cd70d298 PK |
822 | */ |
823 | Terminal.prototype.getOption = function (key, value) { | |
824 | if (!(key in Terminal.defaults)) { | |
825 | throw new Error('No option with key "' + key + '"'); | |
826 | } | |
827 | if (typeof this.options[key] !== 'undefined') { | |
828 | return this.options[key]; | |
829 | } | |
830 | return this[key]; | |
831 | }; | |
832 | /** | |
5ce522a4 PK |
833 | * Sets an option on the terminal. |
834 | * @param {string} key The option key. | |
835 | * @param {string} value The option value. | |
cd70d298 PK |
836 | */ |
837 | Terminal.prototype.setOption = function (key, value) { | |
838 | if (!(key in Terminal.defaults)) { | |
839 | throw new Error('No option with key "' + key + '"'); | |
840 | } | |
841 | this[key] = value; | |
842 | this.options[key] = value; | |
843 | }; | |
844 | /** | |
5ce522a4 PK |
845 | * Binds the desired focus behavior on a given terminal object. |
846 | * | |
847 | * @static | |
cd70d298 PK |
848 | */ |
849 | Terminal.bindFocus = function (term) { | |
850 | on(term.textarea, 'focus', function (ev) { | |
851 | if (term.sendFocus) { | |
852 | term.send('\x1b[I'); | |
853 | } | |
854 | term.element.classList.add('focus'); | |
855 | term.showCursor(); | |
856 | Terminal.focus = term; | |
857 | term.emit('focus', { terminal: term }); | |
858 | }); | |
859 | }; | |
860 | /** | |
5ce522a4 | 861 | * Blur the terminal. Delegates blur handling to the terminal's DOM element. |
cd70d298 PK |
862 | */ |
863 | Terminal.prototype.blur = function () { | |
864 | return this.textarea.blur(); | |
865 | }; | |
866 | /** | |
5ce522a4 PK |
867 | * Binds the desired blur behavior on a given terminal object. |
868 | * | |
869 | * @static | |
cd70d298 PK |
870 | */ |
871 | Terminal.bindBlur = function (term) { | |
872 | on(term.textarea, 'blur', function (ev) { | |
873 | term.refresh(term.y, term.y); | |
874 | if (term.sendFocus) { | |
875 | term.send('\x1b[O'); | |
876 | } | |
877 | term.element.classList.remove('focus'); | |
878 | Terminal.focus = null; | |
879 | term.emit('blur', { terminal: term }); | |
880 | }); | |
881 | }; | |
882 | /** | |
5ce522a4 | 883 | * Initialize default behavior |
cd70d298 PK |
884 | */ |
885 | Terminal.prototype.initGlobal = function () { | |
886 | var term = this; | |
887 | Terminal.bindKeys(this); | |
888 | Terminal.bindFocus(this); | |
889 | Terminal.bindBlur(this); | |
890 | // Bind clipboard functionality | |
891 | on(this.element, 'copy', function (ev) { | |
892 | Clipboard_js_1.copyHandler.call(this, ev, term); | |
893 | }); | |
894 | on(this.textarea, 'paste', function (ev) { | |
895 | Clipboard_js_1.pasteHandler.call(this, ev, term); | |
896 | }); | |
897 | function rightClickHandlerWrapper(ev) { | |
898 | Clipboard_js_1.rightClickHandler.call(this, ev, term); | |
899 | } | |
900 | if (term.browser.isFirefox) { | |
901 | on(this.element, 'mousedown', function (ev) { | |
902 | if (ev.button == 2) { | |
903 | rightClickHandlerWrapper(ev); | |
904 | } | |
905 | }); | |
906 | } | |
907 | else { | |
908 | on(this.element, 'contextmenu', rightClickHandlerWrapper); | |
909 | } | |
910 | }; | |
911 | /** | |
5ce522a4 | 912 | * Apply key handling to the terminal |
cd70d298 PK |
913 | */ |
914 | Terminal.bindKeys = function (term) { | |
915 | on(term.element, 'keydown', function (ev) { | |
916 | if (document.activeElement != this) { | |
917 | return; | |
918 | } | |
919 | term.keyDown(ev); | |
920 | }, true); | |
921 | on(term.element, 'keypress', function (ev) { | |
922 | if (document.activeElement != this) { | |
923 | return; | |
924 | } | |
925 | term.keyPress(ev); | |
926 | }, true); | |
927 | on(term.element, 'keyup', term.focus.bind(term)); | |
928 | on(term.textarea, 'keydown', function (ev) { | |
929 | term.keyDown(ev); | |
930 | }, true); | |
931 | on(term.textarea, 'keypress', function (ev) { | |
932 | term.keyPress(ev); | |
933 | // Truncate the textarea's value, since it is not needed | |
934 | this.value = ''; | |
935 | }, true); | |
936 | on(term.textarea, 'compositionstart', term.compositionHelper.compositionstart.bind(term.compositionHelper)); | |
937 | on(term.textarea, 'compositionupdate', term.compositionHelper.compositionupdate.bind(term.compositionHelper)); | |
938 | on(term.textarea, 'compositionend', term.compositionHelper.compositionend.bind(term.compositionHelper)); | |
939 | term.on('refresh', term.compositionHelper.updateCompositionElements.bind(term.compositionHelper)); | |
940 | }; | |
941 | /** | |
5ce522a4 PK |
942 | * Insert the given row to the terminal or produce a new one |
943 | * if no row argument is passed. Return the inserted row. | |
944 | * @param {HTMLElement} row (optional) The row to append to the terminal. | |
cd70d298 PK |
945 | */ |
946 | Terminal.prototype.insertRow = function (row) { | |
947 | if (typeof row != 'object') { | |
948 | row = document.createElement('div'); | |
949 | } | |
950 | this.rowContainer.appendChild(row); | |
951 | this.children.push(row); | |
952 | return row; | |
953 | }; | |
954 | /** | |
955 | * Opens the terminal within an element. | |
5ce522a4 PK |
956 | * |
957 | * @param {HTMLElement} parent The element to create the terminal within. | |
cd70d298 PK |
958 | */ |
959 | Terminal.prototype.open = function (parent) { | |
960 | var self = this, i = 0, div; | |
961 | this.parent = parent || this.parent; | |
962 | if (!this.parent) { | |
963 | throw new Error('Terminal requires a parent element.'); | |
964 | } | |
965 | // Grab global elements | |
966 | this.context = this.parent.ownerDocument.defaultView; | |
967 | this.document = this.parent.ownerDocument; | |
968 | this.body = this.document.getElementsByTagName('body')[0]; | |
969 | //Create main element container | |
970 | this.element = this.document.createElement('div'); | |
971 | this.element.classList.add('terminal'); | |
972 | this.element.classList.add('xterm'); | |
973 | this.element.classList.add('xterm-theme-' + this.theme); | |
974 | this.element.style.height; | |
975 | this.element.setAttribute('tabindex', 0); | |
976 | this.viewportElement = document.createElement('div'); | |
977 | this.viewportElement.classList.add('xterm-viewport'); | |
978 | this.element.appendChild(this.viewportElement); | |
979 | this.viewportScrollArea = document.createElement('div'); | |
980 | this.viewportScrollArea.classList.add('xterm-scroll-area'); | |
981 | this.viewportElement.appendChild(this.viewportScrollArea); | |
982 | // Create the container that will hold the lines of the terminal and then | |
983 | // produce the lines the lines. | |
984 | this.rowContainer = document.createElement('div'); | |
985 | this.rowContainer.classList.add('xterm-rows'); | |
986 | this.element.appendChild(this.rowContainer); | |
987 | this.children = []; | |
988 | // Create the container that will hold helpers like the textarea for | |
989 | // capturing DOM Events. Then produce the helpers. | |
990 | this.helperContainer = document.createElement('div'); | |
991 | this.helperContainer.classList.add('xterm-helpers'); | |
992 | // TODO: This should probably be inserted once it's filled to prevent an additional layout | |
993 | this.element.appendChild(this.helperContainer); | |
994 | this.textarea = document.createElement('textarea'); | |
995 | this.textarea.classList.add('xterm-helper-textarea'); | |
996 | this.textarea.setAttribute('autocorrect', 'off'); | |
997 | this.textarea.setAttribute('autocapitalize', 'off'); | |
998 | this.textarea.setAttribute('spellcheck', 'false'); | |
999 | this.textarea.tabIndex = 0; | |
1000 | this.textarea.addEventListener('focus', function () { | |
1001 | self.emit('focus', { terminal: self }); | |
1002 | }); | |
1003 | this.textarea.addEventListener('blur', function () { | |
1004 | self.emit('blur', { terminal: self }); | |
1005 | }); | |
1006 | this.helperContainer.appendChild(this.textarea); | |
1007 | this.compositionView = document.createElement('div'); | |
1008 | this.compositionView.classList.add('composition-view'); | |
1009 | this.compositionHelper = new CompositionHelper_js_1.CompositionHelper(this.textarea, this.compositionView, this); | |
1010 | this.helperContainer.appendChild(this.compositionView); | |
1011 | this.charMeasureElement = document.createElement('div'); | |
1012 | this.charMeasureElement.classList.add('xterm-char-measure-element'); | |
1013 | this.charMeasureElement.innerHTML = 'W'; | |
1014 | this.helperContainer.appendChild(this.charMeasureElement); | |
1015 | for (; i < this.rows; i++) { | |
1016 | this.insertRow(); | |
1017 | } | |
1018 | this.parent.appendChild(this.element); | |
1019 | this.viewport = new Viewport_js_1.Viewport(this, this.viewportElement, this.viewportScrollArea, this.charMeasureElement); | |
1020 | // Draw the screen. | |
1021 | this.refresh(0, this.rows - 1); | |
1022 | // Initialize global actions that | |
1023 | // need to be taken on the document. | |
1024 | this.initGlobal(); | |
1025 | // Ensure there is a Terminal.focus. | |
1026 | this.focus(); | |
1027 | on(this.element, 'click', function () { | |
1028 | var selection = document.getSelection(), collapsed = selection.isCollapsed, isRange = typeof collapsed == 'boolean' ? !collapsed : selection.type == 'Range'; | |
1029 | if (!isRange) { | |
1030 | self.focus(); | |
1031 | } | |
1032 | }); | |
1033 | // Listen for mouse events and translate | |
1034 | // them into terminal mouse protocols. | |
1035 | this.bindMouse(); | |
1036 | // Figure out whether boldness affects | |
1037 | // the character width of monospace fonts. | |
1038 | if (Terminal.brokenBold == null) { | |
1039 | Terminal.brokenBold = isBoldBroken(this.document); | |
1040 | } | |
1041 | /** | |
1042 | * This event is emitted when terminal has completed opening. | |
1043 | * | |
1044 | * @event open | |
1045 | */ | |
1046 | this.emit('open'); | |
1047 | }; | |
1048 | /** | |
5ce522a4 PK |
1049 | * Attempts to load an add-on using CommonJS or RequireJS (whichever is available). |
1050 | * @param {string} addon The name of the addon to load | |
1051 | * @static | |
cd70d298 PK |
1052 | */ |
1053 | Terminal.loadAddon = function (addon, callback) { | |
1054 | if (typeof exports === 'object' && typeof module === 'object') { | |
1055 | // CommonJS | |
1056 | return require('./addons/' + addon + '/' + addon); | |
1057 | } | |
1058 | else if (typeof define == 'function') { | |
1059 | // RequireJS | |
1060 | return require(['./addons/' + addon + '/' + addon], callback); | |
1061 | } | |
1062 | else { | |
1063 | console.error('Cannot load a module without a CommonJS or RequireJS environment.'); | |
1064 | return false; | |
1065 | } | |
1066 | }; | |
1067 | /** | |
5ce522a4 PK |
1068 | * XTerm mouse events |
1069 | * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking | |
1070 | * To better understand these | |
1071 | * the xterm code is very helpful: | |
1072 | * Relevant files: | |
1073 | * button.c, charproc.c, misc.c | |
1074 | * Relevant functions in xterm/button.c: | |
1075 | * BtnCode, EmitButtonCode, EditorButton, SendMousePosition | |
cd70d298 PK |
1076 | */ |
1077 | Terminal.prototype.bindMouse = function () { | |
1078 | var el = this.element, self = this, pressed = 32; | |
1079 | // mouseup, mousedown, wheel | |
1080 | // left click: ^[[M 3<^[[M#3< | |
1081 | // wheel up: ^[[M`3> | |
1082 | function sendButton(ev) { | |
1083 | var button, pos; | |
1084 | // get the xterm-style button | |
1085 | button = getButton(ev); | |
1086 | // get mouse coordinates | |
1087 | pos = getCoords(ev); | |
1088 | if (!pos) | |
1089 | return; | |
1090 | sendEvent(button, pos); | |
1091 | switch (ev.overrideType || ev.type) { | |
1092 | case 'mousedown': | |
1093 | pressed = button; | |
1094 | break; | |
1095 | case 'mouseup': | |
1096 | // keep it at the left | |
1097 | // button, just in case. | |
1098 | pressed = 32; | |
1099 | break; | |
1100 | case 'wheel': | |
1101 | // nothing. don't | |
1102 | // interfere with | |
1103 | // `pressed`. | |
1104 | break; | |
1105 | } | |
1106 | } | |
1107 | // motion example of a left click: | |
1108 | // ^[[M 3<^[[M@4<^[[M@5<^[[M@6<^[[M@7<^[[M#7< | |
1109 | function sendMove(ev) { | |
1110 | var button = pressed, pos; | |
1111 | pos = getCoords(ev); | |
1112 | if (!pos) | |
1113 | return; | |
1114 | // buttons marked as motions | |
1115 | // are incremented by 32 | |
1116 | button += 32; | |
1117 | sendEvent(button, pos); | |
1118 | } | |
1119 | // encode button and | |
1120 | // position to characters | |
1121 | function encode(data, ch) { | |
1122 | if (!self.utfMouse) { | |
1123 | if (ch === 255) | |
1124 | return data.push(0); | |
1125 | if (ch > 127) | |
1126 | ch = 127; | |
1127 | data.push(ch); | |
1128 | } | |
1129 | else { | |
1130 | if (ch === 2047) | |
1131 | return data.push(0); | |
1132 | if (ch < 127) { | |
1133 | data.push(ch); | |
1134 | } | |
1135 | else { | |
1136 | if (ch > 2047) | |
1137 | ch = 2047; | |
1138 | data.push(0xC0 | (ch >> 6)); | |
1139 | data.push(0x80 | (ch & 0x3F)); | |
1140 | } | |
1141 | } | |
1142 | } | |
1143 | // send a mouse event: | |
1144 | // regular/utf8: ^[[M Cb Cx Cy | |
1145 | // urxvt: ^[[ Cb ; Cx ; Cy M | |
1146 | // sgr: ^[[ Cb ; Cx ; Cy M/m | |
1147 | // vt300: ^[[ 24(1/3/5)~ [ Cx , Cy ] \r | |
1148 | // locator: CSI P e ; P b ; P r ; P c ; P p & w | |
1149 | function sendEvent(button, pos) { | |
1150 | // self.emit('mouse', { | |
1151 | // x: pos.x - 32, | |
1152 | // y: pos.x - 32, | |
1153 | // button: button | |
1154 | // }); | |
1155 | if (self.vt300Mouse) { | |
1156 | // NOTE: Unstable. | |
1157 | // http://www.vt100.net/docs/vt3xx-gp/chapter15.html | |
1158 | button &= 3; | |
1159 | pos.x -= 32; | |
1160 | pos.y -= 32; | |
1161 | var data = '\x1b[24'; | |
1162 | if (button === 0) | |
1163 | data += '1'; | |
1164 | else if (button === 1) | |
1165 | data += '3'; | |
1166 | else if (button === 2) | |
1167 | data += '5'; | |
1168 | else if (button === 3) | |
1169 | return; | |
1170 | else | |
1171 | data += '0'; | |
1172 | data += '~[' + pos.x + ',' + pos.y + ']\r'; | |
1173 | self.send(data); | |
1174 | return; | |
1175 | } | |
1176 | if (self.decLocator) { | |
1177 | // NOTE: Unstable. | |
1178 | button &= 3; | |
1179 | pos.x -= 32; | |
1180 | pos.y -= 32; | |
1181 | if (button === 0) | |
1182 | button = 2; | |
1183 | else if (button === 1) | |
1184 | button = 4; | |
1185 | else if (button === 2) | |
1186 | button = 6; | |
1187 | else if (button === 3) | |
1188 | button = 3; | |
1189 | self.send('\x1b[' | |
1190 | + button | |
1191 | + ';' | |
1192 | + (button === 3 ? 4 : 0) | |
1193 | + ';' | |
1194 | + pos.y | |
1195 | + ';' | |
1196 | + pos.x | |
1197 | + ';' | |
1198 | + (pos.page || 0) | |
1199 | + '&w'); | |
1200 | return; | |
1201 | } | |
1202 | if (self.urxvtMouse) { | |
1203 | pos.x -= 32; | |
1204 | pos.y -= 32; | |
1205 | pos.x++; | |
1206 | pos.y++; | |
1207 | self.send('\x1b[' + button + ';' + pos.x + ';' + pos.y + 'M'); | |
1208 | return; | |
1209 | } | |
1210 | if (self.sgrMouse) { | |
1211 | pos.x -= 32; | |
1212 | pos.y -= 32; | |
1213 | self.send('\x1b[<' | |
1214 | + ((button & 3) === 3 ? button & ~3 : button) | |
1215 | + ';' | |
1216 | + pos.x | |
1217 | + ';' | |
1218 | + pos.y | |
1219 | + ((button & 3) === 3 ? 'm' : 'M')); | |
1220 | return; | |
1221 | } | |
1222 | var data = []; | |
1223 | encode(data, button); | |
1224 | encode(data, pos.x); | |
1225 | encode(data, pos.y); | |
1226 | self.send('\x1b[M' + String.fromCharCode.apply(String, data)); | |
1227 | } | |
1228 | function getButton(ev) { | |
1229 | var button, shift, meta, ctrl, mod; | |
1230 | // two low bits: | |
1231 | // 0 = left | |
1232 | // 1 = middle | |
1233 | // 2 = right | |
1234 | // 3 = release | |
1235 | // wheel up/down: | |
1236 | // 1, and 2 - with 64 added | |
1237 | switch (ev.overrideType || ev.type) { | |
1238 | case 'mousedown': | |
1239 | button = ev.button != null | |
1240 | ? +ev.button | |
1241 | : ev.which != null | |
1242 | ? ev.which - 1 | |
1243 | : null; | |
1244 | if (self.browser.isMSIE) { | |
1245 | button = button === 1 ? 0 : button === 4 ? 1 : button; | |
1246 | } | |
1247 | break; | |
1248 | case 'mouseup': | |
1249 | button = 3; | |
1250 | break; | |
1251 | case 'DOMMouseScroll': | |
1252 | button = ev.detail < 0 | |
1253 | ? 64 | |
1254 | : 65; | |
1255 | break; | |
1256 | case 'wheel': | |
1257 | button = ev.wheelDeltaY > 0 | |
1258 | ? 64 | |
1259 | : 65; | |
1260 | break; | |
1261 | } | |
1262 | // next three bits are the modifiers: | |
1263 | // 4 = shift, 8 = meta, 16 = control | |
1264 | shift = ev.shiftKey ? 4 : 0; | |
1265 | meta = ev.metaKey ? 8 : 0; | |
1266 | ctrl = ev.ctrlKey ? 16 : 0; | |
1267 | mod = shift | meta | ctrl; | |
1268 | // no mods | |
1269 | if (self.vt200Mouse) { | |
1270 | // ctrl only | |
1271 | mod &= ctrl; | |
1272 | } | |
1273 | else if (!self.normalMouse) { | |
1274 | mod = 0; | |
1275 | } | |
1276 | // increment to SP | |
1277 | button = (32 + (mod << 2)) + button; | |
1278 | return button; | |
1279 | } | |
1280 | // mouse coordinates measured in cols/rows | |
1281 | function getCoords(ev) { | |
1282 | var x, y, w, h, el; | |
1283 | // ignore browsers without pageX for now | |
1284 | if (ev.pageX == null) | |
1285 | return; | |
1286 | x = ev.pageX; | |
1287 | y = ev.pageY; | |
1288 | el = self.element; | |
1289 | // should probably check offsetParent | |
1290 | // but this is more portable | |
1291 | while (el && el !== self.document.documentElement) { | |
1292 | x -= el.offsetLeft; | |
1293 | y -= el.offsetTop; | |
1294 | el = 'offsetParent' in el | |
1295 | ? el.offsetParent | |
1296 | : el.parentNode; | |
1297 | } | |
1298 | // convert to cols/rows | |
1299 | w = self.element.clientWidth; | |
1300 | h = self.element.clientHeight; | |
1301 | x = Math.ceil((x / w) * self.cols); | |
1302 | y = Math.ceil((y / h) * self.rows); | |
1303 | // be sure to avoid sending | |
1304 | // bad positions to the program | |
1305 | if (x < 0) | |
1306 | x = 0; | |
1307 | if (x > self.cols) | |
1308 | x = self.cols; | |
1309 | if (y < 0) | |
1310 | y = 0; | |
1311 | if (y > self.rows) | |
1312 | y = self.rows; | |
1313 | // xterm sends raw bytes and | |
1314 | // starts at 32 (SP) for each. | |
1315 | x += 32; | |
1316 | y += 32; | |
1317 | return { | |
1318 | x: x, | |
1319 | y: y, | |
1320 | type: 'wheel' | |
1321 | }; | |
1322 | } | |
1323 | on(el, 'mousedown', function (ev) { | |
1324 | if (!self.mouseEvents) | |
1325 | return; | |
1326 | // send the button | |
1327 | sendButton(ev); | |
1328 | // ensure focus | |
1329 | self.focus(); | |
1330 | // fix for odd bug | |
1331 | //if (self.vt200Mouse && !self.normalMouse) { | |
1332 | if (self.vt200Mouse) { | |
1333 | ev.overrideType = 'mouseup'; | |
1334 | sendButton(ev); | |
1335 | return self.cancel(ev); | |
1336 | } | |
1337 | // bind events | |
1338 | if (self.normalMouse) | |
1339 | on(self.document, 'mousemove', sendMove); | |
1340 | // x10 compatibility mode can't send button releases | |
1341 | if (!self.x10Mouse) { | |
1342 | on(self.document, 'mouseup', function up(ev) { | |
1343 | sendButton(ev); | |
1344 | if (self.normalMouse) | |
1345 | off(self.document, 'mousemove', sendMove); | |
1346 | off(self.document, 'mouseup', up); | |
1347 | return self.cancel(ev); | |
1348 | }); | |
1349 | } | |
1350 | return self.cancel(ev); | |
1351 | }); | |
1352 | //if (self.normalMouse) { | |
1353 | // on(self.document, 'mousemove', sendMove); | |
1354 | //} | |
1355 | on(el, 'wheel', function (ev) { | |
1356 | if (!self.mouseEvents) | |
1357 | return; | |
1358 | if (self.x10Mouse | |
1359 | || self.vt300Mouse | |
1360 | || self.decLocator) | |
1361 | return; | |
1362 | sendButton(ev); | |
1363 | return self.cancel(ev); | |
1364 | }); | |
1365 | // allow wheel scrolling in | |
1366 | // the shell for example | |
1367 | on(el, 'wheel', function (ev) { | |
1368 | if (self.mouseEvents) | |
1369 | return; | |
1370 | self.viewport.onWheel(ev); | |
1371 | return self.cancel(ev); | |
1372 | }); | |
1373 | }; | |
1374 | /** | |
5ce522a4 | 1375 | * Destroys the terminal. |
cd70d298 PK |
1376 | */ |
1377 | Terminal.prototype.destroy = function () { | |
1378 | this.readable = false; | |
1379 | this.writable = false; | |
1380 | this._events = {}; | |
1381 | this.handler = function () { }; | |
1382 | this.write = function () { }; | |
1383 | if (this.element.parentNode) { | |
1384 | this.element.parentNode.removeChild(this.element); | |
1385 | } | |
1386 | //this.emit('close'); | |
1387 | }; | |
1388 | /** | |
5ce522a4 | 1389 | * Flags used to render terminal text properly |
cd70d298 PK |
1390 | */ |
1391 | Terminal.flags = { | |
1392 | BOLD: 1, | |
1393 | UNDERLINE: 2, | |
1394 | BLINK: 4, | |
1395 | INVERSE: 8, | |
1396 | INVISIBLE: 16 | |
1397 | }; | |
1398 | /** | |
5ce522a4 PK |
1399 | * Refreshes (re-renders) terminal content within two rows (inclusive) |
1400 | * | |
1401 | * Rendering Engine: | |
1402 | * | |
1403 | * In the screen buffer, each character is stored as a an array with a character | |
1404 | * and a 32-bit integer: | |
1405 | * - First value: a utf-16 character. | |
1406 | * - Second value: | |
1407 | * - Next 9 bits: background color (0-511). | |
1408 | * - Next 9 bits: foreground color (0-511). | |
1409 | * - Next 14 bits: a mask for misc. flags: | |
1410 | * - 1=bold | |
1411 | * - 2=underline | |
1412 | * - 4=blink | |
1413 | * - 8=inverse | |
1414 | * - 16=invisible | |
1415 | * | |
1416 | * @param {number} start The row to start from (between 0 and terminal's height terminal - 1) | |
1417 | * @param {number} end The row to end at (between fromRow and terminal's height terminal - 1) | |
1418 | * @param {boolean} queue Whether the refresh should ran right now or be queued | |
cd70d298 PK |
1419 | */ |
1420 | Terminal.prototype.refresh = function (start, end, queue) { | |
1421 | var self = this; | |
1422 | // queue defaults to true | |
1423 | queue = (typeof queue == 'undefined') ? true : queue; | |
1424 | /** | |
1425 | * The refresh queue allows refresh to execute only approximately 30 times a second. For | |
1426 | * commands that pass a significant amount of output to the write function, this prevents the | |
1427 | * terminal from maxing out the CPU and making the UI unresponsive. While commands can still | |
1428 | * run beyond what they do on the terminal, it is far better with a debounce in place as | |
1429 | * every single terminal manipulation does not need to be constructed in the DOM. | |
1430 | * | |
1431 | * A side-effect of this is that it makes ^C to interrupt a process seem more responsive. | |
1432 | */ | |
1433 | if (queue) { | |
1434 | // If refresh should be queued, order the refresh and return. | |
1435 | if (this._refreshIsQueued) { | |
1436 | // If a refresh has already been queued, just order a full refresh next | |
1437 | this._fullRefreshNext = true; | |
1438 | } | |
1439 | else { | |
1440 | setTimeout(function () { | |
1441 | self.refresh(start, end, false); | |
1442 | }, 34); | |
1443 | this._refreshIsQueued = true; | |
1444 | } | |
1445 | return; | |
1446 | } | |
1447 | // If refresh should be run right now (not be queued), release the lock | |
1448 | this._refreshIsQueued = false; | |
1449 | // If multiple refreshes were requested, make a full refresh. | |
1450 | if (this._fullRefreshNext) { | |
1451 | start = 0; | |
1452 | end = this.rows - 1; | |
1453 | this._fullRefreshNext = false; // reset lock | |
1454 | } | |
1455 | var x, y, i, line, out, ch, ch_width, width, data, attr, bg, fg, flags, row, parent, focused = document.activeElement; | |
1456 | // If this is a big refresh, remove the terminal rows from the DOM for faster calculations | |
1457 | if (end - start >= this.rows / 2) { | |
1458 | parent = this.element.parentNode; | |
1459 | if (parent) { | |
1460 | this.element.removeChild(this.rowContainer); | |
1461 | } | |
1462 | } | |
1463 | width = this.cols; | |
1464 | y = start; | |
1465 | if (end >= this.rows.length) { | |
1466 | this.log('`end` is too large. Most likely a bad CSR.'); | |
1467 | end = this.rows.length - 1; | |
1468 | } | |
1469 | for (; y <= end; y++) { | |
1470 | row = y + this.ydisp; | |
1471 | line = this.lines[row]; | |
1472 | out = ''; | |
1473 | if (this.y === y - (this.ybase - this.ydisp) | |
1474 | && this.cursorState | |
1475 | && !this.cursorHidden) { | |
1476 | x = this.x; | |
1477 | } | |
1478 | else { | |
1479 | x = -1; | |
1480 | } | |
1481 | attr = this.defAttr; | |
1482 | i = 0; | |
1483 | for (; i < width; i++) { | |
1484 | data = line[i][0]; | |
1485 | ch = line[i][1]; | |
1486 | ch_width = line[i][2]; | |
1487 | if (!ch_width) | |
1488 | continue; | |
1489 | if (i === x) | |
1490 | data = -1; | |
1491 | if (data !== attr) { | |
1492 | if (attr !== this.defAttr) { | |
1493 | out += '</span>'; | |
1494 | } | |
1495 | if (data !== this.defAttr) { | |
1496 | if (data === -1) { | |
1497 | out += '<span class="reverse-video terminal-cursor'; | |
1498 | if (this.cursorBlink) { | |
1499 | out += ' blinking'; | |
1500 | } | |
1501 | out += '">'; | |
1502 | } | |
1503 | else { | |
1504 | var classNames = []; | |
1505 | bg = data & 0x1ff; | |
1506 | fg = (data >> 9) & 0x1ff; | |
1507 | flags = data >> 18; | |
1508 | if (flags & Terminal.flags.BOLD) { | |
1509 | if (!Terminal.brokenBold) { | |
1510 | classNames.push('xterm-bold'); | |
1511 | } | |
1512 | // See: XTerm*boldColors | |
1513 | if (fg < 8) | |
1514 | fg += 8; | |
1515 | } | |
1516 | if (flags & Terminal.flags.UNDERLINE) { | |
1517 | classNames.push('xterm-underline'); | |
1518 | } | |
1519 | if (flags & Terminal.flags.BLINK) { | |
1520 | classNames.push('xterm-blink'); | |
1521 | } | |
1522 | // If inverse flag is on, then swap the foreground and background variables. | |
1523 | if (flags & Terminal.flags.INVERSE) { | |
1524 | /* One-line variable swap in JavaScript: http://stackoverflow.com/a/16201730 */ | |
1525 | bg = [fg, fg = bg][0]; | |
1526 | // Should inverse just be before the | |
1527 | // above boldColors effect instead? | |
1528 | if ((flags & 1) && fg < 8) | |
1529 | fg += 8; | |
1530 | } | |
1531 | if (flags & Terminal.flags.INVISIBLE) { | |
1532 | classNames.push('xterm-hidden'); | |
1533 | } | |
1534 | /** | |
1535 | * Weird situation: Invert flag used black foreground and white background results | |
1536 | * in invalid background color, positioned at the 256 index of the 256 terminal | |
1537 | * color map. Pin the colors manually in such a case. | |
1538 | * | |
1539 | * Source: https://github.com/sourcelair/xterm.js/issues/57 | |
1540 | */ | |
1541 | if (flags & Terminal.flags.INVERSE) { | |
1542 | if (bg == 257) { | |
1543 | bg = 15; | |
1544 | } | |
1545 | if (fg == 256) { | |
1546 | fg = 0; | |
1547 | } | |
1548 | } | |
1549 | if (bg < 256) { | |
1550 | classNames.push('xterm-bg-color-' + bg); | |
1551 | } | |
1552 | if (fg < 256) { | |
1553 | classNames.push('xterm-color-' + fg); | |
1554 | } | |
1555 | out += '<span'; | |
1556 | if (classNames.length) { | |
1557 | out += ' class="' + classNames.join(' ') + '"'; | |
1558 | } | |
1559 | out += '>'; | |
1560 | } | |
1561 | } | |
1562 | } | |
1563 | switch (ch) { | |
1564 | case '&': | |
1565 | out += '&'; | |
1566 | break; | |
1567 | case '<': | |
1568 | out += '<'; | |
1569 | break; | |
1570 | case '>': | |
1571 | out += '>'; | |
1572 | break; | |
1573 | default: | |
1574 | if (ch <= ' ') { | |
1575 | out += ' '; | |
1576 | } | |
1577 | else { | |
1578 | out += ch; | |
1579 | } | |
1580 | break; | |
1581 | } | |
1582 | attr = data; | |
1583 | } | |
1584 | if (attr !== this.defAttr) { | |
1585 | out += '</span>'; | |
1586 | } | |
1587 | this.children[y].innerHTML = out; | |
1588 | } | |
1589 | if (parent) { | |
1590 | this.element.appendChild(this.rowContainer); | |
1591 | } | |
1592 | this.emit('refresh', { element: this.element, start: start, end: end }); | |
1593 | }; | |
1594 | /** | |
5ce522a4 | 1595 | * Display the cursor element |
cd70d298 PK |
1596 | */ |
1597 | Terminal.prototype.showCursor = function () { | |
1598 | if (!this.cursorState) { | |
1599 | this.cursorState = 1; | |
1600 | this.refresh(this.y, this.y); | |
1601 | } | |
1602 | }; | |
1603 | /** | |
5ce522a4 | 1604 | * Scroll the terminal |
cd70d298 PK |
1605 | */ |
1606 | Terminal.prototype.scroll = function () { | |
1607 | var row; | |
1608 | if (++this.ybase === this.scrollback) { | |
1609 | this.ybase = this.ybase / 2 | 0; | |
1610 | this.lines = this.lines.slice(-(this.ybase + this.rows) + 1); | |
1611 | } | |
1612 | if (!this.userScrolling) { | |
1613 | this.ydisp = this.ybase; | |
1614 | } | |
1615 | // last line | |
1616 | row = this.ybase + this.rows - 1; | |
1617 | // subtract the bottom scroll region | |
1618 | row -= this.rows - 1 - this.scrollBottom; | |
1619 | if (row === this.lines.length) { | |
1620 | // potential optimization: | |
1621 | // pushing is faster than splicing | |
1622 | // when they amount to the same | |
1623 | // behavior. | |
1624 | this.lines.push(this.blankLine()); | |
1625 | } | |
1626 | else { | |
1627 | // add our new line | |
1628 | this.lines.splice(row, 0, this.blankLine()); | |
1629 | } | |
1630 | if (this.scrollTop !== 0) { | |
1631 | if (this.ybase !== 0) { | |
1632 | this.ybase--; | |
1633 | if (!this.userScrolling) { | |
1634 | this.ydisp = this.ybase; | |
1635 | } | |
1636 | } | |
1637 | this.lines.splice(this.ybase + this.scrollTop, 1); | |
1638 | } | |
1639 | // this.maxRange(); | |
1640 | this.updateRange(this.scrollTop); | |
1641 | this.updateRange(this.scrollBottom); | |
1642 | /** | |
1643 | * This event is emitted whenever the terminal is scrolled. | |
1644 | * The one parameter passed is the new y display position. | |
1645 | * | |
1646 | * @event scroll | |
1647 | */ | |
1648 | this.emit('scroll', this.ydisp); | |
1649 | }; | |
1650 | /** | |
5ce522a4 PK |
1651 | * Scroll the display of the terminal |
1652 | * @param {number} disp The number of lines to scroll down (negatives scroll up). | |
1653 | * @param {boolean} suppressScrollEvent Don't emit the scroll event as scrollDisp. This is used | |
1654 | * to avoid unwanted events being handled by the veiwport when the event was triggered from the | |
1655 | * viewport originally. | |
cd70d298 PK |
1656 | */ |
1657 | Terminal.prototype.scrollDisp = function (disp, suppressScrollEvent) { | |
1658 | if (disp < 0) { | |
1659 | this.userScrolling = true; | |
1660 | } | |
1661 | else if (disp + this.ydisp >= this.ybase) { | |
1662 | this.userScrolling = false; | |
1663 | } | |
1664 | this.ydisp += disp; | |
1665 | if (this.ydisp > this.ybase) { | |
1666 | this.ydisp = this.ybase; | |
1667 | } | |
1668 | else if (this.ydisp < 0) { | |
1669 | this.ydisp = 0; | |
1670 | } | |
1671 | if (!suppressScrollEvent) { | |
1672 | this.emit('scroll', this.ydisp); | |
1673 | } | |
1674 | this.refresh(0, this.rows - 1); | |
1675 | }; | |
1676 | /** | |
521d7dbd PK |
1677 | * Scroll the display of the terminal by a number of pages. |
1678 | * @param {number} pageCount The number of pages to scroll (negative scrolls up). | |
cd70d298 PK |
1679 | */ |
1680 | Terminal.prototype.scrollPages = function (pageCount) { | |
1681 | this.scrollDisp(pageCount * (this.rows - 1)); | |
1682 | }; | |
1683 | /** | |
521d7dbd | 1684 | * Scrolls the display of the terminal to the top. |
cd70d298 PK |
1685 | */ |
1686 | Terminal.prototype.scrollToTop = function () { | |
1687 | this.scrollDisp(-this.ydisp); | |
1688 | }; | |
1689 | /** | |
521d7dbd | 1690 | * Scrolls the display of the terminal to the bottom. |
cd70d298 PK |
1691 | */ |
1692 | Terminal.prototype.scrollToBottom = function () { | |
1693 | this.scrollDisp(this.ybase - this.ydisp); | |
1694 | }; | |
1695 | /** | |
5ce522a4 PK |
1696 | * Writes text to the terminal. |
1697 | * @param {string} text The text to write to the terminal. | |
cd70d298 PK |
1698 | */ |
1699 | Terminal.prototype.write = function (data) { | |
1700 | var l = data.length, i = 0, j, cs, ch, code, low, ch_width, row; | |
1701 | this.refreshStart = this.y; | |
1702 | this.refreshEnd = this.y; | |
1703 | // apply leftover surrogate high from last write | |
1704 | if (this.surrogate_high) { | |
1705 | data = this.surrogate_high + data; | |
1706 | this.surrogate_high = ''; | |
1707 | } | |
1708 | for (; i < l; i++) { | |
1709 | ch = data[i]; | |
1710 | // FIXME: higher chars than 0xa0 are not allowed in escape sequences | |
1711 | // --> maybe move to default | |
1712 | code = data.charCodeAt(i); | |
1713 | if (0xD800 <= code && code <= 0xDBFF) { | |
1714 | // we got a surrogate high | |
1715 | // get surrogate low (next 2 bytes) | |
1716 | low = data.charCodeAt(i + 1); | |
1717 | if (isNaN(low)) { | |
1718 | // end of data stream, save surrogate high | |
1719 | this.surrogate_high = ch; | |
1720 | continue; | |
1721 | } | |
1722 | code = ((code - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000; | |
1723 | ch += data.charAt(i + 1); | |
1724 | } | |
1725 | // surrogate low - already handled above | |
1726 | if (0xDC00 <= code && code <= 0xDFFF) | |
1727 | continue; | |
1728 | switch (this.state) { | |
1729 | case normal: | |
1730 | switch (ch) { | |
1731 | case '\x07': | |
1732 | this.bell(); | |
1733 | break; | |
1734 | // '\n', '\v', '\f' | |
1735 | case '\n': | |
1736 | case '\x0b': | |
1737 | case '\x0c': | |
1738 | if (this.convertEol) { | |
1739 | this.x = 0; | |
1740 | } | |
1741 | this.y++; | |
1742 | if (this.y > this.scrollBottom) { | |
1743 | this.y--; | |
1744 | this.scroll(); | |
1745 | } | |
1746 | break; | |
1747 | // '\r' | |
1748 | case '\r': | |
1749 | this.x = 0; | |
1750 | break; | |
1751 | // '\b' | |
1752 | case '\x08': | |
1753 | if (this.x > 0) { | |
1754 | this.x--; | |
1755 | } | |
1756 | break; | |
1757 | // '\t' | |
1758 | case '\t': | |
1759 | this.x = this.nextStop(); | |
1760 | break; | |
1761 | // shift out | |
1762 | case '\x0e': | |
1763 | this.setgLevel(1); | |
1764 | break; | |
1765 | // shift in | |
1766 | case '\x0f': | |
1767 | this.setgLevel(0); | |
1768 | break; | |
1769 | // '\e' | |
1770 | case '\x1b': | |
1771 | this.state = escaped; | |
1772 | break; | |
1773 | default: | |
1774 | // ' ' | |
1775 | // calculate print space | |
1776 | // expensive call, therefore we save width in line buffer | |
1777 | ch_width = wcwidth(code); | |
1778 | if (ch >= ' ') { | |
1779 | if (this.charset && this.charset[ch]) { | |
1780 | ch = this.charset[ch]; | |
1781 | } | |
1782 | row = this.y + this.ybase; | |
1783 | // insert combining char in last cell | |
1784 | // FIXME: needs handling after cursor jumps | |
1785 | if (!ch_width && this.x) { | |
1786 | // dont overflow left | |
1787 | if (this.lines[row][this.x - 1]) { | |
1788 | if (!this.lines[row][this.x - 1][2]) { | |
1789 | // found empty cell after fullwidth, need to go 2 cells back | |
1790 | if (this.lines[row][this.x - 2]) | |
1791 | this.lines[row][this.x - 2][1] += ch; | |
1792 | } | |
1793 | else { | |
1794 | this.lines[row][this.x - 1][1] += ch; | |
1795 | } | |
1796 | this.updateRange(this.y); | |
1797 | } | |
1798 | break; | |
1799 | } | |
1800 | // goto next line if ch would overflow | |
1801 | // TODO: needs a global min terminal width of 2 | |
1802 | if (this.x + ch_width - 1 >= this.cols) { | |
1803 | // autowrap - DECAWM | |
1804 | if (this.wraparoundMode) { | |
1805 | this.x = 0; | |
1806 | this.y++; | |
1807 | if (this.y > this.scrollBottom) { | |
1808 | this.y--; | |
1809 | this.scroll(); | |
1810 | } | |
1811 | } | |
1812 | else { | |
1813 | this.x = this.cols - 1; | |
1814 | if (ch_width === 2) | |
1815 | continue; | |
1816 | } | |
1817 | } | |
1818 | row = this.y + this.ybase; | |
1819 | // insert mode: move characters to right | |
1820 | if (this.insertMode) { | |
1821 | // do this twice for a fullwidth char | |
1822 | for (var moves = 0; moves < ch_width; ++moves) { | |
1823 | // remove last cell, if it's width is 0 | |
1824 | // we have to adjust the second last cell as well | |
1825 | var removed = this.lines[this.y + this.ybase].pop(); | |
1826 | if (removed[2] === 0 | |
1827 | && this.lines[row][this.cols - 2] | |
1828 | && this.lines[row][this.cols - 2][2] === 2) | |
1829 | this.lines[row][this.cols - 2] = [this.curAttr, ' ', 1]; | |
1830 | // insert empty cell at cursor | |
1831 | this.lines[row].splice(this.x, 0, [this.curAttr, ' ', 1]); | |
1832 | } | |
1833 | } | |
1834 | this.lines[row][this.x] = [this.curAttr, ch, ch_width]; | |
1835 | this.x++; | |
1836 | this.updateRange(this.y); | |
1837 | // fullwidth char - set next cell width to zero and advance cursor | |
1838 | if (ch_width === 2) { | |
1839 | this.lines[row][this.x] = [this.curAttr, '', 0]; | |
1840 | this.x++; | |
1841 | } | |
1842 | } | |
1843 | break; | |
1844 | } | |
1845 | break; | |
1846 | case escaped: | |
1847 | switch (ch) { | |
1848 | // ESC [ Control Sequence Introducer ( CSI is 0x9b). | |
1849 | case '[': | |
1850 | this.params = []; | |
1851 | this.currentParam = 0; | |
1852 | this.state = csi; | |
1853 | break; | |
1854 | // ESC ] Operating System Command ( OSC is 0x9d). | |
1855 | case ']': | |
1856 | this.params = []; | |
1857 | this.currentParam = 0; | |
1858 | this.state = osc; | |
1859 | break; | |
1860 | // ESC P Device Control String ( DCS is 0x90). | |
1861 | case 'P': | |
1862 | this.params = []; | |
1863 | this.currentParam = 0; | |
1864 | this.state = dcs; | |
1865 | break; | |
1866 | // ESC _ Application Program Command ( APC is 0x9f). | |
1867 | case '_': | |
1868 | this.state = ignore; | |
1869 | break; | |
1870 | // ESC ^ Privacy Message ( PM is 0x9e). | |
1871 | case '^': | |
1872 | this.state = ignore; | |
1873 | break; | |
1874 | // ESC c Full Reset (RIS). | |
1875 | case 'c': | |
1876 | this.reset(); | |
1877 | break; | |
1878 | // ESC E Next Line ( NEL is 0x85). | |
1879 | // ESC D Index ( IND is 0x84). | |
1880 | case 'E': | |
1881 | this.x = 0; | |
1882 | ; | |
1883 | case 'D': | |
1884 | this.index(); | |
1885 | break; | |
1886 | // ESC M Reverse Index ( RI is 0x8d). | |
1887 | case 'M': | |
1888 | this.reverseIndex(); | |
1889 | break; | |
1890 | // ESC % Select default/utf-8 character set. | |
1891 | // @ = default, G = utf-8 | |
1892 | case '%': | |
1893 | //this.charset = null; | |
1894 | this.setgLevel(0); | |
1895 | this.setgCharset(0, Terminal.charsets.US); | |
1896 | this.state = normal; | |
1897 | i++; | |
1898 | break; | |
1899 | // ESC (,),*,+,-,. Designate G0-G2 Character Set. | |
1900 | case '(': // <-- this seems to get all the attention | |
1901 | case ')': | |
1902 | case '*': | |
1903 | case '+': | |
1904 | case '-': | |
1905 | case '.': | |
1906 | switch (ch) { | |
1907 | case '(': | |
1908 | this.gcharset = 0; | |
1909 | break; | |
1910 | case ')': | |
1911 | this.gcharset = 1; | |
1912 | break; | |
1913 | case '*': | |
1914 | this.gcharset = 2; | |
1915 | break; | |
1916 | case '+': | |
1917 | this.gcharset = 3; | |
1918 | break; | |
1919 | case '-': | |
1920 | this.gcharset = 1; | |
1921 | break; | |
1922 | case '.': | |
1923 | this.gcharset = 2; | |
1924 | break; | |
1925 | } | |
1926 | this.state = charset; | |
1927 | break; | |
1928 | // Designate G3 Character Set (VT300). | |
1929 | // A = ISO Latin-1 Supplemental. | |
1930 | // Not implemented. | |
1931 | case '/': | |
1932 | this.gcharset = 3; | |
1933 | this.state = charset; | |
1934 | i--; | |
1935 | break; | |
1936 | // ESC N | |
1937 | // Single Shift Select of G2 Character Set | |
1938 | // ( SS2 is 0x8e). This affects next character only. | |
1939 | case 'N': | |
1940 | break; | |
1941 | // ESC O | |
1942 | // Single Shift Select of G3 Character Set | |
1943 | // ( SS3 is 0x8f). This affects next character only. | |
1944 | case 'O': | |
1945 | break; | |
1946 | // ESC n | |
1947 | // Invoke the G2 Character Set as GL (LS2). | |
1948 | case 'n': | |
1949 | this.setgLevel(2); | |
1950 | break; | |
1951 | // ESC o | |
1952 | // Invoke the G3 Character Set as GL (LS3). | |
1953 | case 'o': | |
1954 | this.setgLevel(3); | |
1955 | break; | |
1956 | // ESC | | |
1957 | // Invoke the G3 Character Set as GR (LS3R). | |
1958 | case '|': | |
1959 | this.setgLevel(3); | |
1960 | break; | |
1961 | // ESC } | |
1962 | // Invoke the G2 Character Set as GR (LS2R). | |
1963 | case '}': | |
1964 | this.setgLevel(2); | |
1965 | break; | |
1966 | // ESC ~ | |
1967 | // Invoke the G1 Character Set as GR (LS1R). | |
1968 | case '~': | |
1969 | this.setgLevel(1); | |
1970 | break; | |
1971 | // ESC 7 Save Cursor (DECSC). | |
1972 | case '7': | |
1973 | this.saveCursor(); | |
1974 | this.state = normal; | |
1975 | break; | |
1976 | // ESC 8 Restore Cursor (DECRC). | |
1977 | case '8': | |
1978 | this.restoreCursor(); | |
1979 | this.state = normal; | |
1980 | break; | |
1981 | // ESC # 3 DEC line height/width | |
1982 | case '#': | |
1983 | this.state = normal; | |
1984 | i++; | |
1985 | break; | |
1986 | // ESC H Tab Set (HTS is 0x88). | |
1987 | case 'H': | |
1988 | this.tabSet(); | |
1989 | break; | |
1990 | // ESC = Application Keypad (DECKPAM). | |
1991 | case '=': | |
1992 | this.log('Serial port requested application keypad.'); | |
1993 | this.applicationKeypad = true; | |
1994 | this.viewport.syncScrollArea(); | |
1995 | this.state = normal; | |
1996 | break; | |
1997 | // ESC > Normal Keypad (DECKPNM). | |
1998 | case '>': | |
1999 | this.log('Switching back to normal keypad.'); | |
2000 | this.applicationKeypad = false; | |
2001 | this.viewport.syncScrollArea(); | |
2002 | this.state = normal; | |
2003 | break; | |
2004 | default: | |
2005 | this.state = normal; | |
2006 | this.error('Unknown ESC control: %s.', ch); | |
2007 | break; | |
2008 | } | |
2009 | break; | |
2010 | case charset: | |
2011 | switch (ch) { | |
2012 | case '0': | |
2013 | cs = Terminal.charsets.SCLD; | |
2014 | break; | |
2015 | case 'A': | |
2016 | cs = Terminal.charsets.UK; | |
2017 | break; | |
2018 | case 'B': | |
2019 | cs = Terminal.charsets.US; | |
2020 | break; | |
2021 | case '4': | |
2022 | cs = Terminal.charsets.Dutch; | |
2023 | break; | |
2024 | case 'C': // Finnish | |
2025 | case '5': | |
2026 | cs = Terminal.charsets.Finnish; | |
2027 | break; | |
2028 | case 'R': | |
2029 | cs = Terminal.charsets.French; | |
2030 | break; | |
2031 | case 'Q': | |
2032 | cs = Terminal.charsets.FrenchCanadian; | |
2033 | break; | |
2034 | case 'K': | |
2035 | cs = Terminal.charsets.German; | |
2036 | break; | |
2037 | case 'Y': | |
2038 | cs = Terminal.charsets.Italian; | |
2039 | break; | |
2040 | case 'E': // NorwegianDanish | |
2041 | case '6': | |
2042 | cs = Terminal.charsets.NorwegianDanish; | |
2043 | break; | |
2044 | case 'Z': | |
2045 | cs = Terminal.charsets.Spanish; | |
2046 | break; | |
2047 | case 'H': // Swedish | |
2048 | case '7': | |
2049 | cs = Terminal.charsets.Swedish; | |
2050 | break; | |
2051 | case '=': | |
2052 | cs = Terminal.charsets.Swiss; | |
2053 | break; | |
2054 | case '/': | |
2055 | cs = Terminal.charsets.ISOLatin; | |
2056 | i++; | |
2057 | break; | |
2058 | default: | |
2059 | cs = Terminal.charsets.US; | |
2060 | break; | |
2061 | } | |
2062 | this.setgCharset(this.gcharset, cs); | |
2063 | this.gcharset = null; | |
2064 | this.state = normal; | |
2065 | break; | |
2066 | case osc: | |
2067 | // OSC Ps ; Pt ST | |
2068 | // OSC Ps ; Pt BEL | |
2069 | // Set Text Parameters. | |
2070 | if (ch === '\x1b' || ch === '\x07') { | |
2071 | if (ch === '\x1b') | |
2072 | i++; | |
2073 | this.params.push(this.currentParam); | |
2074 | switch (this.params[0]) { | |
2075 | case 0: | |
2076 | case 1: | |
2077 | case 2: | |
2078 | if (this.params[1]) { | |
2079 | this.title = this.params[1]; | |
2080 | this.handleTitle(this.title); | |
2081 | } | |
2082 | break; | |
2083 | case 3: | |
2084 | // set X property | |
2085 | break; | |
2086 | case 4: | |
2087 | case 5: | |
2088 | // change dynamic colors | |
2089 | break; | |
2090 | case 10: | |
2091 | case 11: | |
2092 | case 12: | |
2093 | case 13: | |
2094 | case 14: | |
2095 | case 15: | |
2096 | case 16: | |
2097 | case 17: | |
2098 | case 18: | |
2099 | case 19: | |
2100 | // change dynamic ui colors | |
2101 | break; | |
2102 | case 46: | |
2103 | // change log file | |
2104 | break; | |
2105 | case 50: | |
2106 | // dynamic font | |
2107 | break; | |
2108 | case 51: | |
2109 | // emacs shell | |
2110 | break; | |
2111 | case 52: | |
2112 | // manipulate selection data | |
2113 | break; | |
2114 | case 104: | |
2115 | case 105: | |
2116 | case 110: | |
2117 | case 111: | |
2118 | case 112: | |
2119 | case 113: | |
2120 | case 114: | |
2121 | case 115: | |
2122 | case 116: | |
2123 | case 117: | |
2124 | case 118: | |
2125 | // reset colors | |
2126 | break; | |
2127 | } | |
2128 | this.params = []; | |
2129 | this.currentParam = 0; | |
2130 | this.state = normal; | |
2131 | } | |
2132 | else { | |
2133 | if (!this.params.length) { | |
2134 | if (ch >= '0' && ch <= '9') { | |
2135 | this.currentParam = | |
2136 | this.currentParam * 10 + ch.charCodeAt(0) - 48; | |
2137 | } | |
2138 | else if (ch === ';') { | |
2139 | this.params.push(this.currentParam); | |
2140 | this.currentParam = ''; | |
2141 | } | |
2142 | } | |
2143 | else { | |
2144 | this.currentParam += ch; | |
2145 | } | |
2146 | } | |
2147 | break; | |
2148 | case csi: | |
2149 | // '?', '>', '!' | |
2150 | if (ch === '?' || ch === '>' || ch === '!') { | |
2151 | this.prefix = ch; | |
2152 | break; | |
2153 | } | |
2154 | // 0 - 9 | |
2155 | if (ch >= '0' && ch <= '9') { | |
2156 | this.currentParam = this.currentParam * 10 + ch.charCodeAt(0) - 48; | |
2157 | break; | |
2158 | } | |
2159 | // '$', '"', ' ', '\'' | |
2160 | if (ch === '$' || ch === '"' || ch === ' ' || ch === '\'') { | |
2161 | this.postfix = ch; | |
2162 | break; | |
2163 | } | |
2164 | this.params.push(this.currentParam); | |
2165 | this.currentParam = 0; | |
2166 | // ';' | |
2167 | if (ch === ';') | |
2168 | break; | |
2169 | this.state = normal; | |
2170 | switch (ch) { | |
2171 | // CSI Ps A | |
2172 | // Cursor Up Ps Times (default = 1) (CUU). | |
2173 | case 'A': | |
2174 | this.cursorUp(this.params); | |
2175 | break; | |
2176 | // CSI Ps B | |
2177 | // Cursor Down Ps Times (default = 1) (CUD). | |
2178 | case 'B': | |
2179 | this.cursorDown(this.params); | |
2180 | break; | |
2181 | // CSI Ps C | |
2182 | // Cursor Forward Ps Times (default = 1) (CUF). | |
2183 | case 'C': | |
2184 | this.cursorForward(this.params); | |
2185 | break; | |
2186 | // CSI Ps D | |
2187 | // Cursor Backward Ps Times (default = 1) (CUB). | |
2188 | case 'D': | |
2189 | this.cursorBackward(this.params); | |
2190 | break; | |
2191 | // CSI Ps ; Ps H | |
2192 | // Cursor Position [row;column] (default = [1,1]) (CUP). | |
2193 | case 'H': | |
2194 | this.cursorPos(this.params); | |
2195 | break; | |
2196 | // CSI Ps J Erase in Display (ED). | |
2197 | case 'J': | |
2198 | this.eraseInDisplay(this.params); | |
2199 | break; | |
2200 | // CSI Ps K Erase in Line (EL). | |
2201 | case 'K': | |
2202 | this.eraseInLine(this.params); | |
2203 | break; | |
2204 | // CSI Pm m Character Attributes (SGR). | |
2205 | case 'm': | |
2206 | if (!this.prefix) { | |
2207 | this.charAttributes(this.params); | |
2208 | } | |
2209 | break; | |
2210 | // CSI Ps n Device Status Report (DSR). | |
2211 | case 'n': | |
2212 | if (!this.prefix) { | |
2213 | this.deviceStatus(this.params); | |
2214 | } | |
2215 | break; | |
2216 | /** | |
2217 | * Additions | |
2218 | */ | |
2219 | // CSI Ps @ | |
2220 | // Insert Ps (Blank) Character(s) (default = 1) (ICH). | |
2221 | case '@': | |
2222 | this.insertChars(this.params); | |
2223 | break; | |
2224 | // CSI Ps E | |
2225 | // Cursor Next Line Ps Times (default = 1) (CNL). | |
2226 | case 'E': | |
2227 | this.cursorNextLine(this.params); | |
2228 | break; | |
2229 | // CSI Ps F | |
2230 | // Cursor Preceding Line Ps Times (default = 1) (CNL). | |
2231 | case 'F': | |
2232 | this.cursorPrecedingLine(this.params); | |
2233 | break; | |
2234 | // CSI Ps G | |
2235 | // Cursor Character Absolute [column] (default = [row,1]) (CHA). | |
2236 | case 'G': | |
2237 | this.cursorCharAbsolute(this.params); | |
2238 | break; | |
2239 | // CSI Ps L | |
2240 | // Insert Ps Line(s) (default = 1) (IL). | |
2241 | case 'L': | |
2242 | this.insertLines(this.params); | |
2243 | break; | |
2244 | // CSI Ps M | |
2245 | // Delete Ps Line(s) (default = 1) (DL). | |
2246 | case 'M': | |
2247 | this.deleteLines(this.params); | |
2248 | break; | |
2249 | // CSI Ps P | |
2250 | // Delete Ps Character(s) (default = 1) (DCH). | |
2251 | case 'P': | |
2252 | this.deleteChars(this.params); | |
2253 | break; | |
2254 | // CSI Ps X | |
2255 | // Erase Ps Character(s) (default = 1) (ECH). | |
2256 | case 'X': | |
2257 | this.eraseChars(this.params); | |
2258 | break; | |
2259 | // CSI Pm ` Character Position Absolute | |
2260 | // [column] (default = [row,1]) (HPA). | |
2261 | case '`': | |
2262 | this.charPosAbsolute(this.params); | |
2263 | break; | |
2264 | // 141 61 a * HPR - | |
2265 | // Horizontal Position Relative | |
2266 | case 'a': | |
2267 | this.HPositionRelative(this.params); | |
2268 | break; | |
2269 | // CSI P s c | |
2270 | // Send Device Attributes (Primary DA). | |
2271 | // CSI > P s c | |
2272 | // Send Device Attributes (Secondary DA) | |
2273 | case 'c': | |
2274 | this.sendDeviceAttributes(this.params); | |
2275 | break; | |
2276 | // CSI Pm d | |
2277 | // Line Position Absolute [row] (default = [1,column]) (VPA). | |
2278 | case 'd': | |
2279 | this.linePosAbsolute(this.params); | |
2280 | break; | |
2281 | // 145 65 e * VPR - Vertical Position Relative | |
2282 | case 'e': | |
2283 | this.VPositionRelative(this.params); | |
2284 | break; | |
2285 | // CSI Ps ; Ps f | |
2286 | // Horizontal and Vertical Position [row;column] (default = | |
2287 | // [1,1]) (HVP). | |
2288 | case 'f': | |
2289 | this.HVPosition(this.params); | |
2290 | break; | |
2291 | // CSI Pm h Set Mode (SM). | |
2292 | // CSI ? Pm h - mouse escape codes, cursor escape codes | |
2293 | case 'h': | |
2294 | this.setMode(this.params); | |
2295 | break; | |
2296 | // CSI Pm l Reset Mode (RM). | |
2297 | // CSI ? Pm l | |
2298 | case 'l': | |
2299 | this.resetMode(this.params); | |
2300 | break; | |
2301 | // CSI Ps ; Ps r | |
2302 | // Set Scrolling Region [top;bottom] (default = full size of win- | |
2303 | // dow) (DECSTBM). | |
2304 | // CSI ? Pm r | |
2305 | case 'r': | |
2306 | this.setScrollRegion(this.params); | |
2307 | break; | |
2308 | // CSI s | |
2309 | // Save cursor (ANSI.SYS). | |
2310 | case 's': | |
2311 | this.saveCursor(this.params); | |
2312 | break; | |
2313 | // CSI u | |
2314 | // Restore cursor (ANSI.SYS). | |
2315 | case 'u': | |
2316 | this.restoreCursor(this.params); | |
2317 | break; | |
2318 | /** | |
2319 | * Lesser Used | |
2320 | */ | |
2321 | // CSI Ps I | |
2322 | // Cursor Forward Tabulation Ps tab stops (default = 1) (CHT). | |
2323 | case 'I': | |
2324 | this.cursorForwardTab(this.params); | |
2325 | break; | |
2326 | // CSI Ps S Scroll up Ps lines (default = 1) (SU). | |
2327 | case 'S': | |
2328 | this.scrollUp(this.params); | |
2329 | break; | |
2330 | // CSI Ps T Scroll down Ps lines (default = 1) (SD). | |
2331 | // CSI Ps ; Ps ; Ps ; Ps ; Ps T | |
2332 | // CSI > Ps; Ps T | |
2333 | case 'T': | |
2334 | // if (this.prefix === '>') { | |
2335 | // this.resetTitleModes(this.params); | |
2336 | // break; | |
2337 | // } | |
2338 | // if (this.params.length > 2) { | |
2339 | // this.initMouseTracking(this.params); | |
2340 | // break; | |
2341 | // } | |
2342 | if (this.params.length < 2 && !this.prefix) { | |
2343 | this.scrollDown(this.params); | |
2344 | } | |
2345 | break; | |
2346 | // CSI Ps Z | |
2347 | // Cursor Backward Tabulation Ps tab stops (default = 1) (CBT). | |
2348 | case 'Z': | |
2349 | this.cursorBackwardTab(this.params); | |
2350 | break; | |
2351 | // CSI Ps b Repeat the preceding graphic character Ps times (REP). | |
2352 | case 'b': | |
2353 | this.repeatPrecedingCharacter(this.params); | |
2354 | break; | |
2355 | // CSI Ps g Tab Clear (TBC). | |
2356 | case 'g': | |
2357 | this.tabClear(this.params); | |
2358 | break; | |
2359 | // CSI Pm i Media Copy (MC). | |
2360 | // CSI ? Pm i | |
2361 | // case 'i': | |
2362 | // this.mediaCopy(this.params); | |
2363 | // break; | |
2364 | // CSI Pm m Character Attributes (SGR). | |
2365 | // CSI > Ps; Ps m | |
2366 | // case 'm': // duplicate | |
2367 | // if (this.prefix === '>') { | |
2368 | // this.setResources(this.params); | |
2369 | // } else { | |
2370 | // this.charAttributes(this.params); | |
2371 | // } | |
2372 | // break; | |
2373 | // CSI Ps n Device Status Report (DSR). | |
2374 | // CSI > Ps n | |
2375 | // case 'n': // duplicate | |
2376 | // if (this.prefix === '>') { | |
2377 | // this.disableModifiers(this.params); | |
2378 | // } else { | |
2379 | // this.deviceStatus(this.params); | |
2380 | // } | |
2381 | // break; | |
2382 | // CSI > Ps p Set pointer mode. | |
2383 | // CSI ! p Soft terminal reset (DECSTR). | |
2384 | // CSI Ps$ p | |
2385 | // Request ANSI mode (DECRQM). | |
2386 | // CSI ? Ps$ p | |
2387 | // Request DEC private mode (DECRQM). | |
2388 | // CSI Ps ; Ps " p | |
2389 | case 'p': | |
2390 | switch (this.prefix) { | |
2391 | // case '>': | |
2392 | // this.setPointerMode(this.params); | |
2393 | // break; | |
2394 | case '!': | |
2395 | this.softReset(this.params); | |
2396 | break; | |
2397 | } | |
2398 | break; | |
2399 | // CSI Ps q Load LEDs (DECLL). | |
2400 | // CSI Ps SP q | |
2401 | // CSI Ps " q | |
2402 | // case 'q': | |
2403 | // if (this.postfix === ' ') { | |
2404 | // this.setCursorStyle(this.params); | |
2405 | // break; | |
2406 | // } | |
2407 | // if (this.postfix === '"') { | |
2408 | // this.setCharProtectionAttr(this.params); | |
2409 | // break; | |
2410 | // } | |
2411 | // this.loadLEDs(this.params); | |
2412 | // break; | |
2413 | // CSI Ps ; Ps r | |
2414 | // Set Scrolling Region [top;bottom] (default = full size of win- | |
2415 | // dow) (DECSTBM). | |
2416 | // CSI ? Pm r | |
2417 | // CSI Pt; Pl; Pb; Pr; Ps$ r | |
2418 | // case 'r': // duplicate | |
2419 | // if (this.prefix === '?') { | |
2420 | // this.restorePrivateValues(this.params); | |
2421 | // } else if (this.postfix === '$') { | |
2422 | // this.setAttrInRectangle(this.params); | |
2423 | // } else { | |
2424 | // this.setScrollRegion(this.params); | |
2425 | // } | |
2426 | // break; | |
2427 | // CSI s Save cursor (ANSI.SYS). | |
2428 | // CSI ? Pm s | |
2429 | // case 's': // duplicate | |
2430 | // if (this.prefix === '?') { | |
2431 | // this.savePrivateValues(this.params); | |
2432 | // } else { | |
2433 | // this.saveCursor(this.params); | |
2434 | // } | |
2435 | // break; | |
2436 | // CSI Ps ; Ps ; Ps t | |
2437 | // CSI Pt; Pl; Pb; Pr; Ps$ t | |
2438 | // CSI > Ps; Ps t | |
2439 | // CSI Ps SP t | |
2440 | // case 't': | |
2441 | // if (this.postfix === '$') { | |
2442 | // this.reverseAttrInRectangle(this.params); | |
2443 | // } else if (this.postfix === ' ') { | |
2444 | // this.setWarningBellVolume(this.params); | |
2445 | // } else { | |
2446 | // if (this.prefix === '>') { | |
2447 | // this.setTitleModeFeature(this.params); | |
2448 | // } else { | |
2449 | // this.manipulateWindow(this.params); | |
2450 | // } | |
2451 | // } | |
2452 | // break; | |
2453 | // CSI u Restore cursor (ANSI.SYS). | |
2454 | // CSI Ps SP u | |
2455 | // case 'u': // duplicate | |
2456 | // if (this.postfix === ' ') { | |
2457 | // this.setMarginBellVolume(this.params); | |
2458 | // } else { | |
2459 | // this.restoreCursor(this.params); | |
2460 | // } | |
2461 | // break; | |
2462 | // CSI Pt; Pl; Pb; Pr; Pp; Pt; Pl; Pp$ v | |
2463 | // case 'v': | |
2464 | // if (this.postfix === '$') { | |
2465 | // this.copyRectagle(this.params); | |
2466 | // } | |
2467 | // break; | |
2468 | // CSI Pt ; Pl ; Pb ; Pr ' w | |
2469 | // case 'w': | |
2470 | // if (this.postfix === '\'') { | |
2471 | // this.enableFilterRectangle(this.params); | |
2472 | // } | |
2473 | // break; | |
2474 | // CSI Ps x Request Terminal Parameters (DECREQTPARM). | |
2475 | // CSI Ps x Select Attribute Change Extent (DECSACE). | |
2476 | // CSI Pc; Pt; Pl; Pb; Pr$ x | |
2477 | // case 'x': | |
2478 | // if (this.postfix === '$') { | |
2479 | // this.fillRectangle(this.params); | |
2480 | // } else { | |
2481 | // this.requestParameters(this.params); | |
2482 | // //this.__(this.params); | |
2483 | // } | |
2484 | // break; | |
2485 | // CSI Ps ; Pu ' z | |
2486 | // CSI Pt; Pl; Pb; Pr$ z | |
2487 | // case 'z': | |
2488 | // if (this.postfix === '\'') { | |
2489 | // this.enableLocatorReporting(this.params); | |
2490 | // } else if (this.postfix === '$') { | |
2491 | // this.eraseRectangle(this.params); | |
2492 | // } | |
2493 | // break; | |
2494 | // CSI Pm ' { | |
2495 | // CSI Pt; Pl; Pb; Pr$ { | |
2496 | // case '{': | |
2497 | // if (this.postfix === '\'') { | |
2498 | // this.setLocatorEvents(this.params); | |
2499 | // } else if (this.postfix === '$') { | |
2500 | // this.selectiveEraseRectangle(this.params); | |
2501 | // } | |
2502 | // break; | |
2503 | // CSI Ps ' | | |
2504 | // case '|': | |
2505 | // if (this.postfix === '\'') { | |
2506 | // this.requestLocatorPosition(this.params); | |
2507 | // } | |
2508 | // break; | |
2509 | // CSI P m SP } | |
2510 | // Insert P s Column(s) (default = 1) (DECIC), VT420 and up. | |
2511 | // case '}': | |
2512 | // if (this.postfix === ' ') { | |
2513 | // this.insertColumns(this.params); | |
2514 | // } | |
2515 | // break; | |
2516 | // CSI P m SP ~ | |
2517 | // Delete P s Column(s) (default = 1) (DECDC), VT420 and up | |
2518 | // case '~': | |
2519 | // if (this.postfix === ' ') { | |
2520 | // this.deleteColumns(this.params); | |
2521 | // } | |
2522 | // break; | |
2523 | default: | |
2524 | this.error('Unknown CSI code: %s.', ch); | |
2525 | break; | |
2526 | } | |
2527 | this.prefix = ''; | |
2528 | this.postfix = ''; | |
2529 | break; | |
2530 | case dcs: | |
2531 | if (ch === '\x1b' || ch === '\x07') { | |
2532 | if (ch === '\x1b') | |
2533 | i++; | |
2534 | switch (this.prefix) { | |
2535 | // User-Defined Keys (DECUDK). | |
2536 | case '': | |
2537 | break; | |
2538 | // Request Status String (DECRQSS). | |
2539 | // test: echo -e '\eP$q"p\e\\' | |
2540 | case '$q': | |
2541 | var pt = this.currentParam, valid = false; | |
2542 | switch (pt) { | |
2543 | // DECSCA | |
2544 | case '"q': | |
2545 | pt = '0"q'; | |
2546 | break; | |
2547 | // DECSCL | |
2548 | case '"p': | |
2549 | pt = '61"p'; | |
2550 | break; | |
2551 | // DECSTBM | |
2552 | case 'r': | |
2553 | pt = '' | |
2554 | + (this.scrollTop + 1) | |
2555 | + ';' | |
2556 | + (this.scrollBottom + 1) | |
2557 | + 'r'; | |
2558 | break; | |
2559 | // SGR | |
2560 | case 'm': | |
2561 | pt = '0m'; | |
2562 | break; | |
2563 | default: | |
2564 | this.error('Unknown DCS Pt: %s.', pt); | |
2565 | pt = ''; | |
2566 | break; | |
2567 | } | |
2568 | this.send('\x1bP' + +valid + '$r' + pt + '\x1b\\'); | |
2569 | break; | |
2570 | // Set Termcap/Terminfo Data (xterm, experimental). | |
2571 | case '+p': | |
2572 | break; | |
2573 | // Request Termcap/Terminfo String (xterm, experimental) | |
2574 | // Regular xterm does not even respond to this sequence. | |
2575 | // This can cause a small glitch in vim. | |
2576 | // test: echo -ne '\eP+q6b64\e\\' | |
2577 | case '+q': | |
2578 | var pt = this.currentParam, valid = false; | |
2579 | this.send('\x1bP' + +valid + '+r' + pt + '\x1b\\'); | |
2580 | break; | |
2581 | default: | |
2582 | this.error('Unknown DCS prefix: %s.', this.prefix); | |
2583 | break; | |
2584 | } | |
2585 | this.currentParam = 0; | |
2586 | this.prefix = ''; | |
2587 | this.state = normal; | |
2588 | } | |
2589 | else if (!this.currentParam) { | |
2590 | if (!this.prefix && ch !== '$' && ch !== '+') { | |
2591 | this.currentParam = ch; | |
2592 | } | |
2593 | else if (this.prefix.length === 2) { | |
2594 | this.currentParam = ch; | |
2595 | } | |
2596 | else { | |
2597 | this.prefix += ch; | |
2598 | } | |
2599 | } | |
2600 | else { | |
2601 | this.currentParam += ch; | |
2602 | } | |
2603 | break; | |
2604 | case ignore: | |
2605 | // For PM and APC. | |
2606 | if (ch === '\x1b' || ch === '\x07') { | |
2607 | if (ch === '\x1b') | |
2608 | i++; | |
2609 | this.state = normal; | |
2610 | } | |
2611 | break; | |
2612 | } | |
2613 | } | |
2614 | this.updateRange(this.y); | |
2615 | this.refresh(this.refreshStart, this.refreshEnd); | |
2616 | }; | |
2617 | /** | |
5ce522a4 PK |
2618 | * Writes text to the terminal, followed by a break line character (\n). |
2619 | * @param {string} text The text to write to the terminal. | |
cd70d298 PK |
2620 | */ |
2621 | Terminal.prototype.writeln = function (data) { | |
2622 | this.write(data + '\r\n'); | |
2623 | }; | |
2624 | /** | |
5ce522a4 PK |
2625 | * Attaches a custom keydown handler which is run before keys are processed, giving consumers of |
2626 | * xterm.js ultimate control as to what keys should be processed by the terminal and what keys | |
2627 | * should not. | |
2628 | * @param {function} customKeydownHandler The custom KeyboardEvent handler to attach. This is a | |
2629 | * function that takes a KeyboardEvent, allowing consumers to stop propogation and/or prevent | |
2630 | * the default action. The function returns whether the event should be processed by xterm.js. | |
cd70d298 PK |
2631 | */ |
2632 | Terminal.prototype.attachCustomKeydownHandler = function (customKeydownHandler) { | |
2633 | this.customKeydownHandler = customKeydownHandler; | |
2634 | }; | |
2635 | /** | |
5ce522a4 PK |
2636 | * Handle a keydown event |
2637 | * Key Resources: | |
2638 | * - https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent | |
2639 | * @param {KeyboardEvent} ev The keydown event to be handled. | |
cd70d298 PK |
2640 | */ |
2641 | Terminal.prototype.keyDown = function (ev) { | |
2642 | if (this.customKeydownHandler && this.customKeydownHandler(ev) === false) { | |
2643 | return false; | |
2644 | } | |
2645 | if (!this.compositionHelper.keydown.bind(this.compositionHelper)(ev)) { | |
2646 | if (this.ybase !== this.ydisp) { | |
2647 | this.scrollToBottom(); | |
2648 | } | |
2649 | return false; | |
2650 | } | |
2651 | var self = this; | |
2652 | var result = this.evaluateKeyEscapeSequence(ev); | |
2653 | if (result.scrollDisp) { | |
2654 | this.scrollDisp(result.scrollDisp); | |
2655 | return this.cancel(ev, true); | |
2656 | } | |
2657 | if (isThirdLevelShift(this, ev)) { | |
2658 | return true; | |
2659 | } | |
2660 | if (result.cancel) { | |
2661 | // The event is canceled at the end already, is this necessary? | |
2662 | this.cancel(ev, true); | |
2663 | } | |
2664 | if (!result.key) { | |
2665 | return true; | |
2666 | } | |
2667 | this.emit('keydown', ev); | |
2668 | this.emit('key', result.key, ev); | |
2669 | this.showCursor(); | |
2670 | this.handler(result.key); | |
2671 | return this.cancel(ev, true); | |
2672 | }; | |
2673 | /** | |
5ce522a4 PK |
2674 | * Returns an object that determines how a KeyboardEvent should be handled. The key of the |
2675 | * returned value is the new key code to pass to the PTY. | |
2676 | * | |
2677 | * Reference: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html | |
2678 | * @param {KeyboardEvent} ev The keyboard event to be translated to key escape sequence. | |
cd70d298 PK |
2679 | */ |
2680 | Terminal.prototype.evaluateKeyEscapeSequence = function (ev) { | |
2681 | var result = { | |
2682 | // Whether to cancel event propogation (NOTE: this may not be needed since the event is | |
2683 | // canceled at the end of keyDown | |
2684 | cancel: false, | |
2685 | // The new key even to emit | |
2686 | key: undefined, | |
2687 | // The number of characters to scroll, if this is defined it will cancel the event | |
2688 | scrollDisp: undefined | |
2689 | }; | |
2690 | var modifiers = ev.shiftKey << 0 | ev.altKey << 1 | ev.ctrlKey << 2 | ev.metaKey << 3; | |
2691 | switch (ev.keyCode) { | |
2692 | case 8: | |
2693 | // backspace | |
2694 | if (ev.shiftKey) { | |
2695 | result.key = '\x08'; // ^H | |
2696 | break; | |
2697 | } | |
2698 | result.key = '\x7f'; // ^? | |
2699 | break; | |
2700 | case 9: | |
2701 | // tab | |
2702 | if (ev.shiftKey) { | |
2703 | result.key = '\x1b[Z'; | |
2704 | break; | |
2705 | } | |
2706 | result.key = '\t'; | |
2707 | result.cancel = true; | |
2708 | break; | |
2709 | case 13: | |
2710 | // return/enter | |
2711 | result.key = '\r'; | |
2712 | result.cancel = true; | |
2713 | break; | |
2714 | case 27: | |
2715 | // escape | |
2716 | result.key = '\x1b'; | |
2717 | result.cancel = true; | |
2718 | break; | |
2719 | case 37: | |
2720 | // left-arrow | |
2721 | if (modifiers) { | |
2722 | result.key = '\x1b[1;' + (modifiers + 1) + 'D'; | |
2723 | // HACK: Make Alt + left-arrow behave like Ctrl + left-arrow: move one word backwards | |
2724 | // http://unix.stackexchange.com/a/108106 | |
2725 | if (result.key == '\x1b[1;3D') { | |
2726 | result.key = '\x1b[1;5D'; | |
2727 | } | |
2728 | } | |
2729 | else if (this.applicationCursor) { | |
2730 | result.key = '\x1bOD'; | |
2731 | } | |
2732 | else { | |
2733 | result.key = '\x1b[D'; | |
2734 | } | |
2735 | break; | |
2736 | case 39: | |
2737 | // right-arrow | |
2738 | if (modifiers) { | |
2739 | result.key = '\x1b[1;' + (modifiers + 1) + 'C'; | |
2740 | // HACK: Make Alt + right-arrow behave like Ctrl + right-arrow: move one word forward | |
2741 | // http://unix.stackexchange.com/a/108106 | |
2742 | if (result.key == '\x1b[1;3C') { | |
2743 | result.key = '\x1b[1;5C'; | |
2744 | } | |
2745 | } | |
2746 | else if (this.applicationCursor) { | |
2747 | result.key = '\x1bOC'; | |
2748 | } | |
2749 | else { | |
2750 | result.key = '\x1b[C'; | |
2751 | } | |
2752 | break; | |
2753 | case 38: | |
2754 | // up-arrow | |
2755 | if (modifiers) { | |
2756 | result.key = '\x1b[1;' + (modifiers + 1) + 'A'; | |
2757 | // HACK: Make Alt + up-arrow behave like Ctrl + up-arrow | |
2758 | // http://unix.stackexchange.com/a/108106 | |
2759 | if (result.key == '\x1b[1;3A') { | |
2760 | result.key = '\x1b[1;5A'; | |
2761 | } | |
2762 | } | |
2763 | else if (this.applicationCursor) { | |
2764 | result.key = '\x1bOA'; | |
2765 | } | |
2766 | else { | |
2767 | result.key = '\x1b[A'; | |
2768 | } | |
2769 | break; | |
2770 | case 40: | |
2771 | // down-arrow | |
2772 | if (modifiers) { | |
2773 | result.key = '\x1b[1;' + (modifiers + 1) + 'B'; | |
2774 | // HACK: Make Alt + down-arrow behave like Ctrl + down-arrow | |
2775 | // http://unix.stackexchange.com/a/108106 | |
2776 | if (result.key == '\x1b[1;3B') { | |
2777 | result.key = '\x1b[1;5B'; | |
2778 | } | |
2779 | } | |
2780 | else if (this.applicationCursor) { | |
2781 | result.key = '\x1bOB'; | |
2782 | } | |
2783 | else { | |
2784 | result.key = '\x1b[B'; | |
2785 | } | |
2786 | break; | |
2787 | case 45: | |
2788 | // insert | |
2789 | if (!ev.shiftKey && !ev.ctrlKey) { | |
2790 | // <Ctrl> or <Shift> + <Insert> are used to | |
2791 | // copy-paste on some systems. | |
2792 | result.key = '\x1b[2~'; | |
2793 | } | |
2794 | break; | |
2795 | case 46: | |
2796 | // delete | |
2797 | if (modifiers) { | |
2798 | result.key = '\x1b[3;' + (modifiers + 1) + '~'; | |
2799 | } | |
2800 | else { | |
2801 | result.key = '\x1b[3~'; | |
2802 | } | |
2803 | break; | |
2804 | case 36: | |
2805 | // home | |
2806 | if (modifiers) | |
2807 | result.key = '\x1b[1;' + (modifiers + 1) + 'H'; | |
2808 | else if (this.applicationCursor) | |
2809 | result.key = '\x1bOH'; | |
2810 | else | |
2811 | result.key = '\x1b[H'; | |
2812 | break; | |
2813 | case 35: | |
2814 | // end | |
2815 | if (modifiers) | |
2816 | result.key = '\x1b[1;' + (modifiers + 1) + 'F'; | |
2817 | else if (this.applicationCursor) | |
2818 | result.key = '\x1bOF'; | |
2819 | else | |
2820 | result.key = '\x1b[F'; | |
2821 | break; | |
2822 | case 33: | |
2823 | // page up | |
2824 | if (ev.shiftKey) { | |
2825 | result.scrollDisp = -(this.rows - 1); | |
2826 | } | |
2827 | else { | |
2828 | result.key = '\x1b[5~'; | |
2829 | } | |
2830 | break; | |
2831 | case 34: | |
2832 | // page down | |
2833 | if (ev.shiftKey) { | |
2834 | result.scrollDisp = this.rows - 1; | |
2835 | } | |
2836 | else { | |
2837 | result.key = '\x1b[6~'; | |
2838 | } | |
2839 | break; | |
2840 | case 112: | |
2841 | // F1-F12 | |
2842 | if (modifiers) { | |
2843 | result.key = '\x1b[1;' + (modifiers + 1) + 'P'; | |
2844 | } | |
2845 | else { | |
2846 | result.key = '\x1bOP'; | |
2847 | } | |
2848 | break; | |
2849 | case 113: | |
2850 | if (modifiers) { | |
2851 | result.key = '\x1b[1;' + (modifiers + 1) + 'Q'; | |
2852 | } | |
2853 | else { | |
2854 | result.key = '\x1bOQ'; | |
2855 | } | |
2856 | break; | |
2857 | case 114: | |
2858 | if (modifiers) { | |
2859 | result.key = '\x1b[1;' + (modifiers + 1) + 'R'; | |
2860 | } | |
2861 | else { | |
2862 | result.key = '\x1bOR'; | |
2863 | } | |
2864 | break; | |
2865 | case 115: | |
2866 | if (modifiers) { | |
2867 | result.key = '\x1b[1;' + (modifiers + 1) + 'S'; | |
2868 | } | |
2869 | else { | |
2870 | result.key = '\x1bOS'; | |
2871 | } | |
2872 | break; | |
2873 | case 116: | |
2874 | if (modifiers) { | |
2875 | result.key = '\x1b[15;' + (modifiers + 1) + '~'; | |
2876 | } | |
2877 | else { | |
2878 | result.key = '\x1b[15~'; | |
2879 | } | |
2880 | break; | |
2881 | case 117: | |
2882 | if (modifiers) { | |
2883 | result.key = '\x1b[17;' + (modifiers + 1) + '~'; | |
2884 | } | |
2885 | else { | |
2886 | result.key = '\x1b[17~'; | |
2887 | } | |
2888 | break; | |
2889 | case 118: | |
2890 | if (modifiers) { | |
2891 | result.key = '\x1b[18;' + (modifiers + 1) + '~'; | |
2892 | } | |
2893 | else { | |
2894 | result.key = '\x1b[18~'; | |
2895 | } | |
2896 | break; | |
2897 | case 119: | |
2898 | if (modifiers) { | |
2899 | result.key = '\x1b[19;' + (modifiers + 1) + '~'; | |
2900 | } | |
2901 | else { | |
2902 | result.key = '\x1b[19~'; | |
2903 | } | |
2904 | break; | |
2905 | case 120: | |
2906 | if (modifiers) { | |
2907 | result.key = '\x1b[20;' + (modifiers + 1) + '~'; | |
2908 | } | |
2909 | else { | |
2910 | result.key = '\x1b[20~'; | |
2911 | } | |
2912 | break; | |
2913 | case 121: | |
2914 | if (modifiers) { | |
2915 | result.key = '\x1b[21;' + (modifiers + 1) + '~'; | |
2916 | } | |
2917 | else { | |
2918 | result.key = '\x1b[21~'; | |
2919 | } | |
2920 | break; | |
2921 | case 122: | |
2922 | if (modifiers) { | |
2923 | result.key = '\x1b[23;' + (modifiers + 1) + '~'; | |
2924 | } | |
2925 | else { | |
2926 | result.key = '\x1b[23~'; | |
2927 | } | |
2928 | break; | |
2929 | case 123: | |
2930 | if (modifiers) { | |
2931 | result.key = '\x1b[24;' + (modifiers + 1) + '~'; | |
2932 | } | |
2933 | else { | |
2934 | result.key = '\x1b[24~'; | |
2935 | } | |
2936 | break; | |
2937 | default: | |
2938 | // a-z and space | |
2939 | if (ev.ctrlKey && !ev.shiftKey && !ev.altKey && !ev.metaKey) { | |
2940 | if (ev.keyCode >= 65 && ev.keyCode <= 90) { | |
2941 | result.key = String.fromCharCode(ev.keyCode - 64); | |
2942 | } | |
2943 | else if (ev.keyCode === 32) { | |
2944 | // NUL | |
2945 | result.key = String.fromCharCode(0); | |
2946 | } | |
2947 | else if (ev.keyCode >= 51 && ev.keyCode <= 55) { | |
2948 | // escape, file sep, group sep, record sep, unit sep | |
2949 | result.key = String.fromCharCode(ev.keyCode - 51 + 27); | |
2950 | } | |
2951 | else if (ev.keyCode === 56) { | |
2952 | // delete | |
2953 | result.key = String.fromCharCode(127); | |
2954 | } | |
2955 | else if (ev.keyCode === 219) { | |
2956 | // ^[ - Control Sequence Introducer (CSI) | |
2957 | result.key = String.fromCharCode(27); | |
2958 | } | |
2959 | else if (ev.keyCode === 220) { | |
2960 | // ^\ - String Terminator (ST) | |
2961 | result.key = String.fromCharCode(28); | |
2962 | } | |
2963 | else if (ev.keyCode === 221) { | |
2964 | // ^] - Operating System Command (OSC) | |
2965 | result.key = String.fromCharCode(29); | |
2966 | } | |
2967 | } | |
2968 | else if (!this.browser.isMac && ev.altKey && !ev.ctrlKey && !ev.metaKey) { | |
2969 | // On Mac this is a third level shift. Use <Esc> instead. | |
2970 | if (ev.keyCode >= 65 && ev.keyCode <= 90) { | |
2971 | result.key = '\x1b' + String.fromCharCode(ev.keyCode + 32); | |
2972 | } | |
2973 | else if (ev.keyCode === 192) { | |
2974 | result.key = '\x1b`'; | |
2975 | } | |
2976 | else if (ev.keyCode >= 48 && ev.keyCode <= 57) { | |
2977 | result.key = '\x1b' + (ev.keyCode - 48); | |
2978 | } | |
2979 | } | |
2980 | break; | |
2981 | } | |
2982 | return result; | |
2983 | }; | |
2984 | /** | |
5ce522a4 PK |
2985 | * Set the G level of the terminal |
2986 | * @param g | |
cd70d298 PK |
2987 | */ |
2988 | Terminal.prototype.setgLevel = function (g) { | |
2989 | this.glevel = g; | |
2990 | this.charset = this.charsets[g]; | |
2991 | }; | |
2992 | /** | |
5ce522a4 PK |
2993 | * Set the charset for the given G level of the terminal |
2994 | * @param g | |
2995 | * @param charset | |
cd70d298 PK |
2996 | */ |
2997 | Terminal.prototype.setgCharset = function (g, charset) { | |
2998 | this.charsets[g] = charset; | |
2999 | if (this.glevel === g) { | |
3000 | this.charset = charset; | |
3001 | } | |
3002 | }; | |
3003 | /** | |
5ce522a4 PK |
3004 | * Handle a keypress event. |
3005 | * Key Resources: | |
3006 | * - https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent | |
3007 | * @param {KeyboardEvent} ev The keypress event to be handled. | |
cd70d298 PK |
3008 | */ |
3009 | Terminal.prototype.keyPress = function (ev) { | |
3010 | var key; | |
3011 | this.cancel(ev); | |
3012 | if (ev.charCode) { | |
3013 | key = ev.charCode; | |
3014 | } | |
3015 | else if (ev.which == null) { | |
3016 | key = ev.keyCode; | |
3017 | } | |
3018 | else if (ev.which !== 0 && ev.charCode !== 0) { | |
3019 | key = ev.which; | |
3020 | } | |
3021 | else { | |
3022 | return false; | |
3023 | } | |
3024 | if (!key || ((ev.altKey || ev.ctrlKey || ev.metaKey) && !isThirdLevelShift(this, ev))) { | |
3025 | return false; | |
3026 | } | |
3027 | key = String.fromCharCode(key); | |
3028 | this.emit('keypress', key, ev); | |
3029 | this.emit('key', key, ev); | |
3030 | this.showCursor(); | |
3031 | this.handler(key); | |
3032 | return false; | |
3033 | }; | |
3034 | /** | |
5ce522a4 PK |
3035 | * Send data for handling to the terminal |
3036 | * @param {string} data | |
cd70d298 PK |
3037 | */ |
3038 | Terminal.prototype.send = function (data) { | |
3039 | var self = this; | |
3040 | if (!this.queue) { | |
3041 | setTimeout(function () { | |
3042 | self.handler(self.queue); | |
3043 | self.queue = ''; | |
3044 | }, 1); | |
3045 | } | |
3046 | this.queue += data; | |
3047 | }; | |
3048 | /** | |
5ce522a4 PK |
3049 | * Ring the bell. |
3050 | * Note: We could do sweet things with webaudio here | |
cd70d298 PK |
3051 | */ |
3052 | Terminal.prototype.bell = function () { | |
3053 | if (!this.visualBell) | |
3054 | return; | |
3055 | var self = this; | |
3056 | this.element.style.borderColor = 'white'; | |
3057 | setTimeout(function () { | |
3058 | self.element.style.borderColor = ''; | |
3059 | }, 10); | |
3060 | if (this.popOnBell) | |
3061 | this.focus(); | |
3062 | }; | |
3063 | /** | |
5ce522a4 | 3064 | * Log the current state to the console. |
cd70d298 PK |
3065 | */ |
3066 | Terminal.prototype.log = function () { | |
3067 | if (!this.debug) | |
3068 | return; | |
3069 | if (!this.context.console || !this.context.console.log) | |
3070 | return; | |
3071 | var args = Array.prototype.slice.call(arguments); | |
3072 | this.context.console.log.apply(this.context.console, args); | |
3073 | }; | |
3074 | /** | |
5ce522a4 | 3075 | * Log the current state as error to the console. |
cd70d298 PK |
3076 | */ |
3077 | Terminal.prototype.error = function () { | |
3078 | if (!this.debug) | |
3079 | return; | |
3080 | if (!this.context.console || !this.context.console.error) | |
3081 | return; | |
3082 | var args = Array.prototype.slice.call(arguments); | |
3083 | this.context.console.error.apply(this.context.console, args); | |
3084 | }; | |
3085 | /** | |
5ce522a4 PK |
3086 | * Resizes the terminal. |
3087 | * | |
3088 | * @param {number} x The number of columns to resize to. | |
3089 | * @param {number} y The number of rows to resize to. | |
cd70d298 PK |
3090 | */ |
3091 | Terminal.prototype.resize = function (x, y) { | |
3092 | var line, el, i, j, ch, addToY; | |
3093 | if (x === this.cols && y === this.rows) { | |
3094 | return; | |
3095 | } | |
3096 | if (x < 1) | |
3097 | x = 1; | |
3098 | if (y < 1) | |
3099 | y = 1; | |
3100 | // resize cols | |
3101 | j = this.cols; | |
3102 | if (j < x) { | |
3103 | ch = [this.defAttr, ' ', 1]; // does xterm use the default attr? | |
3104 | i = this.lines.length; | |
3105 | while (i--) { | |
3106 | while (this.lines[i].length < x) { | |
3107 | this.lines[i].push(ch); | |
3108 | } | |
3109 | } | |
3110 | } | |
3111 | else { | |
3112 | i = this.lines.length; | |
3113 | while (i--) { | |
3114 | while (this.lines[i].length > x) { | |
3115 | this.lines[i].pop(); | |
3116 | } | |
3117 | } | |
3118 | } | |
3119 | this.setupStops(j); | |
3120 | this.cols = x; | |
3121 | // resize rows | |
3122 | j = this.rows; | |
3123 | addToY = 0; | |
3124 | if (j < y) { | |
3125 | el = this.element; | |
3126 | while (j++ < y) { | |
3127 | // y is rows, not this.y | |
3128 | if (this.lines.length < y + this.ybase) { | |
3129 | if (this.ybase > 0 && this.lines.length <= this.ybase + this.y + addToY + 1) { | |
3130 | // There is room above the buffer and there are no empty elements below the line, | |
3131 | // scroll up | |
3132 | this.ybase--; | |
3133 | addToY++; | |
3134 | if (this.ydisp > 0) { | |
3135 | // Viewport is at the top of the buffer, must increase downwards | |
3136 | this.ydisp--; | |
3137 | } | |
3138 | } | |
3139 | else { | |
3140 | // Add a blank line if there is no buffer left at the top to scroll to, or if there | |
3141 | // are blank lines after the cursor | |
3142 | this.lines.push(this.blankLine()); | |
3143 | } | |
3144 | } | |
3145 | if (this.children.length < y) { | |
3146 | this.insertRow(); | |
3147 | } | |
3148 | } | |
3149 | } | |
3150 | else { | |
3151 | while (j-- > y) { | |
3152 | if (this.lines.length > y + this.ybase) { | |
3153 | if (this.lines.length > this.ybase + this.y + 1) { | |
3154 | // The line is a blank line below the cursor, remove it | |
3155 | this.lines.pop(); | |
3156 | } | |
3157 | else { | |
3158 | // The line is the cursor, scroll down | |
3159 | this.ybase++; | |
3160 | this.ydisp++; | |
3161 | } | |
3162 | } | |
3163 | if (this.children.length > y) { | |
3164 | el = this.children.shift(); | |
3165 | if (!el) | |
3166 | continue; | |
3167 | el.parentNode.removeChild(el); | |
3168 | } | |
3169 | } | |
3170 | } | |
3171 | this.rows = y; | |
3172 | // Make sure that the cursor stays on screen | |
3173 | if (this.y >= y) { | |
3174 | this.y = y - 1; | |
3175 | } | |
3176 | if (addToY) { | |
3177 | this.y += addToY; | |
3178 | } | |
3179 | if (this.x >= x) { | |
3180 | this.x = x - 1; | |
3181 | } | |
3182 | this.scrollTop = 0; | |
3183 | this.scrollBottom = y - 1; | |
3184 | this.refresh(0, this.rows - 1); | |
3185 | this.normal = null; | |
3186 | this.geometry = [this.cols, this.rows]; | |
3187 | this.emit('resize', { terminal: this, cols: x, rows: y }); | |
3188 | }; | |
3189 | /** | |
5ce522a4 PK |
3190 | * Updates the range of rows to refresh |
3191 | * @param {number} y The number of rows to refresh next. | |
cd70d298 PK |
3192 | */ |
3193 | Terminal.prototype.updateRange = function (y) { | |
3194 | if (y < this.refreshStart) | |
3195 | this.refreshStart = y; | |
3196 | if (y > this.refreshEnd) | |
3197 | this.refreshEnd = y; | |
3198 | // if (y > this.refreshEnd) { | |
3199 | // this.refreshEnd = y; | |
3200 | // if (y > this.rows - 1) { | |
3201 | // this.refreshEnd = this.rows - 1; | |
3202 | // } | |
3203 | // } | |
3204 | }; | |
3205 | /** | |
521d7dbd | 3206 | * Set the range of refreshing to the maximum value |
cd70d298 PK |
3207 | */ |
3208 | Terminal.prototype.maxRange = function () { | |
3209 | this.refreshStart = 0; | |
3210 | this.refreshEnd = this.rows - 1; | |
3211 | }; | |
3212 | /** | |
5ce522a4 PK |
3213 | * Setup the tab stops. |
3214 | * @param {number} i | |
cd70d298 PK |
3215 | */ |
3216 | Terminal.prototype.setupStops = function (i) { | |
3217 | if (i != null) { | |
3218 | if (!this.tabs[i]) { | |
3219 | i = this.prevStop(i); | |
3220 | } | |
3221 | } | |
3222 | else { | |
3223 | this.tabs = {}; | |
3224 | i = 0; | |
3225 | } | |
3226 | for (; i < this.cols; i += 8) { | |
3227 | this.tabs[i] = true; | |
3228 | } | |
3229 | }; | |
3230 | /** | |
5ce522a4 PK |
3231 | * Move the cursor to the previous tab stop from the given position (default is current). |
3232 | * @param {number} x The position to move the cursor to the previous tab stop. | |
cd70d298 PK |
3233 | */ |
3234 | Terminal.prototype.prevStop = function (x) { | |
3235 | if (x == null) | |
3236 | x = this.x; | |
3237 | while (!this.tabs[--x] && x > 0) | |
3238 | ; | |
3239 | return x >= this.cols | |
3240 | ? this.cols - 1 | |
3241 | : x < 0 ? 0 : x; | |
3242 | }; | |
3243 | /** | |
5ce522a4 PK |
3244 | * Move the cursor one tab stop forward from the given position (default is current). |
3245 | * @param {number} x The position to move the cursor one tab stop forward. | |
cd70d298 PK |
3246 | */ |
3247 | Terminal.prototype.nextStop = function (x) { | |
3248 | if (x == null) | |
3249 | x = this.x; | |
3250 | while (!this.tabs[++x] && x < this.cols) | |
3251 | ; | |
3252 | return x >= this.cols | |
3253 | ? this.cols - 1 | |
3254 | : x < 0 ? 0 : x; | |
3255 | }; | |
3256 | /** | |
5ce522a4 PK |
3257 | * Erase in the identified line everything from "x" to the end of the line (right). |
3258 | * @param {number} x The column from which to start erasing to the end of the line. | |
3259 | * @param {number} y The line in which to operate. | |
cd70d298 PK |
3260 | */ |
3261 | Terminal.prototype.eraseRight = function (x, y) { | |
3262 | var line = this.lines[this.ybase + y], ch = [this.eraseAttr(), ' ', 1]; // xterm | |
3263 | for (; x < this.cols; x++) { | |
3264 | line[x] = ch; | |
3265 | } | |
3266 | this.updateRange(y); | |
3267 | }; | |
3268 | /** | |
5ce522a4 PK |
3269 | * Erase in the identified line everything from "x" to the start of the line (left). |
3270 | * @param {number} x The column from which to start erasing to the start of the line. | |
3271 | * @param {number} y The line in which to operate. | |
cd70d298 PK |
3272 | */ |
3273 | Terminal.prototype.eraseLeft = function (x, y) { | |
3274 | var line = this.lines[this.ybase + y], ch = [this.eraseAttr(), ' ', 1]; // xterm | |
3275 | x++; | |
3276 | while (x--) | |
3277 | line[x] = ch; | |
3278 | this.updateRange(y); | |
3279 | }; | |
3280 | /** | |
5ce522a4 | 3281 | * Clears the entire buffer, making the prompt line the new first line. |
cd70d298 PK |
3282 | */ |
3283 | Terminal.prototype.clear = function () { | |
3284 | if (this.ybase === 0 && this.y === 0) { | |
3285 | // Don't clear if it's already clear | |
3286 | return; | |
3287 | } | |
3288 | this.lines = [this.lines[this.ybase + this.y]]; | |
3289 | this.ydisp = 0; | |
3290 | this.ybase = 0; | |
3291 | this.y = 0; | |
3292 | for (var i = 1; i < this.rows; i++) { | |
3293 | this.lines.push(this.blankLine()); | |
3294 | } | |
3295 | this.refresh(0, this.rows - 1); | |
3296 | this.emit('scroll', this.ydisp); | |
3297 | }; | |
3298 | /** | |
5ce522a4 PK |
3299 | * Erase all content in the given line |
3300 | * @param {number} y The line to erase all of its contents. | |
cd70d298 PK |
3301 | */ |
3302 | Terminal.prototype.eraseLine = function (y) { | |
3303 | this.eraseRight(0, y); | |
3304 | }; | |
3305 | /** | |
5ce522a4 PK |
3306 | * Return the data array of a blank line/ |
3307 | * @param {number} cur First bunch of data for each "blank" character. | |
cd70d298 PK |
3308 | */ |
3309 | Terminal.prototype.blankLine = function (cur) { | |
3310 | var attr = cur | |
3311 | ? this.eraseAttr() | |
3312 | : this.defAttr; | |
3313 | var ch = [attr, ' ', 1] // width defaults to 1 halfwidth character | |
3314 | , line = [], i = 0; | |
3315 | for (; i < this.cols; i++) { | |
3316 | line[i] = ch; | |
3317 | } | |
3318 | return line; | |
3319 | }; | |
3320 | /** | |
5ce522a4 PK |
3321 | * If cur return the back color xterm feature attribute. Else return defAttr. |
3322 | * @param {object} cur | |
cd70d298 PK |
3323 | */ |
3324 | Terminal.prototype.ch = function (cur) { | |
3325 | return cur | |
3326 | ? [this.eraseAttr(), ' ', 1] | |
3327 | : [this.defAttr, ' ', 1]; | |
3328 | }; | |
3329 | /** | |
5ce522a4 PK |
3330 | * Evaluate if the current erminal is the given argument. |
3331 | * @param {object} term The terminal to evaluate | |
cd70d298 PK |
3332 | */ |
3333 | Terminal.prototype.is = function (term) { | |
3334 | var name = this.termName; | |
3335 | return (name + '').indexOf(term) === 0; | |
3336 | }; | |
3337 | /** | |
521d7dbd PK |
3338 | * Emit the 'data' event and populate the given data. |
3339 | * @param {string} data The data to populate in the event. | |
cd70d298 PK |
3340 | */ |
3341 | Terminal.prototype.handler = function (data) { | |
3342 | // Input is being sent to the terminal, the terminal should focus the prompt. | |
3343 | if (this.ybase !== this.ydisp) { | |
3344 | this.scrollToBottom(); | |
3345 | } | |
3346 | this.emit('data', data); | |
3347 | }; | |
3348 | /** | |
5ce522a4 PK |
3349 | * Emit the 'title' event and populate the given title. |
3350 | * @param {string} title The title to populate in the event. | |
cd70d298 PK |
3351 | */ |
3352 | Terminal.prototype.handleTitle = function (title) { | |
3353 | /** | |
3354 | * This event is emitted when the title of the terminal is changed | |
3355 | * from inside the terminal. The parameter is the new title. | |
3356 | * | |
3357 | * @event title | |
3358 | */ | |
3359 | this.emit('title', title); | |
3360 | }; | |
3361 | /** | |
5ce522a4 | 3362 | * ESC |
cd70d298 PK |
3363 | */ |
3364 | /** | |
5ce522a4 | 3365 | * ESC D Index (IND is 0x84). |
cd70d298 PK |
3366 | */ |
3367 | Terminal.prototype.index = function () { | |
3368 | this.y++; | |
3369 | if (this.y > this.scrollBottom) { | |
3370 | this.y--; | |
3371 | this.scroll(); | |
3372 | } | |
3373 | this.state = normal; | |
3374 | }; | |
3375 | /** | |
5ce522a4 | 3376 | * ESC M Reverse Index (RI is 0x8d). |
cd70d298 PK |
3377 | */ |
3378 | Terminal.prototype.reverseIndex = function () { | |
3379 | var j; | |
3380 | this.y--; | |
3381 | if (this.y < this.scrollTop) { | |
3382 | this.y++; | |
3383 | // possibly move the code below to term.reverseScroll(); | |
3384 | // test: echo -ne '\e[1;1H\e[44m\eM\e[0m' | |
3385 | // blankLine(true) is xterm/linux behavior | |
3386 | this.lines.splice(this.y + this.ybase, 0, this.blankLine(true)); | |
3387 | j = this.rows - 1 - this.scrollBottom; | |
3388 | this.lines.splice(this.rows - 1 + this.ybase - j + 1, 1); | |
3389 | // this.maxRange(); | |
3390 | this.updateRange(this.scrollTop); | |
3391 | this.updateRange(this.scrollBottom); | |
3392 | } | |
3393 | this.state = normal; | |
3394 | }; | |
3395 | /** | |
5ce522a4 | 3396 | * ESC c Full Reset (RIS). |
cd70d298 PK |
3397 | */ |
3398 | Terminal.prototype.reset = function () { | |
3399 | this.options.rows = this.rows; | |
3400 | this.options.cols = this.cols; | |
3401 | var customKeydownHandler = this.customKeydownHandler; | |
3402 | Terminal.call(this, this.options); | |
3403 | this.customKeydownHandler = customKeydownHandler; | |
3404 | this.refresh(0, this.rows - 1); | |
3405 | this.viewport.syncScrollArea(); | |
3406 | }; | |
3407 | /** | |
5ce522a4 | 3408 | * ESC H Tab Set (HTS is 0x88). |
cd70d298 PK |
3409 | */ |
3410 | Terminal.prototype.tabSet = function () { | |
3411 | this.tabs[this.x] = true; | |
3412 | this.state = normal; | |
3413 | }; | |
3414 | /** | |
5ce522a4 | 3415 | * CSI |
cd70d298 PK |
3416 | */ |
3417 | /** | |
5ce522a4 PK |
3418 | * CSI Ps A |
3419 | * Cursor Up Ps Times (default = 1) (CUU). | |
cd70d298 PK |
3420 | */ |
3421 | Terminal.prototype.cursorUp = function (params) { | |
3422 | var param = params[0]; | |
3423 | if (param < 1) | |
3424 | param = 1; | |
3425 | this.y -= param; | |
3426 | if (this.y < 0) | |
3427 | this.y = 0; | |
3428 | }; | |
3429 | /** | |
5ce522a4 PK |
3430 | * CSI Ps B |
3431 | * Cursor Down Ps Times (default = 1) (CUD). | |
cd70d298 PK |
3432 | */ |
3433 | Terminal.prototype.cursorDown = function (params) { | |
3434 | var param = params[0]; | |
3435 | if (param < 1) | |
3436 | param = 1; | |
3437 | this.y += param; | |
3438 | if (this.y >= this.rows) { | |
3439 | this.y = this.rows - 1; | |
3440 | } | |
3441 | }; | |
3442 | /** | |
5ce522a4 PK |
3443 | * CSI Ps C |
3444 | * Cursor Forward Ps Times (default = 1) (CUF). | |
cd70d298 PK |
3445 | */ |
3446 | Terminal.prototype.cursorForward = function (params) { | |
3447 | var param = params[0]; | |
3448 | if (param < 1) | |
3449 | param = 1; | |
3450 | this.x += param; | |
3451 | if (this.x >= this.cols) { | |
3452 | this.x = this.cols - 1; | |
3453 | } | |
3454 | }; | |
3455 | /** | |
5ce522a4 PK |
3456 | * CSI Ps D |
3457 | * Cursor Backward Ps Times (default = 1) (CUB). | |
cd70d298 PK |
3458 | */ |
3459 | Terminal.prototype.cursorBackward = function (params) { | |
3460 | var param = params[0]; | |
3461 | if (param < 1) | |
3462 | param = 1; | |
3463 | this.x -= param; | |
3464 | if (this.x < 0) | |
3465 | this.x = 0; | |
3466 | }; | |
3467 | /** | |
5ce522a4 PK |
3468 | * CSI Ps ; Ps H |
3469 | * Cursor Position [row;column] (default = [1,1]) (CUP). | |
cd70d298 PK |
3470 | */ |
3471 | Terminal.prototype.cursorPos = function (params) { | |
3472 | var row, col; | |
3473 | row = params[0] - 1; | |
3474 | if (params.length >= 2) { | |
3475 | col = params[1] - 1; | |
3476 | } | |
3477 | else { | |
3478 | col = 0; | |
3479 | } | |
3480 | if (row < 0) { | |
3481 | row = 0; | |
3482 | } | |
3483 | else if (row >= this.rows) { | |
3484 | row = this.rows - 1; | |
3485 | } | |
3486 | if (col < 0) { | |
3487 | col = 0; | |
3488 | } | |
3489 | else if (col >= this.cols) { | |
3490 | col = this.cols - 1; | |
3491 | } | |
3492 | this.x = col; | |
3493 | this.y = row; | |
3494 | }; | |
3495 | /** | |
5ce522a4 PK |
3496 | * CSI Ps J Erase in Display (ED). |
3497 | * Ps = 0 -> Erase Below (default). | |
3498 | * Ps = 1 -> Erase Above. | |
3499 | * Ps = 2 -> Erase All. | |
3500 | * Ps = 3 -> Erase Saved Lines (xterm). | |
3501 | * CSI ? Ps J | |
3502 | * Erase in Display (DECSED). | |
3503 | * Ps = 0 -> Selective Erase Below (default). | |
3504 | * Ps = 1 -> Selective Erase Above. | |
3505 | * Ps = 2 -> Selective Erase All. | |
cd70d298 PK |
3506 | */ |
3507 | Terminal.prototype.eraseInDisplay = function (params) { | |
3508 | var j; | |
3509 | switch (params[0]) { | |
3510 | case 0: | |
3511 | this.eraseRight(this.x, this.y); | |
3512 | j = this.y + 1; | |
3513 | for (; j < this.rows; j++) { | |
3514 | this.eraseLine(j); | |
3515 | } | |
3516 | break; | |
3517 | case 1: | |
3518 | this.eraseLeft(this.x, this.y); | |
3519 | j = this.y; | |
3520 | while (j--) { | |
3521 | this.eraseLine(j); | |
3522 | } | |
3523 | break; | |
3524 | case 2: | |
3525 | j = this.rows; | |
3526 | while (j--) | |
3527 | this.eraseLine(j); | |
3528 | break; | |
3529 | case 3: | |
3530 | ; // no saved lines | |
3531 | break; | |
3532 | } | |
3533 | }; | |
3534 | /** | |
5ce522a4 PK |
3535 | * CSI Ps K Erase in Line (EL). |
3536 | * Ps = 0 -> Erase to Right (default). | |
3537 | * Ps = 1 -> Erase to Left. | |
3538 | * Ps = 2 -> Erase All. | |
3539 | * CSI ? Ps K | |
3540 | * Erase in Line (DECSEL). | |
3541 | * Ps = 0 -> Selective Erase to Right (default). | |
3542 | * Ps = 1 -> Selective Erase to Left. | |
3543 | * Ps = 2 -> Selective Erase All. | |
cd70d298 PK |
3544 | */ |
3545 | Terminal.prototype.eraseInLine = function (params) { | |
3546 | switch (params[0]) { | |
3547 | case 0: | |
3548 | this.eraseRight(this.x, this.y); | |
3549 | break; | |
3550 | case 1: | |
3551 | this.eraseLeft(this.x, this.y); | |
3552 | break; | |
3553 | case 2: | |
3554 | this.eraseLine(this.y); | |
3555 | break; | |
3556 | } | |
3557 | }; | |
3558 | /** | |
5ce522a4 PK |
3559 | * CSI Pm m Character Attributes (SGR). |
3560 | * Ps = 0 -> Normal (default). | |
3561 | * Ps = 1 -> Bold. | |
3562 | * Ps = 4 -> Underlined. | |
3563 | * Ps = 5 -> Blink (appears as Bold). | |
3564 | * Ps = 7 -> Inverse. | |
3565 | * Ps = 8 -> Invisible, i.e., hidden (VT300). | |
3566 | * Ps = 2 2 -> Normal (neither bold nor faint). | |
3567 | * Ps = 2 4 -> Not underlined. | |
3568 | * Ps = 2 5 -> Steady (not blinking). | |
3569 | * Ps = 2 7 -> Positive (not inverse). | |
3570 | * Ps = 2 8 -> Visible, i.e., not hidden (VT300). | |
3571 | * Ps = 3 0 -> Set foreground color to Black. | |
3572 | * Ps = 3 1 -> Set foreground color to Red. | |
3573 | * Ps = 3 2 -> Set foreground color to Green. | |
3574 | * Ps = 3 3 -> Set foreground color to Yellow. | |
3575 | * Ps = 3 4 -> Set foreground color to Blue. | |
3576 | * Ps = 3 5 -> Set foreground color to Magenta. | |
3577 | * Ps = 3 6 -> Set foreground color to Cyan. | |
3578 | * Ps = 3 7 -> Set foreground color to White. | |
3579 | * Ps = 3 9 -> Set foreground color to default (original). | |
3580 | * Ps = 4 0 -> Set background color to Black. | |
3581 | * Ps = 4 1 -> Set background color to Red. | |
3582 | * Ps = 4 2 -> Set background color to Green. | |
3583 | * Ps = 4 3 -> Set background color to Yellow. | |
3584 | * Ps = 4 4 -> Set background color to Blue. | |
3585 | * Ps = 4 5 -> Set background color to Magenta. | |
3586 | * Ps = 4 6 -> Set background color to Cyan. | |
3587 | * Ps = 4 7 -> Set background color to White. | |
3588 | * Ps = 4 9 -> Set background color to default (original). | |
3589 | * | |
3590 | * If 16-color support is compiled, the following apply. Assume | |
3591 | * that xterm's resources are set so that the ISO color codes are | |
3592 | * the first 8 of a set of 16. Then the aixterm colors are the | |
3593 | * bright versions of the ISO colors: | |
3594 | * Ps = 9 0 -> Set foreground color to Black. | |
3595 | * Ps = 9 1 -> Set foreground color to Red. | |
3596 | * Ps = 9 2 -> Set foreground color to Green. | |
3597 | * Ps = 9 3 -> Set foreground color to Yellow. | |
3598 | * Ps = 9 4 -> Set foreground color to Blue. | |
3599 | * Ps = 9 5 -> Set foreground color to Magenta. | |
3600 | * Ps = 9 6 -> Set foreground color to Cyan. | |
3601 | * Ps = 9 7 -> Set foreground color to White. | |
3602 | * Ps = 1 0 0 -> Set background color to Black. | |
3603 | * Ps = 1 0 1 -> Set background color to Red. | |
3604 | * Ps = 1 0 2 -> Set background color to Green. | |
3605 | * Ps = 1 0 3 -> Set background color to Yellow. | |
3606 | * Ps = 1 0 4 -> Set background color to Blue. | |
3607 | * Ps = 1 0 5 -> Set background color to Magenta. | |
3608 | * Ps = 1 0 6 -> Set background color to Cyan. | |
3609 | * Ps = 1 0 7 -> Set background color to White. | |
3610 | * | |
3611 | * If xterm is compiled with the 16-color support disabled, it | |
3612 | * supports the following, from rxvt: | |
3613 | * Ps = 1 0 0 -> Set foreground and background color to | |
3614 | * default. | |
3615 | * | |
3616 | * If 88- or 256-color support is compiled, the following apply. | |
3617 | * Ps = 3 8 ; 5 ; Ps -> Set foreground color to the second | |
3618 | * Ps. | |
3619 | * Ps = 4 8 ; 5 ; Ps -> Set background color to the second | |
3620 | * Ps. | |
cd70d298 PK |
3621 | */ |
3622 | Terminal.prototype.charAttributes = function (params) { | |
3623 | // Optimize a single SGR0. | |
3624 | if (params.length === 1 && params[0] === 0) { | |
3625 | this.curAttr = this.defAttr; | |
3626 | return; | |
3627 | } | |
3628 | var l = params.length, i = 0, flags = this.curAttr >> 18, fg = (this.curAttr >> 9) & 0x1ff, bg = this.curAttr & 0x1ff, p; | |
3629 | for (; i < l; i++) { | |
3630 | p = params[i]; | |
3631 | if (p >= 30 && p <= 37) { | |
3632 | // fg color 8 | |
3633 | fg = p - 30; | |
3634 | } | |
3635 | else if (p >= 40 && p <= 47) { | |
3636 | // bg color 8 | |
3637 | bg = p - 40; | |
3638 | } | |
3639 | else if (p >= 90 && p <= 97) { | |
3640 | // fg color 16 | |
3641 | p += 8; | |
3642 | fg = p - 90; | |
3643 | } | |
3644 | else if (p >= 100 && p <= 107) { | |
3645 | // bg color 16 | |
3646 | p += 8; | |
3647 | bg = p - 100; | |
3648 | } | |
3649 | else if (p === 0) { | |
3650 | // default | |
3651 | flags = this.defAttr >> 18; | |
3652 | fg = (this.defAttr >> 9) & 0x1ff; | |
3653 | bg = this.defAttr & 0x1ff; | |
3654 | } | |
3655 | else if (p === 1) { | |
3656 | // bold text | |
3657 | flags |= 1; | |
3658 | } | |
3659 | else if (p === 4) { | |
3660 | // underlined text | |
3661 | flags |= 2; | |
3662 | } | |
3663 | else if (p === 5) { | |
3664 | // blink | |
3665 | flags |= 4; | |
3666 | } | |
3667 | else if (p === 7) { | |
3668 | // inverse and positive | |
3669 | // test with: echo -e '\e[31m\e[42mhello\e[7mworld\e[27mhi\e[m' | |
3670 | flags |= 8; | |
3671 | } | |
3672 | else if (p === 8) { | |
3673 | // invisible | |
3674 | flags |= 16; | |
3675 | } | |
3676 | else if (p === 22) { | |
3677 | // not bold | |
3678 | flags &= ~1; | |
3679 | } | |
3680 | else if (p === 24) { | |
3681 | // not underlined | |
3682 | flags &= ~2; | |
3683 | } | |
3684 | else if (p === 25) { | |
3685 | // not blink | |
3686 | flags &= ~4; | |
3687 | } | |
3688 | else if (p === 27) { | |
3689 | // not inverse | |
3690 | flags &= ~8; | |
3691 | } | |
3692 | else if (p === 28) { | |
3693 | // not invisible | |
3694 | flags &= ~16; | |
3695 | } | |
3696 | else if (p === 39) { | |
3697 | // reset fg | |
3698 | fg = (this.defAttr >> 9) & 0x1ff; | |
3699 | } | |
3700 | else if (p === 49) { | |
3701 | // reset bg | |
3702 | bg = this.defAttr & 0x1ff; | |
3703 | } | |
3704 | else if (p === 38) { | |
3705 | // fg color 256 | |
3706 | if (params[i + 1] === 2) { | |
3707 | i += 2; | |
3708 | fg = matchColor(params[i] & 0xff, params[i + 1] & 0xff, params[i + 2] & 0xff); | |
3709 | if (fg === -1) | |
3710 | fg = 0x1ff; | |
3711 | i += 2; | |
3712 | } | |
3713 | else if (params[i + 1] === 5) { | |
3714 | i += 2; | |
3715 | p = params[i] & 0xff; | |
3716 | fg = p; | |
3717 | } | |
3718 | } | |
3719 | else if (p === 48) { | |
3720 | // bg color 256 | |
3721 | if (params[i + 1] === 2) { | |
3722 | i += 2; | |
3723 | bg = matchColor(params[i] & 0xff, params[i + 1] & 0xff, params[i + 2] & 0xff); | |
3724 | if (bg === -1) | |
3725 | bg = 0x1ff; | |
3726 | i += 2; | |
3727 | } | |
3728 | else if (params[i + 1] === 5) { | |
3729 | i += 2; | |
3730 | p = params[i] & 0xff; | |
3731 | bg = p; | |
3732 | } | |
3733 | } | |
3734 | else if (p === 100) { | |
3735 | // reset fg/bg | |
3736 | fg = (this.defAttr >> 9) & 0x1ff; | |
3737 | bg = this.defAttr & 0x1ff; | |
3738 | } | |
3739 | else { | |
3740 | this.error('Unknown SGR attribute: %d.', p); | |
3741 | } | |
3742 | } | |
3743 | this.curAttr = (flags << 18) | (fg << 9) | bg; | |
3744 | }; | |
3745 | /** | |
5ce522a4 PK |
3746 | * CSI Ps n Device Status Report (DSR). |
3747 | * Ps = 5 -> Status Report. Result (``OK'') is | |
3748 | * CSI 0 n | |
3749 | * Ps = 6 -> Report Cursor Position (CPR) [row;column]. | |
3750 | * Result is | |
3751 | * CSI r ; c R | |
3752 | * CSI ? Ps n | |
3753 | * Device Status Report (DSR, DEC-specific). | |
3754 | * Ps = 6 -> Report Cursor Position (CPR) [row;column] as CSI | |
3755 | * ? r ; c R (assumes page is zero). | |
3756 | * Ps = 1 5 -> Report Printer status as CSI ? 1 0 n (ready). | |
3757 | * or CSI ? 1 1 n (not ready). | |
3758 | * Ps = 2 5 -> Report UDK status as CSI ? 2 0 n (unlocked) | |
3759 | * or CSI ? 2 1 n (locked). | |
3760 | * Ps = 2 6 -> Report Keyboard status as | |
3761 | * CSI ? 2 7 ; 1 ; 0 ; 0 n (North American). | |
3762 | * The last two parameters apply to VT400 & up, and denote key- | |
3763 | * board ready and LK01 respectively. | |
3764 | * Ps = 5 3 -> Report Locator status as | |
3765 | * CSI ? 5 3 n Locator available, if compiled-in, or | |
3766 | * CSI ? 5 0 n No Locator, if not. | |
cd70d298 PK |
3767 | */ |
3768 | Terminal.prototype.deviceStatus = function (params) { | |
3769 | if (!this.prefix) { | |
3770 | switch (params[0]) { | |
3771 | case 5: | |
3772 | // status report | |
3773 | this.send('\x1b[0n'); | |
3774 | break; | |
3775 | case 6: | |
3776 | // cursor position | |
3777 | this.send('\x1b[' | |
3778 | + (this.y + 1) | |
3779 | + ';' | |
3780 | + (this.x + 1) | |
3781 | + 'R'); | |
3782 | break; | |
3783 | } | |
3784 | } | |
3785 | else if (this.prefix === '?') { | |
3786 | // modern xterm doesnt seem to | |
3787 | // respond to any of these except ?6, 6, and 5 | |
3788 | switch (params[0]) { | |
3789 | case 6: | |
3790 | // cursor position | |
3791 | this.send('\x1b[?' | |
3792 | + (this.y + 1) | |
3793 | + ';' | |
3794 | + (this.x + 1) | |
3795 | + 'R'); | |
3796 | break; | |
3797 | case 15: | |
3798 | // no printer | |
3799 | // this.send('\x1b[?11n'); | |
3800 | break; | |
3801 | case 25: | |
3802 | // dont support user defined keys | |
3803 | // this.send('\x1b[?21n'); | |
3804 | break; | |
3805 | case 26: | |
3806 | // north american keyboard | |
3807 | // this.send('\x1b[?27;1;0;0n'); | |
3808 | break; | |
3809 | case 53: | |
3810 | // no dec locator/mouse | |
3811 | // this.send('\x1b[?50n'); | |
3812 | break; | |
3813 | } | |
3814 | } | |
3815 | }; | |
3816 | /** | |
5ce522a4 | 3817 | * Additions |
cd70d298 PK |
3818 | */ |
3819 | /** | |
5ce522a4 PK |
3820 | * CSI Ps @ |
3821 | * Insert Ps (Blank) Character(s) (default = 1) (ICH). | |
cd70d298 PK |
3822 | */ |
3823 | Terminal.prototype.insertChars = function (params) { | |
3824 | var param, row, j, ch; | |
3825 | param = params[0]; | |
3826 | if (param < 1) | |
3827 | param = 1; | |
3828 | row = this.y + this.ybase; | |
3829 | j = this.x; | |
3830 | ch = [this.eraseAttr(), ' ', 1]; // xterm | |
3831 | while (param-- && j < this.cols) { | |
3832 | this.lines[row].splice(j++, 0, ch); | |
3833 | this.lines[row].pop(); | |
3834 | } | |
3835 | }; | |
3836 | /** | |
5ce522a4 PK |
3837 | * CSI Ps E |
3838 | * Cursor Next Line Ps Times (default = 1) (CNL). | |
3839 | * same as CSI Ps B ? | |
cd70d298 PK |
3840 | */ |
3841 | Terminal.prototype.cursorNextLine = function (params) { | |
3842 | var param = params[0]; | |
3843 | if (param < 1) | |
3844 | param = 1; | |
3845 | this.y += param; | |
3846 | if (this.y >= this.rows) { | |
3847 | this.y = this.rows - 1; | |
3848 | } | |
3849 | this.x = 0; | |
3850 | }; | |
3851 | /** | |
5ce522a4 PK |
3852 | * CSI Ps F |
3853 | * Cursor Preceding Line Ps Times (default = 1) (CNL). | |
3854 | * reuse CSI Ps A ? | |
cd70d298 PK |
3855 | */ |
3856 | Terminal.prototype.cursorPrecedingLine = function (params) { | |
3857 | var param = params[0]; | |
3858 | if (param < 1) | |
3859 | param = 1; | |
3860 | this.y -= param; | |
3861 | if (this.y < 0) | |
3862 | this.y = 0; | |
3863 | this.x = 0; | |
3864 | }; | |
3865 | /** | |
5ce522a4 PK |
3866 | * CSI Ps G |
3867 | * Cursor Character Absolute [column] (default = [row,1]) (CHA). | |
cd70d298 PK |
3868 | */ |
3869 | Terminal.prototype.cursorCharAbsolute = function (params) { | |
3870 | var param = params[0]; | |
3871 | if (param < 1) | |
3872 | param = 1; | |
3873 | this.x = param - 1; | |
3874 | }; | |
3875 | /** | |
5ce522a4 PK |
3876 | * CSI Ps L |
3877 | * Insert Ps Line(s) (default = 1) (IL). | |
cd70d298 PK |
3878 | */ |
3879 | Terminal.prototype.insertLines = function (params) { | |
3880 | var param, row, j; | |
3881 | param = params[0]; | |
3882 | if (param < 1) | |
3883 | param = 1; | |
3884 | row = this.y + this.ybase; | |
3885 | j = this.rows - 1 - this.scrollBottom; | |
3886 | j = this.rows - 1 + this.ybase - j + 1; | |
3887 | while (param--) { | |
3888 | // test: echo -e '\e[44m\e[1L\e[0m' | |
3889 | // blankLine(true) - xterm/linux behavior | |
3890 | this.lines.splice(row, 0, this.blankLine(true)); | |
3891 | this.lines.splice(j, 1); | |
3892 | } | |
3893 | // this.maxRange(); | |
3894 | this.updateRange(this.y); | |
3895 | this.updateRange(this.scrollBottom); | |
3896 | }; | |
3897 | /** | |
5ce522a4 PK |
3898 | * CSI Ps M |
3899 | * Delete Ps Line(s) (default = 1) (DL). | |
cd70d298 PK |
3900 | */ |
3901 | Terminal.prototype.deleteLines = function (params) { | |
3902 | var param, row, j; | |
3903 | param = params[0]; | |
3904 | if (param < 1) | |
3905 | param = 1; | |
3906 | row = this.y + this.ybase; | |
3907 | j = this.rows - 1 - this.scrollBottom; | |
3908 | j = this.rows - 1 + this.ybase - j; | |
3909 | while (param--) { | |
3910 | // test: echo -e '\e[44m\e[1M\e[0m' | |
3911 | // blankLine(true) - xterm/linux behavior | |
3912 | this.lines.splice(j + 1, 0, this.blankLine(true)); | |
3913 | this.lines.splice(row, 1); | |
3914 | } | |
3915 | // this.maxRange(); | |
3916 | this.updateRange(this.y); | |
3917 | this.updateRange(this.scrollBottom); | |
3918 | }; | |
3919 | /** | |
5ce522a4 PK |
3920 | * CSI Ps P |
3921 | * Delete Ps Character(s) (default = 1) (DCH). | |
cd70d298 PK |
3922 | */ |
3923 | Terminal.prototype.deleteChars = function (params) { | |
3924 | var param, row, ch; | |
3925 | param = params[0]; | |
3926 | if (param < 1) | |
3927 | param = 1; | |
3928 | row = this.y + this.ybase; | |
3929 | ch = [this.eraseAttr(), ' ', 1]; // xterm | |
3930 | while (param--) { | |
3931 | this.lines[row].splice(this.x, 1); | |
3932 | this.lines[row].push(ch); | |
3933 | } | |
3934 | }; | |
3935 | /** | |
5ce522a4 PK |
3936 | * CSI Ps X |
3937 | * Erase Ps Character(s) (default = 1) (ECH). | |
cd70d298 PK |
3938 | */ |
3939 | Terminal.prototype.eraseChars = function (params) { | |
3940 | var param, row, j, ch; | |
3941 | param = params[0]; | |
3942 | if (param < 1) | |
3943 | param = 1; | |
3944 | row = this.y + this.ybase; | |
3945 | j = this.x; | |
3946 | ch = [this.eraseAttr(), ' ', 1]; // xterm | |
3947 | while (param-- && j < this.cols) { | |
3948 | this.lines[row][j++] = ch; | |
3949 | } | |
3950 | }; | |
3951 | /** | |
5ce522a4 PK |
3952 | * CSI Pm ` Character Position Absolute |
3953 | * [column] (default = [row,1]) (HPA). | |
cd70d298 PK |
3954 | */ |
3955 | Terminal.prototype.charPosAbsolute = function (params) { | |
3956 | var param = params[0]; | |
3957 | if (param < 1) | |
3958 | param = 1; | |
3959 | this.x = param - 1; | |
3960 | if (this.x >= this.cols) { | |
3961 | this.x = this.cols - 1; | |
3962 | } | |
3963 | }; | |
3964 | /** | |
5ce522a4 PK |
3965 | * 141 61 a * HPR - |
3966 | * Horizontal Position Relative | |
3967 | * reuse CSI Ps C ? | |
cd70d298 PK |
3968 | */ |
3969 | Terminal.prototype.HPositionRelative = function (params) { | |
3970 | var param = params[0]; | |
3971 | if (param < 1) | |
3972 | param = 1; | |
3973 | this.x += param; | |
3974 | if (this.x >= this.cols) { | |
3975 | this.x = this.cols - 1; | |
3976 | } | |
3977 | }; | |
3978 | /** | |
5ce522a4 PK |
3979 | * CSI Ps c Send Device Attributes (Primary DA). |
3980 | * Ps = 0 or omitted -> request attributes from terminal. The | |
3981 | * response depends on the decTerminalID resource setting. | |
3982 | * -> CSI ? 1 ; 2 c (``VT100 with Advanced Video Option'') | |
3983 | * -> CSI ? 1 ; 0 c (``VT101 with No Options'') | |
3984 | * -> CSI ? 6 c (``VT102'') | |
3985 | * -> CSI ? 6 0 ; 1 ; 2 ; 6 ; 8 ; 9 ; 1 5 ; c (``VT220'') | |
3986 | * The VT100-style response parameters do not mean anything by | |
3987 | * themselves. VT220 parameters do, telling the host what fea- | |
3988 | * tures the terminal supports: | |
3989 | * Ps = 1 -> 132-columns. | |
3990 | * Ps = 2 -> Printer. | |
3991 | * Ps = 6 -> Selective erase. | |
3992 | * Ps = 8 -> User-defined keys. | |
3993 | * Ps = 9 -> National replacement character sets. | |
3994 | * Ps = 1 5 -> Technical characters. | |
3995 | * Ps = 2 2 -> ANSI color, e.g., VT525. | |
3996 | * Ps = 2 9 -> ANSI text locator (i.e., DEC Locator mode). | |
3997 | * CSI > Ps c | |
3998 | * Send Device Attributes (Secondary DA). | |
3999 | * Ps = 0 or omitted -> request the terminal's identification | |
4000 | * code. The response depends on the decTerminalID resource set- | |
4001 | * ting. It should apply only to VT220 and up, but xterm extends | |
4002 | * this to VT100. | |
4003 | * -> CSI > Pp ; Pv ; Pc c | |
4004 | * where Pp denotes the terminal type | |
4005 | * Pp = 0 -> ``VT100''. | |
4006 | * Pp = 1 -> ``VT220''. | |
4007 | * and Pv is the firmware version (for xterm, this was originally | |
4008 | * the XFree86 patch number, starting with 95). In a DEC termi- | |
4009 | * nal, Pc indicates the ROM cartridge registration number and is | |
4010 | * always zero. | |
4011 | * More information: | |
4012 | * xterm/charproc.c - line 2012, for more information. | |
4013 | * vim responds with ^[[?0c or ^[[?1c after the terminal's response (?) | |
cd70d298 PK |
4014 | */ |
4015 | Terminal.prototype.sendDeviceAttributes = function (params) { | |
4016 | if (params[0] > 0) | |
4017 | return; | |
4018 | if (!this.prefix) { | |
4019 | if (this.is('xterm') | |
4020 | || this.is('rxvt-unicode') | |
4021 | || this.is('screen')) { | |
4022 | this.send('\x1b[?1;2c'); | |
4023 | } | |
4024 | else if (this.is('linux')) { | |
4025 | this.send('\x1b[?6c'); | |
4026 | } | |
4027 | } | |
4028 | else if (this.prefix === '>') { | |
4029 | // xterm and urxvt | |
4030 | // seem to spit this | |
4031 | // out around ~370 times (?). | |
4032 | if (this.is('xterm')) { | |
4033 | this.send('\x1b[>0;276;0c'); | |
4034 | } | |
4035 | else if (this.is('rxvt-unicode')) { | |
4036 | this.send('\x1b[>85;95;0c'); | |
4037 | } | |
4038 | else if (this.is('linux')) { | |
4039 | // not supported by linux console. | |
4040 | // linux console echoes parameters. | |
4041 | this.send(params[0] + 'c'); | |
4042 | } | |
4043 | else if (this.is('screen')) { | |
4044 | this.send('\x1b[>83;40003;0c'); | |
4045 | } | |
4046 | } | |
4047 | }; | |
4048 | /** | |
5ce522a4 PK |
4049 | * CSI Pm d |
4050 | * Line Position Absolute [row] (default = [1,column]) (VPA). | |
cd70d298 PK |
4051 | */ |
4052 | Terminal.prototype.linePosAbsolute = function (params) { | |
4053 | var param = params[0]; | |
4054 | if (param < 1) | |
4055 | param = 1; | |
4056 | this.y = param - 1; | |
4057 | if (this.y >= this.rows) { | |
4058 | this.y = this.rows - 1; | |
4059 | } | |
4060 | }; | |
4061 | /** | |
5ce522a4 PK |
4062 | * 145 65 e * VPR - Vertical Position Relative |
4063 | * reuse CSI Ps B ? | |
cd70d298 PK |
4064 | */ |
4065 | Terminal.prototype.VPositionRelative = function (params) { | |
4066 | var param = params[0]; | |
4067 | if (param < 1) | |
4068 | param = 1; | |
4069 | this.y += param; | |
4070 | if (this.y >= this.rows) { | |
4071 | this.y = this.rows - 1; | |
4072 | } | |
4073 | }; | |
4074 | /** | |
5ce522a4 PK |
4075 | * CSI Ps ; Ps f |
4076 | * Horizontal and Vertical Position [row;column] (default = | |
4077 | * [1,1]) (HVP). | |
cd70d298 PK |
4078 | */ |
4079 | Terminal.prototype.HVPosition = function (params) { | |
4080 | if (params[0] < 1) | |
4081 | params[0] = 1; | |
4082 | if (params[1] < 1) | |
4083 | params[1] = 1; | |
4084 | this.y = params[0] - 1; | |
4085 | if (this.y >= this.rows) { | |
4086 | this.y = this.rows - 1; | |
4087 | } | |
4088 | this.x = params[1] - 1; | |
4089 | if (this.x >= this.cols) { | |
4090 | this.x = this.cols - 1; | |
4091 | } | |
4092 | }; | |
4093 | /** | |
5ce522a4 PK |
4094 | * CSI Pm h Set Mode (SM). |
4095 | * Ps = 2 -> Keyboard Action Mode (AM). | |
4096 | * Ps = 4 -> Insert Mode (IRM). | |
4097 | * Ps = 1 2 -> Send/receive (SRM). | |
4098 | * Ps = 2 0 -> Automatic Newline (LNM). | |
4099 | * CSI ? Pm h | |
4100 | * DEC Private Mode Set (DECSET). | |
4101 | * Ps = 1 -> Application Cursor Keys (DECCKM). | |
4102 | * Ps = 2 -> Designate USASCII for character sets G0-G3 | |
4103 | * (DECANM), and set VT100 mode. | |
4104 | * Ps = 3 -> 132 Column Mode (DECCOLM). | |
4105 | * Ps = 4 -> Smooth (Slow) Scroll (DECSCLM). | |
4106 | * Ps = 5 -> Reverse Video (DECSCNM). | |
4107 | * Ps = 6 -> Origin Mode (DECOM). | |
4108 | * Ps = 7 -> Wraparound Mode (DECAWM). | |
4109 | * Ps = 8 -> Auto-repeat Keys (DECARM). | |
4110 | * Ps = 9 -> Send Mouse X & Y on button press. See the sec- | |
4111 | * tion Mouse Tracking. | |
4112 | * Ps = 1 0 -> Show toolbar (rxvt). | |
4113 | * Ps = 1 2 -> Start Blinking Cursor (att610). | |
4114 | * Ps = 1 8 -> Print form feed (DECPFF). | |
4115 | * Ps = 1 9 -> Set print extent to full screen (DECPEX). | |
4116 | * Ps = 2 5 -> Show Cursor (DECTCEM). | |
4117 | * Ps = 3 0 -> Show scrollbar (rxvt). | |
4118 | * Ps = 3 5 -> Enable font-shifting functions (rxvt). | |
4119 | * Ps = 3 8 -> Enter Tektronix Mode (DECTEK). | |
4120 | * Ps = 4 0 -> Allow 80 -> 132 Mode. | |
4121 | * Ps = 4 1 -> more(1) fix (see curses resource). | |
4122 | * Ps = 4 2 -> Enable Nation Replacement Character sets (DECN- | |
4123 | * RCM). | |
4124 | * Ps = 4 4 -> Turn On Margin Bell. | |
4125 | * Ps = 4 5 -> Reverse-wraparound Mode. | |
4126 | * Ps = 4 6 -> Start Logging. This is normally disabled by a | |
4127 | * compile-time option. | |
4128 | * Ps = 4 7 -> Use Alternate Screen Buffer. (This may be dis- | |
4129 | * abled by the titeInhibit resource). | |
4130 | * Ps = 6 6 -> Application keypad (DECNKM). | |
4131 | * Ps = 6 7 -> Backarrow key sends backspace (DECBKM). | |
4132 | * Ps = 1 0 0 0 -> Send Mouse X & Y on button press and | |
4133 | * release. See the section Mouse Tracking. | |
4134 | * Ps = 1 0 0 1 -> Use Hilite Mouse Tracking. | |
4135 | * Ps = 1 0 0 2 -> Use Cell Motion Mouse Tracking. | |
4136 | * Ps = 1 0 0 3 -> Use All Motion Mouse Tracking. | |
4137 | * Ps = 1 0 0 4 -> Send FocusIn/FocusOut events. | |
4138 | * Ps = 1 0 0 5 -> Enable Extended Mouse Mode. | |
4139 | * Ps = 1 0 1 0 -> Scroll to bottom on tty output (rxvt). | |
4140 | * Ps = 1 0 1 1 -> Scroll to bottom on key press (rxvt). | |
4141 | * Ps = 1 0 3 4 -> Interpret "meta" key, sets eighth bit. | |
4142 | * (enables the eightBitInput resource). | |
4143 | * Ps = 1 0 3 5 -> Enable special modifiers for Alt and Num- | |
4144 | * Lock keys. (This enables the numLock resource). | |
4145 | * Ps = 1 0 3 6 -> Send ESC when Meta modifies a key. (This | |
4146 | * enables the metaSendsEscape resource). | |
4147 | * Ps = 1 0 3 7 -> Send DEL from the editing-keypad Delete | |
4148 | * key. | |
4149 | * Ps = 1 0 3 9 -> Send ESC when Alt modifies a key. (This | |
4150 | * enables the altSendsEscape resource). | |
4151 | * Ps = 1 0 4 0 -> Keep selection even if not highlighted. | |
4152 | * (This enables the keepSelection resource). | |
4153 | * Ps = 1 0 4 1 -> Use the CLIPBOARD selection. (This enables | |
4154 | * the selectToClipboard resource). | |
4155 | * Ps = 1 0 4 2 -> Enable Urgency window manager hint when | |
4156 | * Control-G is received. (This enables the bellIsUrgent | |
4157 | * resource). | |
4158 | * Ps = 1 0 4 3 -> Enable raising of the window when Control-G | |
4159 | * is received. (enables the popOnBell resource). | |
4160 | * Ps = 1 0 4 7 -> Use Alternate Screen Buffer. (This may be | |
4161 | * disabled by the titeInhibit resource). | |
4162 | * Ps = 1 0 4 8 -> Save cursor as in DECSC. (This may be dis- | |
4163 | * abled by the titeInhibit resource). | |
4164 | * Ps = 1 0 4 9 -> Save cursor as in DECSC and use Alternate | |
4165 | * Screen Buffer, clearing it first. (This may be disabled by | |
4166 | * the titeInhibit resource). This combines the effects of the 1 | |
4167 | * 0 4 7 and 1 0 4 8 modes. Use this with terminfo-based | |
4168 | * applications rather than the 4 7 mode. | |
4169 | * Ps = 1 0 5 0 -> Set terminfo/termcap function-key mode. | |
4170 | * Ps = 1 0 5 1 -> Set Sun function-key mode. | |
4171 | * Ps = 1 0 5 2 -> Set HP function-key mode. | |
4172 | * Ps = 1 0 5 3 -> Set SCO function-key mode. | |
4173 | * Ps = 1 0 6 0 -> Set legacy keyboard emulation (X11R6). | |
4174 | * Ps = 1 0 6 1 -> Set VT220 keyboard emulation. | |
4175 | * Ps = 2 0 0 4 -> Set bracketed paste mode. | |
4176 | * Modes: | |
4177 | * http: *vt100.net/docs/vt220-rm/chapter4.html | |
cd70d298 PK |
4178 | */ |
4179 | Terminal.prototype.setMode = function (params) { | |
4180 | if (typeof params === 'object') { | |
4181 | var l = params.length, i = 0; | |
4182 | for (; i < l; i++) { | |
4183 | this.setMode(params[i]); | |
4184 | } | |
4185 | return; | |
4186 | } | |
4187 | if (!this.prefix) { | |
4188 | switch (params) { | |
4189 | case 4: | |
4190 | this.insertMode = true; | |
4191 | break; | |
4192 | case 20: | |
4193 | //this.convertEol = true; | |
4194 | break; | |
4195 | } | |
4196 | } | |
4197 | else if (this.prefix === '?') { | |
4198 | switch (params) { | |
4199 | case 1: | |
4200 | this.applicationCursor = true; | |
4201 | break; | |
4202 | case 2: | |
4203 | this.setgCharset(0, Terminal.charsets.US); | |
4204 | this.setgCharset(1, Terminal.charsets.US); | |
4205 | this.setgCharset(2, Terminal.charsets.US); | |
4206 | this.setgCharset(3, Terminal.charsets.US); | |
4207 | // set VT100 mode here | |
4208 | break; | |
4209 | case 3: | |
4210 | this.savedCols = this.cols; | |
4211 | this.resize(132, this.rows); | |
4212 | break; | |
4213 | case 6: | |
4214 | this.originMode = true; | |
4215 | break; | |
4216 | case 7: | |
4217 | this.wraparoundMode = true; | |
4218 | break; | |
4219 | case 12: | |
4220 | // this.cursorBlink = true; | |
4221 | break; | |
4222 | case 66: | |
4223 | this.log('Serial port requested application keypad.'); | |
4224 | this.applicationKeypad = true; | |
4225 | this.viewport.syncScrollArea(); | |
4226 | break; | |
4227 | case 9: // X10 Mouse | |
4228 | // no release, no motion, no wheel, no modifiers. | |
4229 | case 1000: // vt200 mouse | |
4230 | // no motion. | |
4231 | // no modifiers, except control on the wheel. | |
4232 | case 1002: // button event mouse | |
4233 | case 1003: | |
4234 | // any event - sends motion events, | |
4235 | // even if there is no button held down. | |
4236 | this.x10Mouse = params === 9; | |
4237 | this.vt200Mouse = params === 1000; | |
4238 | this.normalMouse = params > 1000; | |
4239 | this.mouseEvents = true; | |
4240 | this.element.style.cursor = 'default'; | |
4241 | this.log('Binding to mouse events.'); | |
4242 | break; | |
4243 | case 1004: | |
4244 | // focusin: ^[[I | |
4245 | // focusout: ^[[O | |
4246 | this.sendFocus = true; | |
4247 | break; | |
4248 | case 1005: | |
4249 | this.utfMouse = true; | |
4250 | // for wide terminals | |
4251 | // simply encodes large values as utf8 characters | |
4252 | break; | |
4253 | case 1006: | |
4254 | this.sgrMouse = true; | |
4255 | // for wide terminals | |
4256 | // does not add 32 to fields | |
4257 | // press: ^[[<b;x;yM | |
4258 | // release: ^[[<b;x;ym | |
4259 | break; | |
4260 | case 1015: | |
4261 | this.urxvtMouse = true; | |
4262 | // for wide terminals | |
4263 | // numbers for fields | |
4264 | // press: ^[[b;x;yM | |
4265 | // motion: ^[[b;x;yT | |
4266 | break; | |
4267 | case 25: | |
4268 | this.cursorHidden = false; | |
4269 | break; | |
4270 | case 1049: | |
4271 | //this.saveCursor(); | |
4272 | ; // FALL-THROUGH | |
4273 | case 47: // alt screen buffer | |
4274 | case 1047: | |
4275 | if (!this.normal) { | |
4276 | var normal = { | |
4277 | lines: this.lines, | |
4278 | ybase: this.ybase, | |
4279 | ydisp: this.ydisp, | |
4280 | x: this.x, | |
4281 | y: this.y, | |
4282 | scrollTop: this.scrollTop, | |
4283 | scrollBottom: this.scrollBottom, | |
4284 | tabs: this.tabs | |
4285 | }; | |
4286 | this.reset(); | |
4287 | this.normal = normal; | |
4288 | this.showCursor(); | |
4289 | } | |
4290 | break; | |
4291 | } | |
4292 | } | |
4293 | }; | |
4294 | /** | |
5ce522a4 PK |
4295 | * CSI Pm l Reset Mode (RM). |
4296 | * Ps = 2 -> Keyboard Action Mode (AM). | |
4297 | * Ps = 4 -> Replace Mode (IRM). | |
4298 | * Ps = 1 2 -> Send/receive (SRM). | |
4299 | * Ps = 2 0 -> Normal Linefeed (LNM). | |
4300 | * CSI ? Pm l | |
4301 | * DEC Private Mode Reset (DECRST). | |
4302 | * Ps = 1 -> Normal Cursor Keys (DECCKM). | |
4303 | * Ps = 2 -> Designate VT52 mode (DECANM). | |
4304 | * Ps = 3 -> 80 Column Mode (DECCOLM). | |
4305 | * Ps = 4 -> Jump (Fast) Scroll (DECSCLM). | |
4306 | * Ps = 5 -> Normal Video (DECSCNM). | |
4307 | * Ps = 6 -> Normal Cursor Mode (DECOM). | |
4308 | * Ps = 7 -> No Wraparound Mode (DECAWM). | |
4309 | * Ps = 8 -> No Auto-repeat Keys (DECARM). | |
4310 | * Ps = 9 -> Don't send Mouse X & Y on button press. | |
4311 | * Ps = 1 0 -> Hide toolbar (rxvt). | |
4312 | * Ps = 1 2 -> Stop Blinking Cursor (att610). | |
4313 | * Ps = 1 8 -> Don't print form feed (DECPFF). | |
4314 | * Ps = 1 9 -> Limit print to scrolling region (DECPEX). | |
4315 | * Ps = 2 5 -> Hide Cursor (DECTCEM). | |
4316 | * Ps = 3 0 -> Don't show scrollbar (rxvt). | |
4317 | * Ps = 3 5 -> Disable font-shifting functions (rxvt). | |
4318 | * Ps = 4 0 -> Disallow 80 -> 132 Mode. | |
4319 | * Ps = 4 1 -> No more(1) fix (see curses resource). | |
4320 | * Ps = 4 2 -> Disable Nation Replacement Character sets (DEC- | |
4321 | * NRCM). | |
4322 | * Ps = 4 4 -> Turn Off Margin Bell. | |
4323 | * Ps = 4 5 -> No Reverse-wraparound Mode. | |
4324 | * Ps = 4 6 -> Stop Logging. (This is normally disabled by a | |
4325 | * compile-time option). | |
4326 | * Ps = 4 7 -> Use Normal Screen Buffer. | |
4327 | * Ps = 6 6 -> Numeric keypad (DECNKM). | |
4328 | * Ps = 6 7 -> Backarrow key sends delete (DECBKM). | |
4329 | * Ps = 1 0 0 0 -> Don't send Mouse X & Y on button press and | |
4330 | * release. See the section Mouse Tracking. | |
4331 | * Ps = 1 0 0 1 -> Don't use Hilite Mouse Tracking. | |
4332 | * Ps = 1 0 0 2 -> Don't use Cell Motion Mouse Tracking. | |
4333 | * Ps = 1 0 0 3 -> Don't use All Motion Mouse Tracking. | |
4334 | * Ps = 1 0 0 4 -> Don't send FocusIn/FocusOut events. | |
4335 | * Ps = 1 0 0 5 -> Disable Extended Mouse Mode. | |
4336 | * Ps = 1 0 1 0 -> Don't scroll to bottom on tty output | |
4337 | * (rxvt). | |
4338 | * Ps = 1 0 1 1 -> Don't scroll to bottom on key press (rxvt). | |
4339 | * Ps = 1 0 3 4 -> Don't interpret "meta" key. (This disables | |
4340 | * the eightBitInput resource). | |
4341 | * Ps = 1 0 3 5 -> Disable special modifiers for Alt and Num- | |
4342 | * Lock keys. (This disables the numLock resource). | |
4343 | * Ps = 1 0 3 6 -> Don't send ESC when Meta modifies a key. | |
4344 | * (This disables the metaSendsEscape resource). | |
4345 | * Ps = 1 0 3 7 -> Send VT220 Remove from the editing-keypad | |
4346 | * Delete key. | |
4347 | * Ps = 1 0 3 9 -> Don't send ESC when Alt modifies a key. | |
4348 | * (This disables the altSendsEscape resource). | |
4349 | * Ps = 1 0 4 0 -> Do not keep selection when not highlighted. | |
4350 | * (This disables the keepSelection resource). | |
4351 | * Ps = 1 0 4 1 -> Use the PRIMARY selection. (This disables | |
4352 | * the selectToClipboard resource). | |
4353 | * Ps = 1 0 4 2 -> Disable Urgency window manager hint when | |
4354 | * Control-G is received. (This disables the bellIsUrgent | |
4355 | * resource). | |
4356 | * Ps = 1 0 4 3 -> Disable raising of the window when Control- | |
4357 | * G is received. (This disables the popOnBell resource). | |
4358 | * Ps = 1 0 4 7 -> Use Normal Screen Buffer, clearing screen | |
4359 | * first if in the Alternate Screen. (This may be disabled by | |
4360 | * the titeInhibit resource). | |
4361 | * Ps = 1 0 4 8 -> Restore cursor as in DECRC. (This may be | |
4362 | * disabled by the titeInhibit resource). | |
4363 | * Ps = 1 0 4 9 -> Use Normal Screen Buffer and restore cursor | |
4364 | * as in DECRC. (This may be disabled by the titeInhibit | |
4365 | * resource). This combines the effects of the 1 0 4 7 and 1 0 | |
4366 | * 4 8 modes. Use this with terminfo-based applications rather | |
4367 | * than the 4 7 mode. | |
4368 | * Ps = 1 0 5 0 -> Reset terminfo/termcap function-key mode. | |
4369 | * Ps = 1 0 5 1 -> Reset Sun function-key mode. | |
4370 | * Ps = 1 0 5 2 -> Reset HP function-key mode. | |
4371 | * Ps = 1 0 5 3 -> Reset SCO function-key mode. | |
4372 | * Ps = 1 0 6 0 -> Reset legacy keyboard emulation (X11R6). | |
4373 | * Ps = 1 0 6 1 -> Reset keyboard emulation to Sun/PC style. | |
4374 | * Ps = 2 0 0 4 -> Reset bracketed paste mode. | |
cd70d298 PK |
4375 | */ |
4376 | Terminal.prototype.resetMode = function (params) { | |
4377 | if (typeof params === 'object') { | |
4378 | var l = params.length, i = 0; | |
4379 | for (; i < l; i++) { | |
4380 | this.resetMode(params[i]); | |
4381 | } | |
4382 | return; | |
4383 | } | |
4384 | if (!this.prefix) { | |
4385 | switch (params) { | |
4386 | case 4: | |
4387 | this.insertMode = false; | |
4388 | break; | |
4389 | case 20: | |
4390 | //this.convertEol = false; | |
4391 | break; | |
4392 | } | |
4393 | } | |
4394 | else if (this.prefix === '?') { | |
4395 | switch (params) { | |
4396 | case 1: | |
4397 | this.applicationCursor = false; | |
4398 | break; | |
4399 | case 3: | |
4400 | if (this.cols === 132 && this.savedCols) { | |
4401 | this.resize(this.savedCols, this.rows); | |
4402 | } | |
4403 | delete this.savedCols; | |
4404 | break; | |
4405 | case 6: | |
4406 | this.originMode = false; | |
4407 | break; | |
4408 | case 7: | |
4409 | this.wraparoundMode = false; | |
4410 | break; | |
4411 | case 12: | |
4412 | // this.cursorBlink = false; | |
4413 | break; | |
4414 | case 66: | |
4415 | this.log('Switching back to normal keypad.'); | |
4416 | this.applicationKeypad = false; | |
4417 | this.viewport.syncScrollArea(); | |
4418 | break; | |
4419 | case 9: // X10 Mouse | |
4420 | case 1000: // vt200 mouse | |
4421 | case 1002: // button event mouse | |
4422 | case 1003: | |
4423 | this.x10Mouse = false; | |
4424 | this.vt200Mouse = false; | |
4425 | this.normalMouse = false; | |
4426 | this.mouseEvents = false; | |
4427 | this.element.style.cursor = ''; | |
4428 | break; | |
4429 | case 1004: | |
4430 | this.sendFocus = false; | |
4431 | break; | |
4432 | case 1005: | |
4433 | this.utfMouse = false; | |
4434 | break; | |
4435 | case 1006: | |
4436 | this.sgrMouse = false; | |
4437 | break; | |
4438 | case 1015: | |
4439 | this.urxvtMouse = false; | |
4440 | break; | |
4441 | case 25: | |
4442 | this.cursorHidden = true; | |
4443 | break; | |
4444 | case 1049: | |
4445 | ; // FALL-THROUGH | |
4446 | case 47: // normal screen buffer | |
4447 | case 1047: | |
4448 | if (this.normal) { | |
4449 | this.lines = this.normal.lines; | |
4450 | this.ybase = this.normal.ybase; | |
4451 | this.ydisp = this.normal.ydisp; | |
4452 | this.x = this.normal.x; | |
4453 | this.y = this.normal.y; | |
4454 | this.scrollTop = this.normal.scrollTop; | |
4455 | this.scrollBottom = this.normal.scrollBottom; | |
4456 | this.tabs = this.normal.tabs; | |
4457 | this.normal = null; | |
4458 | // if (params === 1049) { | |
4459 | // this.x = this.savedX; | |
4460 | // this.y = this.savedY; | |
4461 | // } | |
4462 | this.refresh(0, this.rows - 1); | |
4463 | this.showCursor(); | |
4464 | } | |
4465 | break; | |
4466 | } | |
4467 | } | |
4468 | }; | |
4469 | /** | |
5ce522a4 PK |
4470 | * CSI Ps ; Ps r |
4471 | * Set Scrolling Region [top;bottom] (default = full size of win- | |
4472 | * dow) (DECSTBM). | |
4473 | * CSI ? Pm r | |
cd70d298 PK |
4474 | */ |
4475 | Terminal.prototype.setScrollRegion = function (params) { | |
4476 | if (this.prefix) | |
4477 | return; | |
4478 | this.scrollTop = (params[0] || 1) - 1; | |
4479 | this.scrollBottom = (params[1] || this.rows) - 1; | |
4480 | this.x = 0; | |
4481 | this.y = 0; | |
4482 | }; | |
4483 | /** | |
5ce522a4 PK |
4484 | * CSI s |
4485 | * Save cursor (ANSI.SYS). | |
cd70d298 PK |
4486 | */ |
4487 | Terminal.prototype.saveCursor = function (params) { | |
4488 | this.savedX = this.x; | |
4489 | this.savedY = this.y; | |
4490 | }; | |
4491 | /** | |
5ce522a4 PK |
4492 | * CSI u |
4493 | * Restore cursor (ANSI.SYS). | |
cd70d298 PK |
4494 | */ |
4495 | Terminal.prototype.restoreCursor = function (params) { | |
4496 | this.x = this.savedX || 0; | |
4497 | this.y = this.savedY || 0; | |
4498 | }; | |
4499 | /** | |
5ce522a4 | 4500 | * Lesser Used |
cd70d298 PK |
4501 | */ |
4502 | /** | |
5ce522a4 PK |
4503 | * CSI Ps I |
4504 | * Cursor Forward Tabulation Ps tab stops (default = 1) (CHT). | |
cd70d298 PK |
4505 | */ |
4506 | Terminal.prototype.cursorForwardTab = function (params) { | |
4507 | var param = params[0] || 1; | |
4508 | while (param--) { | |
4509 | this.x = this.nextStop(); | |
4510 | } | |
4511 | }; | |
4512 | /** | |
5ce522a4 | 4513 | * CSI Ps S Scroll up Ps lines (default = 1) (SU). |
cd70d298 PK |
4514 | */ |
4515 | Terminal.prototype.scrollUp = function (params) { | |
4516 | var param = params[0] || 1; | |
4517 | while (param--) { | |
4518 | this.lines.splice(this.ybase + this.scrollTop, 1); | |
4519 | this.lines.splice(this.ybase + this.scrollBottom, 0, this.blankLine()); | |
4520 | } | |
4521 | // this.maxRange(); | |
4522 | this.updateRange(this.scrollTop); | |
4523 | this.updateRange(this.scrollBottom); | |
4524 | }; | |
4525 | /** | |
521d7dbd | 4526 | * CSI Ps T Scroll down Ps lines (default = 1) (SD). |
cd70d298 PK |
4527 | */ |
4528 | Terminal.prototype.scrollDown = function (params) { | |
4529 | var param = params[0] || 1; | |
4530 | while (param--) { | |
4531 | this.lines.splice(this.ybase + this.scrollBottom, 1); | |
4532 | this.lines.splice(this.ybase + this.scrollTop, 0, this.blankLine()); | |
4533 | } | |
4534 | // this.maxRange(); | |
4535 | this.updateRange(this.scrollTop); | |
4536 | this.updateRange(this.scrollBottom); | |
4537 | }; | |
4538 | /** | |
5ce522a4 PK |
4539 | * CSI Ps ; Ps ; Ps ; Ps ; Ps T |
4540 | * Initiate highlight mouse tracking. Parameters are | |
4541 | * [func;startx;starty;firstrow;lastrow]. See the section Mouse | |
4542 | * Tracking. | |
cd70d298 PK |
4543 | */ |
4544 | Terminal.prototype.initMouseTracking = function (params) { | |
4545 | // Relevant: DECSET 1001 | |
4546 | }; | |
4547 | /** | |
5ce522a4 PK |
4548 | * CSI > Ps; Ps T |
4549 | * Reset one or more features of the title modes to the default | |
4550 | * value. Normally, "reset" disables the feature. It is possi- | |
4551 | * ble to disable the ability to reset features by compiling a | |
4552 | * different default for the title modes into xterm. | |
4553 | * Ps = 0 -> Do not set window/icon labels using hexadecimal. | |
4554 | * Ps = 1 -> Do not query window/icon labels using hexadeci- | |
4555 | * mal. | |
4556 | * Ps = 2 -> Do not set window/icon labels using UTF-8. | |
4557 | * Ps = 3 -> Do not query window/icon labels using UTF-8. | |
4558 | * (See discussion of "Title Modes"). | |
cd70d298 PK |
4559 | */ |
4560 | Terminal.prototype.resetTitleModes = function (params) { | |
4561 | ; | |
4562 | }; | |
4563 | /** | |
5ce522a4 | 4564 | * CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT). |
cd70d298 PK |
4565 | */ |
4566 | Terminal.prototype.cursorBackwardTab = function (params) { | |
4567 | var param = params[0] || 1; | |
4568 | while (param--) { | |
4569 | this.x = this.prevStop(); | |
4570 | } | |
4571 | }; | |
4572 | /** | |
5ce522a4 | 4573 | * CSI Ps b Repeat the preceding graphic character Ps times (REP). |
cd70d298 PK |
4574 | */ |
4575 | Terminal.prototype.repeatPrecedingCharacter = function (params) { | |
4576 | var param = params[0] || 1, line = this.lines[this.ybase + this.y], ch = line[this.x - 1] || [this.defAttr, ' ', 1]; | |
4577 | while (param--) | |
4578 | line[this.x++] = ch; | |
4579 | }; | |
4580 | /** | |
5ce522a4 PK |
4581 | * CSI Ps g Tab Clear (TBC). |
4582 | * Ps = 0 -> Clear Current Column (default). | |
4583 | * Ps = 3 -> Clear All. | |
4584 | * Potentially: | |
4585 | * Ps = 2 -> Clear Stops on Line. | |
4586 | * http://vt100.net/annarbor/aaa-ug/section6.html | |
cd70d298 PK |
4587 | */ |
4588 | Terminal.prototype.tabClear = function (params) { | |
4589 | var param = params[0]; | |
4590 | if (param <= 0) { | |
4591 | delete this.tabs[this.x]; | |
4592 | } | |
4593 | else if (param === 3) { | |
4594 | this.tabs = {}; | |
4595 | } | |
4596 | }; | |
4597 | /** | |
5ce522a4 PK |
4598 | * CSI Pm i Media Copy (MC). |
4599 | * Ps = 0 -> Print screen (default). | |
4600 | * Ps = 4 -> Turn off printer controller mode. | |
4601 | * Ps = 5 -> Turn on printer controller mode. | |
4602 | * CSI ? Pm i | |
4603 | * Media Copy (MC, DEC-specific). | |
4604 | * Ps = 1 -> Print line containing cursor. | |
4605 | * Ps = 4 -> Turn off autoprint mode. | |
4606 | * Ps = 5 -> Turn on autoprint mode. | |
4607 | * Ps = 1 0 -> Print composed display, ignores DECPEX. | |
4608 | * Ps = 1 1 -> Print all pages. | |
cd70d298 PK |
4609 | */ |
4610 | Terminal.prototype.mediaCopy = function (params) { | |
4611 | ; | |
4612 | }; | |
4613 | /** | |
5ce522a4 PK |
4614 | * CSI > Ps; Ps m |
4615 | * Set or reset resource-values used by xterm to decide whether | |
4616 | * to construct escape sequences holding information about the | |
4617 | * modifiers pressed with a given key. The first parameter iden- | |
4618 | * tifies the resource to set/reset. The second parameter is the | |
4619 | * value to assign to the resource. If the second parameter is | |
4620 | * omitted, the resource is reset to its initial value. | |
4621 | * Ps = 1 -> modifyCursorKeys. | |
4622 | * Ps = 2 -> modifyFunctionKeys. | |
4623 | * Ps = 4 -> modifyOtherKeys. | |
4624 | * If no parameters are given, all resources are reset to their | |
4625 | * initial values. | |
cd70d298 PK |
4626 | */ |
4627 | Terminal.prototype.setResources = function (params) { | |
4628 | ; | |
4629 | }; | |
4630 | /** | |
5ce522a4 PK |
4631 | * CSI > Ps n |
4632 | * Disable modifiers which may be enabled via the CSI > Ps; Ps m | |
4633 | * sequence. This corresponds to a resource value of "-1", which | |
4634 | * cannot be set with the other sequence. The parameter identi- | |
4635 | * fies the resource to be disabled: | |
4636 | * Ps = 1 -> modifyCursorKeys. | |
4637 | * Ps = 2 -> modifyFunctionKeys. | |
4638 | * Ps = 4 -> modifyOtherKeys. | |
4639 | * If the parameter is omitted, modifyFunctionKeys is disabled. | |
4640 | * When modifyFunctionKeys is disabled, xterm uses the modifier | |
4641 | * keys to make an extended sequence of functions rather than | |
4642 | * adding a parameter to each function key to denote the modi- | |
4643 | * fiers. | |
cd70d298 PK |
4644 | */ |
4645 | Terminal.prototype.disableModifiers = function (params) { | |
4646 | ; | |
4647 | }; | |
4648 | /** | |
5ce522a4 PK |
4649 | * CSI > Ps p |
4650 | * Set resource value pointerMode. This is used by xterm to | |
4651 | * decide whether to hide the pointer cursor as the user types. | |
4652 | * Valid values for the parameter: | |
4653 | * Ps = 0 -> never hide the pointer. | |
4654 | * Ps = 1 -> hide if the mouse tracking mode is not enabled. | |
4655 | * Ps = 2 -> always hide the pointer. If no parameter is | |
4656 | * given, xterm uses the default, which is 1 . | |
cd70d298 PK |
4657 | */ |
4658 | Terminal.prototype.setPointerMode = function (params) { | |
4659 | ; | |
4660 | }; | |
4661 | /** | |
5ce522a4 PK |
4662 | * CSI ! p Soft terminal reset (DECSTR). |
4663 | * http://vt100.net/docs/vt220-rm/table4-10.html | |
cd70d298 PK |
4664 | */ |
4665 | Terminal.prototype.softReset = function (params) { | |
4666 | this.cursorHidden = false; | |
4667 | this.insertMode = false; | |
4668 | this.originMode = false; | |
4669 | this.wraparoundMode = false; // autowrap | |
4670 | this.applicationKeypad = false; // ? | |
4671 | this.viewport.syncScrollArea(); | |
4672 | this.applicationCursor = false; | |
4673 | this.scrollTop = 0; | |
4674 | this.scrollBottom = this.rows - 1; | |
4675 | this.curAttr = this.defAttr; | |
4676 | this.x = this.y = 0; // ? | |
4677 | this.charset = null; | |
4678 | this.glevel = 0; // ?? | |
4679 | this.charsets = [null]; // ?? | |
4680 | }; | |
4681 | /** | |
5ce522a4 PK |
4682 | * CSI Ps$ p |
4683 | * Request ANSI mode (DECRQM). For VT300 and up, reply is | |
4684 | * CSI Ps; Pm$ y | |
4685 | * where Ps is the mode number as in RM, and Pm is the mode | |
4686 | * value: | |
4687 | * 0 - not recognized | |
4688 | * 1 - set | |
4689 | * 2 - reset | |
4690 | * 3 - permanently set | |
4691 | * 4 - permanently reset | |
cd70d298 PK |
4692 | */ |
4693 | Terminal.prototype.requestAnsiMode = function (params) { | |
4694 | ; | |
4695 | }; | |
4696 | /** | |
5ce522a4 PK |
4697 | * CSI ? Ps$ p |
4698 | * Request DEC private mode (DECRQM). For VT300 and up, reply is | |
4699 | * CSI ? Ps; Pm$ p | |
4700 | * where Ps is the mode number as in DECSET, Pm is the mode value | |
4701 | * as in the ANSI DECRQM. | |
cd70d298 PK |
4702 | */ |
4703 | Terminal.prototype.requestPrivateMode = function (params) { | |
4704 | ; | |
4705 | }; | |
4706 | /** | |
5ce522a4 PK |
4707 | * CSI Ps ; Ps " p |
4708 | * Set conformance level (DECSCL). Valid values for the first | |
4709 | * parameter: | |
4710 | * Ps = 6 1 -> VT100. | |
4711 | * Ps = 6 2 -> VT200. | |
4712 | * Ps = 6 3 -> VT300. | |
4713 | * Valid values for the second parameter: | |
4714 | * Ps = 0 -> 8-bit controls. | |
4715 | * Ps = 1 -> 7-bit controls (always set for VT100). | |
4716 | * Ps = 2 -> 8-bit controls. | |
cd70d298 PK |
4717 | */ |
4718 | Terminal.prototype.setConformanceLevel = function (params) { | |
4719 | ; | |
4720 | }; | |
4721 | /** | |
5ce522a4 PK |
4722 | * CSI Ps q Load LEDs (DECLL). |
4723 | * Ps = 0 -> Clear all LEDS (default). | |
4724 | * Ps = 1 -> Light Num Lock. | |
4725 | * Ps = 2 -> Light Caps Lock. | |
4726 | * Ps = 3 -> Light Scroll Lock. | |
4727 | * Ps = 2 1 -> Extinguish Num Lock. | |
4728 | * Ps = 2 2 -> Extinguish Caps Lock. | |
4729 | * Ps = 2 3 -> Extinguish Scroll Lock. | |
cd70d298 PK |
4730 | */ |
4731 | Terminal.prototype.loadLEDs = function (params) { | |
4732 | ; | |
4733 | }; | |
4734 | /** | |
5ce522a4 PK |
4735 | * CSI Ps SP q |
4736 | * Set cursor style (DECSCUSR, VT520). | |
4737 | * Ps = 0 -> blinking block. | |
4738 | * Ps = 1 -> blinking block (default). | |
4739 | * Ps = 2 -> steady block. | |
4740 | * Ps = 3 -> blinking underline. | |
4741 | * Ps = 4 -> steady underline. | |
cd70d298 PK |
4742 | */ |
4743 | Terminal.prototype.setCursorStyle = function (params) { | |
4744 | ; | |
4745 | }; | |
4746 | /** | |
5ce522a4 PK |
4747 | * CSI Ps " q |
4748 | * Select character protection attribute (DECSCA). Valid values | |
4749 | * for the parameter: | |
4750 | * Ps = 0 -> DECSED and DECSEL can erase (default). | |
4751 | * Ps = 1 -> DECSED and DECSEL cannot erase. | |
4752 | * Ps = 2 -> DECSED and DECSEL can erase. | |
cd70d298 PK |
4753 | */ |
4754 | Terminal.prototype.setCharProtectionAttr = function (params) { | |
4755 | ; | |
4756 | }; | |
4757 | /** | |
5ce522a4 PK |
4758 | * CSI ? Pm r |
4759 | * Restore DEC Private Mode Values. The value of Ps previously | |
4760 | * saved is restored. Ps values are the same as for DECSET. | |
cd70d298 PK |
4761 | */ |
4762 | Terminal.prototype.restorePrivateValues = function (params) { | |
4763 | ; | |
4764 | }; | |
4765 | /** | |
5ce522a4 PK |
4766 | * CSI Pt; Pl; Pb; Pr; Ps$ r |
4767 | * Change Attributes in Rectangular Area (DECCARA), VT400 and up. | |
4768 | * Pt; Pl; Pb; Pr denotes the rectangle. | |
4769 | * Ps denotes the SGR attributes to change: 0, 1, 4, 5, 7. | |
4770 | * NOTE: xterm doesn't enable this code by default. | |
cd70d298 PK |
4771 | */ |
4772 | Terminal.prototype.setAttrInRectangle = function (params) { | |
4773 | var t = params[0], l = params[1], b = params[2], r = params[3], attr = params[4]; | |
4774 | var line, i; | |
4775 | for (; t < b + 1; t++) { | |
4776 | line = this.lines[this.ybase + t]; | |
4777 | for (i = l; i < r; i++) { | |
4778 | line[i] = [attr, line[i][1]]; | |
4779 | } | |
4780 | } | |
4781 | // this.maxRange(); | |
4782 | this.updateRange(params[0]); | |
4783 | this.updateRange(params[2]); | |
4784 | }; | |
4785 | /** | |
5ce522a4 PK |
4786 | * CSI Pc; Pt; Pl; Pb; Pr$ x |
4787 | * Fill Rectangular Area (DECFRA), VT420 and up. | |
4788 | * Pc is the character to use. | |
4789 | * Pt; Pl; Pb; Pr denotes the rectangle. | |
4790 | * NOTE: xterm doesn't enable this code by default. | |
cd70d298 PK |
4791 | */ |
4792 | Terminal.prototype.fillRectangle = function (params) { | |
4793 | var ch = params[0], t = params[1], l = params[2], b = params[3], r = params[4]; | |
4794 | var line, i; | |
4795 | for (; t < b + 1; t++) { | |
4796 | line = this.lines[this.ybase + t]; | |
4797 | for (i = l; i < r; i++) { | |
4798 | line[i] = [line[i][0], String.fromCharCode(ch)]; | |
4799 | } | |
4800 | } | |
4801 | // this.maxRange(); | |
4802 | this.updateRange(params[1]); | |
4803 | this.updateRange(params[3]); | |
4804 | }; | |
4805 | /** | |
5ce522a4 PK |
4806 | * CSI Ps ; Pu ' z |
4807 | * Enable Locator Reporting (DECELR). | |
4808 | * Valid values for the first parameter: | |
4809 | * Ps = 0 -> Locator disabled (default). | |
4810 | * Ps = 1 -> Locator enabled. | |
4811 | * Ps = 2 -> Locator enabled for one report, then disabled. | |
4812 | * The second parameter specifies the coordinate unit for locator | |
4813 | * reports. | |
4814 | * Valid values for the second parameter: | |
4815 | * Pu = 0 <- or omitted -> default to character cells. | |
4816 | * Pu = 1 <- device physical pixels. | |
4817 | * Pu = 2 <- character cells. | |
cd70d298 PK |
4818 | */ |
4819 | Terminal.prototype.enableLocatorReporting = function (params) { | |
4820 | var val = params[0] > 0; | |
4821 | //this.mouseEvents = val; | |
4822 | //this.decLocator = val; | |
4823 | }; | |
4824 | /** | |
5ce522a4 PK |
4825 | * CSI Pt; Pl; Pb; Pr$ z |
4826 | * Erase Rectangular Area (DECERA), VT400 and up. | |
4827 | * Pt; Pl; Pb; Pr denotes the rectangle. | |
4828 | * NOTE: xterm doesn't enable this code by default. | |
cd70d298 PK |
4829 | */ |
4830 | Terminal.prototype.eraseRectangle = function (params) { | |
4831 | var t = params[0], l = params[1], b = params[2], r = params[3]; | |
4832 | var line, i, ch; | |
4833 | ch = [this.eraseAttr(), ' ', 1]; // xterm? | |
4834 | for (; t < b + 1; t++) { | |
4835 | line = this.lines[this.ybase + t]; | |
4836 | for (i = l; i < r; i++) { | |
4837 | line[i] = ch; | |
4838 | } | |
4839 | } | |
4840 | // this.maxRange(); | |
4841 | this.updateRange(params[0]); | |
4842 | this.updateRange(params[2]); | |
4843 | }; | |
4844 | /** | |
5ce522a4 PK |
4845 | * CSI P m SP } |
4846 | * Insert P s Column(s) (default = 1) (DECIC), VT420 and up. | |
4847 | * NOTE: xterm doesn't enable this code by default. | |
cd70d298 PK |
4848 | */ |
4849 | Terminal.prototype.insertColumns = function () { | |
4850 | var param = params[0], l = this.ybase + this.rows, ch = [this.eraseAttr(), ' ', 1] // xterm? | |
4851 | , i; | |
4852 | while (param--) { | |
4853 | for (i = this.ybase; i < l; i++) { | |
4854 | this.lines[i].splice(this.x + 1, 0, ch); | |
4855 | this.lines[i].pop(); | |
4856 | } | |
4857 | } | |
4858 | this.maxRange(); | |
4859 | }; | |
4860 | /** | |
5ce522a4 PK |
4861 | * CSI P m SP ~ |
4862 | * Delete P s Column(s) (default = 1) (DECDC), VT420 and up | |
4863 | * NOTE: xterm doesn't enable this code by default. | |
cd70d298 PK |
4864 | */ |
4865 | Terminal.prototype.deleteColumns = function () { | |
4866 | var param = params[0], l = this.ybase + this.rows, ch = [this.eraseAttr(), ' ', 1] // xterm? | |
4867 | , i; | |
4868 | while (param--) { | |
4869 | for (i = this.ybase; i < l; i++) { | |
4870 | this.lines[i].splice(this.x, 1); | |
4871 | this.lines[i].push(ch); | |
4872 | } | |
4873 | } | |
4874 | this.maxRange(); | |
4875 | }; | |
4876 | /** | |
5ce522a4 | 4877 | * Character Sets |
cd70d298 PK |
4878 | */ |
4879 | Terminal.charsets = {}; | |
4880 | // DEC Special Character and Line Drawing Set. | |
5ce522a4 PK |
4881 | // http://vt100.net/docs/vt102-ug/table5-13.html |
4882 | // A lot of curses apps use this if they see TERM=xterm. | |
4883 | // testing: echo -e '\e(0a\e(B' | |
4884 | // The xterm output sometimes seems to conflict with the | |
4885 | // reference above. xterm seems in line with the reference | |
4886 | // when running vttest however. | |
4887 | // The table below now uses xterm's output from vttest. | |
cd70d298 PK |
4888 | Terminal.charsets.SCLD = { |
4889 | '`': '\u25c6', | |
4890 | 'a': '\u2592', | |
4891 | 'b': '\u0009', | |
4892 | 'c': '\u000c', | |
4893 | 'd': '\u000d', | |
4894 | 'e': '\u000a', | |
4895 | 'f': '\u00b0', | |
4896 | 'g': '\u00b1', | |
4897 | 'h': '\u2424', | |
4898 | 'i': '\u000b', | |
4899 | 'j': '\u2518', | |
4900 | 'k': '\u2510', | |
4901 | 'l': '\u250c', | |
4902 | 'm': '\u2514', | |
4903 | 'n': '\u253c', | |
4904 | 'o': '\u23ba', | |
4905 | 'p': '\u23bb', | |
4906 | 'q': '\u2500', | |
4907 | 'r': '\u23bc', | |
4908 | 's': '\u23bd', | |
4909 | 't': '\u251c', | |
4910 | 'u': '\u2524', | |
4911 | 'v': '\u2534', | |
4912 | 'w': '\u252c', | |
4913 | 'x': '\u2502', | |
4914 | 'y': '\u2264', | |
4915 | 'z': '\u2265', | |
4916 | '{': '\u03c0', | |
4917 | '|': '\u2260', | |
4918 | '}': '\u00a3', | |
4919 | '~': '\u00b7' // 'ยท' | |
4920 | }; | |
4921 | Terminal.charsets.UK = null; // (A | |
4922 | Terminal.charsets.US = null; // (B (USASCII) | |
4923 | Terminal.charsets.Dutch = null; // (4 | |
4924 | Terminal.charsets.Finnish = null; // (C or (5 | |
4925 | Terminal.charsets.French = null; // (R | |
4926 | Terminal.charsets.FrenchCanadian = null; // (Q | |
4927 | Terminal.charsets.German = null; // (K | |
4928 | Terminal.charsets.Italian = null; // (Y | |
4929 | Terminal.charsets.NorwegianDanish = null; // (E or (6 | |
4930 | Terminal.charsets.Spanish = null; // (Z | |
4931 | Terminal.charsets.Swedish = null; // (H or (7 | |
4932 | Terminal.charsets.Swiss = null; // (= | |
4933 | Terminal.charsets.ISOLatin = null; // /A | |
5ce522a4 PK |
4934 | /** |
4935 | * Helpers | |
cd70d298 PK |
4936 | */ |
4937 | function on(el, type, handler, capture) { | |
4938 | if (!Array.isArray(el)) { | |
4939 | el = [el]; | |
4940 | } | |
4941 | el.forEach(function (element) { | |
4942 | element.addEventListener(type, handler, capture || false); | |
4943 | }); | |
4944 | } | |
4945 | function off(el, type, handler, capture) { | |
4946 | el.removeEventListener(type, handler, capture || false); | |
4947 | } | |
4948 | function cancel(ev, force) { | |
4949 | if (!this.cancelEvents && !force) { | |
4950 | return; | |
4951 | } | |
4952 | ev.preventDefault(); | |
4953 | ev.stopPropagation(); | |
4954 | return false; | |
4955 | } | |
4956 | function inherits(child, parent) { | |
4957 | function f() { | |
4958 | this.constructor = child; | |
4959 | } | |
4960 | f.prototype = parent.prototype; | |
4961 | child.prototype = new f; | |
4962 | } | |
4963 | // if bold is broken, we can't | |
5ce522a4 | 4964 | // use it in the terminal. |
cd70d298 PK |
4965 | function isBoldBroken(document) { |
4966 | var body = document.getElementsByTagName('body')[0]; | |
4967 | var el = document.createElement('span'); | |
4968 | el.innerHTML = 'hello world'; | |
4969 | body.appendChild(el); | |
4970 | var w1 = el.scrollWidth; | |
4971 | el.style.fontWeight = 'bold'; | |
4972 | var w2 = el.scrollWidth; | |
4973 | body.removeChild(el); | |
4974 | return w1 !== w2; | |
4975 | } | |
4976 | function indexOf(obj, el) { | |
4977 | var i = obj.length; | |
4978 | while (i--) { | |
4979 | if (obj[i] === el) | |
4980 | return i; | |
4981 | } | |
4982 | return -1; | |
4983 | } | |
4984 | function isThirdLevelShift(term, ev) { | |
4985 | var thirdLevelKey = (term.browser.isMac && ev.altKey && !ev.ctrlKey && !ev.metaKey) || | |
4986 | (term.browser.isMSWindows && ev.altKey && ev.ctrlKey && !ev.metaKey); | |
4987 | if (ev.type == 'keypress') { | |
4988 | return thirdLevelKey; | |
4989 | } | |
4990 | // Don't invoke for arrows, pageDown, home, backspace, etc. (on non-keypress events) | |
4991 | return thirdLevelKey && (!ev.keyCode || ev.keyCode > 47); | |
4992 | } | |
4993 | function matchColor(r1, g1, b1) { | |
4994 | var hash = (r1 << 16) | (g1 << 8) | b1; | |
4995 | if (matchColor._cache[hash] != null) { | |
4996 | return matchColor._cache[hash]; | |
4997 | } | |
4998 | var ldiff = Infinity, li = -1, i = 0, c, r2, g2, b2, diff; | |
4999 | for (; i < Terminal.vcolors.length; i++) { | |
5000 | c = Terminal.vcolors[i]; | |
5001 | r2 = c[0]; | |
5002 | g2 = c[1]; | |
5003 | b2 = c[2]; | |
5004 | diff = matchColor.distance(r1, g1, b1, r2, g2, b2); | |
5005 | if (diff === 0) { | |
5006 | li = i; | |
5007 | break; | |
5008 | } | |
5009 | if (diff < ldiff) { | |
5010 | ldiff = diff; | |
5011 | li = i; | |
5012 | } | |
5013 | } | |
5014 | return matchColor._cache[hash] = li; | |
5015 | } | |
5016 | matchColor._cache = {}; | |
5017 | // http://stackoverflow.com/questions/1633828 | |
5018 | matchColor.distance = function (r1, g1, b1, r2, g2, b2) { | |
5019 | return Math.pow(30 * (r1 - r2), 2) | |
5020 | + Math.pow(59 * (g1 - g2), 2) | |
5021 | + Math.pow(11 * (b1 - b2), 2); | |
5022 | }; | |
5023 | function each(obj, iter, con) { | |
5024 | if (obj.forEach) | |
5025 | return obj.forEach(iter, con); | |
5026 | for (var i = 0; i < obj.length; i++) { | |
5027 | iter.call(con, obj[i], i, obj); | |
5028 | } | |
5029 | } | |
5030 | function keys(obj) { | |
5031 | if (Object.keys) | |
5032 | return Object.keys(obj); | |
5033 | var key, keys = []; | |
5034 | for (key in obj) { | |
5035 | if (Object.prototype.hasOwnProperty.call(obj, key)) { | |
5036 | keys.push(key); | |
5037 | } | |
5038 | } | |
5039 | return keys; | |
5040 | } | |
5041 | var wcwidth = (function (opts) { | |
5042 | // extracted from https://www.cl.cam.ac.uk/%7Emgk25/ucs/wcwidth.c | |
5043 | // combining characters | |
5044 | var COMBINING = [ | |
5045 | [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489], | |
5046 | [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2], | |
5047 | [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603], | |
5048 | [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670], | |
5049 | [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED], | |
5050 | [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A], | |
5051 | [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902], | |
5052 | [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D], | |
5053 | [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981], | |
5054 | [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD], | |
5055 | [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C], | |
5056 | [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D], | |
5057 | [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC], | |
5058 | [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD], | |
5059 | [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C], | |
5060 | [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D], | |
5061 | [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0], | |
5062 | [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48], | |
5063 | [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC], | |
5064 | [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD], | |
5065 | [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D], | |
5066 | [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6], | |
5067 | [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E], | |
5068 | [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC], | |
5069 | [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35], | |
5070 | [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E], | |
5071 | [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97], | |
5072 | [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030], | |
5073 | [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039], | |
5074 | [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F], | |
5075 | [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753], | |
5076 | [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD], | |
5077 | [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD], | |
5078 | [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922], | |
5079 | [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B], | |
5080 | [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34], | |
5081 | [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42], | |
5082 | [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF], | |
5083 | [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063], | |
5084 | [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F], | |
5085 | [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B], | |
5086 | [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F], | |
5087 | [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB], | |
5088 | [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F], | |
5089 | [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169], | |
5090 | [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD], | |
5091 | [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F], | |
5092 | [0xE0100, 0xE01EF] | |
5093 | ]; | |
5094 | // binary search | |
5095 | function bisearch(ucs) { | |
5096 | var min = 0; | |
5097 | var max = COMBINING.length - 1; | |
5098 | var mid; | |
5099 | if (ucs < COMBINING[0][0] || ucs > COMBINING[max][1]) | |
5100 | return false; | |
5101 | while (max >= min) { | |
5102 | mid = Math.floor((min + max) / 2); | |
5103 | if (ucs > COMBINING[mid][1]) | |
5104 | min = mid + 1; | |
5105 | else if (ucs < COMBINING[mid][0]) | |
5106 | max = mid - 1; | |
5107 | else | |
5108 | return true; | |
5109 | } | |
5110 | return false; | |
5111 | } | |
5112 | function wcwidth(ucs) { | |
5113 | // test for 8-bit control characters | |
5114 | if (ucs === 0) | |
5115 | return opts.nul; | |
5116 | if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0)) | |
5117 | return opts.control; | |
5118 | // binary search in table of non-spacing characters | |
5119 | if (bisearch(ucs)) | |
5120 | return 0; | |
5121 | // if we arrive here, ucs is not a combining or C0/C1 control character | |
5122 | return 1 + | |
5123 | (ucs >= 0x1100 && | |
5124 | (ucs <= 0x115f || | |
5125 | ucs == 0x2329 || | |
5126 | ucs == 0x232a || | |
5127 | (ucs >= 0x2e80 && ucs <= 0xa4cf && ucs != 0x303f) || | |
5128 | (ucs >= 0xac00 && ucs <= 0xd7a3) || | |
5129 | (ucs >= 0xf900 && ucs <= 0xfaff) || | |
5130 | (ucs >= 0xfe10 && ucs <= 0xfe19) || | |
5131 | (ucs >= 0xfe30 && ucs <= 0xfe6f) || | |
5132 | (ucs >= 0xff00 && ucs <= 0xff60) || | |
5133 | (ucs >= 0xffe0 && ucs <= 0xffe6) || | |
5134 | (ucs >= 0x20000 && ucs <= 0x2fffd) || | |
5135 | (ucs >= 0x30000 && ucs <= 0x3fffd))); | |
5136 | } | |
5137 | return wcwidth; | |
5138 | })({ nul: 0, control: 0 }); // configurable options | |
5ce522a4 PK |
5139 | /** |
5140 | * Expose | |
cd70d298 PK |
5141 | */ |
5142 | Terminal.EventEmitter = EventEmitter_js_1.EventEmitter; | |
5143 | Terminal.inherits = inherits; | |
5144 | /** | |
5ce522a4 PK |
5145 | * Adds an event listener to the terminal. |
5146 | * | |
5147 | * @param {string} event The name of the event. TODO: Document all event types | |
5148 | * @param {function} callback The function to call when the event is triggered. | |
cd70d298 PK |
5149 | */ |
5150 | Terminal.on = on; | |
5151 | Terminal.off = off; | |
5152 | Terminal.cancel = cancel; | |
5153 | module.exports = Terminal; | |
5ce522a4 | 5154 | |
521d7dbd | 5155 | },{"./CompositionHelper.js":1,"./EventEmitter.js":2,"./Viewport.js":3,"./handlers/Clipboard.js":4,"./utils/Browser":5}]},{},[7])(7) |
5ce522a4 PK |
5156 | }); |
5157 | //# sourceMappingURL=xterm.js.map |