start using zero-indexed instance of Program.

This commit is contained in:
Christopher Jeffrey 2013-07-12 00:36:36 -05:00
parent 5a96c3611d
commit ead26b4a66
2 changed files with 31 additions and 25 deletions

View File

@ -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;

View File

@ -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);