Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/assets/term/term.js
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/**6* tty.js - an xterm emulator7*8* Copyright (c) 2012, Christopher Jeffrey (https://github.com/chjj/tty.js)9*10* Permission is hereby granted, free of charge, to any person obtaining a copy11* of this software and associated documentation files (the "Software"), to deal12* in the Software without restriction, including without limitation the rights13* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell14* copies of the Software, and to permit persons to whom the Software is15* furnished to do so, subject to the following conditions:16*17* The above copyright notice and this permission notice shall be included in18* all copies or substantial portions of the Software.19*20* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR21* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,22* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE23* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER24* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,25* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN26* THE SOFTWARE.27*28* Originally forked from (with the author's permission):29* Fabrice Bellard's javascript vt100 for jslinux:30* http://bellard.org/jslinux/31* Copyright (c) 2011 Fabrice Bellard32* The original design remains. The terminal itself33* has been extended to include xterm CSI codes, among34* other features.35*/3637(function() {38/**39* Terminal Emulation References:40* http://vt100.net/41* http://invisible-island.net/xterm/ctlseqs/ctlseqs.txt42* http://invisible-island.net/xterm/ctlseqs/ctlseqs.html43* http://invisible-island.net/vttest/44* http://www.inwap.com/pdp10/ansicode.txt45* http://linux.die.net/man/4/console_codes46* http://linux.die.net/man/7/urxvt47*/4849"use strict";5051/**52* Shared53*/5455var window = this,56document = this.document;5758/**59* EventEmitter60*/6162function EventEmitter() {63this._events = this._events || {};64}6566EventEmitter.prototype.addListener = function(type, listener) {67this._events[type] = this._events[type] || [];68this._events[type].push(listener);69};7071EventEmitter.prototype.on = EventEmitter.prototype.addListener;7273EventEmitter.prototype.removeListener = function(type, listener) {74if (!this._events[type]) return;7576var obj = this._events[type],77i = obj.length;7879while (i--) {80if (obj[i] === listener || obj[i].listener === listener) {81obj.splice(i, 1);82return;83}84}85};8687EventEmitter.prototype.off = EventEmitter.prototype.removeListener;8889EventEmitter.prototype.removeAllListeners = function(type) {90if (this._events[type]) delete this._events[type];91};9293EventEmitter.prototype.once = function(type, listener) {94function on() {95var args = Array.prototype.slice.call(arguments);96this.removeListener(type, on);97return listener.apply(this, args);98}99on.listener = listener;100return this.on(type, on);101};102103EventEmitter.prototype.emit = function(type) {104if (!this._events[type]) return;105106var args = Array.prototype.slice.call(arguments, 1),107obj = this._events[type],108l = obj.length,109i = 0;110111for (; i < l; i++) {112obj[i].apply(this, args);113}114};115116EventEmitter.prototype.listeners = function(type) {117return (this._events[type] = this._events[type] || []);118};119120/**121* States122*/123124var normal = 0,125escaped = 1,126csi = 2,127osc = 3,128charset = 4,129dcs = 5,130ignore = 6;131132/**133* Terminal134*/135136function Terminal(cols, rows, handler) {137EventEmitter.call(this);138139var options;140// Yes, we have to check for null! See https://github.com/sagemathinc/cocalc/issues/5961141if (cols != null && typeof cols === "object") {142options = cols;143cols = options.cols;144rows = options.rows;145handler = options.handler;146}147this._options = options || {};148149this.cols = cols || Terminal.geometry[0];150this.rows = rows || Terminal.geometry[1];151152if (handler) {153this.on("data", handler);154}155156this.ybase = 0;157this.ydisp = 0;158this.x = 0;159this.y = 0;160this.cursorState = 0;161this.cursorHidden = false;162this.convertEol = false;163this.state = 0;164this.queue = "";165this.scrollTop = 0;166this.scrollBottom = this.rows - 1;167168// modes169this.applicationKeypad = false;170this.originMode = false;171this.insertMode = false;172this.wraparoundMode = false;173this.normal = null;174175// charset176this.charset = null;177this.gcharset = null;178this.glevel = 0;179this.charsets = [null];180181// mouse properties182this.decLocator;183this.x10Mouse;184this.vt200Mouse;185this.vt300Mouse;186this.normalMouse;187this.mouseEvents;188this.sendFocus;189this.utfMouse;190this.sgrMouse;191this.urxvtMouse;192193// misc194this.element;195this.children;196this.refreshStart;197this.refreshEnd;198this.savedX;199this.savedY;200this.savedCols;201202// stream203this.readable = true;204this.writable = true;205206this.defAttr = (257 << 9) | 256;207this.curAttr = this.defAttr;208209this.params = [];210this.currentParam = 0;211this.prefix = "";212this.postfix = "";213214this.lines = [];215var i = this.rows;216while (i--) {217this.lines.push(this.blankLine());218}219220this.tabs;221this.setupStops();222}223224inherits(Terminal, EventEmitter);225226/**227* Colors228*/229230// Colors 0-15231Terminal.colors = [232// dark:233"#000000", // black234"#cc0000", // red235"#4e9a06", // green236"#c4a000", // yellow237"#3465a4", // blue238"#75507b", // magenta239"#06989a", // cyan240"#d3d7cf", // white-ish (really light grey)241// bright versions of the above.242"#555753", // bright black243"#ef2929", // bright red244"#8ae234", // bright green245"#fce94f", // bright yellow246"#729fcf", // bright blue247"#ad7fa8", // bright magenta248"#34e2e2", // bright cyan249"#ffffff" // bright white250];251252// Colors 16-255253// Much thanks to TooTallNate for writing this.254Terminal.colors = (function() {255var colors = Terminal.colors,256r = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff],257i;258259// 16-231260i = 0;261for (; i < 216; i++) {262out(r[((i / 36) % 6) | 0], r[((i / 6) % 6) | 0], r[i % 6]);263}264265// 232-255 (grey)266i = 0;267for (; i < 24; i++) {268r = 8 + i * 10;269out(r, r, r);270}271272function out(r, g, b) {273colors.push("#" + hex(r) + hex(g) + hex(b));274}275276function hex(c) {277c = c.toString(16);278return c.length < 2 ? "0" + c : c;279}280281return colors;282})();283284// Default BG/FG285Terminal.defaultColors = {286bg: Terminal.colors[15], // '#ffffff',287fg: Terminal.colors[0] // '#000000'288};289290Terminal.colors[256] = Terminal.defaultColors.bg;291Terminal.colors[257] = Terminal.defaultColors.fg;292293/**294* Options295*/296297Terminal.termName = "xterm";298Terminal.geometry = [80, 24];299Terminal.cursorBlink = false;300Terminal.visualBell = false;301Terminal.popOnBell = false;302Terminal.scrollback = 1000;303Terminal.screenKeys = false;304Terminal.programFeatures = false;305Terminal.debug = false;306307/**308* Focused Terminal309*/310311Terminal.focus = null;312313Terminal.prototype.blur = function() {314if (Terminal.focus !== this) return;315if (Terminal.focus) {316Terminal.focus.cursorState = 0;317Terminal.focus.refresh(Terminal.focus.y, Terminal.focus.y);318if (Terminal.focus.sendFocus) Terminal.focus.send("\x1b[O");319}320Terminal.focus = undefined;321};322323Terminal.prototype.focus = function() {324if (Terminal.focus === this) return;325if (Terminal.focus) {326Terminal.focus.cursorState = 0;327Terminal.focus.refresh(Terminal.focus.y, Terminal.focus.y);328if (Terminal.focus.sendFocus) Terminal.focus.send("\x1b[O");329}330Terminal.focus = this;331if (this.sendFocus) this.send("\x1b[I");332this.showCursor();333};334335/**336* Global Events for key handling337*/338339function getSelectionHtml() {340/* from http://stackoverflow.com/questions/5222814/window-getselection-return-html */341var html = "";342if (typeof window.getSelection != "undefined") {343var sel = window.getSelection();344if (sel.rangeCount) {345var container = document.createElement("div");346for (var i = 0, len = sel.rangeCount; i < len; ++i) {347container.appendChild(sel.getRangeAt(i).cloneContents());348}349html = container.innerHTML;350}351} else if (typeof document.selection != "undefined") {352if (document.selection.type == "Text") {353html = document.selection.createRange().htmlText;354}355}356return html;357}358359Terminal.keys_are_bound = false;360Terminal.bindKeys = function(client_keydown) {361if (Terminal.focus) return;362363/* It is critical that we only bind to the keyboard once in the whole program.364If we bind more than once, than multiple terms on the same365page will result in multiple key data being sent.366*/367if (Terminal.keys_are_bound) return;368Terminal.keys_are_bound = true;369370// We handle composite characters, which otherwise371// would not work with firefox and opera. This372// addresses https://github.com/sagemathinc/cocalc/issues/2211373// Idea/work done by Gonzalo Tornaría.374on(375document,376"compositionend",377function(ev) {378Terminal.focus.handler(ev.data);379},380true381);382383on(384document,385"keydown",386function(ev) {387if (typeof Terminal.focus === "undefined") {388return;389}390391//console.log('term.js keydown ', ev);392393if (394typeof client_keydown != "undefined" &&395client_keydown(ev) === false396) {397return false;398}399400if (!isMac) {401// on OS X ctrl-C does *not* copy, so we don't need to do this.402if (ev.ctrlKey && ev.keyCode == 67 && getSelectionHtml() != "") {403// copy404return false;405}406407if (ev.ctrlKey && ev.keyCode == 86) {408// paste409return false;410}411}412413/* term -- handle the keystroke via the xterm . */414if (typeof Terminal.focus === "object") {415return Terminal.focus.keyDown(ev);416}417},418true419);420421on(422document,423"keypress",424function(ev) {425if (typeof Terminal.focus === "undefined") {426return;427}428429if (typeof Terminal.focus === "object") {430return Terminal.focus.keyPress(ev);431}432},433true434);435};436437/*Terminal.bindKeys = function() {438if (Terminal.focus) return;439440// We could put an "if (Terminal.focus)" check441// here, but it shouldn't be necessary.442on(document, 'keydown', function(ev) {443if (ev.metaKey) { return false ; } // allow copy/paste/etc. on OS X444return Terminal.focus.keyDown(ev);445}, true);446447on(document, 'keypress', function(ev) {448if (ev.metaKey) { return false ; } // allow copy/paste/etc. on OS X449return Terminal.focus.keyPress(ev);450}, true);451};452*/453454/**455* Open Terminal456*/457458Terminal.prototype.open = function() {459var self = this,460i = 0,461div;462463this.set_color_scheme("default");464this.element = document.createElement("div");465this.element.setAttribute("spellcheck", "false");466this.children = [];467468for (; i < this.rows; i++) {469div = document.createElement("div");470this.element.appendChild(div);471this.children.push(div);472}473474document.body.appendChild(this.element);475476this.refresh(0, this.rows - 1);477478Terminal.bindKeys(this.client_keydown);479this.focus();480481this.startBlink();482483on(this.element, "mousedown", function() {484self.focus();485});486487// This probably shouldn't work,488// ... but it does. Firefox's paste489// event seems to only work for textareas?490on(491this.element,492"mousedown",493function(ev) {494var button =495ev.button != null496? +ev.button497: ev.which != null498? ev.which - 1499: null;500501// Does IE9 do this?502if (~navigator.userAgent.indexOf("MSIE")) {503button = button === 1 ? 0 : button === 4 ? 1 : button;504}505506if (button !== 2) return;507508self.element.contentEditable = "true";509setTimeout(function() {510self.element.contentEditable = "inherit"; // 'false';511}, 1);512},513true514);515516on(this.element, "paste", function(ev) {517if (ev.clipboardData) {518self.send(ev.clipboardData.getData("text/plain"));519} else if (window.clipboardData) {520self.send(window.clipboardData.getData("Text"));521}522// Not necessary. Do it anyway for good measure.523self.element.contentEditable = "inherit";524return cancel(ev);525});526527this.bindMouse();528529// XXX - hack, move this somewhere else.530if (Terminal.brokenBold == null) {531Terminal.brokenBold = isBoldBroken();532}533534// sync default bg/fg colors535this.element.style.backgroundColor = this.defaultColors.bg;536this.element.style.color = this.defaultColors.fg;537538//this.emit('open');539};540541Terminal.prototype.set_color_scheme = function(color_scheme) {542const data = Terminal.color_schemes[color_scheme];543if (data == null) {544console.warn(`unknown color scheme "${color_scheme}"`);545return;546}547const colors = data.colors;548this.colors = [];549for (let i = 0; i < 16; i++) {550this.colors[i] = colors[i];551}552553if (colors.length > 16) {554this.defaultColors = {555fg: colors[16],556bg: colors[17]557};558} else {559this.defaultColors = {560fg: colors[15],561bg: colors[0]562};563}564this.colors[256] = this.defaultColors.bg;565this.colors[257] = this.defaultColors.fg;566567if (this.element != null) {568this.element.style.backgroundColor = this.defaultColors.bg;569this.element.style.color = this.defaultColors.fg;570}571};572573Terminal.prototype.set_font_size = function(size) {574$(this.element).css("font-size", `${size}px`);575};576577Terminal.prototype.set_font_family = function(family) {578$(this.element).css("font-family", `${family}, Monospace`);579};580581// XTerm mouse events582// http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking583// To better understand these584// the xterm code is very helpful:585// Relevant files:586// button.c, charproc.c, misc.c587// Relevant functions in xterm/button.c:588// BtnCode, EmitButtonCode, EditorButton, SendMousePosition589Terminal.prototype.bindMouse = function() {590var el = this.element,591self = this,592pressed = 32;593594var wheelEvent = "onmousewheel" in window ? "mousewheel" : "DOMMouseScroll";595596// mouseup, mousedown, mousewheel597// left click: ^[[M 3<^[[M#3<598// mousewheel up: ^[[M`3>599function sendButton(ev) {600var button, pos;601602// get the xterm-style button603button = getButton(ev);604605// get mouse coordinates606pos = getCoords(ev);607if (!pos) return;608609sendEvent(button, pos);610611switch (ev.type) {612case "mousedown":613pressed = button;614break;615case "mouseup":616// keep it at the left617// button, just in case.618pressed = 32;619break;620case wheelEvent:621// nothing. don't622// interfere with623// `pressed`.624break;625}626}627628// motion example of a left click:629// ^[[M 3<^[[M@4<^[[M@5<^[[M@6<^[[M@7<^[[M#7<630function sendMove(ev) {631var button = pressed,632pos;633634pos = getCoords(ev);635if (!pos) return;636637// buttons marked as motions638// are incremented by 32639button += 32;640641sendEvent(button, pos);642}643644// encode button and645// position to characters646function encode(data, ch) {647if (!self.utfMouse) {648if (ch === 255) return data.push(0);649if (ch > 127) ch = 127;650data.push(ch);651} else {652if (ch === 2047) return data.push(0);653if (ch < 127) {654data.push(ch);655} else {656if (ch > 2047) ch = 2047;657data.push(0xc0 | (ch >> 6));658data.push(0x80 | (ch & 0x3f));659}660}661}662663// send a mouse event:664// regular/utf8: ^[[M Cb Cx Cy665// urxvt: ^[[ Cb ; Cx ; Cy M666// sgr: ^[[ Cb ; Cx ; Cy M/m667// vt300: ^[[ 24(1/3/5)~ [ Cx , Cy ] \r668// locator: CSI P e ; P b ; P r ; P c ; P p & w669function sendEvent(button, pos) {670// self.emit('mouse', {671// x: pos.x - 32,672// y: pos.x - 32,673// button: button674// });675676if (self.vt300Mouse) {677// NOTE: Unstable.678// http://www.vt100.net/docs/vt3xx-gp/chapter15.html679button &= 3;680pos.x -= 32;681pos.y -= 32;682var data = "\x1b[24";683if (button === 0) data += "1";684else if (button === 1) data += "3";685else if (button === 2) data += "5";686else if (button === 3) return;687else data += "0";688data += "~[" + pos.x + "," + pos.y + "]\r";689self.send(data);690return;691}692693if (self.decLocator) {694// NOTE: Unstable.695button &= 3;696pos.x -= 32;697pos.y -= 32;698if (button === 0) button = 2;699else if (button === 1) button = 4;700else if (button === 2) button = 6;701else if (button === 3) button = 3;702self.send(703"\x1b[" +704button +705";" +706(button === 3 ? 4 : 0) +707";" +708pos.y +709";" +710pos.x +711";" +712(pos.page || 0) +713"&w"714);715return;716}717718if (self.urxvtMouse) {719pos.x -= 32;720pos.y -= 32;721pos.x++;722pos.y++;723self.send("\x1b[" + button + ";" + pos.x + ";" + pos.y + "M");724return;725}726727if (self.sgrMouse) {728pos.x -= 32;729pos.y -= 32;730self.send(731"\x1b[<" +732((button & 3) === 3 ? button & ~3 : button) +733";" +734pos.x +735";" +736pos.y +737((button & 3) === 3 ? "m" : "M")738);739return;740}741742var data = [];743744encode(data, button);745encode(data, pos.x);746encode(data, pos.y);747748self.send("\x1b[M" + String.fromCharCode.apply(String, data));749}750751function getButton(ev) {752var button, shift, meta, ctrl, mod;753754// two low bits:755// 0 = left756// 1 = middle757// 2 = right758// 3 = release759// wheel up/down:760// 1, and 2 - with 64 added761switch (ev.type) {762case "mousedown":763button =764ev.button != null765? +ev.button766: ev.which != null767? ev.which - 1768: null;769770if (~navigator.userAgent.indexOf("MSIE")) {771button = button === 1 ? 0 : button === 4 ? 1 : button;772}773break;774case "mouseup":775button = 3;776break;777case "DOMMouseScroll":778button = ev.detail < 0 ? 64 : 65;779break;780case "mousewheel":781button = ev.wheelDeltaY > 0 ? 64 : 65;782break;783}784785// next three bits are the modifiers:786// 4 = shift, 8 = meta, 16 = control787shift = ev.shiftKey ? 4 : 0;788meta = ev.metaKey ? 8 : 0;789ctrl = ev.ctrlKey ? 16 : 0;790mod = shift | meta | ctrl;791792// no mods793if (self.vt200Mouse) {794// ctrl only795mod &= ctrl;796} else if (!self.normalMouse) {797mod = 0;798}799800// increment to SP801button = 32 + (mod << 2) + button;802803return button;804}805806// mouse coordinates measured in cols/rows807function getCoords(ev) {808var x, y, w, h, el;809810// ignore browsers without pageX for now811if (ev.pageX == null) return;812813x = ev.pageX;814y = ev.pageY;815el = self.element;816817// should probably check offsetParent but this is more portable818var offset = $(el).offset();819x -= offset.left;820y -= offset.top;821822// convert to cols/rows823w = self.element.clientWidth;824h = self.element.clientHeight;825x = (x / w * self.cols) | 0;826y = (y / h * self.rows) | 0;827x += 1;828y += 1;829830// be sure to avoid sending831// bad positions to the program832if (x < 0) x = 0;833if (x > self.cols) x = self.cols;834if (y < 0) y = 0;835if (y > self.rows) y = self.rows;836837// xterm sends raw bytes and838// starts at 32 (SP) for each.839x += 32;840y += 32;841842return {843x: x,844y: y,845down: ev.type === "mousedown",846up: ev.type === "mouseup",847wheel: ev.type === wheelEvent,848move: ev.type === "mousemove"849};850}851852on(el, "mousedown", function(ev) {853if (!self.mouseEvents) return;854855// send the button856sendButton(ev);857858// ensure focus859self.focus();860861// fix for odd bug862if (self.vt200Mouse) {863sendButton(new ev.constructor("mouseup", ev));864return cancel(ev);865}866867// bind events868if (self.normalMouse) on(document, "mousemove", sendMove);869870// x10 compatibility mode can't send button releases871if (!self.x10Mouse) {872on(document, "mouseup", function up(ev) {873sendButton(ev);874if (self.normalMouse) off(document, "mousemove", sendMove);875off(document, "mouseup", up);876return cancel(ev);877});878}879880return cancel(ev);881});882883on(el, wheelEvent, function(ev) {884if (!self.mouseEvents) return;885if (self.x10Mouse || self.vt300Mouse || self.decLocator) return;886sendButton(ev);887return cancel(ev);888});889890// allow mousewheel scrolling in891// the shell for example892on(el, wheelEvent, function(ev) {893if (self.mouseEvents) return;894if (self.applicationKeypad) return;895if (ev.type === "DOMMouseScroll") {896self.scrollDisp(ev.detail < 0 ? -5 : 5);897} else {898self.scrollDisp(ev.wheelDeltaY > 0 ? -5 : 5);899}900return cancel(ev);901});902};903904/**905* Destroy Terminal906*/907908Terminal.prototype.destroy = function() {909this.readable = false;910this.writable = false;911this._events = {};912this.handler = function() {};913this.write = function() {};914//this.emit('close');915this.removeAllListeners();916};917918/**919* Rendering Engine920*/921922// In the screen buffer, each character923// is stored as an array with a character924// and a 32-bit integer.925// First value: a utf-16 character.926// Second value:927// Next 9 bits: background color (0-511).928// Next 9 bits: foreground color (0-511).929// Next 14 bits: a mask for misc. flags:930// 1=bold, 2=underline, 4=inverse931932Terminal.prototype.refresh = function(start, end) {933if (934typeof this.custom_renderer !== "undefined" &&935this.custom_renderer !== null936) {937this.custom_renderer(start, end);938return;939}940941var x,942y,943i,944line,945out,946ch,947width,948data,949attr,950fgColor,951bgColor,952flags,953row,954parent;955956if (end - start >= this.rows / 2) {957parent = this.element.parentNode;958if (parent) parent.removeChild(this.element);959}960961width = this.cols;962y = start;963964for (; y <= end; y++) {965row = y + this.ydisp;966967if (row >= this.lines.length) break;968line = this.lines[row];969out = "";970971if (972y === this.y &&973this.cursorState &&974this.ydisp === this.ybase &&975!this.cursorHidden976) {977x = this.x;978} else {979x = -1;980}981982attr = this.defAttr;983i = 0;984985if (typeof line === "undefined" || line === null) {986/* I added this since sometimes "line.length" below raises an exception crashing everything. */987continue;988}989var w = Math.min(width, line.length);990991/*992var ln="", j;993for(j=0;j<w;j++) {994ln += line[j][1];995}996console.log("line=",ln); */997998for (; i < w; i++) {999if (!(line[i] != null)) {1000continue;1001}1002data = line[i][0];1003ch = line[i][1];10041005if (i === x) data = -1;10061007if (data !== attr) {1008if (attr !== this.defAttr) {1009out += "</span>";1010}1011if (data !== this.defAttr) {1012if (data === -1) {1013out += '<span class="webapp-console-cursor-focus">';1014} else {1015out += '<span style="';10161017bgColor = data & 0x1ff;1018fgColor = (data >> 9) & 0x1ff;1019flags = data >> 18;10201021if (flags & 1) {1022if (!Terminal.brokenBold) {1023out += "font-weight:bold;";1024}1025// see: XTerm*boldColors1026if (fgColor < 8) fgColor += 8;1027}10281029if (flags & 2) {1030out += "text-decoration:underline;";1031}10321033if (bgColor !== 256) {1034out += "background-color:" + this.colors[bgColor] + ";";1035}10361037if (fgColor !== 257) {1038out += "color:" + this.colors[fgColor] + ";";1039}10401041out += '">';1042}1043}1044}10451046switch (ch) {1047case "&":1048out += "&";1049break;1050case "<":1051out += "<";1052break;1053case ">":1054out += ">";1055break;1056default:1057if (ch <= " ") {1058out += " ";1059} else {1060out += ch;1061}1062break;1063}10641065attr = data;1066}10671068if (attr !== this.defAttr) {1069out += "</span>";1070}10711072var a = this.children[y];1073if (a != null) {1074/* Strip trailing 's, which helps massively with copy/paste. */1075/* TODO: should do this with a regexp, but I couldn't easily think of one... */1076i = out.length;1077while (out.slice(i - 6, i) === " ") {1078i -= 6;1079}1080out = out.slice(0, i);1081if (out.length === 0) {1082out = " ";1083}10841085a.innerHTML = out;1086}1087}10881089if (parent) parent.appendChild(this.element);1090};10911092Terminal.prototype.cursorBlink = function() {1093return; /* we use css for this */1094if (Terminal.focus !== this) return;1095this.cursorState ^= 1;1096this.refresh(this.y, this.y);1097};10981099Terminal.prototype.showCursor = function() {1100if (!this.cursorState) {1101this.cursorState = 1;1102this.refresh(this.y, this.y);1103} else {1104// Temporarily disabled:1105// this.refreshBlink();1106}1107};11081109Terminal.prototype.startBlink = function() {1110return; /* we use css for this */1111if (!Terminal.cursorBlink) return;1112var self = this;1113this._blinker = function() {1114self.cursorBlink();1115};1116this._blink = setInterval(this._blinker, 500);1117};11181119Terminal.prototype.refreshBlink = function() {1120return; /* we use css for this */1121if (!Terminal.cursorBlink) return;1122clearInterval(this._blink);1123this._blink = setInterval(this._blinker, 500);1124};11251126Terminal.prototype.scroll = function() {1127var row;11281129if (++this.ybase === Terminal.scrollback) {1130this.ybase = (this.ybase / 2) | 0;1131this.lines = this.lines.slice(-(this.ybase + this.rows) + 1);1132}11331134this.ydisp = this.ybase;11351136// last line1137row = this.ybase + this.rows - 1;11381139// subtract the bottom scroll region1140row -= this.rows - 1 - this.scrollBottom;11411142if (row === this.lines.length) {1143// potential optimization:1144// pushing is faster than splicing1145// when they amount to the same1146// behavior.1147this.lines.push(this.blankLine());1148} else {1149// add our new line1150this.lines.splice(row, 0, this.blankLine());1151}11521153if (this.scrollTop !== 0) {1154if (this.ybase !== 0) {1155this.ybase--;1156this.ydisp = this.ybase;1157}1158this.lines.splice(this.ybase + this.scrollTop, 1);1159}11601161// this.maxRange();1162this.updateRange(this.scrollTop);1163this.updateRange(this.scrollBottom);1164};11651166Terminal.prototype.scrollDisp = function(disp) {1167this.ydisp += disp;11681169if (this.ydisp > this.ybase) {1170this.ydisp = this.ybase;1171} else if (this.ydisp < 0) {1172this.ydisp = 0;1173}11741175this.emit("scroll", this.ydisp, this.ybase);11761177this.refresh(0, this.rows - 1);1178};11791180Terminal.prototype.setchar = function(x, y, attr, ch) {1181var line = this.lines[y];1182if (line != null) {1183line[x] = [attr, ch];1184}1185};11861187Terminal.prototype.write = function(data) {1188var l = data.length,1189i = 0,1190cs,1191ch;11921193this.refreshStart = this.y;1194this.refreshEnd = this.y;11951196if (this.ybase !== this.ydisp) {1197this.ydisp = this.ybase;1198this.maxRange();1199}12001201// this.log(JSON.stringify(data.replace(/\x1b/g, '^[')));12021203for (; i < l; i++) {1204ch = data[i];1205switch (this.state) {1206case normal:1207switch (ch) {1208// '\0'1209// case '\0':1210// break;12111212// '\a'1213case "\x07":1214this.bell();1215break;12161217// '\n', '\v', '\f'1218case "\n":1219case "\x0b":1220case "\x0c":1221if (this.convertEol) {1222this.x = 0;1223}1224this.y++;1225if (this.y > this.scrollBottom) {1226this.y--;1227this.scroll();1228}1229break;12301231// '\r'1232case "\r":1233this.x = 0;1234break;12351236// '\b'1237case "\x08":1238if (this.x > 0) {1239this.x--;1240}1241break;12421243// '\t'1244case "\t":1245this.x = this.nextStop();1246break;12471248// shift out1249case "\x0e":1250this.setgLevel(1);1251break;12521253// shift in1254case "\x0f":1255this.setgLevel(0);1256break;12571258// '\e'1259case "\x1b":1260this.state = escaped;1261break;12621263default:1264// ' '1265if (ch >= " ") {1266if (this.charset && this.charset[ch]) {1267ch = this.charset[ch];1268}1269if (this.x >= this.cols) {1270this.x = 0;1271this.y++;1272if (this.y > this.scrollBottom) {1273this.y--;1274this.scroll();1275}1276}1277/* this.lines[this.y + this.ybase][this.x] = [this.curAttr, ch]; */1278this.setchar(this.x, this.y + this.ybase, this.curAttr, ch);1279this.x++;1280this.updateRange(this.y);1281}1282break;1283}1284break;1285case escaped:1286switch (ch) {1287// ESC [ Control Sequence Introducer ( CSI is 0x9b).1288case "[":1289this.params = [];1290this.currentParam = 0;1291this.state = csi;1292break;12931294// ESC ] Operating System Command ( OSC is 0x9d).1295case "]":1296this.params = [];1297this.currentParam = 0;1298this.state = osc;1299break;13001301// ESC P Device Control String ( DCS is 0x90).1302case "P":1303this.params = [];1304this.currentParam = 0;1305this.state = dcs;1306break;13071308// ESC _ Application Program Command ( APC is 0x9f).1309case "_":1310this.state = ignore;1311break;13121313// ESC ^ Privacy Message ( PM is 0x9e).1314case "^":1315this.state = ignore;1316break;13171318// ESC c Full Reset (RIS).1319case "c":1320this.reset();1321break;13221323// ESC E Next Line ( NEL is 0x85).1324// ESC D Index ( IND is 0x84).1325case "E":1326this.x = 0;1327case "D":1328this.index();1329break;13301331// ESC M Reverse Index ( RI is 0x8d).1332case "M":1333this.reverseIndex();1334break;13351336// ESC % Select default/utf-8 character set.1337// @ = default, G = utf-81338case "%":1339//this.charset = null;1340this.setgLevel(0);1341this.setgCharset(0, Terminal.charsets.US);1342this.state = normal;1343i++;1344break;13451346// ESC (,),*,+,-,. Designate G0-G2 Character Set.1347case "(": // <-- this seems to get all the attention1348case ")":1349case "*":1350case "+":1351case "-":1352case ".":1353switch (ch) {1354case "(":1355this.gcharset = 0;1356break;1357case ")":1358this.gcharset = 1;1359break;1360case "*":1361this.gcharset = 2;1362break;1363case "+":1364this.gcharset = 3;1365break;1366case "-":1367this.gcharset = 1;1368break;1369case ".":1370this.gcharset = 2;1371break;1372}1373this.state = charset;1374break;13751376// Designate G3 Character Set (VT300).1377// A = ISO Latin-1 Supplemental.1378// Not implemented.1379case "/":1380this.gcharset = 3;1381this.state = charset;1382i--;1383break;13841385// ESC N1386// Single Shift Select of G2 Character Set1387// ( SS2 is 0x8e). This affects next character only.1388case "N":1389break;1390// ESC O1391// Single Shift Select of G3 Character Set1392// ( SS3 is 0x8f). This affects next character only.1393case "O":1394break;1395// ESC n1396// Invoke the G2 Character Set as GL (LS2).1397case "n":1398this.setgLevel(2);1399break;1400// ESC o1401// Invoke the G3 Character Set as GL (LS3).1402case "o":1403this.setgLevel(3);1404break;1405// ESC |1406// Invoke the G3 Character Set as GR (LS3R).1407case "|":1408this.setgLevel(3);1409break;1410// ESC }1411// Invoke the G2 Character Set as GR (LS2R).1412case "}":1413this.setgLevel(2);1414break;1415// ESC ~1416// Invoke the G1 Character Set as GR (LS1R).1417case "~":1418this.setgLevel(1);1419break;14201421// ESC 7 Save Cursor (DECSC).1422case "7":1423this.saveCursor();1424this.state = normal;1425break;14261427// ESC 8 Restore Cursor (DECRC).1428case "8":1429this.restoreCursor();1430this.state = normal;1431break;14321433// ESC # 3 DEC line height/width1434case "#":1435this.state = normal;1436i++;1437break;14381439// ESC H Tab Set (HTS is 0x88).1440case "H":1441this.tabSet();1442break;14431444// ESC = Application Keypad (DECPAM).1445case "=":1446this.log("Serial port requested application keypad.");1447this.applicationKeypad = true;1448this.state = normal;1449break;14501451// ESC > Normal Keypad (DECPNM).1452case ">":1453this.log("Switching back to normal keypad.");1454this.applicationKeypad = false;1455this.state = normal;1456break;14571458default:1459this.state = normal;1460this.error("Unknown ESC control: %s.", ch);1461break;1462}1463break;14641465case charset:1466switch (ch) {1467case "0": // DEC Special Character and Line Drawing Set.1468cs = Terminal.charsets.SCLD;1469break;1470case "A": // UK1471cs = Terminal.charsets.UK;1472break;1473case "B": // United States (USASCII).1474cs = Terminal.charsets.US;1475break;1476case "4": // Dutch1477cs = Terminal.charsets.Dutch;1478break;1479case "C": // Finnish1480case "5":1481cs = Terminal.charsets.Finnish;1482break;1483case "R": // French1484cs = Terminal.charsets.French;1485break;1486case "Q": // FrenchCanadian1487cs = Terminal.charsets.FrenchCanadian;1488break;1489case "K": // German1490cs = Terminal.charsets.German;1491break;1492case "Y": // Italian1493cs = Terminal.charsets.Italian;1494break;1495case "E": // NorwegianDanish1496case "6":1497cs = Terminal.charsets.NorwegianDanish;1498break;1499case "Z": // Spanish1500cs = Terminal.charsets.Spanish;1501break;1502case "H": // Swedish1503case "7":1504cs = Terminal.charsets.Swedish;1505break;1506case "=": // Swiss1507cs = Terminal.charsets.Swiss;1508break;1509case "/": // ISOLatin (actually /A)1510cs = Terminal.charsets.ISOLatin;1511i++;1512break;1513default:1514// Default1515cs = Terminal.charsets.US;1516break;1517}1518this.setgCharset(this.gcharset, cs);1519this.gcharset = null;1520this.state = normal;1521break;15221523case osc:1524// OSC Ps ; Pt ST1525// OSC Ps ; Pt BEL1526// Set Text Parameters.1527if (ch === "\x1b" || ch === "\x07") {1528if (ch === "\x1b") i++;15291530this.params.push(this.currentParam);15311532// console.log("code=", this.params[0]);15331534switch (this.params[0]) {1535case 0:1536case 1:1537case 2:1538if (this.params[1]) {1539this.title = this.params[1];1540this.handleTitle(this.title);1541}1542break;1543case 3:1544// set X property1545break;1546case 4:1547case 5:1548// change dynamic colors1549break;1550case 10:1551case 11:1552case 12:1553case 13:1554case 14:1555case 15:1556case 16:1557case 17:1558case 18:1559case 19:1560// change dynamic ui colors1561break;1562case 46:1563// change log file1564break;1565case 49:1566// I'm just making this up! -- William -- I couldn't find any use of code 49...1567if (this.params[1]) {1568this.handleMesg(this.params[1]);1569}1570break;1571case 50:1572// dynamic font1573break;1574case 51:1575// emacs shell1576break;1577case 52:1578// manipulate selection data1579break;1580case 105:1581case 110:1582case 111:1583case 112:1584case 113:1585case 114:1586case 115:1587case 116:1588case 117:1589case 118:1590// reset colors1591break;1592}15931594this.params = [];1595this.currentParam = 0;1596this.state = normal;1597} else {1598if (!this.params.length) {1599if (ch >= "0" && ch <= "9") {1600this.currentParam =1601this.currentParam * 10 + ch.charCodeAt(0) - 48;1602} else if (ch === ";") {1603this.params.push(this.currentParam);1604this.currentParam = "";1605}1606} else {1607this.currentParam += ch;1608}1609}1610break;16111612case csi:1613// '?', '>', '!'1614if (ch === "?" || ch === ">" || ch === "!") {1615this.prefix = ch;1616break;1617}16181619// 0 - 91620if (ch >= "0" && ch <= "9") {1621this.currentParam = this.currentParam * 10 + ch.charCodeAt(0) - 48;1622break;1623}16241625// '$', '"', ' ', '\''1626if (ch === "$" || ch === '"' || ch === " " || ch === "'") {1627this.postfix = ch;1628break;1629}16301631this.params.push(this.currentParam);1632this.currentParam = 0;16331634// ';'1635if (ch === ";") break;16361637this.state = normal;16381639// console.log("ch = ", ch);1640switch (ch) {1641// CSI Ps A1642// Cursor Up Ps Times (default = 1) (CUU).1643case "A":1644this.cursorUp(this.params);1645break;16461647// CSI Ps B1648// Cursor Down Ps Times (default = 1) (CUD).1649case "B":1650this.cursorDown(this.params);1651break;16521653// CSI Ps C1654// Cursor Forward Ps Times (default = 1) (CUF).1655case "C":1656this.cursorForward(this.params);1657break;16581659// CSI Ps D1660// Cursor Backward Ps Times (default = 1) (CUB).1661case "D":1662this.cursorBackward(this.params);1663break;16641665// CSI Ps ; Ps H1666// Cursor Position [row;column] (default = [1,1]) (CUP).1667case "H":1668this.cursorPos(this.params);1669break;16701671// CSI Ps J Erase in Display (ED).1672case "J":1673this.eraseInDisplay(this.params);1674break;16751676// CSI Ps K Erase in Line (EL).1677case "K":1678this.eraseInLine(this.params);1679break;16801681// CSI Pm m Character Attributes (SGR).1682case "m":1683this.charAttributes(this.params);1684break;16851686// CSI Ps n Device Status Report (DSR).1687case "n":1688this.deviceStatus(this.params);1689break;16901691/**1692* Additions1693*/16941695// CSI Ps @1696// Insert Ps (Blank) Character(s) (default = 1) (ICH).1697case "@":1698this.insertChars(this.params);1699break;17001701// CSI Ps E1702// Cursor Next Line Ps Times (default = 1) (CNL).1703case "E":1704this.cursorNextLine(this.params);1705break;17061707// CSI Ps F1708// Cursor Preceding Line Ps Times (default = 1) (CNL).1709case "F":1710this.cursorPrecedingLine(this.params);1711break;17121713// CSI Ps G1714// Cursor Character Absolute [column] (default = [row,1]) (CHA).1715case "G":1716this.cursorCharAbsolute(this.params);1717break;17181719// CSI Ps L1720// Insert Ps Line(s) (default = 1) (IL).1721case "L":1722this.insertLines(this.params);1723break;17241725// CSI Ps M1726// Delete Ps Line(s) (default = 1) (DL).1727case "M":1728this.deleteLines(this.params);1729break;17301731// CSI Ps P1732// Delete Ps Character(s) (default = 1) (DCH).1733case "P":1734this.deleteChars(this.params);1735break;17361737// CSI Ps X1738// Erase Ps Character(s) (default = 1) (ECH).1739case "X":1740this.eraseChars(this.params);1741break;17421743// CSI Pm ` Character Position Absolute1744// [column] (default = [row,1]) (HPA).1745case "`":1746this.charPosAbsolute(this.params);1747break;17481749// 141 61 a * HPR -1750// Horizontal Position Relative1751case "a":1752this.HPositionRelative(this.params);1753break;17541755// CSI P s c1756// Send Device Attributes (Primary DA).1757// CSI > P s c1758// Send Device Attributes (Secondary DA)1759case "c":1760this.sendDeviceAttributes(this.params);1761break;17621763// CSI Pm d1764// Line Position Absolute [row] (default = [1,column]) (VPA).1765case "d":1766this.linePosAbsolute(this.params);1767break;17681769// 145 65 e * VPR - Vertical Position Relative1770case "e":1771this.VPositionRelative(this.params);1772break;17731774// CSI Ps ; Ps f1775// Horizontal and Vertical Position [row;column] (default =1776// [1,1]) (HVP).1777case "f":1778this.HVPosition(this.params);1779break;17801781// CSI Pm h Set Mode (SM).1782// CSI ? Pm h - mouse escape codes, cursor escape codes1783case "h":1784this.setMode(this.params);1785break;17861787// CSI Pm l Reset Mode (RM).1788// CSI ? Pm l1789case "l":1790this.resetMode(this.params);1791break;17921793// CSI Ps ; Ps r1794// Set Scrolling Region [top;bottom] (default = full size of win-1795// dow) (DECSTBM).1796// CSI ? Pm r1797case "r":1798this.setScrollRegion(this.params);1799break;18001801// CSI s1802// Save cursor (ANSI.SYS).1803case "s":1804this.saveCursor(this.params);1805break;18061807// CSI u1808// Restore cursor (ANSI.SYS).1809case "u":1810this.restoreCursor(this.params);1811break;18121813/**1814* Lesser Used1815*/18161817// CSI Ps I1818// Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).1819case "I":1820this.cursorForwardTab(this.params);1821break;18221823// CSI Ps S Scroll up Ps lines (default = 1) (SU).1824case "S":1825this.scrollUp(this.params);1826break;18271828// CSI Ps T Scroll down Ps lines (default = 1) (SD).1829// CSI Ps ; Ps ; Ps ; Ps ; Ps T1830// CSI > Ps; Ps T1831case "T":1832// if (this.prefix === '>') {1833// this.resetTitleModes(this.params);1834// break;1835// }1836// if (this.params.length > 2) {1837// this.initMouseTracking(this.params);1838// break;1839// }1840if (this.params.length < 2 && !this.prefix) {1841this.scrollDown(this.params);1842}1843break;18441845// CSI Ps Z1846// Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).1847case "Z":1848this.cursorBackwardTab(this.params);1849break;18501851// CSI Ps b Repeat the preceding graphic character Ps times (REP).1852case "b":1853this.repeatPrecedingCharacter(this.params);1854break;18551856// CSI Ps g Tab Clear (TBC).1857case "g":1858this.tabClear(this.params);1859break;18601861// CSI Pm i Media Copy (MC).1862// CSI ? Pm i1863// case 'i':1864// this.mediaCopy(this.params);1865// break;18661867// CSI Pm m Character Attributes (SGR).1868// CSI > Ps; Ps m1869// case 'm': // duplicate1870// if (this.prefix === '>') {1871// this.setResources(this.params);1872// } else {1873// this.charAttributes(this.params);1874// }1875// break;18761877// CSI Ps n Device Status Report (DSR).1878// CSI > Ps n1879// case 'n': // duplicate1880// if (this.prefix === '>') {1881// this.disableModifiers(this.params);1882// } else {1883// this.deviceStatus(this.params);1884// }1885// break;18861887// CSI > Ps p Set pointer mode.1888// CSI ! p Soft terminal reset (DECSTR).1889// CSI Ps$ p1890// Request ANSI mode (DECRQM).1891// CSI ? Ps$ p1892// Request DEC private mode (DECRQM).1893// CSI Ps ; Ps " p1894case "p":1895switch (this.prefix) {1896// case '>':1897// this.setPointerMode(this.params);1898// break;1899case "!":1900this.softReset(this.params);1901break;1902// case '?':1903// if (this.postfix === '$') {1904// this.requestPrivateMode(this.params);1905// }1906// break;1907// default:1908// if (this.postfix === '"') {1909// this.setConformanceLevel(this.params);1910// } else if (this.postfix === '$') {1911// this.requestAnsiMode(this.params);1912// }1913// break;1914}1915break;19161917// CSI Ps q Load LEDs (DECLL).1918// CSI Ps SP q1919// CSI Ps " q1920// case 'q':1921// if (this.postfix === ' ') {1922// this.setCursorStyle(this.params);1923// break;1924// }1925// if (this.postfix === '"') {1926// this.setCharProtectionAttr(this.params);1927// break;1928// }1929// this.loadLEDs(this.params);1930// break;19311932// CSI Ps ; Ps r1933// Set Scrolling Region [top;bottom] (default = full size of win-1934// dow) (DECSTBM).1935// CSI ? Pm r1936// CSI Pt; Pl; Pb; Pr; Ps$ r1937// case 'r': // duplicate1938// if (this.prefix === '?') {1939// this.restorePrivateValues(this.params);1940// } else if (this.postfix === '$') {1941// this.setAttrInRectangle(this.params);1942// } else {1943// this.setScrollRegion(this.params);1944// }1945// break;19461947// CSI s Save cursor (ANSI.SYS).1948// CSI ? Pm s1949// case 's': // duplicate1950// if (this.prefix === '?') {1951// this.savePrivateValues(this.params);1952// } else {1953// this.saveCursor(this.params);1954// }1955// break;19561957// CSI Ps ; Ps ; Ps t1958// CSI Pt; Pl; Pb; Pr; Ps$ t1959// CSI > Ps; Ps t1960// CSI Ps SP t1961// case 't':1962// if (this.postfix === '$') {1963// this.reverseAttrInRectangle(this.params);1964// } else if (this.postfix === ' ') {1965// this.setWarningBellVolume(this.params);1966// } else {1967// if (this.prefix === '>') {1968// this.setTitleModeFeature(this.params);1969// } else {1970// this.manipulateWindow(this.params);1971// }1972// }1973// break;19741975// CSI u Restore cursor (ANSI.SYS).1976// CSI Ps SP u1977// case 'u': // duplicate1978// if (this.postfix === ' ') {1979// this.setMarginBellVolume(this.params);1980// } else {1981// this.restoreCursor(this.params);1982// }1983// break;19841985// CSI Pt; Pl; Pb; Pr; Pp; Pt; Pl; Pp$ v1986// case 'v':1987// if (this.postfix === '$') {1988// this.copyRectagle(this.params);1989// }1990// break;19911992// CSI Pt ; Pl ; Pb ; Pr ' w1993// case 'w':1994// if (this.postfix === '\'') {1995// this.enableFilterRectangle(this.params);1996// }1997// break;19981999// CSI Ps x Request Terminal Parameters (DECREQTPARM).2000// CSI Ps x Select Attribute Change Extent (DECSACE).2001// CSI Pc; Pt; Pl; Pb; Pr$ x2002// case 'x':2003// if (this.postfix === '$') {2004// this.fillRectangle(this.params);2005// } else {2006// this.requestParameters(this.params);2007// //this.__(this.params);2008// }2009// break;20102011// CSI Ps ; Pu ' z2012// CSI Pt; Pl; Pb; Pr$ z2013// case 'z':2014// if (this.postfix === '\'') {2015// this.enableLocatorReporting(this.params);2016// } else if (this.postfix === '$') {2017// this.eraseRectangle(this.params);2018// }2019// break;20202021// CSI Pm ' {2022// CSI Pt; Pl; Pb; Pr$ {2023// case '{':2024// if (this.postfix === '\'') {2025// this.setLocatorEvents(this.params);2026// } else if (this.postfix === '$') {2027// this.selectiveEraseRectangle(this.params);2028// }2029// break;20302031// CSI Ps ' |2032// case '|':2033// if (this.postfix === '\'') {2034// this.requestLocatorPosition(this.params);2035// }2036// break;20372038// CSI P m SP }2039// Insert P s Column(s) (default = 1) (DECIC), VT420 and up.2040// case '}':2041// if (this.postfix === ' ') {2042// this.insertColumns(this.params);2043// }2044// break;20452046// CSI P m SP ~2047// Delete P s Column(s) (default = 1) (DECDC), VT420 and up2048// case '~':2049// if (this.postfix === ' ') {2050// this.deleteColumns(this.params);2051// }2052// break;20532054default:2055this.error("Unknown CSI code: %s.", ch);2056break;2057}20582059this.prefix = "";2060this.postfix = "";2061break;20622063case dcs:2064if (ch === "\x1b" || ch === "\x07") {2065if (ch === "\x1b") i++;20662067switch (this.prefix) {2068// User-Defined Keys (DECUDK).2069case "":2070break;20712072// Request Status String (DECRQSS).2073// test: echo -e '\eP$q"p\e\\'2074case "$q":2075var pt = this.currentParam,2076valid = false;20772078switch (pt) {2079// DECSCA2080case '"q':2081pt = '0"q';2082break;20832084// DECSCL2085case '"p':2086pt = '61"p';2087break;20882089// DECSTBM2090case "r":2091pt =2092"" +2093(this.scrollTop + 1) +2094";" +2095(this.scrollBottom + 1) +2096"r";2097break;20982099// SGR2100case "m":2101pt = "0m";2102break;21032104default:2105this.error("Unknown DCS Pt: %s.", pt);2106pt = "";2107break;2108}21092110this.send("\x1bP" + +valid + "$r" + pt + "\x1b\\");2111break;21122113// Set Termcap/Terminfo Data (xterm, experimental).2114case "+p":2115break;21162117// Request Termcap/Terminfo String (xterm, experimental)2118// Regular xterm does not even respond to this sequence.2119// This can cause a small glitch in vim.2120// test: echo -ne '\eP+q6b64\e\\'2121case "+q":2122var pt = this.currentParam,2123valid = false;21242125this.send("\x1bP" + +valid + "+r" + pt + "\x1b\\");2126break;21272128default:2129this.error("Unknown DCS prefix: %s.", this.prefix);2130break;2131}21322133this.currentParam = 0;2134this.prefix = "";2135this.state = normal;2136} else if (!this.currentParam) {2137if (!this.prefix && ch !== "$" && ch !== "+") {2138this.currentParam = ch;2139} else if (this.prefix.length === 2) {2140this.currentParam = ch;2141} else {2142this.prefix += ch;2143}2144} else {2145this.currentParam += ch;2146}2147break;21482149case ignore:2150// For PM and APC.2151if (ch === "\x1b" || ch === "\x07") {2152if (ch === "\x1b") i++;2153this.state = normal;2154}2155break;2156}2157}21582159this.updateRange(this.y);2160this.refresh(this.refreshStart, this.refreshEnd);2161};21622163Terminal.prototype.writeln = function(data) {2164this.write(data + "\r\n");2165};21662167Terminal.prototype.keyDown = function(ev) {2168var key;2169// console.log("term.js.keyDown: ", ev);2170switch (ev.keyCode) {2171// backspace2172case 8:2173if (ev.shiftKey) {2174key = "\x08"; // ^H2175break;2176}2177key = "\x7f"; // ^?2178break;2179// tab2180case 9:2181if (ev.shiftKey) {2182key = "\x1b[Z";2183break;2184}2185key = "\t";2186break;2187// return/enter2188case 13:2189key = "\r";2190break;2191// escape2192case 27:2193key = "\x1b";2194break;2195// left-arrow2196case 37:2197if (this.applicationKeypad) {2198key = "\x1bOD"; // SS3 as ^[O for 7-bit2199//key = '\x8fD'; // SS3 as 0x8f for 8-bit2200break;2201}2202key = "\x1b[D";2203break;2204// right-arrow2205case 39:2206if (this.applicationKeypad) {2207key = "\x1bOC";2208break;2209}2210key = "\x1b[C";2211break;2212// up-arrow2213case 38:2214if (this.applicationKeypad) {2215key = "\x1bOA";2216break;2217}2218if (ev.ctrlKey) {2219this.scrollDisp(-1);2220return cancel(ev);2221} else {2222key = "\x1b[A";2223}2224break;2225// down-arrow2226case 40:2227if (this.applicationKeypad) {2228key = "\x1bOB";2229break;2230}2231if (ev.ctrlKey) {2232this.scrollDisp(1);2233return cancel(ev);2234} else {2235key = "\x1b[B";2236}2237break;2238// delete2239case 46:2240key = "\x1b[3~";2241break;2242// insert2243case 45:2244key = "\x1b[2~";2245break;2246// home2247case 36:2248if (this.applicationKeypad) {2249key = "\x1bOH";2250break;2251}2252key = "\x1bOH";2253break;2254// end2255case 35:2256if (this.applicationKeypad) {2257key = "\x1bOF";2258break;2259}2260key = "\x1bOF";2261break;2262// page up2263case 33:2264if (ev.shiftKey) {2265this.scrollDisp(-(this.rows - 1));2266return cancel(ev);2267} else {2268key = "\x1b[5~";2269}2270break;2271// page down2272case 34:2273if (ev.shiftKey) {2274this.scrollDisp(this.rows - 1);2275return cancel(ev);2276} else {2277key = "\x1b[6~";2278}2279break;2280// F12281case 112:2282key = "\x1bOP";2283break;2284// F22285case 113:2286key = "\x1bOQ";2287break;2288// F32289case 114:2290key = "\x1bOR";2291break;2292// F42293case 115:2294key = "\x1bOS";2295break;2296// F52297case 116:2298key = "\x1b[15~";2299break;2300// F62301case 117:2302key = "\x1b[17~";2303break;2304// F72305case 118:2306key = "\x1b[18~";2307break;2308// F82309case 119:2310key = "\x1b[19~";2311break;2312// F92313case 120:2314key = "\x1b[20~";2315break;2316// F102317case 121:2318key = "\x1b[21~";2319break;2320// F112321case 122:2322key = "\x1b[23~";2323break;2324// F122325case 123:2326key = "\x1b[24~";2327break;2328default:2329// a-z and space2330if (ev.ctrlKey) {2331if (ev.keyCode >= 65 && ev.keyCode <= 90) {2332key = String.fromCharCode(ev.keyCode - 64);2333} else if (ev.keyCode === 32) {2334// NUL2335key = String.fromCharCode(0);2336} else if (ev.keyCode >= 51 && ev.keyCode <= 55) {2337// escape, file sep, group sep, record sep, unit sep2338key = String.fromCharCode(ev.keyCode - 51 + 27);2339} else if (ev.keyCode === 56) {2340// delete2341key = String.fromCharCode(127);2342} else if (ev.keyCode === 219) {2343// ^[ - escape2344key = String.fromCharCode(27);2345} else if (ev.keyCode === 221) {2346// ^] - group sep2347key = String.fromCharCode(29);2348}2349} else if ((!isMac && ev.altKey) || (isMac && ev.metaKey)) {2350if (ev.keyCode >= 65 && ev.keyCode <= 90) {2351key = "\x1b" + String.fromCharCode(ev.keyCode + 32);2352} else if (ev.keyCode === 192) {2353key = "\x1b`";2354} else if (ev.keyCode >= 48 && ev.keyCode <= 57) {2355key = "\x1b" + (ev.keyCode - 48);2356}2357}2358break;2359}23602361if (!key) {2362/* some devices, e.g., the iPad Pro with SmartKeyboard, have keys that do not have2363a keyCode, but do corresponding to something above. */2364switch (ev.key) {2365// left-arrow2366case "UIKeyInputLeftArrow":2367if (this.applicationKeypad) {2368key = "\x1bOD"; // SS3 as ^[O for 7-bit2369//key = '\x8fD'; // SS3 as 0x8f for 8-bit2370break;2371}2372key = "\x1b[D";2373break;2374// right-arrow2375case "UIKeyInputRightArrow":2376if (this.applicationKeypad) {2377key = "\x1bOC";2378break;2379}2380key = "\x1b[C";2381break;2382// up-arrow2383case "UIKeyInputUpArrow":2384if (this.applicationKeypad) {2385key = "\x1bOA";2386break;2387}2388if (ev.ctrlKey) {2389this.scrollDisp(-1);2390return cancel(ev);2391} else {2392key = "\x1b[A";2393}2394break;2395// down-arrow2396case "UIKeyInputDownArrow":2397if (this.applicationKeypad) {2398key = "\x1bOB";2399break;2400}2401if (ev.ctrlKey) {2402this.scrollDisp(1);2403return cancel(ev);2404} else {2405key = "\x1b[B";2406}2407break;2408}2409}24102411//console.log("term.js.keyDown: after switch, key=", key);24122413this.emit("keydown", ev);24142415if (key) {2416this.emit("key", key, ev);24172418this.showCursor();2419this.handler(key);24202421return cancel(ev);2422} else {2423if (this.IS_TOUCH && ev.keyCode == 32) {2424/* On iPad with external Keyboard,2425the spacebar keyPress fires but with charCode, etc., set to 0. Ugh.2426We thus simulate the proper code. */2427this.keyPress({ charCode: 32 });2428/* We then cancel the space event, since otherwise the browser2429will scroll the page down. Also, this will prevent seeing two2430spaces in case this bug is fixed or not present on some touch devices! */2431return cancel(ev);2432}2433}24342435return true;2436};24372438Terminal.prototype.setgLevel = function(g) {2439this.glevel = g;2440this.charset = this.charsets[g];2441};24422443Terminal.prototype.setgCharset = function(g, charset) {2444this.charsets[g] = charset;2445if (this.glevel === g) {2446this.charset = charset;2447}2448};24492450Terminal.prototype.keyPress = function(ev) {2451var key;24522453/* Doing cancel here seems to server no purpose, *and* completely breaks2454using Ctrl-c to copy on firefox. */2455/* cancel(ev);*/2456//console.log("term.js.keyPress: ", ev);24572458if (ev.charCode) {2459key = ev.charCode;2460} else if (ev.which == null) {2461key = ev.keyCode;2462} else if (ev.which !== 0 && ev.charCode !== 0) {2463key = ev.which;2464} else {2465return false;2466}24672468//console.log("term.js.keyPress: got key=", key);24692470if (!key || ev.ctrlKey || ev.altKey || ev.metaKey) return false;24712472key = String.fromCharCode(key);2473//console.log("term.js.keyPress: got string=", key);24742475this.emit("keypress", key, ev);2476this.emit("key", key, ev);24772478this.showCursor();2479this.handler(key);24802481return false;2482};24832484Terminal.prototype.send = function(data) {2485var self = this;24862487if (!this.queue) {2488setTimeout(function() {2489self.handler(self.queue);2490self.queue = "";2491}, 50); /* this was 1 but it causes trouble in some cases. */2492}24932494this.queue += data;2495};24962497Terminal.prototype.bell = function() {2498if (!Terminal.visualBell) return;2499var self = this;2500this.element.style.borderColor = "white";2501setTimeout(function() {2502self.element.style.borderColor = "";2503}, 10);2504if (Terminal.popOnBell) this.focus();2505};25062507Terminal.prototype.log = function() {2508if (!Terminal.debug) return;2509if (!window.console || !window.console.log) return;2510var args = Array.prototype.slice.call(arguments);2511window.console.log.apply(window.console, args);2512};25132514Terminal.prototype.error = function() {2515if (!Terminal.debug) return;2516if (!window.console || !window.console.error) return;2517var args = Array.prototype.slice.call(arguments);2518window.console.error.apply(window.console, args);2519};25202521Terminal.prototype.resize = function(x, y) {2522var line, el, i, j, ch;25232524if (x < 1) x = 1;2525if (y < 1) y = 1;25262527// resize cols2528j = this.cols;2529if (j < x) {2530ch = [this.defAttr, " "];2531i = this.lines.length;2532while (i--) {2533while (this.lines[i].length < x) {2534this.lines[i].push(ch);2535}2536}2537} else if (j > x) {2538i = this.lines.length;2539while (i--) {2540while (this.lines[i].length > x) {2541this.lines[i].pop();2542}2543}2544}2545this.setupStops(j);2546this.cols = x;25472548// resize rows2549j = this.rows;2550if (j < y) {2551el = this.element;2552while (j++ < y) {2553if (this.lines.length < y + this.ybase) {2554this.lines.push(this.blankLine());2555}2556if (this.children.length < y) {2557line = document.createElement("div");2558el.appendChild(line);2559this.children.push(line);2560}2561}2562} else if (j > y) {2563while (j-- > y) {2564if (this.lines.length > y + this.ybase) {2565this.lines.pop();2566}2567if (this.children.length > y) {2568el = this.children.pop();2569if (!el) continue;2570el.parentNode.removeChild(el);2571}2572}2573}2574this.rows = y;25752576// make sure the cursor stays on screen2577if (this.y >= y) this.y = y - 1;2578if (this.x >= x) this.x = x - 1;25792580this.scrollTop = 0;2581this.scrollBottom = y - 1;25822583this.refresh(0, this.rows - 1);25842585// it's a real nightmare trying2586// to resize the original2587// screen buffer. just set it2588// to null for now.2589this.normal = null;2590};25912592Terminal.prototype.updateRange = function(y) {2593if (y < this.refreshStart) this.refreshStart = y;2594if (y > this.refreshEnd) this.refreshEnd = y;2595};25962597Terminal.prototype.maxRange = function() {2598this.refreshStart = 0;2599this.refreshEnd = this.rows - 1;2600};26012602Terminal.prototype.setupStops = function(i) {2603if (i != null) {2604if (!this.tabs[i]) {2605i = this.prevStop(i);2606}2607} else {2608this.tabs = {};2609i = 0;2610}26112612for (; i < this.cols; i += 8) {2613this.tabs[i] = true;2614}2615};26162617Terminal.prototype.prevStop = function(x) {2618if (x == null) x = this.x;2619while (!this.tabs[--x] && x > 0);2620return x >= this.cols ? this.cols - 1 : x < 0 ? 0 : x;2621};26222623Terminal.prototype.nextStop = function(x) {2624if (x == null) x = this.x;2625while (!this.tabs[++x] && x < this.cols);2626return x >= this.cols ? this.cols - 1 : x < 0 ? 0 : x;2627};26282629Terminal.prototype.eraseRight = function(x, y) {2630if (this.ybase + y >= this.lines.length) return;26312632var line = this.lines[this.ybase + y],2633ch = [this.curAttr, " "]; // xterm26342635if (!(typeof line !== "undefined" && line !== null)) {2636return;2637}26382639for (; x < this.cols; x++) {2640line[x] = ch;2641}26422643this.updateRange(y);2644};26452646Terminal.prototype.eraseLeft = function(x, y) {2647if (this.ybase + y >= this.lines.length) return;26482649var line = this.lines[this.ybase + y],2650ch = [this.curAttr, " "]; // xterm26512652x++;2653while (x--) line[x] = ch;26542655this.updateRange(y);2656};26572658Terminal.prototype.eraseLine = function(y) {2659this.eraseRight(0, y);2660};26612662Terminal.prototype.blankLine = function(cur) {2663var attr = cur ? this.curAttr : this.defAttr;26642665var ch = [attr, " "],2666line = [],2667i = 0;26682669for (; i < this.cols; i++) {2670line[i] = ch;2671}26722673return line;2674};26752676Terminal.prototype.ch = function(cur) {2677return cur ? [this.curAttr, " "] : [this.defAttr, " "];2678};26792680Terminal.prototype.is = function(term) {2681var name = this.termName || Terminal.termName;2682return (name + "").indexOf(term) === 0;2683};26842685Terminal.prototype.handler = function(data) {2686this.emit("data", data);2687};26882689Terminal.prototype.handleTitle = function(title) {2690this.emit("title", title);2691};26922693/* Message as (nearly) arbitrary string. Client sends a message by printing this:26942695\x1b]49;any string you want goes here\x0726962697*/2698Terminal.prototype.handleMesg = function(mesg) {2699this.emit("mesg", mesg);2700};27012702/**2703* ESC2704*/27052706// ESC D Index (IND is 0x84).2707Terminal.prototype.index = function() {2708this.y++;2709if (this.y > this.scrollBottom) {2710this.y--;2711this.scroll();2712}2713this.state = normal;2714};27152716// ESC M Reverse Index (RI is 0x8d).2717Terminal.prototype.reverseIndex = function() {2718var j;2719this.y--;2720if (this.y < this.scrollTop) {2721this.y++;2722// possibly move the code below to term.reverseScroll();2723// test: echo -ne '\e[1;1H\e[44m\eM\e[0m'2724// blankLine(true) is xterm/linux behavior2725this.lines.splice(this.y + this.ybase, 0, this.blankLine(true));2726j = this.rows - 1 - this.scrollBottom;2727this.lines.splice(this.rows - 1 + this.ybase - j + 1, 1);2728// this.maxRange();2729this.updateRange(this.scrollTop);2730this.updateRange(this.scrollBottom);2731}2732this.state = normal;2733};27342735// ESC c Full Reset (RIS).2736Terminal.prototype.reset = function() {2737Terminal.call(this, this.cols, this.rows);2738this.refresh(0, this.rows - 1);2739};27402741// ESC H Tab Set (HTS is 0x88).2742Terminal.prototype.tabSet = function() {2743this.tabs[this.x] = true;2744this.state = normal;2745};27462747/**2748* CSI2749*/27502751// CSI Ps A2752// Cursor Up Ps Times (default = 1) (CUU).2753Terminal.prototype.cursorUp = function(params) {2754var param = params[0];2755if (param < 1) param = 1;2756this.y -= param;2757if (this.y < 0) this.y = 0;2758};27592760// CSI Ps B2761// Cursor Down Ps Times (default = 1) (CUD).2762Terminal.prototype.cursorDown = function(params) {2763var param = params[0];2764if (param < 1) param = 1;2765this.y += param;2766if (this.y >= this.rows) {2767this.y = this.rows - 1;2768}2769};27702771// CSI Ps C2772// Cursor Forward Ps Times (default = 1) (CUF).2773Terminal.prototype.cursorForward = function(params) {2774var param = params[0];2775if (param < 1) param = 1;2776this.x += param;2777if (this.x >= this.cols) {2778this.x = this.cols - 1;2779}2780};27812782// CSI Ps D2783// Cursor Backward Ps Times (default = 1) (CUB).2784Terminal.prototype.cursorBackward = function(params) {2785var param = params[0];2786if (param < 1) param = 1;2787this.x -= param;2788if (this.x < 0) this.x = 0;2789};27902791// CSI Ps ; Ps H2792// Cursor Position [row;column] (default = [1,1]) (CUP).2793Terminal.prototype.cursorPos = function(params) {2794var row, col;27952796row = params[0] - 1;27972798if (params.length >= 2) {2799col = params[1] - 1;2800} else {2801col = 0;2802}28032804if (row < 0) {2805row = 0;2806} else if (row >= this.rows) {2807row = this.rows - 1;2808}28092810if (col < 0) {2811col = 0;2812} else if (col >= this.cols) {2813col = this.cols - 1;2814}28152816this.x = col;2817this.y = row;2818};28192820// CSI Ps J Erase in Display (ED).2821// Ps = 0 -> Erase Below (default).2822// Ps = 1 -> Erase Above.2823// Ps = 2 -> Erase All.2824// Ps = 3 -> Erase Saved Lines (xterm).2825// CSI ? Ps J2826// Erase in Display (DECSED).2827// Ps = 0 -> Selective Erase Below (default).2828// Ps = 1 -> Selective Erase Above.2829// Ps = 2 -> Selective Erase All.2830Terminal.prototype.eraseInDisplay = function(params) {2831var j;2832switch (params[0]) {2833case 0:2834this.eraseRight(this.x, this.y);2835j = this.y + 1;2836for (; j < this.rows; j++) {2837this.eraseLine(j);2838}2839break;2840case 1:2841this.eraseLeft(this.x, this.y);2842j = this.y;2843while (j--) {2844this.eraseLine(j);2845}2846break;2847case 2:2848j = this.rows;2849while (j--) this.eraseLine(j);2850break;2851case 3: // no saved lines2852break;2853}2854};28552856// CSI Ps K Erase in Line (EL).2857// Ps = 0 -> Erase to Right (default).2858// Ps = 1 -> Erase to Left.2859// Ps = 2 -> Erase All.2860// CSI ? Ps K2861// Erase in Line (DECSEL).2862// Ps = 0 -> Selective Erase to Right (default).2863// Ps = 1 -> Selective Erase to Left.2864// Ps = 2 -> Selective Erase All.2865Terminal.prototype.eraseInLine = function(params) {2866switch (params[0]) {2867case 0:2868this.eraseRight(this.x, this.y);2869break;2870case 1:2871this.eraseLeft(this.x, this.y);2872break;2873case 2:2874this.eraseLine(this.y);2875break;2876}2877};28782879// CSI Pm m Character Attributes (SGR).2880// Ps = 0 -> Normal (default).2881// Ps = 1 -> Bold.2882// Ps = 4 -> Underlined.2883// Ps = 5 -> Blink (appears as Bold).2884// Ps = 7 -> Inverse.2885// Ps = 8 -> Invisible, i.e., hidden (VT300).2886// Ps = 2 2 -> Normal (neither bold nor faint).2887// Ps = 2 4 -> Not underlined.2888// Ps = 2 5 -> Steady (not blinking).2889// Ps = 2 7 -> Positive (not inverse).2890// Ps = 2 8 -> Visible, i.e., not hidden (VT300).2891// Ps = 3 0 -> Set foreground color to Black.2892// Ps = 3 1 -> Set foreground color to Red.2893// Ps = 3 2 -> Set foreground color to Green.2894// Ps = 3 3 -> Set foreground color to Yellow.2895// Ps = 3 4 -> Set foreground color to Blue.2896// Ps = 3 5 -> Set foreground color to Magenta.2897// Ps = 3 6 -> Set foreground color to Cyan.2898// Ps = 3 7 -> Set foreground color to White.2899// Ps = 3 9 -> Set foreground color to default (original).2900// Ps = 4 0 -> Set background color to Black.2901// Ps = 4 1 -> Set background color to Red.2902// Ps = 4 2 -> Set background color to Green.2903// Ps = 4 3 -> Set background color to Yellow.2904// Ps = 4 4 -> Set background color to Blue.2905// Ps = 4 5 -> Set background color to Magenta.2906// Ps = 4 6 -> Set background color to Cyan.2907// Ps = 4 7 -> Set background color to White.2908// Ps = 4 9 -> Set background color to default (original).29092910// If 16-color support is compiled, the following apply. Assume2911// that xterm's resources are set so that the ISO color codes are2912// the first 8 of a set of 16. Then the aixterm colors are the2913// bright versions of the ISO colors:2914// Ps = 9 0 -> Set foreground color to Black.2915// Ps = 9 1 -> Set foreground color to Red.2916// Ps = 9 2 -> Set foreground color to Green.2917// Ps = 9 3 -> Set foreground color to Yellow.2918// Ps = 9 4 -> Set foreground color to Blue.2919// Ps = 9 5 -> Set foreground color to Magenta.2920// Ps = 9 6 -> Set foreground color to Cyan.2921// Ps = 9 7 -> Set foreground color to White.2922// Ps = 1 0 0 -> Set background color to Black.2923// Ps = 1 0 1 -> Set background color to Red.2924// Ps = 1 0 2 -> Set background color to Green.2925// Ps = 1 0 3 -> Set background color to Yellow.2926// Ps = 1 0 4 -> Set background color to Blue.2927// Ps = 1 0 5 -> Set background color to Magenta.2928// Ps = 1 0 6 -> Set background color to Cyan.2929// Ps = 1 0 7 -> Set background color to White.29302931// If xterm is compiled with the 16-color support disabled, it2932// supports the following, from rxvt:2933// Ps = 1 0 0 -> Set foreground and background color to2934// default.29352936// If 88- or 256-color support is compiled, the following apply.2937// Ps = 3 8 ; 5 ; Ps -> Set foreground color to the second2938// Ps.2939// Ps = 4 8 ; 5 ; Ps -> Set background color to the second2940// Ps.2941Terminal.prototype.charAttributes = function(params) {2942var l = params.length,2943i = 0,2944bg,2945fg,2946p;29472948for (; i < l; i++) {2949p = params[i];2950if (p >= 30 && p <= 37) {2951// fg color 82952this.curAttr = (this.curAttr & ~(0x1ff << 9)) | ((p - 30) << 9);2953} else if (p >= 40 && p <= 47) {2954// bg color 82955this.curAttr = (this.curAttr & ~0x1ff) | (p - 40);2956} else if (p >= 90 && p <= 97) {2957// fg color 162958p += 8;2959this.curAttr = (this.curAttr & ~(0x1ff << 9)) | ((p - 90) << 9);2960} else if (p >= 100 && p <= 107) {2961// bg color 162962p += 8;2963this.curAttr = (this.curAttr & ~0x1ff) | (p - 100);2964} else if (p === 0) {2965// default2966this.curAttr = this.defAttr;2967} else if (p === 1) {2968// bold text2969this.curAttr = this.curAttr | (1 << 18);2970} else if (p === 4) {2971// underlined text2972if (this.prefix === ">") {2973// > is a mode reset, according to the docs, and this gets triggered on exit from emacs.2974//2975//CSI > Ps; Ps T2976// Reset one or more features of the title modes to the default2977// value. Normally, "reset" disables the feature.2978} else {2979this.curAttr = this.curAttr | (2 << 18);2980}2981} else if (p === 7 || p === 27) {2982// inverse and positive2983// test with: echo -e '\e[31m\e[42mhello\e[7mworld\e[27mhi\e[m'2984if (p === 7) {2985if ((this.curAttr >> 18) & 4) continue;2986this.curAttr = this.curAttr | (4 << 18);2987} else if (p === 27) {2988if (~(this.curAttr >> 18) & 4) continue;2989this.curAttr = this.curAttr & ~(4 << 18);2990}29912992bg = this.curAttr & 0x1ff;2993fg = (this.curAttr >> 9) & 0x1ff;29942995this.curAttr = (this.curAttr & ~0x3ffff) | ((bg << 9) | fg);2996} else if (p === 22) {2997// not bold2998this.curAttr = this.curAttr & ~(1 << 18);2999} else if (p === 24) {3000// not underlined3001this.curAttr = this.curAttr & ~(2 << 18);3002} else if (p === 39) {3003// reset fg3004this.curAttr = this.curAttr & ~(0x1ff << 9);3005this.curAttr = this.curAttr | (((this.defAttr >> 9) & 0x1ff) << 9);3006} else if (p === 49) {3007// reset bg3008this.curAttr = this.curAttr & ~0x1ff;3009this.curAttr = this.curAttr | (this.defAttr & 0x1ff);3010} else if (p === 38) {3011// fg color 2563012if (params[i + 1] !== 5) continue;3013i += 2;3014p = params[i] & 0xff;3015// convert 88 colors to 2563016// if (this.is('rxvt-unicode') && p < 88) p = p * 2.9090 | 0;3017this.curAttr = (this.curAttr & ~(0x1ff << 9)) | (p << 9);3018} else if (p === 48) {30191; // bg color 2563020if (params[i + 1] !== 5) continue;3021i += 2;3022p = params[i] & 0xff;3023// convert 88 colors to 2563024// if (this.is('rxvt-unicode') && p < 88) p = p * 2.9090 | 0;3025this.curAttr = (this.curAttr & ~0x1ff) | p;3026}3027}3028};30293030// CSI Ps n Device Status Report (DSR).3031// Ps = 5 -> Status Report. Result (``OK'') is3032// CSI 0 n3033// Ps = 6 -> Report Cursor Position (CPR) [row;column].3034// Result is3035// CSI r ; c R3036// CSI ? Ps n3037// Device Status Report (DSR, DEC-specific).3038// Ps = 6 -> Report Cursor Position (CPR) [row;column] as CSI3039// ? r ; c R (assumes page is zero).3040// Ps = 1 5 -> Report Printer status as CSI ? 1 0 n (ready).3041// or CSI ? 1 1 n (not ready).3042// Ps = 2 5 -> Report UDK status as CSI ? 2 0 n (unlocked)3043// or CSI ? 2 1 n (locked).3044// Ps = 2 6 -> Report Keyboard status as3045// CSI ? 2 7 ; 1 ; 0 ; 0 n (North American).3046// The last two parameters apply to VT400 & up, and denote key-3047// board ready and LK01 respectively.3048// Ps = 5 3 -> Report Locator status as3049// CSI ? 5 3 n Locator available, if compiled-in, or3050// CSI ? 5 0 n No Locator, if not.3051Terminal.prototype.deviceStatus = function(params) {3052if (!this.prefix) {3053switch (params[0]) {3054case 5:3055// status report3056this.send("\x1b[0n");3057break;3058case 6:3059// cursor position3060this.send("\x1b[" + (this.y + 1) + ";" + (this.x + 1) + "R");3061break;3062}3063} else if (this.prefix === "?") {3064// modern xterm doesnt seem to3065// respond to any of these except ?6, 6, and 53066switch (params[0]) {3067case 6:3068// cursor position3069this.send("\x1b[?" + (this.y + 1) + ";" + (this.x + 1) + "R");3070break;3071case 15:3072// no printer3073// this.send('\x1b[?11n');3074break;3075case 25:3076// dont support user defined keys3077// this.send('\x1b[?21n');3078break;3079case 26:3080// north american keyboard3081// this.send('\x1b[?27;1;0;0n');3082break;3083case 53:3084// no dec locator/mouse3085// this.send('\x1b[?50n');3086break;3087}3088}3089};30903091/**3092* Additions3093*/30943095// CSI Ps @3096// Insert Ps (Blank) Character(s) (default = 1) (ICH).3097Terminal.prototype.insertChars = function(params) {3098var param, row, j, ch;30993100param = params[0];3101if (param < 1) param = 1;31023103row = this.y + this.ybase;3104j = this.x;3105ch = [this.curAttr, " "]; // xterm31063107while (param-- && j < this.cols) {3108// sometimes, row is too large3109if (row >= this.lines.length) {3110continue;3111}3112// Question: How can you possibly have a problem because of running that code? It seems3113// like if you don't have that commented out code, then the next line would3114// cause a traceback? Answer: well, those tracebacks are there right now.3115// With this code there, the output started to do weird things, repeating3116// parts of the text, etc. So, I know this is a problem, but I don't3117// want to fix it by making it worse.3118this.lines[row].splice(j++, 0, ch);3119this.lines[row].pop();3120}3121};31223123// CSI Ps E3124// Cursor Next Line Ps Times (default = 1) (CNL).3125// same as CSI Ps B ?3126Terminal.prototype.cursorNextLine = function(params) {3127var param = params[0];3128if (param < 1) param = 1;3129this.y += param;3130if (this.y >= this.rows) {3131this.y = this.rows - 1;3132}3133this.x = 0;3134};31353136// CSI Ps F3137// Cursor Preceding Line Ps Times (default = 1) (CNL).3138// reuse CSI Ps A ?3139Terminal.prototype.cursorPrecedingLine = function(params) {3140var param = params[0];3141if (param < 1) param = 1;3142this.y -= param;3143if (this.y < 0) this.y = 0;3144this.x = 0;3145};31463147// CSI Ps G3148// Cursor Character Absolute [column] (default = [row,1]) (CHA).3149Terminal.prototype.cursorCharAbsolute = function(params) {3150var param = params[0];3151if (param < 1) param = 1;3152this.x = param - 1;3153};31543155// CSI Ps L3156// Insert Ps Line(s) (default = 1) (IL).3157Terminal.prototype.insertLines = function(params) {3158var param, row, j;31593160param = params[0];3161if (param < 1) param = 1;3162row = this.y + this.ybase;31633164j = this.rows - 1 - this.scrollBottom;3165j = this.rows - 1 + this.ybase - j + 1;31663167while (param--) {3168// test: echo -e '\e[44m\e[1L\e[0m'3169// blankLine(true) - xterm/linux behavior3170this.lines.splice(row, 0, this.blankLine(true));3171this.lines.splice(j, 1);3172}31733174// this.maxRange();3175this.updateRange(this.y);3176this.updateRange(this.scrollBottom);3177};31783179// CSI Ps M3180// Delete Ps Line(s) (default = 1) (DL).3181Terminal.prototype.deleteLines = function(params) {3182var param, row, j;31833184param = params[0];3185if (param < 1) param = 1;3186row = this.y + this.ybase;31873188j = this.rows - 1 - this.scrollBottom;3189j = this.rows - 1 + this.ybase - j;31903191while (param--) {3192// test: echo -e '\e[44m\e[1M\e[0m'3193// blankLine(true) - xterm/linux behavior3194this.lines.splice(j + 1, 0, this.blankLine(true));3195this.lines.splice(row, 1);3196}31973198// this.maxRange();3199this.updateRange(this.y);3200this.updateRange(this.scrollBottom);3201};32023203// CSI Ps P3204// Delete Ps Character(s) (default = 1) (DCH).3205Terminal.prototype.deleteChars = function(params) {3206var param, row, ch;32073208param = params[0];3209if (param < 1) param = 1;32103211row = this.y + this.ybase;3212ch = [this.curAttr, " "]; // xterm32133214while (param--) {3215if (row < this.lines.length) {3216this.lines[row].splice(this.x, 1);3217this.lines[row].push(ch);3218}3219}3220};32213222// CSI Ps X3223// Erase Ps Character(s) (default = 1) (ECH).3224Terminal.prototype.eraseChars = function(params) {3225var param, row, j, ch;32263227param = params[0];3228if (param < 1) param = 1;32293230row = this.y + this.ybase;3231j = this.x;3232ch = [this.curAttr, " "]; // xterm32333234while (param-- && j < this.cols) {3235this.lines[row][j++] = ch;3236}3237};32383239// CSI Pm ` Character Position Absolute3240// [column] (default = [row,1]) (HPA).3241Terminal.prototype.charPosAbsolute = function(params) {3242var param = params[0];3243if (param < 1) param = 1;3244this.x = param - 1;3245if (this.x >= this.cols) {3246this.x = this.cols - 1;3247}3248};32493250// 141 61 a * HPR -3251// Horizontal Position Relative3252// reuse CSI Ps C ?3253Terminal.prototype.HPositionRelative = function(params) {3254var param = params[0];3255if (param < 1) param = 1;3256this.x += param;3257if (this.x >= this.cols) {3258this.x = this.cols - 1;3259}3260};32613262// CSI Ps c Send Device Attributes (Primary DA).3263// Ps = 0 or omitted -> request attributes from terminal. The3264// response depends on the decTerminalID resource setting.3265// -> CSI ? 1 ; 2 c (``VT100 with Advanced Video Option'')3266// -> CSI ? 1 ; 0 c (``VT101 with No Options'')3267// -> CSI ? 6 c (``VT102'')3268// -> CSI ? 6 0 ; 1 ; 2 ; 6 ; 8 ; 9 ; 1 5 ; c (``VT220'')3269// The VT100-style response parameters do not mean anything by3270// themselves. VT220 parameters do, telling the host what fea-3271// tures the terminal supports:3272// Ps = 1 -> 132-columns.3273// Ps = 2 -> Printer.3274// Ps = 6 -> Selective erase.3275// Ps = 8 -> User-defined keys.3276// Ps = 9 -> National replacement character sets.3277// Ps = 1 5 -> Technical characters.3278// Ps = 2 2 -> ANSI color, e.g., VT525.3279// Ps = 2 9 -> ANSI text locator (i.e., DEC Locator mode).3280// CSI > Ps c3281// Send Device Attributes (Secondary DA).3282// Ps = 0 or omitted -> request the terminal's identification3283// code. The response depends on the decTerminalID resource set-3284// ting. It should apply only to VT220 and up, but xterm extends3285// this to VT100.3286// -> CSI > Pp ; Pv ; Pc c3287// where Pp denotes the terminal type3288// Pp = 0 -> ``VT100''.3289// Pp = 1 -> ``VT220''.3290// and Pv is the firmware version (for xterm, this was originally3291// the XFree86 patch number, starting with 95). In a DEC termi-3292// nal, Pc indicates the ROM cartridge registration number and is3293// always zero.3294// More information:3295// xterm/charproc.c - line 2012, for more information.3296// vim responds with ^[[?0c or ^[[?1c after the terminal's response (?)3297Terminal.prototype.sendDeviceAttributes = function(params) {3298if (params[0] > 0) return;32993300if (!this.prefix) {3301if (this.is("xterm") || this.is("rxvt-unicode") || this.is("screen")) {3302// This causes enormous pain - I don't understand it.3303// To trigger this pain in CoCalc,3304// type this into a terminal:3305// printf "\E[c\n" ; sleep 1 ; echo3306// See https://stackoverflow.com/questions/47691348/how-to-determine-graphics-capabilities-of-an-x11-terminal-window3307this.send('\x1b[?1;2c');3308} else if (this.is("linux")) {3309this.send("\x1b[?6c");3310}3311} else if (this.prefix === ">") {3312// xterm and urxvt3313// seem to spit this3314// out around ~370 times (?).3315if (this.is("xterm")) {3316this.send("\x1b[>0;276;0c");3317} else if (this.is("rxvt-unicode")) {3318this.send("\x1b[>85;95;0c");3319} else if (this.is("linux")) {3320// not supported by linux console.3321// linux console echoes parameters.3322this.send(params[0] + "c");3323} else if (this.is("screen")) {3324this.send("\x1b[>83;40003;0c");3325}3326}3327};33283329// CSI Pm d3330// Line Position Absolute [row] (default = [1,column]) (VPA).3331Terminal.prototype.linePosAbsolute = function(params) {3332var param = params[0];3333if (param < 1) param = 1;3334this.y = param - 1;3335if (this.y >= this.rows) {3336this.y = this.rows - 1;3337}3338};33393340// 145 65 e * VPR - Vertical Position Relative3341// reuse CSI Ps B ?3342Terminal.prototype.VPositionRelative = function(params) {3343var param = params[0];3344if (param < 1) param = 1;3345this.y += param;3346if (this.y >= this.rows) {3347this.y = this.rows - 1;3348}3349};33503351// CSI Ps ; Ps f3352// Horizontal and Vertical Position [row;column] (default =3353// [1,1]) (HVP).3354Terminal.prototype.HVPosition = function(params) {3355if (params[0] < 1) params[0] = 1;3356if (params[1] < 1) params[1] = 1;33573358this.y = params[0] - 1;3359if (this.y >= this.rows) {3360this.y = this.rows - 1;3361}33623363this.x = params[1] - 1;3364if (this.x >= this.cols) {3365this.x = this.cols - 1;3366}3367};33683369// CSI Pm h Set Mode (SM).3370// Ps = 2 -> Keyboard Action Mode (AM).3371// Ps = 4 -> Insert Mode (IRM).3372// Ps = 1 2 -> Send/receive (SRM).3373// Ps = 2 0 -> Automatic Newline (LNM).3374// CSI ? Pm h3375// DEC Private Mode Set (DECSET).3376// Ps = 1 -> Application Cursor Keys (DECCKM).3377// Ps = 2 -> Designate USASCII for character sets G0-G33378// (DECANM), and set VT100 mode.3379// Ps = 3 -> 132 Column Mode (DECCOLM).3380// Ps = 4 -> Smooth (Slow) Scroll (DECSCLM).3381// Ps = 5 -> Reverse Video (DECSCNM).3382// Ps = 6 -> Origin Mode (DECOM).3383// Ps = 7 -> Wraparound Mode (DECAWM).3384// Ps = 8 -> Auto-repeat Keys (DECARM).3385// Ps = 9 -> Send Mouse X & Y on button press. See the sec-3386// tion Mouse Tracking.3387// Ps = 1 0 -> Show toolbar (rxvt).3388// Ps = 1 2 -> Start Blinking Cursor (att610).3389// Ps = 1 8 -> Print form feed (DECPFF).3390// Ps = 1 9 -> Set print extent to full screen (DECPEX).3391// Ps = 2 5 -> Show Cursor (DECTCEM).3392// Ps = 3 0 -> Show scrollbar (rxvt).3393// Ps = 3 5 -> Enable font-shifting functions (rxvt).3394// Ps = 3 8 -> Enter Tektronix Mode (DECTEK).3395// Ps = 4 0 -> Allow 80 -> 132 Mode.3396// Ps = 4 1 -> more(1) fix (see curses resource).3397// Ps = 4 2 -> Enable Nation Replacement Character sets (DECN-3398// RCM).3399// Ps = 4 4 -> Turn On Margin Bell.3400// Ps = 4 5 -> Reverse-wraparound Mode.3401// Ps = 4 6 -> Start Logging. This is normally disabled by a3402// compile-time option.3403// Ps = 4 7 -> Use Alternate Screen Buffer. (This may be dis-3404// abled by the titeInhibit resource).3405// Ps = 6 6 -> Application keypad (DECNKM).3406// Ps = 6 7 -> Backarrow key sends backspace (DECBKM).3407// Ps = 1 0 0 0 -> Send Mouse X & Y on button press and3408// release. See the section Mouse Tracking.3409// Ps = 1 0 0 1 -> Use Hilite Mouse Tracking.3410// Ps = 1 0 0 2 -> Use Cell Motion Mouse Tracking.3411// Ps = 1 0 0 3 -> Use All Motion Mouse Tracking.3412// Ps = 1 0 0 4 -> Send FocusIn/FocusOut events.3413// Ps = 1 0 0 5 -> Enable Extended Mouse Mode.3414// Ps = 1 0 1 0 -> Scroll to bottom on tty output (rxvt).3415// Ps = 1 0 1 1 -> Scroll to bottom on key press (rxvt).3416// Ps = 1 0 3 4 -> Interpret "meta" key, sets eighth bit.3417// (enables the eightBitInput resource).3418// Ps = 1 0 3 5 -> Enable special modifiers for Alt and Num-3419// Lock keys. (This enables the numLock resource).3420// Ps = 1 0 3 6 -> Send ESC when Meta modifies a key. (This3421// enables the metaSendsEscape resource).3422// Ps = 1 0 3 7 -> Send DEL from the editing-keypad Delete3423// key.3424// Ps = 1 0 3 9 -> Send ESC when Alt modifies a key. (This3425// enables the altSendsEscape resource).3426// Ps = 1 0 4 0 -> Keep selection even if not highlighted.3427// (This enables the keepSelection resource).3428// Ps = 1 0 4 1 -> Use the CLIPBOARD selection. (This enables3429// the selectToClipboard resource).3430// Ps = 1 0 4 2 -> Enable Urgency window manager hint when3431// Control-G is received. (This enables the bellIsUrgent3432// resource).3433// Ps = 1 0 4 3 -> Enable raising of the window when Control-G3434// is received. (enables the popOnBell resource).3435// Ps = 1 0 4 7 -> Use Alternate Screen Buffer. (This may be3436// disabled by the titeInhibit resource).3437// Ps = 1 0 4 8 -> Save cursor as in DECSC. (This may be dis-3438// abled by the titeInhibit resource).3439// Ps = 1 0 4 9 -> Save cursor as in DECSC and use Alternate3440// Screen Buffer, clearing it first. (This may be disabled by3441// the titeInhibit resource). This combines the effects of the 13442// 0 4 7 and 1 0 4 8 modes. Use this with terminfo-based3443// applications rather than the 4 7 mode.3444// Ps = 1 0 5 0 -> Set terminfo/termcap function-key mode.3445// Ps = 1 0 5 1 -> Set Sun function-key mode.3446// Ps = 1 0 5 2 -> Set HP function-key mode.3447// Ps = 1 0 5 3 -> Set SCO function-key mode.3448// Ps = 1 0 6 0 -> Set legacy keyboard emulation (X11R6).3449// Ps = 1 0 6 1 -> Set VT220 keyboard emulation.3450// Ps = 2 0 0 4 -> Set bracketed paste mode.3451// Modes:3452// http://vt100.net/docs/vt220-rm/chapter4.html3453Terminal.prototype.setMode = function(params) {3454if (typeof params === "object") {3455var l = params.length,3456i = 0;34573458for (; i < l; i++) {3459this.setMode(params[i]);3460}34613462return;3463}34643465if (!this.prefix) {3466switch (params) {3467case 4:3468this.insertMode = true;3469break;3470case 20:3471//this.convertEol = true;3472break;3473}3474} else if (this.prefix === "?") {3475switch (params) {3476case 1:3477this.applicationKeypad = true;3478break;3479case 2:3480this.setgCharset(0, Terminal.charsets.US);3481this.setgCharset(1, Terminal.charsets.US);3482this.setgCharset(2, Terminal.charsets.US);3483this.setgCharset(3, Terminal.charsets.US);3484// set VT100 mode here3485break;3486case 3: // 132 col mode3487this.savedCols = this.cols;3488this.resize(132, this.rows);3489break;3490case 6:3491this.originMode = true;3492break;3493case 7:3494this.wraparoundMode = true;3495break;3496case 12:3497// this.cursorBlink = true;3498break;3499case 9: // X10 Mouse3500// no release, no motion, no wheel, no modifiers.3501case 1000: // vt200 mouse3502// no motion.3503// no modifiers, except control on the wheel.3504case 1002: // button event mouse3505case 1003: // any event mouse3506// any event - sends motion events,3507// even if there is no button held down.3508this.x10Mouse = params === 9;3509this.vt200Mouse = params === 1000;3510this.normalMouse = params > 1000;3511this.mouseEvents = true;3512this.element.style.cursor = "default";3513this.log("Binding to mouse events.");3514break;3515case 1004: // send focusin/focusout events3516// focusin: ^[[I3517// focusout: ^[[O3518this.sendFocus = true;3519break;3520case 1005: // utf8 ext mode mouse3521this.utfMouse = true;3522// for wide terminals3523// simply encodes large values as utf8 characters3524break;3525case 1006: // sgr ext mode mouse3526this.sgrMouse = true;3527// for wide terminals3528// does not add 32 to fields3529// press: ^[[<b;x;yM3530// release: ^[[<b;x;ym3531break;3532case 1015: // urxvt ext mode mouse3533this.urxvtMouse = true;3534// for wide terminals3535// numbers for fields3536// press: ^[[b;x;yM3537// motion: ^[[b;x;yT3538break;3539case 25: // show cursor3540this.cursorHidden = false;3541break;3542case 1049: // alt screen buffer cursor3543//this.saveCursor(); // FALL-THROUGH3544case 47: // alt screen buffer3545case 1047: // alt screen buffer3546if (!this.normal) {3547var normal = {3548lines: this.lines,3549ybase: this.ybase,3550ydisp: this.ydisp,3551x: this.x,3552y: this.y,3553scrollTop: this.scrollTop,3554scrollBottom: this.scrollBottom,3555tabs: this.tabs3556// XXX save charset(s) here?3557// charset: this.charset,3558// glevel: this.glevel,3559// charsets: this.charsets3560};3561this.reset();3562this.normal = normal;3563this.showCursor();3564}3565break;3566}3567}3568};35693570// CSI Pm l Reset Mode (RM).3571// Ps = 2 -> Keyboard Action Mode (AM).3572// Ps = 4 -> Replace Mode (IRM).3573// Ps = 1 2 -> Send/receive (SRM).3574// Ps = 2 0 -> Normal Linefeed (LNM).3575// CSI ? Pm l3576// DEC Private Mode Reset (DECRST).3577// Ps = 1 -> Normal Cursor Keys (DECCKM).3578// Ps = 2 -> Designate VT52 mode (DECANM).3579// Ps = 3 -> 80 Column Mode (DECCOLM).3580// Ps = 4 -> Jump (Fast) Scroll (DECSCLM).3581// Ps = 5 -> Normal Video (DECSCNM).3582// Ps = 6 -> Normal Cursor Mode (DECOM).3583// Ps = 7 -> No Wraparound Mode (DECAWM).3584// Ps = 8 -> No Auto-repeat Keys (DECARM).3585// Ps = 9 -> Don't send Mouse X & Y on button press.3586// Ps = 1 0 -> Hide toolbar (rxvt).3587// Ps = 1 2 -> Stop Blinking Cursor (att610).3588// Ps = 1 8 -> Don't print form feed (DECPFF).3589// Ps = 1 9 -> Limit print to scrolling region (DECPEX).3590// Ps = 2 5 -> Hide Cursor (DECTCEM).3591// Ps = 3 0 -> Don't show scrollbar (rxvt).3592// Ps = 3 5 -> Disable font-shifting functions (rxvt).3593// Ps = 4 0 -> Disallow 80 -> 132 Mode.3594// Ps = 4 1 -> No more(1) fix (see curses resource).3595// Ps = 4 2 -> Disable Nation Replacement Character sets (DEC-3596// NRCM).3597// Ps = 4 4 -> Turn Off Margin Bell.3598// Ps = 4 5 -> No Reverse-wraparound Mode.3599// Ps = 4 6 -> Stop Logging. (This is normally disabled by a3600// compile-time option).3601// Ps = 4 7 -> Use Normal Screen Buffer.3602// Ps = 6 6 -> Numeric keypad (DECNKM).3603// Ps = 6 7 -> Backarrow key sends delete (DECBKM).3604// Ps = 1 0 0 0 -> Don't send Mouse X & Y on button press and3605// release. See the section Mouse Tracking.3606// Ps = 1 0 0 1 -> Don't use Hilite Mouse Tracking.3607// Ps = 1 0 0 2 -> Don't use Cell Motion Mouse Tracking.3608// Ps = 1 0 0 3 -> Don't use All Motion Mouse Tracking.3609// Ps = 1 0 0 4 -> Don't send FocusIn/FocusOut events.3610// Ps = 1 0 0 5 -> Disable Extended Mouse Mode.3611// Ps = 1 0 1 0 -> Don't scroll to bottom on tty output3612// (rxvt).3613// Ps = 1 0 1 1 -> Don't scroll to bottom on key press (rxvt).3614// Ps = 1 0 3 4 -> Don't interpret "meta" key. (This disables3615// the eightBitInput resource).3616// Ps = 1 0 3 5 -> Disable special modifiers for Alt and Num-3617// Lock keys. (This disables the numLock resource).3618// Ps = 1 0 3 6 -> Don't send ESC when Meta modifies a key.3619// (This disables the metaSendsEscape resource).3620// Ps = 1 0 3 7 -> Send VT220 Remove from the editing-keypad3621// Delete key.3622// Ps = 1 0 3 9 -> Don't send ESC when Alt modifies a key.3623// (This disables the altSendsEscape resource).3624// Ps = 1 0 4 0 -> Do not keep selection when not highlighted.3625// (This disables the keepSelection resource).3626// Ps = 1 0 4 1 -> Use the PRIMARY selection. (This disables3627// the selectToClipboard resource).3628// Ps = 1 0 4 2 -> Disable Urgency window manager hint when3629// Control-G is received. (This disables the bellIsUrgent3630// resource).3631// Ps = 1 0 4 3 -> Disable raising of the window when Control-3632// G is received. (This disables the popOnBell resource).3633// Ps = 1 0 4 7 -> Use Normal Screen Buffer, clearing screen3634// first if in the Alternate Screen. (This may be disabled by3635// the titeInhibit resource).3636// Ps = 1 0 4 8 -> Restore cursor as in DECRC. (This may be3637// disabled by the titeInhibit resource).3638// Ps = 1 0 4 9 -> Use Normal Screen Buffer and restore cursor3639// as in DECRC. (This may be disabled by the titeInhibit3640// resource). This combines the effects of the 1 0 4 7 and 1 03641// 4 8 modes. Use this with terminfo-based applications rather3642// than the 4 7 mode.3643// Ps = 1 0 5 0 -> Reset terminfo/termcap function-key mode.3644// Ps = 1 0 5 1 -> Reset Sun function-key mode.3645// Ps = 1 0 5 2 -> Reset HP function-key mode.3646// Ps = 1 0 5 3 -> Reset SCO function-key mode.3647// Ps = 1 0 6 0 -> Reset legacy keyboard emulation (X11R6).3648// Ps = 1 0 6 1 -> Reset keyboard emulation to Sun/PC style.3649// Ps = 2 0 0 4 -> Reset bracketed paste mode.3650Terminal.prototype.resetMode = function(params) {3651if (typeof params === "object") {3652var l = params.length,3653i = 0;36543655for (; i < l; i++) {3656this.resetMode(params[i]);3657}36583659return;3660}36613662if (!this.prefix) {3663switch (params) {3664case 4:3665this.insertMode = false;3666break;3667case 20:3668//this.convertEol = false;3669break;3670}3671} else if (this.prefix === "?") {3672switch (params) {3673case 1:3674this.applicationKeypad = false;3675break;3676case 3:3677if (this.cols === 132 && this.savedCols) {3678this.resize(this.savedCols, this.rows);3679}3680delete this.savedCols;3681break;3682case 6:3683this.originMode = false;3684break;3685case 7:3686this.wraparoundMode = false;3687break;3688case 12:3689// this.cursorBlink = false;3690break;3691case 9: // X10 Mouse3692case 1000: // vt200 mouse3693case 1002: // button event mouse3694case 1003: // any event mouse3695this.x10Mouse = false;3696this.vt200Mouse = false;3697this.normalMouse = false;3698this.mouseEvents = false;3699this.element.style.cursor = "";3700break;3701case 1004: // send focusin/focusout events3702this.sendFocus = false;3703break;3704case 1005: // utf8 ext mode mouse3705this.utfMouse = false;3706break;3707case 1006: // sgr ext mode mouse3708this.sgrMouse = false;3709break;3710case 1015: // urxvt ext mode mouse3711this.urxvtMouse = false;3712break;3713case 25: // hide cursor3714this.cursorHidden = true;3715break;3716case 1049: // alt screen buffer cursor // FALL-THROUGH3717case 47: // normal screen buffer3718case 1047: // normal screen buffer - clearing it first3719if (this.normal) {3720this.lines = this.normal.lines;3721this.ybase = this.normal.ybase;3722this.ydisp = this.normal.ydisp;3723this.x = this.normal.x;3724this.y = this.normal.y;3725this.scrollTop = this.normal.scrollTop;3726this.scrollBottom = this.normal.scrollBottom;3727this.tabs = this.normal.tabs;3728this.normal = null;3729// if (params === 1049) {3730// this.x = this.savedX;3731// this.y = this.savedY;3732// }3733this.refresh(0, this.rows - 1);3734this.showCursor();3735}3736break;3737}3738}3739};37403741// CSI Ps ; Ps r3742// Set Scrolling Region [top;bottom] (default = full size of win-3743// dow) (DECSTBM).3744// CSI ? Pm r3745Terminal.prototype.setScrollRegion = function(params) {3746if (this.prefix) return;3747this.scrollTop = (params[0] || 1) - 1;3748this.scrollBottom = (params[1] || this.rows) - 1;3749this.x = 0;3750this.y = 0;3751};37523753// CSI s3754// Save cursor (ANSI.SYS).3755Terminal.prototype.saveCursor = function(params) {3756this.savedX = this.x;3757this.savedY = this.y;3758};37593760// CSI u3761// Restore cursor (ANSI.SYS).3762Terminal.prototype.restoreCursor = function(params) {3763this.x = this.savedX || 0;3764this.y = this.savedY || 0;3765};37663767/**3768* Lesser Used3769*/37703771// CSI Ps I3772// Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).3773Terminal.prototype.cursorForwardTab = function(params) {3774var param = params[0] || 1;3775while (param--) {3776this.x = this.nextStop();3777}3778};37793780// CSI Ps S Scroll up Ps lines (default = 1) (SU).3781Terminal.prototype.scrollUp = function(params) {3782var param = params[0] || 1;3783while (param--) {3784this.lines.splice(this.ybase + this.scrollTop, 1);3785this.lines.splice(this.ybase + this.scrollBottom, 0, this.blankLine());3786}3787// this.maxRange();3788this.updateRange(this.scrollTop);3789this.updateRange(this.scrollBottom);3790};37913792// CSI Ps T Scroll down Ps lines (default = 1) (SD).3793Terminal.prototype.scrollDown = function(params) {3794var param = params[0] || 1;3795while (param--) {3796this.lines.splice(this.ybase + this.scrollBottom, 1);3797this.lines.splice(this.ybase + this.scrollTop, 0, this.blankLine());3798}3799// this.maxRange();3800this.updateRange(this.scrollTop);3801this.updateRange(this.scrollBottom);3802};38033804// CSI Ps ; Ps ; Ps ; Ps ; Ps T3805// Initiate highlight mouse tracking. Parameters are3806// [func;startx;starty;firstrow;lastrow]. See the section Mouse3807// Tracking.3808Terminal.prototype.initMouseTracking = function(params) {3809// Relevant: DECSET 10013810};38113812// CSI > Ps; Ps T3813// Reset one or more features of the title modes to the default3814// value. Normally, "reset" disables the feature. It is possi-3815// ble to disable the ability to reset features by compiling a3816// different default for the title modes into xterm.3817// Ps = 0 -> Do not set window/icon labels using hexadecimal.3818// Ps = 1 -> Do not query window/icon labels using hexadeci-3819// mal.3820// Ps = 2 -> Do not set window/icon labels using UTF-8.3821// Ps = 3 -> Do not query window/icon labels using UTF-8.3822// (See discussion of "Title Modes").3823Terminal.prototype.resetTitleModes = function(params) {};38243825// CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).3826Terminal.prototype.cursorBackwardTab = function(params) {3827var param = params[0] || 1;3828while (param--) {3829this.x = this.prevStop();3830}3831};38323833// CSI Ps b Repeat the preceding graphic character Ps times (REP).3834Terminal.prototype.repeatPrecedingCharacter = function(params) {3835var param = params[0] || 1,3836line = this.lines[this.ybase + this.y],3837ch = line[this.x - 1] || [this.defAttr, " "];38383839while (param--) line[this.x++] = ch;3840};38413842// CSI Ps g Tab Clear (TBC).3843// Ps = 0 -> Clear Current Column (default).3844// Ps = 3 -> Clear All.3845// Potentially:3846// Ps = 2 -> Clear Stops on Line.3847// http://vt100.net/annarbor/aaa-ug/section6.html3848Terminal.prototype.tabClear = function(params) {3849var param = params[0];3850if (param <= 0) {3851delete this.tabs[this.x];3852} else if (param === 3) {3853this.tabs = {};3854}3855};38563857// CSI Pm i Media Copy (MC).3858// Ps = 0 -> Print screen (default).3859// Ps = 4 -> Turn off printer controller mode.3860// Ps = 5 -> Turn on printer controller mode.3861// CSI ? Pm i3862// Media Copy (MC, DEC-specific).3863// Ps = 1 -> Print line containing cursor.3864// Ps = 4 -> Turn off autoprint mode.3865// Ps = 5 -> Turn on autoprint mode.3866// Ps = 1 0 -> Print composed display, ignores DECPEX.3867// Ps = 1 1 -> Print all pages.3868Terminal.prototype.mediaCopy = function(params) {};38693870// CSI > Ps; Ps m3871// Set or reset resource-values used by xterm to decide whether3872// to construct escape sequences holding information about the3873// modifiers pressed with a given key. The first parameter iden-3874// tifies the resource to set/reset. The second parameter is the3875// value to assign to the resource. If the second parameter is3876// omitted, the resource is reset to its initial value.3877// Ps = 1 -> modifyCursorKeys.3878// Ps = 2 -> modifyFunctionKeys.3879// Ps = 4 -> modifyOtherKeys.3880// If no parameters are given, all resources are reset to their3881// initial values.3882Terminal.prototype.setResources = function(params) {};38833884// CSI > Ps n3885// Disable modifiers which may be enabled via the CSI > Ps; Ps m3886// sequence. This corresponds to a resource value of "-1", which3887// cannot be set with the other sequence. The parameter identi-3888// fies the resource to be disabled:3889// Ps = 1 -> modifyCursorKeys.3890// Ps = 2 -> modifyFunctionKeys.3891// Ps = 4 -> modifyOtherKeys.3892// If the parameter is omitted, modifyFunctionKeys is disabled.3893// When modifyFunctionKeys is disabled, xterm uses the modifier3894// keys to make an extended sequence of functions rather than3895// adding a parameter to each function key to denote the modi-3896// fiers.3897Terminal.prototype.disableModifiers = function(params) {};38983899// CSI > Ps p3900// Set resource value pointerMode. This is used by xterm to3901// decide whether to hide the pointer cursor as the user types.3902// Valid values for the parameter:3903// Ps = 0 -> never hide the pointer.3904// Ps = 1 -> hide if the mouse tracking mode is not enabled.3905// Ps = 2 -> always hide the pointer. If no parameter is3906// given, xterm uses the default, which is 1 .3907Terminal.prototype.setPointerMode = function(params) {};39083909// CSI ! p Soft terminal reset (DECSTR).3910// http://vt100.net/docs/vt220-rm/table4-10.html3911Terminal.prototype.softReset = function(params) {3912this.cursorHidden = false;3913this.insertMode = false;3914this.originMode = false;3915this.wraparoundMode = false; // autowrap3916this.applicationKeypad = false; // ?3917this.scrollTop = 0;3918this.scrollBottom = this.rows - 1;3919this.curAttr = this.defAttr;3920this.x = this.y = 0; // ?3921this.charset = null;3922this.glevel = 0; // ??3923this.charsets = [null]; // ??3924};39253926// CSI Ps$ p3927// Request ANSI mode (DECRQM). For VT300 and up, reply is3928// CSI Ps; Pm$ y3929// where Ps is the mode number as in RM, and Pm is the mode3930// value:3931// 0 - not recognized3932// 1 - set3933// 2 - reset3934// 3 - permanently set3935// 4 - permanently reset3936Terminal.prototype.requestAnsiMode = function(params) {};39373938// CSI ? Ps$ p3939// Request DEC private mode (DECRQM). For VT300 and up, reply is3940// CSI ? Ps; Pm$ p3941// where Ps is the mode number as in DECSET, Pm is the mode value3942// as in the ANSI DECRQM.3943Terminal.prototype.requestPrivateMode = function(params) {};39443945// CSI Ps ; Ps " p3946// Set conformance level (DECSCL). Valid values for the first3947// parameter:3948// Ps = 6 1 -> VT100.3949// Ps = 6 2 -> VT200.3950// Ps = 6 3 -> VT300.3951// Valid values for the second parameter:3952// Ps = 0 -> 8-bit controls.3953// Ps = 1 -> 7-bit controls (always set for VT100).3954// Ps = 2 -> 8-bit controls.3955Terminal.prototype.setConformanceLevel = function(params) {};39563957// CSI Ps q Load LEDs (DECLL).3958// Ps = 0 -> Clear all LEDS (default).3959// Ps = 1 -> Light Num Lock.3960// Ps = 2 -> Light Caps Lock.3961// Ps = 3 -> Light Scroll Lock.3962// Ps = 2 1 -> Extinguish Num Lock.3963// Ps = 2 2 -> Extinguish Caps Lock.3964// Ps = 2 3 -> Extinguish Scroll Lock.3965Terminal.prototype.loadLEDs = function(params) {};39663967// CSI Ps SP q3968// Set cursor style (DECSCUSR, VT520).3969// Ps = 0 -> blinking block.3970// Ps = 1 -> blinking block (default).3971// Ps = 2 -> steady block.3972// Ps = 3 -> blinking underline.3973// Ps = 4 -> steady underline.3974Terminal.prototype.setCursorStyle = function(params) {};39753976// CSI Ps " q3977// Select character protection attribute (DECSCA). Valid values3978// for the parameter:3979// Ps = 0 -> DECSED and DECSEL can erase (default).3980// Ps = 1 -> DECSED and DECSEL cannot erase.3981// Ps = 2 -> DECSED and DECSEL can erase.3982Terminal.prototype.setCharProtectionAttr = function(params) {};39833984// CSI ? Pm r3985// Restore DEC Private Mode Values. The value of Ps previously3986// saved is restored. Ps values are the same as for DECSET.3987Terminal.prototype.restorePrivateValues = function(params) {};39883989// CSI Pt; Pl; Pb; Pr; Ps$ r3990// Change Attributes in Rectangular Area (DECCARA), VT400 and up.3991// Pt; Pl; Pb; Pr denotes the rectangle.3992// Ps denotes the SGR attributes to change: 0, 1, 4, 5, 7.3993// NOTE: xterm doesn't enable this code by default.3994Terminal.prototype.setAttrInRectangle = function(params) {3995var t = params[0],3996l = params[1],3997b = params[2],3998r = params[3],3999attr = params[4];40004001var line, i;40024003for (; t < b + 1; t++) {4004line = this.lines[this.ybase + t];4005for (i = l; i < r; i++) {4006line[i] = [attr, line[i][1]];4007}4008}40094010// this.maxRange();4011this.updateRange(params[0]);4012this.updateRange(params[2]);4013};40144015// CSI ? Pm s4016// Save DEC Private Mode Values. Ps values are the same as for4017// DECSET.4018Terminal.prototype.savePrivateValues = function(params) {};40194020// CSI Ps ; Ps ; Ps t4021// Window manipulation (from dtterm, as well as extensions).4022// These controls may be disabled using the allowWindowOps4023// resource. Valid values for the first (and any additional4024// parameters) are:4025// Ps = 1 -> De-iconify window.4026// Ps = 2 -> Iconify window.4027// Ps = 3 ; x ; y -> Move window to [x, y].4028// Ps = 4 ; height ; width -> Resize the xterm window to4029// height and width in pixels.4030// Ps = 5 -> Raise the xterm window to the front of the stack-4031// ing order.4032// Ps = 6 -> Lower the xterm window to the bottom of the4033// stacking order.4034// Ps = 7 -> Refresh the xterm window.4035// Ps = 8 ; height ; width -> Resize the text area to4036// [height;width] in characters.4037// Ps = 9 ; 0 -> Restore maximized window.4038// Ps = 9 ; 1 -> Maximize window (i.e., resize to screen4039// size).4040// Ps = 1 0 ; 0 -> Undo full-screen mode.4041// Ps = 1 0 ; 1 -> Change to full-screen.4042// Ps = 1 1 -> Report xterm window state. If the xterm window4043// is open (non-iconified), it returns CSI 1 t . If the xterm4044// window is iconified, it returns CSI 2 t .4045// Ps = 1 3 -> Report xterm window position. Result is CSI 34046// ; x ; y t4047// Ps = 1 4 -> Report xterm window in pixels. Result is CSI4048// 4 ; height ; width t4049// Ps = 1 8 -> Report the size of the text area in characters.4050// Result is CSI 8 ; height ; width t4051// Ps = 1 9 -> Report the size of the screen in characters.4052// Result is CSI 9 ; height ; width t4053// Ps = 2 0 -> Report xterm window's icon label. Result is4054// OSC L label ST4055// Ps = 2 1 -> Report xterm window's title. Result is OSC l4056// label ST4057// Ps = 2 2 ; 0 -> Save xterm icon and window title on4058// stack.4059// Ps = 2 2 ; 1 -> Save xterm icon title on stack.4060// Ps = 2 2 ; 2 -> Save xterm window title on stack.4061// Ps = 2 3 ; 0 -> Restore xterm icon and window title from4062// stack.4063// Ps = 2 3 ; 1 -> Restore xterm icon title from stack.4064// Ps = 2 3 ; 2 -> Restore xterm window title from stack.4065// Ps >= 2 4 -> Resize to Ps lines (DECSLPP).4066Terminal.prototype.manipulateWindow = function(params) {};40674068// CSI Pt; Pl; Pb; Pr; Ps$ t4069// Reverse Attributes in Rectangular Area (DECRARA), VT400 and4070// up.4071// Pt; Pl; Pb; Pr denotes the rectangle.4072// Ps denotes the attributes to reverse, i.e., 1, 4, 5, 7.4073// NOTE: xterm doesn't enable this code by default.4074Terminal.prototype.reverseAttrInRectangle = function(params) {};40754076// CSI > Ps; Ps t4077// Set one or more features of the title modes. Each parameter4078// enables a single feature.4079// Ps = 0 -> Set window/icon labels using hexadecimal.4080// Ps = 1 -> Query window/icon labels using hexadecimal.4081// Ps = 2 -> Set window/icon labels using UTF-8.4082// Ps = 3 -> Query window/icon labels using UTF-8. (See dis-4083// cussion of "Title Modes")4084Terminal.prototype.setTitleModeFeature = function(params) {};40854086// CSI Ps SP t4087// Set warning-bell volume (DECSWBV, VT520).4088// Ps = 0 or 1 -> off.4089// Ps = 2 , 3 or 4 -> low.4090// Ps = 5 , 6 , 7 , or 8 -> high.4091Terminal.prototype.setWarningBellVolume = function(params) {};40924093// CSI Ps SP u4094// Set margin-bell volume (DECSMBV, VT520).4095// Ps = 1 -> off.4096// Ps = 2 , 3 or 4 -> low.4097// Ps = 0 , 5 , 6 , 7 , or 8 -> high.4098Terminal.prototype.setMarginBellVolume = function(params) {};40994100// CSI Pt; Pl; Pb; Pr; Pp; Pt; Pl; Pp$ v4101// Copy Rectangular Area (DECCRA, VT400 and up).4102// Pt; Pl; Pb; Pr denotes the rectangle.4103// Pp denotes the source page.4104// Pt; Pl denotes the target location.4105// Pp denotes the target page.4106// NOTE: xterm doesn't enable this code by default.4107Terminal.prototype.copyRectangle = function(params) {};41084109// CSI Pt ; Pl ; Pb ; Pr ' w4110// Enable Filter Rectangle (DECEFR), VT420 and up.4111// Parameters are [top;left;bottom;right].4112// Defines the coordinates of a filter rectangle and activates4113// it. Anytime the locator is detected outside of the filter4114// rectangle, an outside rectangle event is generated and the4115// rectangle is disabled. Filter rectangles are always treated4116// as "one-shot" events. Any parameters that are omitted default4117// to the current locator position. If all parameters are omit-4118// ted, any locator motion will be reported. DECELR always can-4119// cels any previous rectangle definition.4120Terminal.prototype.enableFilterRectangle = function(params) {};41214122// CSI Ps x Request Terminal Parameters (DECREQTPARM).4123// if Ps is a "0" (default) or "1", and xterm is emulating VT100,4124// the control sequence elicits a response of the same form whose4125// parameters describe the terminal:4126// Ps -> the given Ps incremented by 2.4127// Pn = 1 <- no parity.4128// Pn = 1 <- eight bits.4129// Pn = 1 <- 2 8 transmit 38.4k baud.4130// Pn = 1 <- 2 8 receive 38.4k baud.4131// Pn = 1 <- clock multiplier.4132// Pn = 0 <- STP flags.4133Terminal.prototype.requestParameters = function(params) {};41344135// CSI Ps x Select Attribute Change Extent (DECSACE).4136// Ps = 0 -> from start to end position, wrapped.4137// Ps = 1 -> from start to end position, wrapped.4138// Ps = 2 -> rectangle (exact).4139Terminal.prototype.selectChangeExtent = function(params) {};41404141// CSI Pc; Pt; Pl; Pb; Pr$ x4142// Fill Rectangular Area (DECFRA), VT420 and up.4143// Pc is the character to use.4144// Pt; Pl; Pb; Pr denotes the rectangle.4145// NOTE: xterm doesn't enable this code by default.4146Terminal.prototype.fillRectangle = function(params) {4147var ch = params[0],4148t = params[1],4149l = params[2],4150b = params[3],4151r = params[4];41524153var line, i;41544155for (; t < b + 1; t++) {4156line = this.lines[this.ybase + t];4157for (i = l; i < r; i++) {4158line[i] = [line[i][0], String.fromCharCode(ch)];4159}4160}41614162// this.maxRange();4163this.updateRange(params[1]);4164this.updateRange(params[3]);4165};41664167// CSI Ps ; Pu ' z4168// Enable Locator Reporting (DECELR).4169// Valid values for the first parameter:4170// Ps = 0 -> Locator disabled (default).4171// Ps = 1 -> Locator enabled.4172// Ps = 2 -> Locator enabled for one report, then disabled.4173// The second parameter specifies the coordinate unit for locator4174// reports.4175// Valid values for the second parameter:4176// Pu = 0 <- or omitted -> default to character cells.4177// Pu = 1 <- device physical pixels.4178// Pu = 2 <- character cells.4179Terminal.prototype.enableLocatorReporting = function(params) {4180var val = params[0] > 0;4181//this.mouseEvents = val;4182//this.decLocator = val;4183};41844185// CSI Pt; Pl; Pb; Pr$ z4186// Erase Rectangular Area (DECERA), VT400 and up.4187// Pt; Pl; Pb; Pr denotes the rectangle.4188// NOTE: xterm doesn't enable this code by default.4189Terminal.prototype.eraseRectangle = function(params) {4190var t = params[0],4191l = params[1],4192b = params[2],4193r = params[3];41944195var line, i, ch;41964197ch = [this.curAttr, " "]; // xterm?41984199for (; t < b + 1; t++) {4200line = this.lines[this.ybase + t];4201for (i = l; i < r; i++) {4202line[i] = ch;4203}4204}42054206// this.maxRange();4207this.updateRange(params[0]);4208this.updateRange(params[2]);4209};42104211// CSI Pm ' {4212// Select Locator Events (DECSLE).4213// Valid values for the first (and any additional parameters)4214// are:4215// Ps = 0 -> only respond to explicit host requests (DECRQLP).4216// (This is default). It also cancels any filter4217// rectangle.4218// Ps = 1 -> report button down transitions.4219// Ps = 2 -> do not report button down transitions.4220// Ps = 3 -> report button up transitions.4221// Ps = 4 -> do not report button up transitions.4222Terminal.prototype.setLocatorEvents = function(params) {};42234224// CSI Pt; Pl; Pb; Pr$ {4225// Selective Erase Rectangular Area (DECSERA), VT400 and up.4226// Pt; Pl; Pb; Pr denotes the rectangle.4227Terminal.prototype.selectiveEraseRectangle = function(params) {};42284229// CSI Ps ' |4230// Request Locator Position (DECRQLP).4231// Valid values for the parameter are:4232// Ps = 0 , 1 or omitted -> transmit a single DECLRP locator4233// report.42344235// If Locator Reporting has been enabled by a DECELR, xterm will4236// respond with a DECLRP Locator Report. This report is also4237// generated on button up and down events if they have been4238// enabled with a DECSLE, or when the locator is detected outside4239// of a filter rectangle, if filter rectangles have been enabled4240// with a DECEFR.42414242// -> CSI Pe ; Pb ; Pr ; Pc ; Pp & w42434244// Parameters are [event;button;row;column;page].4245// Valid values for the event:4246// Pe = 0 -> locator unavailable - no other parameters sent.4247// Pe = 1 -> request - xterm received a DECRQLP.4248// Pe = 2 -> left button down.4249// Pe = 3 -> left button up.4250// Pe = 4 -> middle button down.4251// Pe = 5 -> middle button up.4252// Pe = 6 -> right button down.4253// Pe = 7 -> right button up.4254// Pe = 8 -> M4 button down.4255// Pe = 9 -> M4 button up.4256// Pe = 1 0 -> locator outside filter rectangle.4257// ``button'' parameter is a bitmask indicating which buttons are4258// pressed:4259// Pb = 0 <- no buttons down.4260// Pb & 1 <- right button down.4261// Pb & 2 <- middle button down.4262// Pb & 4 <- left button down.4263// Pb & 8 <- M4 button down.4264// ``row'' and ``column'' parameters are the coordinates of the4265// locator position in the xterm window, encoded as ASCII deci-4266// mal.4267// The ``page'' parameter is not used by xterm, and will be omit-4268// ted.4269Terminal.prototype.requestLocatorPosition = function(params) {};42704271// CSI P m SP }4272// Insert P s Column(s) (default = 1) (DECIC), VT420 and up.4273// NOTE: xterm doesn't enable this code by default.4274Terminal.prototype.insertColumns = function() {4275var param = params[0],4276l = this.ybase + this.rows,4277ch = [this.curAttr, " "], // xterm?4278i;42794280while (param--) {4281for (i = this.ybase; i < l; i++) {4282this.lines[i].splice(this.x + 1, 0, ch);4283this.lines[i].pop();4284}4285}42864287this.maxRange();4288};42894290// CSI P m SP ~4291// Delete P s Column(s) (default = 1) (DECDC), VT420 and up4292// NOTE: xterm doesn't enable this code by default.4293Terminal.prototype.deleteColumns = function() {4294var param = params[0],4295l = this.ybase + this.rows,4296ch = [this.curAttr, " "], // xterm?4297i;42984299while (param--) {4300for (i = this.ybase; i < l; i++) {4301this.lines[i].splice(this.x, 1);4302this.lines[i].push(ch);4303}4304}43054306this.maxRange();4307};43084309/**4310* Character Sets4311*/43124313Terminal.charsets = {};43144315// DEC Special Character and Line Drawing Set.4316// http://vt100.net/docs/vt102-ug/table5-13.html4317// A lot of curses apps use this if they see TERM=xterm.4318// testing: echo -e '\e(0a\e(B'4319// The xterm output sometimes seems to conflict with the4320// reference above. xterm seems in line with the reference4321// when running vttest however.4322// The table below now uses xterm's output from vttest.4323Terminal.charsets.SCLD = {4324// (04325"`": "\u25c6", // '◆'4326a: "\u2592", // '▒'4327b: "\u0009", // '\t'4328c: "\u000c", // '\f'4329d: "\u000d", // '\r'4330e: "\u000a", // '\n'4331f: "\u00b0", // '°'4332g: "\u00b1", // '±'4333h: "\u2424", // '\u2424' (NL)4334i: "\u000b", // '\v'4335j: "\u2518", // '┘'4336k: "\u2510", // '┐'4337l: "\u250c", // '┌'4338m: "\u2514", // '└'4339n: "\u253c", // '┼'4340o: "\u23ba", // '⎺'4341p: "\u23bb", // '⎻'4342q: "\u2500", // '─'4343r: "\u23bc", // '⎼'4344s: "\u23bd", // '⎽'4345t: "\u251c", // '├'4346u: "\u2524", // '┤'4347v: "\u2534", // '┴'4348w: "\u252c", // '┬'4349x: "\u2502", // '│'4350y: "\u2264", // '≤'4351z: "\u2265", // '≥'4352"{": "\u03c0", // 'π'4353"|": "\u2260", // '≠'4354"}": "\u00a3", // '£'4355"~": "\u00b7" // '·'4356};43574358Terminal.charsets.UK = null; // (A4359Terminal.charsets.US = null; // (B (USASCII)4360Terminal.charsets.Dutch = null; // (44361Terminal.charsets.Finnish = null; // (C or (54362Terminal.charsets.French = null; // (R4363Terminal.charsets.FrenchCanadian = null; // (Q4364Terminal.charsets.German = null; // (K4365Terminal.charsets.Italian = null; // (Y4366Terminal.charsets.NorwegianDanish = null; // (E or (64367Terminal.charsets.Spanish = null; // (Z4368Terminal.charsets.Swedish = null; // (H or (74369Terminal.charsets.Swiss = null; // (=4370Terminal.charsets.ISOLatin = null; // /A43714372/**4373* Helpers4374*/43754376function on(el, type, handler, capture) {4377el.addEventListener(type, handler, capture || false);4378}43794380function off(el, type, handler, capture) {4381el.removeEventListener(type, handler, capture || false);4382}43834384function cancel(ev) {4385if (ev.preventDefault) ev.preventDefault();4386ev.returnValue = false;4387if (ev.stopPropagation) ev.stopPropagation();4388ev.cancelBubble = true;4389return false;4390}43914392function inherits(child, parent) {4393function f() {4394this.constructor = child;4395}4396f.prototype = parent.prototype;4397child.prototype = new f();4398}43994400var isMac = ~navigator.userAgent.indexOf("Mac");44014402// if bold is broken, we can't4403// use it in the terminal.4404function isBoldBroken() {4405var el = document.createElement("span");4406el.innerHTML = "hello world";4407document.body.appendChild(el);4408var w1 = el.scrollWidth;4409el.style.fontWeight = "bold";4410var w2 = el.scrollWidth;4411document.body.removeChild(el);4412return w1 !== w2;4413}44144415var String = this.String;4416var setTimeout = this.setTimeout;4417var setInterval = this.setInterval;44184419/**4420* Expose4421*/44224423Terminal.EventEmitter = EventEmitter;4424Terminal.isMac = isMac;4425Terminal.inherits = inherits;4426Terminal.on = on;4427Terminal.off = off;4428Terminal.cancel = cancel;44294430if (typeof module !== "undefined") {4431module.exports = Terminal;4432} else {4433this.Terminal = Terminal;4434}4435}.call(4436(function() {4437return this || (typeof window !== "undefined" ? window : global);4438})()4439));444044414442