From ead26b4a660a51e7d3e97fa269a1b71f126725f6 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 12 Jul 2013 00:36:36 -0500 Subject: [PATCH] start using zero-indexed instance of Program. --- lib/program.js | 2 +- lib/widget.js | 54 ++++++++++++++++++++++++++++---------------------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/lib/program.js b/lib/program.js index a579f95..d1127aa 100644 --- a/lib/program.js +++ b/lib/program.js @@ -35,7 +35,7 @@ function Program(options) { this.input = options.input || process.stdin; this.output = options.output || process.stdout; - this.zero = options.zero; + this.zero = options.zero !== false; this.x = 0; this.y = 0; diff --git a/lib/widget.js b/lib/widget.js index 8487c65..5cc5976 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -228,8 +228,11 @@ function Screen(options) { Node.call(this, options); this.program = options.program; + this.program.zero = true; this.tput = this.program.tput; + this.dattr = ((0 << 18) | (0x1ff << 9)) | 0x1ff; + this.position = { left: this.left = this.rleft = 0, right: this.right = this.rright = 0, @@ -496,11 +499,11 @@ Screen.prototype.blankLine = function(ch, dirty) { }; Screen.prototype.insertLine = function(n, y, top, bottom) { - this.program.csr(top + 1, bottom + 1); - this.program.cup(y + 1, 1); + this.program.csr(top, bottom); + this.program.cup(y, 0); this.program.il(1); - this.program.csr(1, this.height - 1 + 1); - this.program.cup(y + 1, 1); + this.program.csr(0, this.height - 1); + this.program.cup(y, 0); if (n < 1) n = 1; @@ -516,11 +519,11 @@ Screen.prototype.insertLine = function(n, y, top, bottom) { }; Screen.prototype.deleteLine = function(n, y, top, bottom) { - this.program.csr(top + 1, bottom + 1); - this.program.cup(y + 1, 1); + this.program.csr(top, bottom); + this.program.cup(y, 0); this.program.dl(1); - this.program.csr(1, this.height - 1 + 1); - this.program.cup(y + 1, 1); + this.program.csr(0, this.height - 1); + this.program.cup(y, 0); if (n < 1) n = 1; @@ -2358,8 +2361,8 @@ function Textbox(options) { function updateCursor() { if (self.screen.focused !== self) return; self.screen.program.cup( - self.top + 1 + (self.border ? 1 : 0), - self.left + 1 + (self.border ? 1 : 0) + self.top + (self.border ? 1 : 0), + self.left + (self.border ? 1 : 0) + self.value.length); } } @@ -2384,8 +2387,8 @@ Textbox.prototype.setInput = function(callback) { // Could possibly save and restore cursor. this.screen.program.cup( - this.top + 1 + (this.border ? 1 : 0), - this.left + 1 + (this.border ? 1 : 0) + this.top + (this.border ? 1 : 0), + this.left + (this.border ? 1 : 0) + this.value.length); this.screen.program.showCursor(); this.screen.program.sgr('normal'); @@ -2520,6 +2523,10 @@ 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 @@ -2537,8 +2544,8 @@ Textarea.prototype.updateCursor = function() { this._clines.length - 1 - this.childBase, this.height - (this.border ? 2 : 0) - 1); - cy = this.top + 1 + (this.border ? 1 : 0) + line; - cx = this.left + 1 + (this.border ? 1 : 0) + last.length; + cy = this.top + (this.border ? 1 : 0) + line; + cx = this.left + (this.border ? 1 : 0) + last.length; if (cy === this.cy && cx === this.cx) { return; @@ -2552,17 +2559,16 @@ Textarea.prototype.updateCursor = function() { } } else if (cx === this.cx) { if (cy > this.cy) { - if (cy - this.cy === 1) { - program.ind(); - } else { - program.cud(cy - this.cy); - } + // if (cy - this.cy === 1) { + // program.ind(); + // } else { + program.cud(cy - this.cy); } else if (cy < this.cy) { - if (this.cy - cy === 1) { - program.ri(); - } else { - program.cuu(this.cy - cy); - } + // Technically works: + // if (this.cy - cy === 1) { + // program.ri(); + // } else { + program.cuu(this.cy - cy); } } else { program.cup(cy, cx);