working nested scrolling.

This commit is contained in:
Christopher Jeffrey 2013-07-26 00:19:57 -05:00
parent ea857ea550
commit 8ea1fe4dab
3 changed files with 81 additions and 63 deletions

View File

@ -1586,7 +1586,8 @@ Program.prototype.resetColors = function(param) {
if (this.has('Cr')) { if (this.has('Cr')) {
return this.put.Cr(param); return this.put.Cr(param);
} }
return this._write('\x1b]112;' + param + '\x07'); return this._write('\x1b]112\x07');
//return this._write('\x1b]112;' + param + '\x07');
}; };
// OSC Ps ; Pt ST // OSC Ps ; Pt ST
@ -1723,10 +1724,10 @@ Program.prototype.eraseInDisplay = function(param) {
}; };
Program.prototype.clear = function() { Program.prototype.clear = function() {
this.x = this.y = 0; this.x = 0;
this.y = 0;
if (this.tput) return this.put.clear(); if (this.tput) return this.put.clear();
return this._write('\x1b[H\x1b[J'); return this._write('\x1b[H\x1b[J');
// return this.ed('all');
}; };
// CSI Ps K Erase in Line (EL). // CSI Ps K Erase in Line (EL).
@ -2973,29 +2974,30 @@ Program.prototype.decscusr =
Program.prototype.setCursorStyle = function(param) { Program.prototype.setCursorStyle = function(param) {
switch (param) { switch (param) {
case 'blinking block': case 'blinking block':
param = '0'; param = 1;
param = '1';
break; break;
case 'block': case 'block':
case 'steady block': case 'steady block':
param = '2'; param = 2;
break; break;
case 'blinking underline': case 'blinking underline':
param = '3'; param = 3;
break; break;
case 'underline': case 'underline':
case 'steady underline': case 'steady underline':
param = '4'; param = 4;
break; break;
case 'blinking bar': case 'blinking bar':
param = '5'; param = 5;
break; break;
case 'bar': case 'bar':
case 'steady bar': case 'steady bar':
param = '6'; param = 6;
break; break;
} }
// extended tput.Se for param=2 if (param === 2 && this.has('Se')) {
return this.put.Se();
}
if (this.has('Ss')) { if (this.has('Ss')) {
return this.put.Ss(param); return this.put.Ss(param);
} }

View File

@ -2646,6 +2646,24 @@ Element.prototype._getCoords = function(get) {
if (el.scrollable) break; if (el.scrollable) break;
} }
// Attempt to shrink the element base on the
// size of the content and child elements.
if (this.shrink) {
coords = this._getShrink(xi, xl, yi, yl);
xi = coords.xi, xl = coords.xl;
yi = coords.yi, yl = coords.yl;
var p = this.screen.program;
if (this.content === 'foo') {
p.sc();
p.cup(1, 0);
p.el();
p.write(JSON.stringify({
yi: yi, yl: yl
}));
p.rc();
}
}
// Check to make sure we're visible and // Check to make sure we're visible and
// inside of the visible scroll area. // inside of the visible scroll area.
// NOTE: Lists have a property where only // NOTE: Lists have a property where only
@ -2658,76 +2676,67 @@ Element.prototype._getCoords = function(get) {
// We only do this when `get` is true, because that gets this.parent.lpos. // We only do this when `get` is true, because that gets this.parent.lpos.
// If it's false, the parent's position is calculated on the spot. // If it's false, the parent's position is calculated on the spot.
var _cb = el.childBase; var _cb = el.childBase;
if (get) { if (0) if (get) {
yi += this.parent.lpos._cb; // childbase of main scrollable element. yi += this.parent.lpos._cb; // childbase of main scrollable element.
yl += this.parent.lpos._cb; yl += this.parent.lpos._cb;
} }
if (0) if (get) {
var _el = this; var _el = this;
while (_el = _el.parent) { if (0) while (_el = _el.parent) {
if (!_el.lpos) continue;
yi += _el.lpos._cb;
yl += _el.lpos._cb;
}
}
ryi = yi - el._getTop(get) - el.itop; // maybe plus
ryl = yl - el._getTop(get) - el.ibottom;
visible = el._getHeight(get) - el.iheight;
if (ryi < el.childBase) {
if (ryl > el.childBase) {
// Is partially covered above.
v = ryl - el.childBase;
v = (ryl - ryi) - v;
base = (this.childBase || 0) + v;
yi += v;
} else {
// Is above.
return;
}
} else if (ryi >= el.childBase + visible) {
// Is below.
return;
} else if (ryl > el.childBase + visible) {
// Is partially covered below.
v = el.childBase + visible + (yl - yi) - ryl;
yl = yi + v;
}
//yi -= el.childBase;
//yl -= el.childBase;
var _el = this;
while (_el = _el.parent) {
if (_el.scrollable) { if (_el.scrollable) {
yi -= _el.childBase; yi -= _el.childBase;
yl -= _el.childBase; yl -= _el.childBase;
break;
} }
} }
if (this.parent.scrollable) {
//yi -= this.parent.childBase;
//yl -= this.parent.childBase;
yi -= this.parent.lpos.base;
yl -= this.parent.lpos.base;
}
if (yi < this.parent.lpos.yi + this.parent.itop) {
if (yl - 1 < this.parent.lpos.yi + this.parent.itop) {
// Is above.
return;
} else {
// Is partially covered below.
v = (this.parent.lpos.yi + this.parent.itop) - yi;
base = (this.childBase || 0) + v;
yi += v;
}
} else if (yl > this.parent.lpos.yl - this.parent.ibottom) {
if (yi > this.parent.lpos.yl - 1 - this.parent.ibottom) {
// Is below.
return;
} else {
// Is partially covered below.
v = yl - (this.parent.lpos.yl - this.parent.ibottom);
yl -= v;
}
}
// Shouldn't be necessary.
if (yi >= yl) return;
var p = this.screen.program; var p = this.screen.program;
if (this.content === 'foo') { if (this.content === 'foo') {
p.sc(); p.sc();
p.cup(p.rows - 1, 0); p.cup(0, 0);
p.el();
p.write(JSON.stringify({ p.write(JSON.stringify({
yi: yi, yl: yl, ryi: ryi, ryl: ryl, yi: yi, yl: yl,
cb: el.childBase, //pyi: this.parent.lpos.yi,
pcb: this.parent.lpos._cb //pyl: this.parent.lpos.yl,
//cb: el.childBase,
//pcb: this.parent.lpos._cb
})); }));
p.rc(); p.rc();
} }
} }
// Attempt to shrink the element base on the
// size of the content and child elements.
if (this.shrink) {
coords = this._getShrink(xi, xl, yi, yl);
xi = coords.xi, xl = coords.xl;
yi = coords.yi, yl = coords.yl;
}
return { return {
xi: xi, xi: xi,
xl: xl, xl: xl,
@ -2748,6 +2757,11 @@ Element.prototype.render = function() {
var coords = this._getCoords(true); var coords = this._getCoords(true);
if (!coords) return; if (!coords) return;
//if (!coords) {
// delete this.lpos;
// return;
//}
var lines = this.screen.lines var lines = this.screen.lines
, xi = coords.xi , xi = coords.xi
, xl = coords.xl , xl = coords.xl

View File

@ -59,7 +59,7 @@ var box2 = blessed.box({
top: 20, top: 20,
width: '80%', width: '80%',
height: 9, height: 9,
border: { border_: {
type: 'ascii' type: 'ascii'
}, },
style: { style: {
@ -89,9 +89,11 @@ var box3 = blessed.box({
top: 2, top: 2,
content: 'foo', content: 'foo',
shrink: true, shrink: true,
//height: 2,
//width: 3,
//width: '80%', //width: '80%',
//height: 5, //height: 5,
border: { border_: {
type: 'ascii' type: 'ascii'
}, },
style: { style: {