diff --git a/lib/program.js b/lib/program.js index 8eb7fcf..473b6cd 100644 --- a/lib/program.js +++ b/lib/program.js @@ -743,6 +743,7 @@ Program.prototype.esc = function(code) { // ESC D Index (IND is 0x84). Program.prototype.index = function() { this.y++; + if (this.tput) return this.tput.ind(); // indn return this.write('\x1bD'); }; @@ -750,6 +751,7 @@ Program.prototype.index = function() { Program.prototype.reverse = Program.prototype.reverseIndex = function() { this.y--; + if (this.tput) return this.tput.ri(); // rin return this.write('\x1bM'); }; @@ -757,17 +759,20 @@ Program.prototype.reverseIndex = function() { Program.prototype.nextLine = function() { this.y++; this.x = 1; + if (this.tput) return this.tput.nel(); return this.write('\x1bE'); }; // ESC c Full Reset (RIS). Program.prototype.reset = function() { //this.x = this.y = 1; + if (this.tput) return this.tput.ris(); return this.write('\x1bc'); }; // ESC H Tab Set (HTS is 0x88). Program.prototype.tabSet = function() { + if (this.tput) return this.tput.hts(); return this.write('\x1bH'); }; @@ -775,6 +780,7 @@ Program.prototype.tabSet = function() { Program.prototype.saveCursor = function() { this.savedX = this.x || 1; this.savedY = this.y || 1; + if (this.tput) return this.tput.decsc(); return this.esc('7'); }; @@ -782,6 +788,7 @@ Program.prototype.saveCursor = function() { Program.prototype.restoreCursor = function() { this.x = this.savedX || 1; this.y = this.savedY || 1; + if (this.tput) return this.tput.decrc(); return this.esc('8'); }; @@ -794,6 +801,8 @@ Program.prototype.lineHeight = function() { Program.prototype.charset = function(val, level) { level = level || 0; + if (this.tput) return this.tput['s' + level](val); + switch (level) { case 0: level = '('; @@ -880,6 +889,7 @@ Program.prototype.charset = function(val, level) { // ESC ~ // Invoke the G1 Character Set as GR (LS1R). Program.prototype.setG = function(val) { + // tput: TODO switch (val) { case 1: val = '~'; // GR @@ -927,6 +937,7 @@ Program.prototype.cuu = Program.prototype.up = Program.prototype.cursorUp = function(param) { this.y -= param || 1; + if (this.tput) return this.tput.cuu(param); return this.write('\x1b[' + (param || '') + 'A'); }; @@ -936,6 +947,7 @@ Program.prototype.cud = Program.prototype.down = Program.prototype.cursorDown = function(param) { this.y += param || 1; + if (this.tput) return this.tput.cud(param); return this.write('\x1b[' + (param || '') + 'B'); }; @@ -946,6 +958,7 @@ Program.prototype.right = Program.prototype.forward = Program.prototype.cursorForward = function(param) { this.x += param || 1; + if (this.tput) return this.tput.cuf(param); return this.write('\x1b[' + (param || '') + 'C'); }; @@ -956,6 +969,7 @@ Program.prototype.left = Program.prototype.back = Program.prototype.cursorBackward = function(param) { this.x -= param || 1; + if (this.tput) return this.tput.cub(param); return this.write('\x1b[' + (param || '') + 'D'); }; @@ -966,6 +980,7 @@ Program.prototype.pos = Program.prototype.cursorPos = function(row, col) { this.x = col || 1; this.y = row || 1; + if (this.tput) return this.tput.cup(row, col); return this.write('\x1b[' + (row || '1') + ';' + (col || '1') + 'H'); }; @@ -981,6 +996,24 @@ Program.prototype.cursorPos = function(row, col) { // Ps = 2 -> Selective Erase All. Program.prototype.ed = Program.prototype.eraseInDisplay = function(param) { + if (this.tput) { + switch (param) { + case 'above': + param = 1; + break; + case 'all': + param = 2; + break; + case 'saved': + param = 3; + break; + case 'below': + default: + param = null; + break; + } + return this.tput.ed(param); + } switch (param) { case 'above': this.write('\x1b[1J'); @@ -1013,6 +1046,21 @@ Program.prototype.clear = function() { // Ps = 2 -> Selective Erase All. Program.prototype.el = Program.prototype.eraseInLine = function(param) { + if (this.tput) { + switch (param) { + case 'left': + param = 1; + break; + case 'all': + param = 2; + break; + case 'right': + default: + param = null; + break; + } + return this.tput.el(param); + } switch (param) { case 'left': this.write('\x1b[1K'); @@ -1394,6 +1442,7 @@ Program.prototype.getCursor = function(callback) { Program.prototype.ich = Program.prototype.insertChars = function(param) { this.x += param || 1; + if (this.tput) return this.tput.ich(param); return this.write('\x1b[' + (param || 1) + '@'); }; @@ -1421,6 +1470,7 @@ Program.prototype.cha = Program.prototype.cursorCharAbsolute = function(param) { this.x = param || 1; this.y = 1; + if (this.tput) return this.tput.cha(param); return this.write('\x1b[' + (param || '') + 'G'); }; @@ -1428,6 +1478,7 @@ Program.prototype.cursorCharAbsolute = function(param) { // Insert Ps Line(s) (default = 1) (IL). Program.prototype.il = Program.prototype.insertLines = function(param) { + if (this.tput) return this.tput.il(param); return this.write('\x1b[' + (param || '') + 'L'); }; @@ -1435,6 +1486,7 @@ Program.prototype.insertLines = function(param) { // Delete Ps Line(s) (default = 1) (DL). Program.prototype.dl = Program.prototype.deleteLines = function(param) { + if (this.tput) return this.tput.dl(param); return this.write('\x1b[' + (param || '') + 'M'); }; @@ -1442,6 +1494,7 @@ Program.prototype.deleteLines = function(param) { // Delete Ps Character(s) (default = 1) (DCH). Program.prototype.dch = Program.prototype.deleteChars = function(param) { + if (this.tput) return this.tput.dch(param); return this.write('\x1b[' + (param || '') + 'P'); }; @@ -1449,6 +1502,7 @@ Program.prototype.deleteChars = function(param) { // Erase Ps Character(s) (default = 1) (ECH). Program.prototype.ech = Program.prototype.eraseChars = function(param) { + if (this.tput) return this.tput.ech(param); return this.write('\x1b[' + (param || '') + 'X'); }; @@ -1457,6 +1511,7 @@ Program.prototype.eraseChars = function(param) { Program.prototype.hpa = Program.prototype.charPosAbsolute = function() { this.x = arguments[0] || 1; + if (this.tput) return this.tput.hpa.apply(this.tput, arguments); var param = Array.prototype.slice.call(arguments).join(';'); return this.write('\x1b[' + (param || '') + '`'); }; @@ -1467,6 +1522,7 @@ Program.prototype.charPosAbsolute = function() { Program.prototype.hpr = Program.prototype.HPositionRelative = function(param) { this.x += param || 1; + if (this.tput) return this.tput.hpr(param); return this.write('\x1b[' + (param || '') + 'a'); }; @@ -1521,6 +1577,7 @@ Program.prototype.sendDeviceAttributes = function(param, callback) { Program.prototype.vpa = Program.prototype.linePosAbsolute = function() { this.y = arguments[0] || 1; + if (this.tput) return this.tput.vpa.apply(this.tput, arguments); var param = Array.prototype.slice.call(arguments).join(';'); return this.write('\x1b[' + (param || '') + 'd'); }; @@ -1530,6 +1587,7 @@ Program.prototype.linePosAbsolute = function() { Program.prototype.vpr = Program.prototype.VPositionRelative = function(param) { this.y += param || 1; + if (this.tput) return this.tput.vpr(param); return this.write('\x1b[' + (param || '') + 'e'); }; @@ -1540,6 +1598,7 @@ Program.prototype.hvp = Program.prototype.HVPosition = function(row, col) { this.y += row || 1; this.x += col || 1; + if (this.tput) return this.tput.hvp(row, col); return this.write('\x1b[' + (row || '1') + ';' + (col || '1') + 'f'); }; @@ -1629,6 +1688,7 @@ Program.prototype.HVPosition = function(row, col) { // http://vt100.net/docs/vt220-rm/chapter4.html Program.prototype.sm = Program.prototype.setMode = function() { + // tput: TODO var param = Array.prototype.slice.call(arguments).join(';'); //if (private) { // return this.write('\x1b[?' + (param || '') + 'h'); @@ -1735,6 +1795,7 @@ Program.prototype.alternateBuffer = function() { // Ps = 2 0 0 4 -> Reset bracketed paste mode. Program.prototype.rm = Program.prototype.resetMode = function() { + // tput: TODO var param = Array.prototype.slice.call(arguments).join(';'); //if (private) { // return this.write('\x1b[?' + (param || '') + 'l'); @@ -1876,6 +1937,7 @@ Program.prototype.setScrollRegion = function(top, bottom) { this.scrollBottom = (bottom || this.rows) - 1; this.x = 1; this.y = 1; + if (this.tput) return this.tput.csr(top - 1, bottom - 1); return this.write('\x1b[' + (top || 1) + ';' + (bottom || this.rows) + 'r'); }; @@ -1884,6 +1946,7 @@ Program.prototype.setScrollRegion = function(top, bottom) { Program.prototype.saveCursor = function() { this.savedX = this.x; this.savedY = this.y; + if (this.tput) return this.tput.sc(); return this.write('\x1b[s'); }; @@ -1892,6 +1955,7 @@ Program.prototype.saveCursor = function() { Program.prototype.restoreCursor = function() { this.x = this.savedX || 1; this.y = this.savedY || 1; + if (this.tput) return this.tput.rc(); return this.write('\x1b[u'); }; @@ -1904,6 +1968,7 @@ Program.prototype.restoreCursor = function() { Program.prototype.cht = Program.prototype.cursorForwardTab = function(param) { this.x += 8; + if (this.tput) return this.tput.cht(param); return this.write('\x1b[' + (param || 1) + 'I'); }; @@ -1911,6 +1976,7 @@ Program.prototype.cursorForwardTab = function(param) { Program.prototype.su = Program.prototype.scrollUp = function(param) { this.y -= param || 1; + if (this.tput) return this.tput.su(param); return this.write('\x1b[' + (param || 1) + 'I'); }; @@ -1918,6 +1984,7 @@ Program.prototype.scrollUp = function(param) { Program.prototype.sd = Program.prototype.scrollDown = function(param) { this.y += param || 1; + if (this.tput) return this.tput.sd(param); return this.write('\x1b[' + (param || 1) + 'T'); }; @@ -1948,6 +2015,7 @@ Program.prototype.resetTitleModes = function() { Program.prototype.cbt = Program.prototype.cursorBackwardTab = function(param) { this.x -= 8; + if (this.tput) return this.tput.cbt(param); return this.write('\x1b[' + (param || 1) + 'Z'); }; @@ -1955,6 +2023,7 @@ Program.prototype.cursorBackwardTab = function(param) { Program.prototype.rep = Program.prototype.repeatPrecedingCharacter = function(param) { //this.x += param || 1; + if (this.tput) return this.tput.rep(param); return this.write('\x1b[' + (param || 1) + 'b'); }; @@ -1966,6 +2035,7 @@ Program.prototype.repeatPrecedingCharacter = function(param) { // http://vt100.net/annarbor/aaa-ug/section6.html Program.prototype.tbc = Program.prototype.tabClear = function(param) { + if (this.tput) return this.tput.tbc(param); return this.write('\x1b[' + (param || 0) + 'g'); }; @@ -1982,6 +2052,7 @@ Program.prototype.tabClear = function(param) { // Ps = 1 1 -> Print all pages. Program.prototype.mc = Program.prototype.mediaCopy = function() { + if (this.tput) return this.tput.mc.apply(this.tput, arguments); //if (dec) { // this.write('\x1b[?' + Array.prototype.slice.call(arguments).join(';') + 'i'); // return; @@ -2430,6 +2501,8 @@ Program.prototype.selectiveEraseRectangle = function(params) { // ted. Program.prototype.decrqlp = Program.prototype.requestLocatorPosition = function(params, callback) { + // Correct for tput? + // if (this.tput) return this.tput.req_mouse_pos.apply(this.tput, arguments); return this.receive('\x1b[' + (param || '') + '\'|', callback); };