diff --git a/lib/program.js b/lib/program.js index d1127aa..8992a55 100644 --- a/lib/program.js +++ b/lib/program.js @@ -725,6 +725,36 @@ Program.prototype.move = function(x, y) { return this.cursorPos(y, x); }; +// TODO: Fix cud and cuu calls. +Program.prototype.omove = function(x, y) { + if (!this.zero) { + x = (x || 1) - 1; + y = (y || 1) - 1; + } else { + x = x || 0; + y = y || 0; + } + if (y === this.y && x === this.x) { + return; + } + if (y === this.y) { + if (x > this.x) { + this.cuf(x - this.x); + } else if (x < this.x) { + this.cub(this.x - x); + } + } else if (x === this.x) { + if (y > this.y) { + this.cud(y - this.y); + } else if (y < this.y) { + this.cuu(this.y - y); + } + } else { + if (!this.zero) x++, y++; + this.cup(y, x); + } +}; + Program.prototype.rsetx = function(x) { // return this.HPositionRelative(x); if (!x) return; @@ -777,7 +807,9 @@ Program.prototype.vtab = function() { return this.write('\x0b'); }; +Program.prototype.ff = Program.prototype.form = function() { + if (this.tput) return this.put.ff(); return this.write('\x0c'); }; @@ -798,10 +830,12 @@ Program.prototype.tab = function() { }; Program.prototype.shiftOut = function() { + // if (this.tput) return this.put.S2(); return this.write('\x0e'); }; Program.prototype.shiftIn = function() { + // if (this.tput) return this.put.S3(); return this.write('\x0f'); }; @@ -1013,6 +1047,8 @@ Program.prototype.rmacs = function() { Program.prototype.setG = function(val) { // tput: TODO // if (this.tput) return this.put('s' + val); + // if (this.tput) return this.put.S2(); + // if (this.tput) return this.put.S3(); switch (val) { case 1: val = '~'; // GR @@ -2238,7 +2274,7 @@ Program.prototype.cht = Program.prototype.cursorForwardTab = function(param) { this.x += 8; this._ncoords(); - // Does not exit (?): + // Does not exist (?): // if (this.tput) return this.put.cht(param); if (this.tput) return this.put.tab(param); // or this.put.ht return this.write('\x1b[' + (param || 1) + 'I'); @@ -2249,7 +2285,7 @@ Program.prototype.su = Program.prototype.scrollUp = function(param) { this.y -= param || 1; this._ncoords(); - // Does not exit: + // Does not exist: // if (this.tput) return this.put.su(param); if (this.tput) return this.put.rin(param); return this.write('\x1b[' + (param || 1) + 'I'); @@ -2260,7 +2296,7 @@ Program.prototype.sd = Program.prototype.scrollDown = function(param) { this.y += param || 1; this._ncoords(); - // Does not exit: + // Does not exist: // if (this.tput) return this.put.sd(param); if (this.tput) return this.put.indn(param); return this.write('\x1b[' + (param || 1) + 'T'); diff --git a/lib/widget.js b/lib/widget.js index 5cc5976..9d17541 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -2064,7 +2064,7 @@ function List(options) { }); } - function resize() { + this.on('resize', function() { var visible = self.height - (self.border ? 2 : 0); if (visible >= self.selected + 1) { //if (self.selected < visible - 1) { @@ -2075,11 +2075,7 @@ function List(options) { self.childBase = self.selected - visible + 1; self.childOffset = visible - 1; } - } - - // this.onScreenEvent('resize', resize); - - this.on('resize', resize); + }); } List.prototype.__proto__ = ScrollableBox.prototype; @@ -2169,6 +2165,7 @@ List.prototype.select = function(index) { if (this.selected === index && this._listInitialized) return; this._listInitialized = true; + // TODO: Handle this a less stupid way. ['bg', 'fg', 'bold', 'underline', 'blink', 'inverse', 'invisible'].forEach(function(name) { if (this.items[this.selected]) { @@ -2506,9 +2503,6 @@ function Textarea(options) { this.value = options.value || ''; - this.cx = -1; - this.cy = -1; - this.__updateCursor = this.updateCursor.bind(this); this.on('resize', this.__updateCursor); this.on('move', this.__updateCursor); @@ -2523,10 +2517,6 @@ Textarea.prototype.updateCursor = function() { return; } - // To test blessed-maintained coords: - // this.cx = this.screen.program.x; - // this.cy = this.screen.program.y; - var last = this._clines[this._clines.length-1] , program = this.screen.program , line @@ -2547,35 +2537,25 @@ Textarea.prototype.updateCursor = function() { cy = this.top + (this.border ? 1 : 0) + line; cx = this.left + (this.border ? 1 : 0) + last.length; - if (cy === this.cy && cx === this.cx) { + if (cy === program.y && cx === program.x) { return; } - if (cy === this.cy) { - if (cx > this.cx) { - program.cuf(cx - this.cx); - } else if (cx < this.cx) { - program.cub(this.cx - cx); + if (cy === program.y) { + if (cx > program.x) { + program.cuf(cx - program.x); + } else if (cx < program.x) { + program.cub(program.x - cx); } - } else if (cx === this.cx) { - if (cy > this.cy) { - // if (cy - this.cy === 1) { - // program.ind(); - // } else { - program.cud(cy - this.cy); - } else if (cy < this.cy) { - // Technically works: - // if (this.cy - cy === 1) { - // program.ri(); - // } else { - program.cuu(this.cy - cy); + } else if (cx === program.x) { + if (cy > program.y) { + program.cud(cy - program.y); + } else if (cy < program.y) { + program.cuu(program.y - cy); } } else { program.cup(cy, cx); } - - this.cx = cx; - this.cy = cy; }; Textarea.prototype.input = @@ -2591,9 +2571,6 @@ Textarea.prototype.setInput = function(callback) { this.screen.grabKeys = true; - this.cx = -1; - this.cy = -1; - this.updateCursor(); this.screen.program.showCursor(); this.screen.program.sgr('normal');