insert, set, get, delete, clear lines.
This commit is contained in:
parent
42399b17ab
commit
933b5442bd
|
@ -1834,6 +1834,8 @@ outer:
|
|||
// box.insertTop('foobar');
|
||||
// Things will break because we're using _lastPos instead of render(true).
|
||||
// Maybe _lastPos could be updated on .left, .right, etc setters?
|
||||
|
||||
// OLD
|
||||
Box.prototype.insertTop = function(line) {
|
||||
if (this._lastPos && this._lastPos.xi === 0 && this._lastPos.xl === this.screen.width) {
|
||||
this.screen.insertTop(this._lastPos.yi, this._lastPos.yl - 1);
|
||||
|
@ -1870,6 +1872,81 @@ Box.prototype.deleteBottom = function() {
|
|||
this.setContent(this._clines.join('\n'), reset);
|
||||
};
|
||||
|
||||
// NEW
|
||||
|
||||
Box.prototype.insertLine = function(i, line) {
|
||||
//if (typeof line === 'string') line = [line];
|
||||
if (this._lastPos && this._lastPos.xi === 0 && this._lastPos.xl === this.screen.width) {
|
||||
i = Math.max(i, 0);
|
||||
i = Math.min(i, this._lastPos.yl - this._lastPos.yi - (this.border ? 2 : 0));
|
||||
//this.screen.insertLine(line.length
|
||||
this.screen.insertLine(1,
|
||||
this._lastPos.yi + (this.border ? 1 : 0) + i,
|
||||
this._lastPos.yi,
|
||||
this._lastPos.yl - 1);
|
||||
}
|
||||
this._clines.splice((this.childBase || 0) + (this.border ? 1 : 0) + i, 0, line);
|
||||
// OR:
|
||||
//line.forEach(function(line, j) {
|
||||
// this._clines.splice((this.childBase || 0) + (this.border ? 1 : 0) + i + j, 0, line);
|
||||
//}, this);
|
||||
this.setContent(this._clines.join('\n'), true);
|
||||
};
|
||||
|
||||
Box.prototype.deleteLine = function(i) {
|
||||
//if (typeof line === 'string') line = [line];
|
||||
var reset = true;
|
||||
if (this._lastPos && this._lastPos.xi === 0 && this._lastPos.xl === this.screen.width) {
|
||||
i = Math.max(i, 0);
|
||||
i = Math.min(i, this._lastPos.yl - this._lastPos.yi - (this.border ? 2 : 0));
|
||||
//this.screen.deleteLine(line.length,
|
||||
this.screen.deleteLine(1,
|
||||
this._lastPos.yi + (this.border ? 1 : 0) + i,
|
||||
this._lastPos.yi,
|
||||
this._lastPos.yl - 1);
|
||||
reset = false;
|
||||
}
|
||||
this._clines.splice((this.childBase || 0) + (this.border ? 1 : 0) + i, 1);
|
||||
// OR:
|
||||
//line.forEach(function(line, j) {
|
||||
// this._clines.splice((this.childBase || 0) + (this.border ? 1 : 0) + i + j, 1);
|
||||
//}, this);
|
||||
this.setContent(this._clines.join('\n'), reset);
|
||||
};
|
||||
|
||||
Box.prototype.insertTop = function(line) {
|
||||
return this.insertLine(0, line);
|
||||
};
|
||||
|
||||
Box.prototype.insertBottom = function(line) {
|
||||
return this.insertLine(this.height - (this.border ? 2 : 0), line);
|
||||
};
|
||||
|
||||
Box.prototype.deleteTop = function() {
|
||||
return this.deleteLine(0);
|
||||
};
|
||||
|
||||
Box.prototype.deleteBottom = function() {
|
||||
return this.deleteLine(this.height - (this.border ? 2 : 0));
|
||||
};
|
||||
|
||||
Box.prototype.setLine = function(i, line) {
|
||||
i = Math.max(i, 0);
|
||||
i = Math.min(i, this._lastPos.yl - this._lastPos.yi - (this.border ? 2 : 0));
|
||||
this._clines[(this.childBase || 0) + (this.border ? 1 : 0) + i] = line;
|
||||
return this.setContent(this._clines.join('\n'), true);
|
||||
};
|
||||
|
||||
Box.prototype.getLine = function(i) {
|
||||
i = Math.max(i, 0);
|
||||
i = Math.min(i, this._lastPos.yl - this._lastPos.yi - (this.border ? 2 : 0));
|
||||
return this._clines[(this.childBase || 0) + (this.border ? 1 : 0) + i];
|
||||
};
|
||||
|
||||
Box.prototype.clearLine = function(i) {
|
||||
return this.setLine(i, '');
|
||||
};
|
||||
|
||||
/**
|
||||
* Text
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue