better movement and method names.

This commit is contained in:
Christopher Jeffrey 2013-01-27 10:01:30 -06:00
parent 6d212aa42f
commit 069bd16e46
1 changed files with 90 additions and 28 deletions

View File

@ -105,49 +105,40 @@ Program.prototype.echo = function(text, attr) {
return this.output.write(text);
};
Program.prototype.setX = function(x) {
return this.cursorPos(this.y, x);
Program.prototype.setx = function(x) {
// return this.cursorCharAbsolute(x);
return this.charPosAbsolute(x);
};
Program.prototype.setY = function(y) {
return this.cursorPos(y, this.x);
Program.prototype.sety = function(y) {
return this.linePosAbsolute(y);
};
Program.prototype.move = function(x, y) {
return this.cursorPos(y, x);
};
// NOTE: There are better ways to do rel movements.
Program.prototype.rsetX = function(x) {
return this.cursorPos(this.y, this.x + x);
Program.prototype.rsetx = function(x) {
// return this.HPositionRelative(x);
if (!x) return;
return x > 0
? this.forward(x)
: this.back(x);
};
Program.prototype.rsetY = function(y) {
return this.cursorPos(this.y + y, this.x);
Program.prototype.rsety = function(y) {
// return this.VPositionRelative(y);
if (!y) return;
return y > 0
? this.up(y)
: this.down(y);
};
Program.prototype.rmove = function(x, y) {
return this.cursorPos(this.y + y, this.x + x);
this.rsetX(x);
this.rsetY(y);
};
/*
Program.prototype.__defineGetter('x', function() {
return this._x || 1;
});
Program.prototype.__defineSetter__('x', function(x) {
this.cursorPos(x, this.y);
return this._x = x;
});
Program.prototype.__defineGetter('y', function() {
return this._y || 1;
});
Program.prototype.__defineSetter__('y', function(y) {
this.cursorPos(this.x, y);
return this._y = y;
});
*/
/**
* Normal
*/
@ -389,6 +380,7 @@ Program.prototype.csi = function(code) {
// CSI Ps A
// Cursor Up Ps Times (default = 1) (CUU).
Program.prototype.cuu =
Program.prototype.up =
Program.prototype.cursorUp = function(param) {
this.y -= param || 1;
@ -397,6 +389,7 @@ Program.prototype.cursorUp = function(param) {
// CSI Ps B
// Cursor Down Ps Times (default = 1) (CUD).
Program.prototype.cud =
Program.prototype.down =
Program.prototype.cursorDown = function(param) {
this.y += param || 1;
@ -405,6 +398,8 @@ Program.prototype.cursorDown = function(param) {
// CSI Ps C
// Cursor Forward Ps Times (default = 1) (CUF).
Program.prototype.cuf =
Program.prototype.right =
Program.prototype.forward =
Program.prototype.cursorForward = function(param) {
this.x += param || 1;
@ -413,6 +408,8 @@ Program.prototype.cursorForward = function(param) {
// CSI Ps D
// Cursor Backward Ps Times (default = 1) (CUB).
Program.prototype.cub =
Program.prototype.left =
Program.prototype.back =
Program.prototype.cursorBackward = function(param) {
this.x -= param || 1;
@ -421,6 +418,7 @@ Program.prototype.cursorBackward = function(param) {
// CSI Ps ; Ps H
// Cursor Position [row;column] (default = [1,1]) (CUP).
Program.prototype.cup =
Program.prototype.pos =
Program.prototype.cursorPos = function(row, col) {
this.x = col || 1;
@ -438,6 +436,7 @@ Program.prototype.cursorPos = function(row, col) {
// Ps = 0 -> Selective Erase Below (default).
// Ps = 1 -> Selective Erase Above.
// Ps = 2 -> Selective Erase All.
Program.prototype.ed =
Program.prototype.eraseInDisplay = function(param) {
switch (param) {
case 'above':
@ -469,6 +468,7 @@ Program.prototype.clear = function() {
// Ps = 0 -> Selective Erase to Right (default).
// Ps = 1 -> Selective Erase to Left.
// Ps = 2 -> Selective Erase All.
Program.prototype.el =
Program.prototype.eraseInLine = function(param) {
switch (param) {
case 'left':
@ -546,6 +546,7 @@ Program.prototype.eraseInLine = function(param) {
// Ps.
// Ps = 4 8 ; 5 ; Ps -> Set background color to the second
// Ps.
Program.prototype.sgr =
Program.prototype.attr =
Program.prototype.charAttributes = function(param, val) {
switch (param) {
@ -683,6 +684,7 @@ 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.dsr =
Program.prototype.deviceStatus = function(param, callback, dec) {
if (dec) {
return this.receive('\x1b[?' + (param || '0') + 'n', callback);
@ -707,6 +709,7 @@ Program.prototype.getCursor = function(callback) {
// CSI Ps @
// Insert Ps (Blank) Character(s) (default = 1) (ICH).
Program.prototype.ich =
Program.prototype.insertChars = function(param) {
this.x += param || 1;
return this.write('\x1b[' + (param || 1) + '@');
@ -715,6 +718,7 @@ Program.prototype.insertChars = function(param) {
// CSI Ps E
// Cursor Next Line Ps Times (default = 1) (CNL).
// same as CSI Ps B ?
Program.prototype.cnl =
Program.prototype.cursorNextLine = function(param) {
this.y += param || 1;
return this.write('\x1b[' + (param || '') + 'E');
@ -723,6 +727,7 @@ Program.prototype.cursorNextLine = function(param) {
// CSI Ps F
// Cursor Preceding Line Ps Times (default = 1) (CNL).
// reuse CSI Ps A ?
Program.prototype.cpl =
Program.prototype.cursorPrecedingLine = function(param) {
this.y -= param || 1;
return this.write('\x1b[' + (param || '') + 'F');
@ -730,6 +735,7 @@ Program.prototype.cursorPrecedingLine = function(param) {
// CSI Ps G
// Cursor Character Absolute [column] (default = [row,1]) (CHA).
Program.prototype.cha =
Program.prototype.cursorCharAbsolute = function(param) {
this.x = param || 1;
this.y = 1;
@ -738,30 +744,35 @@ Program.prototype.cursorCharAbsolute = function(param) {
// CSI Ps L
// Insert Ps Line(s) (default = 1) (IL).
Program.prototype.il =
Program.prototype.insertLines = function(param) {
return this.write('\x1b[' + (param || '') + 'L');
};
// CSI Ps M
// Delete Ps Line(s) (default = 1) (DL).
Program.prototype.dl =
Program.prototype.deleteLines = function(param) {
return this.write('\x1b[' + (param || '') + 'M');
};
// CSI Ps P
// Delete Ps Character(s) (default = 1) (DCH).
Program.prototype.dch =
Program.prototype.deleteChars = function(param) {
return this.write('\x1b[' + (param || '') + 'P');
};
// CSI Ps X
// Erase Ps Character(s) (default = 1) (ECH).
Program.prototype.ech =
Program.prototype.eraseChars = function(param) {
return this.write('\x1b[' + (param || '') + 'X');
};
// CSI Pm ` Character Position Absolute
// [column] (default = [row,1]) (HPA).
Program.prototype.hpa =
Program.prototype.charPosAbsolute = function() {
this.x = arguments[0] || 1;
var param = Array.prototype.slice.call(arguments).join(';');
@ -771,6 +782,7 @@ Program.prototype.charPosAbsolute = function() {
// 141 61 a * HPR -
// Horizontal Position Relative
// reuse CSI Ps C ?
Program.prototype.hpr =
Program.prototype.HPositionRelative = function(param) {
this.x += param || 1;
return this.write('\x1b[' + (param || '') + 'a');
@ -811,6 +823,7 @@ Program.prototype.HPositionRelative = function(param) {
// More information:
// xterm/charproc.c - line 2012, for more information.
// vim responds with ^[[?0c or ^[[?1c after the terminal's response (?)
Program.prototype.da =
Program.prototype.sendDeviceAttributes = function(param, callback) {
return this.receive('\x1b[' + (param || '') + 'c', function(err, response) {
if (err) return callback(err);
@ -823,6 +836,7 @@ Program.prototype.sendDeviceAttributes = function(param, callback) {
// CSI Pm d
// Line Position Absolute [row] (default = [1,column]) (VPA).
Program.prototype.vpa =
Program.prototype.linePosAbsolute = function() {
this.y = arguments[0] || 1;
var param = Array.prototype.slice.call(arguments).join(';');
@ -831,6 +845,7 @@ Program.prototype.linePosAbsolute = function() {
// 145 65 e * VPR - Vertical Position Relative
// reuse CSI Ps B ?
Program.prototype.vpr =
Program.prototype.VPositionRelative = function(param) {
this.y += param || 1;
return this.write('\x1b[' + (param || '') + 'e');
@ -839,6 +854,7 @@ Program.prototype.VPositionRelative = function(param) {
// CSI Ps ; Ps f
// Horizontal and Vertical Position [row;column] (default =
// [1,1]) (HVP).
Program.prototype.hvp =
Program.prototype.HVPosition = function(row, col) {
this.y += row || 1;
this.x += col || 1;
@ -929,6 +945,7 @@ Program.prototype.HVPosition = function(row, col) {
// Ps = 2 0 0 4 -> Set bracketed paste mode.
// Modes:
// http://vt100.net/docs/vt220-rm/chapter4.html
Program.prototype.sm =
Program.prototype.setMode = function() {
var param = Array.prototype.slice.call(arguments).join(';');
//if (private) {
@ -937,10 +954,17 @@ Program.prototype.setMode = function() {
return this.write('\x1b[' + (param || '') + 'h');
};
Program.prototype.decset = function() {
var param = Array.prototype.slice.call(arguments).join(';');
return this.setMode('?' + param);
};
Program.prototype.dectcem =
Program.prototype.showCursor = function() {
return this.setMode('?25');
};
Program.prototype.alternate =
Program.prototype.alternateBuffer = function() {
//return this.setMode('?47');
//return this.setMode('?1047');
@ -1027,6 +1051,7 @@ Program.prototype.alternateBuffer = function() {
// Ps = 1 0 6 0 -> Reset legacy keyboard emulation (X11R6).
// Ps = 1 0 6 1 -> Reset keyboard emulation to Sun/PC style.
// Ps = 2 0 0 4 -> Reset bracketed paste mode.
Program.prototype.rm =
Program.prototype.resetMode = function() {
var param = Array.prototype.slice.call(arguments).join(';');
//if (private) {
@ -1035,6 +1060,12 @@ Program.prototype.resetMode = function() {
return this.write('\x1b[' + (param || '') + 'l');
};
Program.prototype.decrst = function() {
var param = Array.prototype.slice.call(arguments).join(';');
return this.resetMode('?' + param);
};
Program.prototype.dectcemh =
Program.prototype.hideCursor = function() {
return this.resetMode('?25');
};
@ -1049,6 +1080,7 @@ Program.prototype.normalBuffer = function() {
// Set Scrolling Region [top;bottom] (default = full size of win-
// dow) (DECSTBM).
// CSI ? Pm r
Program.prototype.decstbm =
Program.prototype.setScrollRegion = function(top, bottom) {
this.scrollTop = (top || 1) - 1;
this.scrollBottom = (bottom || this.rows) - 1;
@ -1079,18 +1111,21 @@ Program.prototype.restoreCursor = function() {
// CSI Ps I
// Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
Program.prototype.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.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.sd =
Program.prototype.scrollDown = function(param) {
this.y += param || 1;
return this.write('\x1b[' + (param || 1) + 'T');
@ -1120,12 +1155,14 @@ Program.prototype.resetTitleModes = function() {
};
// CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
Program.prototype.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.rep =
Program.prototype.repeatPrecedingCharacter = function(param) {
//this.x += param || 1;
return this.write('\x1b[' + (param || 1) + 'b');
@ -1137,6 +1174,7 @@ Program.prototype.repeatPrecedingCharacter = function(param) {
// Potentially:
// Ps = 2 -> Clear Stops on Line.
// http://vt100.net/annarbor/aaa-ug/section6.html
Program.prototype.tbc =
Program.prototype.tabClear = function(param) {
return this.write('\x1b[' + (param || 0) + 'g');
};
@ -1152,6 +1190,7 @@ Program.prototype.tabClear = function(param) {
// Ps = 5 -> Turn on autoprint mode.
// Ps = 1 0 -> Print composed display, ignores DECPEX.
// Ps = 1 1 -> Print all pages.
Program.prototype.mc =
Program.prototype.mediaCopy = function() {
//if (dec) {
// this.write('\x1b[?' + Array.prototype.slice.call(arguments).join(';') + 'i');
@ -1207,6 +1246,7 @@ Program.prototype.setPointerMode = function(param) {
// CSI ! p Soft terminal reset (DECSTR).
// http://vt100.net/docs/vt220-rm/table4-10.html
Program.prototype.decstr =
Program.prototype.softReset = function() {
return this.write('\x1b[!p');
};
@ -1221,6 +1261,7 @@ Program.prototype.softReset = function() {
// 2 - reset
// 3 - permanently set
// 4 - permanently reset
Program.prototype.decrqm =
Program.prototype.requestAnsiMode = function(param) {
return this.write('\x1b[' + (param || '') + '$p');
};
@ -1230,6 +1271,7 @@ Program.prototype.requestAnsiMode = function(param) {
// 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.decrqmp =
Program.prototype.requestPrivateMode = function(param) {
return this.write('\x1b[?' + (param || '') + '$p');
};
@ -1244,6 +1286,7 @@ Program.prototype.requestPrivateMode = function(param) {
// Ps = 0 -> 8-bit controls.
// Ps = 1 -> 7-bit controls (always set for VT100).
// Ps = 2 -> 8-bit controls.
Program.prototype.decscl =
Program.prototype.setConformanceLevel = function() {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '"p');
};
@ -1256,6 +1299,7 @@ Program.prototype.setConformanceLevel = function() {
// Ps = 2 1 -> Extinguish Num Lock.
// Ps = 2 2 -> Extinguish Caps Lock.
// Ps = 2 3 -> Extinguish Scroll Lock.
Program.prototype.decll =
Program.prototype.loadLEDs = function(param) {
return this.write('\x1b[' + (param || '') + 'q');
};
@ -1267,6 +1311,7 @@ Program.prototype.loadLEDs = function(param) {
// Ps = 2 -> steady block.
// Ps = 3 -> blinking underline.
// Ps = 4 -> steady underline.
Program.prototype.decscusr =
Program.prototype.setCursorStyle = function(param) {
switch (param) {
case 'blinking block':
@ -1301,6 +1346,7 @@ Program.prototype.setCursorStyle = function(param) {
// Ps = 0 -> DECSED and DECSEL can erase (default).
// Ps = 1 -> DECSED and DECSEL cannot erase.
// Ps = 2 -> DECSED and DECSEL can erase.
Program.prototype.decsca =
Program.prototype.setCharProtectionAttr = function(param) {
return this.write('\x1b[' + (param || 0) + '"q');
};
@ -1317,6 +1363,7 @@ Program.prototype.restorePrivateValues = function() {
// 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.deccara =
Program.prototype.setAttrInRectangle = function() {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '$r');
};
@ -1401,6 +1448,7 @@ Program.prototype.getWindowSize = function(callback) {
// 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.decrara =
Program.prototype.reverseAttrInRectangle = function(params) {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '$t');
};
@ -1422,6 +1470,7 @@ Program.prototype.setTitleModeFeature = function(params) {
// Ps = 0 or 1 -> off.
// Ps = 2 , 3 or 4 -> low.
// Ps = 5 , 6 , 7 , or 8 -> high.
Program.prototype.decswbv =
Program.prototype.setWarningBellVolume = function(params) {
return this.write('\x1b[' + (param || '') + ' t');
};
@ -1431,6 +1480,7 @@ Program.prototype.setWarningBellVolume = function(params) {
// Ps = 1 -> off.
// Ps = 2 , 3 or 4 -> low.
// Ps = 0 , 5 , 6 , 7 , or 8 -> high.
Program.prototype.decsmbv =
Program.prototype.setMarginBellVolume = function(params) {
return this.write('\x1b[' + (param || '') + ' u');
};
@ -1442,6 +1492,7 @@ Program.prototype.setMarginBellVolume = function(params) {
// Pt; Pl denotes the target location.
// Pp denotes the target page.
// NOTE: xterm doesn't enable this code by default.
Program.prototype.deccra =
Program.prototype.copyRectangle = function(params) {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '$v');
};
@ -1457,6 +1508,7 @@ Program.prototype.copyRectangle = function(params) {
// 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.decefr =
Program.prototype.enableFilterRectangle = function(params) {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '\'w');
};
@ -1472,6 +1524,7 @@ Program.prototype.enableFilterRectangle = function(params) {
// Pn = 1 <- 2 8 receive 38.4k baud.
// Pn = 1 <- clock multiplier.
// Pn = 0 <- STP flags.
Program.prototype.decreqtparm =
Program.prototype.requestParameters = function(params) {
return this.write('\x1b[' + (param || 0) + 'x');
};
@ -1480,6 +1533,7 @@ Program.prototype.requestParameters = function(params) {
// Ps = 0 -> from start to end position, wrapped.
// Ps = 1 -> from start to end position, wrapped.
// Ps = 2 -> rectangle (exact).
Program.prototype.decsace =
Program.prototype.selectChangeExtent = function(params) {
return this.write('\x1b[' + (param || 0) + 'x');
};
@ -1489,6 +1543,7 @@ Program.prototype.selectChangeExtent = function(params) {
// Pc is the character to use.
// Pt; Pl; Pb; Pr denotes the rectangle.
// NOTE: xterm doesn't enable this code by default.
Program.prototype.decfra =
Program.prototype.fillRectangle = function(params) {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '$x');
};
@ -1505,6 +1560,7 @@ Program.prototype.fillRectangle = function(params) {
// Pu = 0 <- or omitted -> default to character cells.
// Pu = 1 <- device physical pixels.
// Pu = 2 <- character cells.
Program.prototype.decelr =
Program.prototype.enableLocatorReporting = function(params) {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '\'z');
};
@ -1513,6 +1569,7 @@ Program.prototype.enableLocatorReporting = function(params) {
// 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.decera =
Program.prototype.eraseRectangle = function(params) {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '$z');
};
@ -1528,6 +1585,7 @@ Program.prototype.eraseRectangle = function(params) {
// Ps = 2 -> do not report button down transitions.
// Ps = 3 -> report button up transitions.
// Ps = 4 -> do not report button up transitions.
Program.prototype.decsle =
Program.prototype.setLocatorEvents = function(params) {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '\'{');
};
@ -1535,6 +1593,7 @@ Program.prototype.setLocatorEvents = function(params) {
// CSI Pt; Pl; Pb; Pr$ {
// Selective Erase Rectangular Area (DECSERA), VT400 and up.
// Pt; Pl; Pb; Pr denotes the rectangle.
Program.prototype.decsera =
Program.prototype.selectiveEraseRectangle = function(params) {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '${');
};
@ -1579,6 +1638,7 @@ Program.prototype.selectiveEraseRectangle = function(params) {
// mal.
// The ``page'' parameter is not used by xterm, and will be omit-
// ted.
Program.prototype.decrqlp =
Program.prototype.requestLocatorPosition = function(params, callback) {
return this.receive('\x1b[' + (param || '') + '\'|', callback);
};
@ -1586,6 +1646,7 @@ Program.prototype.requestLocatorPosition = function(params, callback) {
// 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.decic =
Program.prototype.insertColumns = function() {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + ' }');
};
@ -1593,6 +1654,7 @@ Program.prototype.insertColumns = function() {
// 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.decdc =
Program.prototype.deleteColumns = function() {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + ' ~');
};