diff --git a/lib/program.js b/lib/program.js index d1a0ff1..77ffdfb 100644 --- a/lib/program.js +++ b/lib/program.js @@ -60,6 +60,12 @@ Program.prototype.listen = function() { self.rows = self.output.rows; self.emit('resize'); }); + + // this.getCursor(function(err, cursor) { + // if (err) return; + // self.x = cursor.x; + // self.y = cursor.y; + // }); }; Program.prototype.receive = function(text, callback) { @@ -85,7 +91,7 @@ Program.prototype.receive = function(text, callback) { return callback(null, data); }); - if (text) this.echo(text); + if (text) this.write(text); }; Program.prototype.listChoices = function(list) { @@ -96,7 +102,7 @@ Program.prototype.write = Program.prototype.echo = function(text, attr) { if (attr) { this.attr(attr, true); - this.echo(text); + this.write(text); this.attr(attr, false); return; } @@ -151,72 +157,230 @@ Program.prototype.__defineSetter__('y', function(y) { */ Program.prototype.nul = function() { - this.echo('\0'); + return this.write('\0'); }; Program.prototype.bell = function() { - this.echo('\x07'); + return this.write('\x07'); }; Program.prototype.vtab = function() { - this.echo('\x0b'); + this.y++; + return this.write('\x0b'); }; Program.prototype.form = function() { - this.echo('\x0c'); + return this.write('\x0c'); }; Program.prototype.backspace = function() { - this.echo('\x08'); + this.x--; + return this.write('\x08'); }; Program.prototype.tab = function() { - this.echo('\t'); + this.x += 8; + return this.write('\t'); }; Program.prototype.shiftOut = function() { - this.echo('\x0e'); + return this.write('\x0e'); }; Program.prototype.shiftIn = function() { - this.echo('\x0f'); + return this.write('\x0f'); }; Program.prototype.return = function() { - this.echo('\r'); + this.x = 1; + return this.write('\r'); }; Program.prototype.feed = function() { - this.echo('\n'); + this.x = 1; + this.y++; + return this.write('\n'); }; /** * Esc */ +Program.prototype.esc = function(code) { + return this.write('\x1b' + code); +}; + // ESC D Index (IND is 0x84). Program.prototype.index = function() { - this.echo('\x1bD'); + this.y++; + return this.write('\x1bD'); }; // ESC M Reverse Index (RI is 0x8d). Program.prototype.reverse = Program.prototype.reverseIndex = function() { - this.echo('\x1bM'); + this.y--; + return this.write('\x1bM'); +}; + +// ESC E Next Line (NEL is 0x85). +Program.prototype.nextLine = function() { + this.y++; + this.x = 1; + return this.write('\x1bE'); }; // ESC c Full Reset (RIS). Program.prototype.reset = function() { - this.echo('\x1bc'); + //this.x = this.y = 1; + return this.write('\x1bc'); }; // ESC H Tab Set (HTS is 0x88). Program.prototype.tabSet = function() { - this.echo('\x1bH'); + return this.write('\x1bH'); }; -Program.prototype.esc = function(code) { - this.echo('\x1b' + code); +// ESC 7 Save Cursor (DECSC). +Program.prototype.saveCursor = function() { + this.savedX = this.x || 1; + this.savedY = this.y || 1; + return this.esc('7'); +}; + +// ESC 8 Restore Cursor (DECRC). +Program.prototype.restoreCursor = function() { + this.x = this.savedX || 1; + this.y = this.savedY || 1; + return this.esc('8'); +}; + +// ESC # 3 DEC line height/width +Program.prototype.lineHeight = function() { + return this.esc('#'); +}; + +// ESC (,),*,+,-,. Designate G0-G2 Character Set. +Program.prototype.charset = function(val, level) { + level = level || 0; + + switch (level) { + case 0: + level = '('; + break; + case 1: + level = ')'; + break; + case 2: + level = '*'; + break; + case 3: + level = '+'; + break; + } + + switch (val) { + case 'SCLD': // DEC Special Character and Line Drawing Set. + val = '0'; + break; + case 'UK': // UK + val = 'A'; + break; + case 'US': // United States (USASCII). + val = 'B'; + break; + case 'Dutch': // Dutch + val = '4'; + break; + case 'Finnish': // Finnish + val = 'C'; + val = '5'; + break; + case 'French': // French + val = 'R'; + break; + case 'FrenchCanadian': // FrenchCanadian + val = 'Q'; + break; + case 'German': // German + val = 'K'; + break; + case 'Italian': // Italian + val = 'Y'; + break; + case 'NorwegianDanish': // NorwegianDanish + val = 'E'; + val = '6'; + break; + case 'Spanish': // Spanish + val = 'Z'; + break; + case 'Swedish': // Swedish + val = 'H'; + val = '7'; + break; + case 'Swiss': // Swiss + val = '='; + break; + case 'ISOLatin': // ISOLatin (actually /A) + val = '/A'; + break; + default: // Default + val = 'B'; + break; + } + + return this.write('\x1b(' + val); +}; + +// ESC N +// Single Shift Select of G2 Character Set +// ( SS2 is 0x8e). This affects next character only. +// ESC O +// Single Shift Select of G3 Character Set +// ( SS3 is 0x8f). This affects next character only. +// ESC n +// Invoke the G2 Character Set as GL (LS2). +// ESC o +// Invoke the G3 Character Set as GL (LS3). +// ESC | +// Invoke the G3 Character Set as GR (LS3R). +// ESC } +// Invoke the G2 Character Set as GR (LS2R). +// ESC ~ +// Invoke the G1 Character Set as GR (LS1R). +Program.prototype.setG = function(val) { + switch (val) { + case 1: + val = '~'; // GR + break; + case 2: + val = 'n'; // GL + val = '}'; // GR + val = 'N'; // Next Char Only + break; + case 3: + val = 'o'; // GL + val = '|'; // GR + val = 'O'; // Next Char Only + break; + } + return this.esc(val); +}; + +/** + * OSC + */ + +Program.prototype.osc = function(code) { + return this.esc(']' + code); +}; + +// OSC Ps ; Pt ST +// OSC Ps ; Pt BEL +// Set Text Parameters. +Program.prototype.setTitle = function(title) { + return this.osc('0;' + title + '\x07'); }; /** @@ -224,7 +388,7 @@ Program.prototype.esc = function(code) { */ Program.prototype.csi = function(code) { - this.esc('[' + code); + return this.esc('[' + code); }; // CSI Ps A @@ -232,7 +396,7 @@ Program.prototype.csi = function(code) { Program.prototype.up = Program.prototype.cursorUp = function(param) { this.y -= param || 1; - this.echo('\x1b[' + (param || '') + 'A'); + return this.write('\x1b[' + (param || '') + 'A'); }; // CSI Ps B @@ -240,7 +404,7 @@ Program.prototype.cursorUp = function(param) { Program.prototype.down = Program.prototype.cursorDown = function(param) { this.y += param || 1; - this.echo('\x1b[' + (param || '') + 'B'); + return this.write('\x1b[' + (param || '') + 'B'); }; // CSI Ps C @@ -248,7 +412,7 @@ Program.prototype.cursorDown = function(param) { Program.prototype.forward = Program.prototype.cursorForward = function(param) { this.x += param || 1; - this.echo('\x1b[' + (param || '') + 'C'); + return this.write('\x1b[' + (param || '') + 'C'); }; // CSI Ps D @@ -256,7 +420,7 @@ Program.prototype.cursorForward = function(param) { Program.prototype.back = Program.prototype.cursorBackward = function(param) { this.x -= param || 1; - this.echo('\x1b[' + (param || '') + 'D'); + return this.write('\x1b[' + (param || '') + 'D'); }; // CSI Ps ; Ps H @@ -265,7 +429,7 @@ Program.prototype.pos = Program.prototype.cursorPos = function(row, col) { this.x = col || 1; this.y = row || 1; - this.echo('\x1b[' + (row || '1') + ';' + (col || '1') + 'H'); + return this.write('\x1b[' + (row || '1') + ';' + (col || '1') + 'H'); }; // CSI Ps J Erase in Display (ED). @@ -281,17 +445,17 @@ Program.prototype.cursorPos = function(row, col) { Program.prototype.eraseInDisplay = function(param) { switch (param) { case 'above': - this.echo('\x1b[1J'); + this.write('\x1b[1J'); break; case 'all': - this.echo('\x1b[2J'); + this.write('\x1b[2J'); break; case 'saved': - this.echo('\x1b[3J'); + this.write('\x1b[3J'); break; case 'below': default: - this.echo('\x1b[J'); + this.write('\x1b[J'); break; } }; @@ -312,14 +476,14 @@ Program.prototype.clear = function() { Program.prototype.eraseInLine = function(param) { switch (param) { case 'left': - this.echo('\x1b[1K'); + this.write('\x1b[1K'); break; case 'all': - this.echo('\x1b[2K'); + this.write('\x1b[2K'); break; case 'right': default: - this.echo('\x1b[K'); + this.write('\x1b[K'); break; } }; @@ -390,172 +554,172 @@ Program.prototype.attr = Program.prototype.charAttributes = function(param, val) { switch (param) { case 'normal': - this.echo('\x1b[m'); + this.write('\x1b[m'); break; case 'bold': if (val === false) { - this.echo('\x1b[22m'); + this.write('\x1b[22m'); } else { - this.echo('\x1b[1m'); + this.write('\x1b[1m'); } break; case 'underlined': if (val === false) { - this.echo('\x1b[24m'); + this.write('\x1b[24m'); } else { - this.echo('\x1b[4m'); + this.write('\x1b[4m'); } break; case 'blink': if (val === false) { - this.echo('\x1b[25m'); + this.write('\x1b[25m'); } else { - this.echo('\x1b[5m'); + this.write('\x1b[5m'); } break; case 'inverse': if (val === false) { - this.echo('\x1b[27m'); + this.write('\x1b[27m'); } else { - this.echo('\x1b[7m'); + this.write('\x1b[7m'); } break; case 'invisible': if (val === false) { - this.echo('\x1b[28m'); + this.write('\x1b[28m'); } else { - this.echo('\x1b[8m'); + this.write('\x1b[8m'); } break; case 'invisible': if (val === false) { - this.echo('\x1b[28m'); + this.write('\x1b[28m'); } else { - this.echo('\x1b[8m'); + this.write('\x1b[8m'); } break; case 'black fg': if (val === false) { - this.echo('\x1b[39m'); + this.write('\x1b[39m'); break; } - this.echo('\x1b[30m'); + this.write('\x1b[30m'); break; case 'red fg': if (val === false) { - this.echo('\x1b[39m'); + this.write('\x1b[39m'); break; } - this.echo('\x1b[31m'); + this.write('\x1b[31m'); break; case 'green fg': if (val === false) { - this.echo('\x1b[39m'); + this.write('\x1b[39m'); break; } - this.echo('\x1b[32m'); + this.write('\x1b[32m'); break; case 'yellow fg': if (val === false) { - this.echo('\x1b[39m'); + this.write('\x1b[39m'); break; } - this.echo('\x1b[33m'); + this.write('\x1b[33m'); break; case 'blue fg': if (val === false) { - this.echo('\x1b[39m'); + this.write('\x1b[39m'); break; } - this.echo('\x1b[34m'); + this.write('\x1b[34m'); break; case 'magenta fg': if (val === false) { - this.echo('\x1b[39m'); + this.write('\x1b[39m'); break; } - this.echo('\x1b[35m'); + this.write('\x1b[35m'); break; case 'cyan fg': if (val === false) { - this.echo('\x1b[39m'); + this.write('\x1b[39m'); break; } - this.echo('\x1b[36m'); + this.write('\x1b[36m'); break; case 'white fg': if (val === false) { - this.echo('\x1b[39m'); + this.write('\x1b[39m'); break; } - this.echo('\x1b[37m'); + this.write('\x1b[37m'); break; case 'default fg': - this.echo('\x1b[39m'); + this.write('\x1b[39m'); break; case 'black bg': if (val === false) { - this.echo('\x1b[49m'); + this.write('\x1b[49m'); break; } - this.echo('\x1b[40m'); + this.write('\x1b[40m'); break; case 'red bg': if (val === false) { - this.echo('\x1b[49m'); + this.write('\x1b[49m'); break; } - this.echo('\x1b[41m'); + this.write('\x1b[41m'); break; case 'green bg': if (val === false) { - this.echo('\x1b[49m'); + this.write('\x1b[49m'); break; } - this.echo('\x1b[42m'); + this.write('\x1b[42m'); break; case 'yellow bg': if (val === false) { - this.echo('\x1b[49m'); + this.write('\x1b[49m'); break; } - this.echo('\x1b[43m'); + this.write('\x1b[43m'); break; case 'blue bg': if (val === false) { - this.echo('\x1b[49m'); + this.write('\x1b[49m'); break; } - this.echo('\x1b[44m'); + this.write('\x1b[44m'); break; case 'magenta bg': if (val === false) { - this.echo('\x1b[49m'); + this.write('\x1b[49m'); break; } - this.echo('\x1b[45m'); + this.write('\x1b[45m'); break; case 'cyan bg': if (val === false) { - this.echo('\x1b[49m'); + this.write('\x1b[49m'); break; } - this.echo('\x1b[46m'); + this.write('\x1b[46m'); break; case 'white bg': if (val === false) { - this.echo('\x1b[49m'); + this.write('\x1b[49m'); break; } - this.echo('\x1b[47m'); + this.write('\x1b[47m'); break; case 'default bg': - this.echo('\x1b[49m'); + this.write('\x1b[49m'); break; default: - this.echo('\x1b[' + param + 'm'); + this.write('\x1b[' + param + 'm'); break; } }; @@ -591,21 +755,33 @@ Program.prototype.setBackground = function(color, val) { // Ps = 5 3 -> Report Locator status as // CSI ? 5 3 n Locator available, if compiled-in, or // CSI ? 5 0 n No Locator, if not. -Program.prototype.deviceStatus = function(params) { +Program.prototype.deviceStatus = function(param, callback, dec) { + if (dec) { + return this.receive('\x1b[?' + (param || '0') + 'n', callback); + } + return this.receive('\x1b[' + (param || '0') + 'n', callback); +}; + +Program.prototype.getCursor = function(callback) { + return this.deviceStatus('6', function(err, data) { + if (err) return callback(err); + data = data.slice(2, -1).split(';'); + return callback(null, { + x: +data[1], + y: +data[0] + }); + }); }; /** * Additions */ -Program.prototype.isArray = function(obj) { - return Object.prototype.toString.call(obj) === '[object Array]'; -}; - // CSI Ps @ // Insert Ps (Blank) Character(s) (default = 1) (ICH). Program.prototype.insertChars = function(param) { - this.echo('\x1b[' + (param || '') + '@'); + this.x += param || 1; + return this.write('\x1b[' + (param || 1) + '@'); }; // CSI Ps E @@ -613,7 +789,7 @@ Program.prototype.insertChars = function(param) { // same as CSI Ps B ? Program.prototype.cursorNextLine = function(param) { this.y += param || 1; - this.echo('\x1b[' + (param || '') + 'E'); + return this.write('\x1b[' + (param || '') + 'E'); }; // CSI Ps F @@ -621,7 +797,7 @@ Program.prototype.cursorNextLine = function(param) { // reuse CSI Ps A ? Program.prototype.cursorPrecedingLine = function(param) { this.y -= param || 1; - this.echo('\x1b[' + (param || '') + 'F'); + return this.write('\x1b[' + (param || '') + 'F'); }; // CSI Ps G @@ -629,45 +805,47 @@ Program.prototype.cursorPrecedingLine = function(param) { Program.prototype.cursorCharAbsolute = function(param) { this.x = param || 1; this.y = 1; - this.echo('\x1b[' + (param || '') + 'G'); + return this.write('\x1b[' + (param || '') + 'G'); }; // CSI Ps L // Insert Ps Line(s) (default = 1) (IL). Program.prototype.insertLines = function(param) { - this.echo('\x1b[' + (param || '') + 'L'); + return this.write('\x1b[' + (param || '') + 'L'); }; // CSI Ps M // Delete Ps Line(s) (default = 1) (DL). Program.prototype.deleteLines = function(param) { - this.echo('\x1b[' + (param || '') + 'M'); + return this.write('\x1b[' + (param || '') + 'M'); }; // CSI Ps P // Delete Ps Character(s) (default = 1) (DCH). Program.prototype.deleteChars = function(param) { - this.echo('\x1b[' + (param || '') + 'P'); + return this.write('\x1b[' + (param || '') + 'P'); }; // CSI Ps X // Erase Ps Character(s) (default = 1) (ECH). Program.prototype.eraseChars = function(param) { - this.echo('\x1b[' + (param || '') + 'X'); + return this.write('\x1b[' + (param || '') + 'X'); }; // CSI Pm ` Character Position Absolute // [column] (default = [row,1]) (HPA). Program.prototype.charPosAbsolute = function() { + this.x = arguments[0] || 1; var param = Array.prototype.slice.call(arguments).join(';'); - this.echo('\x1b[' + (param || '') + '`'); + return this.write('\x1b[' + (param || '') + '`'); }; // 141 61 a * HPR - // Horizontal Position Relative // reuse CSI Ps C ? Program.prototype.HPositionRelative = function(param) { - this.echo('\x1b[' + (param || '') + 'a'); + this.x += param || 1; + return this.write('\x1b[' + (param || '') + 'a'); }; // CSI Ps c Send Device Attributes (Primary DA). @@ -718,21 +896,25 @@ Program.prototype.sendDeviceAttributes = function(param, callback) { // CSI Pm d // Line Position Absolute [row] (default = [1,column]) (VPA). Program.prototype.linePosAbsolute = function() { + this.y = arguments[0] || 1; var param = Array.prototype.slice.call(arguments).join(';'); - this.echo('\x1b[' + (param || '') + 'd'); + return this.write('\x1b[' + (param || '') + 'd'); }; // 145 65 e * VPR - Vertical Position Relative // reuse CSI Ps B ? Program.prototype.VPositionRelative = function(param) { - this.echo('\x1b[' + (param || '') + 'e'); + this.y += param || 1; + return this.write('\x1b[' + (param || '') + 'e'); }; // CSI Ps ; Ps f // Horizontal and Vertical Position [row;column] (default = // [1,1]) (HVP). Program.prototype.HVPosition = function(row, col) { - this.echo('\x1b[' + (row || '1') + ';' + (col || '1') + 'f'); + this.y += row || 1; + this.x += col || 1; + return this.write('\x1b[' + (row || '1') + ';' + (col || '1') + 'f'); }; // CSI Pm h Set Mode (SM). @@ -822,9 +1004,9 @@ Program.prototype.HVPosition = function(row, col) { Program.prototype.setMode = function() { var param = Array.prototype.slice.call(arguments).join(';'); //if (private) { - // return this.echo('\x1b[?' + (param || '') + 'h'); + // return this.write('\x1b[?' + (param || '') + 'h'); //} - this.echo('\x1b[' + (param || '') + 'h'); + return this.write('\x1b[' + (param || '') + 'h'); }; Program.prototype.showCursor = function() { @@ -920,9 +1102,9 @@ Program.prototype.alternateBuffer = function() { Program.prototype.resetMode = function() { var param = Array.prototype.slice.call(arguments).join(';'); //if (private) { - // return this.echo('\x1b[?' + (param || '') + 'l'); + // return this.write('\x1b[?' + (param || '') + 'l'); //} - this.echo('\x1b[' + (param || '') + 'l'); + return this.write('\x1b[' + (param || '') + 'l'); }; Program.prototype.hideCursor = function() { @@ -940,27 +1122,534 @@ Program.prototype.normalBuffer = function() { // dow) (DECSTBM). // CSI ? Pm r Program.prototype.setScrollRegion = function(top, bottom) { - this.echo('\x1b[' + (top || 1) + ';' + (bottom || this.rows) + 'r'); this.scrollTop = (top || 1) - 1; this.scrollBottom = (bottom || this.rows) - 1; - this.x = 0; - this.y = 0; + this.x = 1; + this.y = 1; + return this.write('\x1b[' + (top || 1) + ';' + (bottom || this.rows) + 'r'); }; // CSI s // Save cursor (ANSI.SYS). Program.prototype.saveCursor = function() { - this.echo('\x1b[s'); this.savedX = this.x; this.savedY = this.y; + return this.write('\x1b[s'); }; // CSI u // Restore cursor (ANSI.SYS). Program.prototype.restoreCursor = function() { - this.echo('\x1b[u'); - this.x = this.savedX || 0; - this.y = this.savedY || 0; + this.x = this.savedX || 1; + this.y = this.savedY || 1; + return this.write('\x1b[u'); +}; + +/** + * Lesser Used + */ + +// CSI Ps I +// Cursor Forward Tabulation Ps tab stops (default = 1) (CHT). +Program.prototype.cursorForwardTab = function(param) { + this.x += 8; + return this.write('\x1b[' + (param || 1) + 'I'); +}; + +// CSI Ps S Scroll up Ps lines (default = 1) (SU). +Program.prototype.scrollUp = function(param) { + this.y -= param || 1; + return this.write('\x1b[' + (param || 1) + 'I'); +}; + +// CSI Ps T Scroll down Ps lines (default = 1) (SD). +Program.prototype.scrollDown = function(param) { + this.y += param || 1; + return this.write('\x1b[' + (param || 1) + 'T'); +}; + +// CSI Ps ; Ps ; Ps ; Ps ; Ps T +// Initiate highlight mouse tracking. Parameters are +// [func;startx;starty;firstrow;lastrow]. See the section Mouse +// Tracking. +Program.prototype.initMouseTracking = function() { + return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + 'T'); +}; + +// CSI > Ps; Ps T +// Reset one or more features of the title modes to the default +// value. Normally, "reset" disables the feature. It is possi- +// ble to disable the ability to reset features by compiling a +// different default for the title modes into xterm. +// Ps = 0 -> Do not set window/icon labels using hexadecimal. +// Ps = 1 -> Do not query window/icon labels using hexadeci- +// mal. +// Ps = 2 -> Do not set window/icon labels using UTF-8. +// Ps = 3 -> Do not query window/icon labels using UTF-8. +// (See discussion of "Title Modes"). +Program.prototype.resetTitleModes = function() { + return this.write('\x1b[>' + Array.prototype.slice.call(arguments).join(';') + 'T'); +}; + +// CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT). +Program.prototype.cursorBackwardTab = function(param) { + this.x -= 8; + return this.write('\x1b[' + (param || 1) + 'Z'); +}; + +// CSI Ps b Repeat the preceding graphic character Ps times (REP). +Program.prototype.repeatPrecedingCharacter = function(param) { + //this.x += param || 1; + return this.write('\x1b[' + (param || 1) + 'b'); +}; + +// CSI Ps g Tab Clear (TBC). +// Ps = 0 -> Clear Current Column (default). +// Ps = 3 -> Clear All. +// Potentially: +// Ps = 2 -> Clear Stops on Line. +// http://vt100.net/annarbor/aaa-ug/section6.html +Program.prototype.tabClear = function(param) { + return this.write('\x1b[' + (param || 0) + 'g'); +}; + +// CSI Pm i Media Copy (MC). +// Ps = 0 -> Print screen (default). +// Ps = 4 -> Turn off printer controller mode. +// Ps = 5 -> Turn on printer controller mode. +// CSI ? Pm i +// Media Copy (MC, DEC-specific). +// Ps = 1 -> Print line containing cursor. +// Ps = 4 -> Turn off autoprint mode. +// Ps = 5 -> Turn on autoprint mode. +// Ps = 1 0 -> Print composed display, ignores DECPEX. +// Ps = 1 1 -> Print all pages. +Program.prototype.mediaCopy = function() { + //if (dec) { + // this.write('\x1b[?' + Array.prototype.slice.call(arguments).join(';') + 'i'); + // return; + //} + return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + 'i'); +}; + +// CSI > Ps; Ps m +// Set or reset resource-values used by xterm to decide whether +// to construct escape sequences holding information about the +// modifiers pressed with a given key. The first parameter iden- +// tifies the resource to set/reset. The second parameter is the +// value to assign to the resource. If the second parameter is +// omitted, the resource is reset to its initial value. +// Ps = 1 -> modifyCursorKeys. +// Ps = 2 -> modifyFunctionKeys. +// Ps = 4 -> modifyOtherKeys. +// If no parameters are given, all resources are reset to their +// initial values. +Program.prototype.setResources = function() { + return this.write('\x1b[>' + Array.prototype.slice.call(arguments).join(';') + 'm'); +}; + +// CSI > Ps n +// Disable modifiers which may be enabled via the CSI > Ps; Ps m +// sequence. This corresponds to a resource value of "-1", which +// cannot be set with the other sequence. The parameter identi- +// fies the resource to be disabled: +// Ps = 1 -> modifyCursorKeys. +// Ps = 2 -> modifyFunctionKeys. +// Ps = 4 -> modifyOtherKeys. +// If the parameter is omitted, modifyFunctionKeys is disabled. +// When modifyFunctionKeys is disabled, xterm uses the modifier +// keys to make an extended sequence of functions rather than +// adding a parameter to each function key to denote the modi- +// fiers. +Program.prototype.disableModifiers = function(param) { + return this.write('\x1b[>' + (param || '') + 'n'); +}; + +// CSI > Ps p +// Set resource value pointerMode. This is used by xterm to +// decide whether to hide the pointer cursor as the user types. +// Valid values for the parameter: +// Ps = 0 -> never hide the pointer. +// Ps = 1 -> hide if the mouse tracking mode is not enabled. +// Ps = 2 -> always hide the pointer. If no parameter is +// given, xterm uses the default, which is 1 . +Program.prototype.setPointerMode = function(param) { + return this.write('\x1b[>' + (param || '') + 'p'); +}; + +// CSI ! p Soft terminal reset (DECSTR). +// http://vt100.net/docs/vt220-rm/table4-10.html +Program.prototype.softReset = function() { + return this.write('\x1b[!p'); +}; + +// CSI Ps$ p +// Request ANSI mode (DECRQM). For VT300 and up, reply is +// CSI Ps; Pm$ y +// where Ps is the mode number as in RM, and Pm is the mode +// value: +// 0 - not recognized +// 1 - set +// 2 - reset +// 3 - permanently set +// 4 - permanently reset +Program.prototype.requestAnsiMode = function(param) { + return this.write('\x1b[' + (param || '') + '$p'); +}; + +// CSI ? Ps$ p +// Request DEC private mode (DECRQM). For VT300 and up, reply is +// CSI ? Ps; Pm$ p +// where Ps is the mode number as in DECSET, Pm is the mode value +// as in the ANSI DECRQM. +Program.prototype.requestPrivateMode = function(param) { + return this.write('\x1b[?' + (param || '') + '$p'); +}; + +// CSI Ps ; Ps " p +// Set conformance level (DECSCL). Valid values for the first +// parameter: +// Ps = 6 1 -> VT100. +// Ps = 6 2 -> VT200. +// Ps = 6 3 -> VT300. +// Valid values for the second parameter: +// Ps = 0 -> 8-bit controls. +// Ps = 1 -> 7-bit controls (always set for VT100). +// Ps = 2 -> 8-bit controls. +Program.prototype.setConformanceLevel = function() { + return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '"p'); +}; + +// CSI Ps q Load LEDs (DECLL). +// Ps = 0 -> Clear all LEDS (default). +// Ps = 1 -> Light Num Lock. +// Ps = 2 -> Light Caps Lock. +// Ps = 3 -> Light Scroll Lock. +// Ps = 2 1 -> Extinguish Num Lock. +// Ps = 2 2 -> Extinguish Caps Lock. +// Ps = 2 3 -> Extinguish Scroll Lock. +Program.prototype.loadLEDs = function(param) { + return this.write('\x1b[' + (param || '') + 'q'); +}; + +// CSI Ps SP q +// Set cursor style (DECSCUSR, VT520). +// Ps = 0 -> blinking block. +// Ps = 1 -> blinking block (default). +// Ps = 2 -> steady block. +// Ps = 3 -> blinking underline. +// Ps = 4 -> steady underline. +Program.prototype.setCursorStyle = function(param) { + switch (param) { + case 'blinking block': + param = '0'; + param = '1'; + break; + case 'block': + case 'steady block': + param = '2'; + break; + case 'blinking underline': + param = '3'; + break; + case 'underline': + case 'steady underline': + param = '4'; + break; + case 'blinking bar': + param = '5'; + break; + case 'bar': + case 'steady bar': + param = '6'; + break; + } + return this.write('\x1b[' + (param || 1) + ' q'); +}; + +// CSI Ps " q +// Select character protection attribute (DECSCA). Valid values +// for the parameter: +// Ps = 0 -> DECSED and DECSEL can erase (default). +// Ps = 1 -> DECSED and DECSEL cannot erase. +// Ps = 2 -> DECSED and DECSEL can erase. +Program.prototype.setCharProtectionAttr = function(param) { + return this.write('\x1b[' + (param || 0) + '"q'); +}; + +// CSI ? Pm r +// Restore DEC Private Mode Values. The value of Ps previously +// saved is restored. Ps values are the same as for DECSET. +Program.prototype.restorePrivateValues = function() { + return this.write('\x1b[?' + Array.prototype.slice.call(arguments).join(';') + 'r'); +}; + +// CSI Pt; Pl; Pb; Pr; Ps$ r +// Change Attributes in Rectangular Area (DECCARA), VT400 and up. +// Pt; Pl; Pb; Pr denotes the rectangle. +// Ps denotes the SGR attributes to change: 0, 1, 4, 5, 7. +// NOTE: xterm doesn't enable this code by default. +Program.prototype.setAttrInRectangle = function() { + return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '$r'); +}; + +// CSI ? Pm s +// Save DEC Private Mode Values. Ps values are the same as for +// DECSET. +Program.prototype.savePrivateValues = function(params) { + return this.write('\x1b[?' + Array.prototype.slice.call(arguments).join(';') + 's'); +}; + +// CSI Ps ; Ps ; Ps t +// Window manipulation (from dtterm, as well as extensions). +// These controls may be disabled using the allowWindowOps +// resource. Valid values for the first (and any additional +// parameters) are: +// Ps = 1 -> De-iconify window. +// Ps = 2 -> Iconify window. +// Ps = 3 ; x ; y -> Move window to [x, y]. +// Ps = 4 ; height ; width -> Resize the xterm window to +// height and width in pixels. +// Ps = 5 -> Raise the xterm window to the front of the stack- +// ing order. +// Ps = 6 -> Lower the xterm window to the bottom of the +// stacking order. +// Ps = 7 -> Refresh the xterm window. +// Ps = 8 ; height ; width -> Resize the text area to +// [height;width] in characters. +// Ps = 9 ; 0 -> Restore maximized window. +// Ps = 9 ; 1 -> Maximize window (i.e., resize to screen +// size). +// Ps = 1 0 ; 0 -> Undo full-screen mode. +// Ps = 1 0 ; 1 -> Change to full-screen. +// Ps = 1 1 -> Report xterm window state. If the xterm window +// is open (non-iconified), it returns CSI 1 t . If the xterm +// window is iconified, it returns CSI 2 t . +// Ps = 1 3 -> Report xterm window position. Result is CSI 3 +// ; x ; y t +// Ps = 1 4 -> Report xterm window in pixels. Result is CSI +// 4 ; height ; width t +// Ps = 1 8 -> Report the size of the text area in characters. +// Result is CSI 8 ; height ; width t +// Ps = 1 9 -> Report the size of the screen in characters. +// Result is CSI 9 ; height ; width t +// Ps = 2 0 -> Report xterm window's icon label. Result is +// OSC L label ST +// Ps = 2 1 -> Report xterm window's title. Result is OSC l +// label ST +// Ps = 2 2 ; 0 -> Save xterm icon and window title on +// stack. +// Ps = 2 2 ; 1 -> Save xterm icon title on stack. +// Ps = 2 2 ; 2 -> Save xterm window title on stack. +// Ps = 2 3 ; 0 -> Restore xterm icon and window title from +// stack. +// Ps = 2 3 ; 1 -> Restore xterm icon title from stack. +// Ps = 2 3 ; 2 -> Restore xterm window title from stack. +// Ps >= 2 4 -> Resize to Ps lines (DECSLPP). +Program.prototype.manipulateWindow = function(params) { + return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + 't'); +}; + +// CSI Pt; Pl; Pb; Pr; Ps$ t +// Reverse Attributes in Rectangular Area (DECRARA), VT400 and +// up. +// Pt; Pl; Pb; Pr denotes the rectangle. +// Ps denotes the attributes to reverse, i.e., 1, 4, 5, 7. +// NOTE: xterm doesn't enable this code by default. +Program.prototype.reverseAttrInRectangle = function(params) { + return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '$t'); +}; + +// CSI > Ps; Ps t +// Set one or more features of the title modes. Each parameter +// enables a single feature. +// Ps = 0 -> Set window/icon labels using hexadecimal. +// Ps = 1 -> Query window/icon labels using hexadecimal. +// Ps = 2 -> Set window/icon labels using UTF-8. +// Ps = 3 -> Query window/icon labels using UTF-8. (See dis- +// cussion of "Title Modes") +Program.prototype.setTitleModeFeature = function(params) { + return this.write('\x1b[>' + Array.prototype.slice.call(arguments).join(';') + 't'); +}; + +// CSI Ps SP t +// Set warning-bell volume (DECSWBV, VT520). +// Ps = 0 or 1 -> off. +// Ps = 2 , 3 or 4 -> low. +// Ps = 5 , 6 , 7 , or 8 -> high. +Program.prototype.setWarningBellVolume = function(params) { + return this.write('\x1b[' + (param || '') + ' t'); +}; + +// CSI Ps SP u +// Set margin-bell volume (DECSMBV, VT520). +// Ps = 1 -> off. +// Ps = 2 , 3 or 4 -> low. +// Ps = 0 , 5 , 6 , 7 , or 8 -> high. +Program.prototype.setMarginBellVolume = function(params) { + return this.write('\x1b[' + (param || '') + ' u'); +}; + +// CSI Pt; Pl; Pb; Pr; Pp; Pt; Pl; Pp$ v +// Copy Rectangular Area (DECCRA, VT400 and up). +// Pt; Pl; Pb; Pr denotes the rectangle. +// Pp denotes the source page. +// Pt; Pl denotes the target location. +// Pp denotes the target page. +// NOTE: xterm doesn't enable this code by default. +Program.prototype.copyRectangle = function(params) { + return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '$v'); +}; + +// CSI Pt ; Pl ; Pb ; Pr ' w +// Enable Filter Rectangle (DECEFR), VT420 and up. +// Parameters are [top;left;bottom;right]. +// Defines the coordinates of a filter rectangle and activates +// it. Anytime the locator is detected outside of the filter +// rectangle, an outside rectangle event is generated and the +// rectangle is disabled. Filter rectangles are always treated +// as "one-shot" events. Any parameters that are omitted default +// to the current locator position. If all parameters are omit- +// ted, any locator motion will be reported. DECELR always can- +// cels any prevous rectangle definition. +Program.prototype.enableFilterRectangle = function(params) { + return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '\'w'); +}; + +// CSI Ps x Request Terminal Parameters (DECREQTPARM). +// if Ps is a "0" (default) or "1", and xterm is emulating VT100, +// the control sequence elicits a response of the same form whose +// parameters describe the terminal: +// Ps -> the given Ps incremented by 2. +// Pn = 1 <- no parity. +// Pn = 1 <- eight bits. +// Pn = 1 <- 2 8 transmit 38.4k baud. +// Pn = 1 <- 2 8 receive 38.4k baud. +// Pn = 1 <- clock multiplier. +// Pn = 0 <- STP flags. +Program.prototype.requestParameters = function(params) { + return this.write('\x1b[' + (param || 0) + 'x'); +}; + +// CSI Ps x Select Attribute Change Extent (DECSACE). +// Ps = 0 -> from start to end position, wrapped. +// Ps = 1 -> from start to end position, wrapped. +// Ps = 2 -> rectangle (exact). +Program.prototype.selectChangeExtent = function(params) { + return this.write('\x1b[' + (param || 0) + 'x'); +}; + +// CSI Pc; Pt; Pl; Pb; Pr$ x +// Fill Rectangular Area (DECFRA), VT420 and up. +// Pc is the character to use. +// Pt; Pl; Pb; Pr denotes the rectangle. +// NOTE: xterm doesn't enable this code by default. +Program.prototype.fillRectangle = function(params) { + return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '$x'); +}; + +// CSI Ps ; Pu ' z +// Enable Locator Reporting (DECELR). +// Valid values for the first parameter: +// Ps = 0 -> Locator disabled (default). +// Ps = 1 -> Locator enabled. +// Ps = 2 -> Locator enabled for one report, then disabled. +// The second parameter specifies the coordinate unit for locator +// reports. +// Valid values for the second parameter: +// Pu = 0 <- or omitted -> default to character cells. +// Pu = 1 <- device physical pixels. +// Pu = 2 <- character cells. +Program.prototype.enableLocatorReporting = function(params) { + return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '\'z'); +}; + +// CSI Pt; Pl; Pb; Pr$ z +// Erase Rectangular Area (DECERA), VT400 and up. +// Pt; Pl; Pb; Pr denotes the rectangle. +// NOTE: xterm doesn't enable this code by default. +Program.prototype.eraseRectangle = function(params) { + return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '$z'); +}; + +// CSI Pm ' { +// Select Locator Events (DECSLE). +// Valid values for the first (and any additional parameters) +// are: +// Ps = 0 -> only respond to explicit host requests (DECRQLP). +// (This is default). It also cancels any filter +// rectangle. +// Ps = 1 -> report button down transitions. +// Ps = 2 -> do not report button down transitions. +// Ps = 3 -> report button up transitions. +// Ps = 4 -> do not report button up transitions. +Program.prototype.setLocatorEvents = function(params) { + return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '\'{'); +}; + +// CSI Pt; Pl; Pb; Pr$ { +// Selective Erase Rectangular Area (DECSERA), VT400 and up. +// Pt; Pl; Pb; Pr denotes the rectangle. +Program.prototype.selectiveEraseRectangle = function(params) { + return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '${'); +}; + +// CSI Ps ' | +// Request Locator Position (DECRQLP). +// Valid values for the parameter are: +// Ps = 0 , 1 or omitted -> transmit a single DECLRP locator +// report. + +// If Locator Reporting has been enabled by a DECELR, xterm will +// respond with a DECLRP Locator Report. This report is also +// generated on button up and down events if they have been +// enabled with a DECSLE, or when the locator is detected outside +// of a filter rectangle, if filter rectangles have been enabled +// with a DECEFR. + +// -> CSI Pe ; Pb ; Pr ; Pc ; Pp & w + +// Parameters are [event;button;row;column;page]. +// Valid values for the event: +// Pe = 0 -> locator unavailable - no other parameters sent. +// Pe = 1 -> request - xterm received a DECRQLP. +// Pe = 2 -> left button down. +// Pe = 3 -> left button up. +// Pe = 4 -> middle button down. +// Pe = 5 -> middle button up. +// Pe = 6 -> right button down. +// Pe = 7 -> right button up. +// Pe = 8 -> M4 button down. +// Pe = 9 -> M4 button up. +// Pe = 1 0 -> locator outside filter rectangle. +// ``button'' parameter is a bitmask indicating which buttons are +// pressed: +// Pb = 0 <- no buttons down. +// Pb & 1 <- right button down. +// Pb & 2 <- middle button down. +// Pb & 4 <- left button down. +// Pb & 8 <- M4 button down. +// ``row'' and ``column'' parameters are the coordinates of the +// locator position in the xterm window, encoded as ASCII deci- +// mal. +// The ``page'' parameter is not used by xterm, and will be omit- +// ted. +Program.prototype.requestLocatorPosition = function(params) { + return this.write('\x1b[' + (param || '') + '\'|'); +}; + +// CSI P m SP } +// Insert P s Column(s) (default = 1) (DECIC), VT420 and up. +// NOTE: xterm doesn't enable this code by default. +Program.prototype.insertColumns = function() { + return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + ' }'); +}; + +// CSI P m SP ~ +// Delete P s Column(s) (default = 1) (DECDC), VT420 and up +// NOTE: xterm doesn't enable this code by default. +Program.prototype.deleteColumns = function() { + return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + ' ~'); }; /**