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