improve border docking. selective border drawing.

This commit is contained in:
Christopher Jeffrey 2015-04-06 18:40:33 -07:00
parent df21507d50
commit 67bdab7e4f
3 changed files with 474 additions and 167 deletions

View File

@ -737,6 +737,8 @@ Screen.prototype.render = function() {
this.emit('prerender');
this._borderStops = {};
// TODO: Possibly get rid of .dirty altogether.
// TODO: Could possibly drop .dirty and just clear the `lines` buffer every
// time before a screen.render. This way clearRegion doesn't have to be
@ -753,6 +755,10 @@ Screen.prototype.render = function() {
});
this._ci = -1;
if (this.screen.dockBorders) {
this._dockBorders();
}
this.draw(0, this.lines.length - 1);
// XXX Workaround to deal with cursor pos before the screen has rendered and
@ -2086,6 +2092,10 @@ function Element(options) {
this.style.border.bg = this.border.bg;
}
//this.border.style = this.style.border;
if (this.border.left == null) this.border.left = true;
if (this.border.top == null) this.border.top = true;
if (this.border.right == null) this.border.right = true;
if (this.border.bottom == null) this.border.bottom = true;
}
if (options.clickable) {
@ -2204,12 +2214,14 @@ Element.prototype.sattr = function(style, fg, bg) {
if (typeof fg === 'function') fg = fg(this);
if (typeof bg === 'function') bg = bg(this);
return ((((invisible ? 16 : 0) << 18)
// return (this.uid << 24)
// | ((this.dockBorders ? 32 : 0) << 18)
return ((invisible ? 16 : 0) << 18)
| ((inverse ? 8 : 0) << 18)
| ((blink ? 4 : 0) << 18)
| ((underline ? 2 : 0) << 18))
| ((underline ? 2 : 0) << 18)
| ((bold ? 1 : 0) << 18)
| (colors.convert(fg) << 9))
| (colors.convert(fg) << 9)
| colors.convert(bg);
};
@ -3288,25 +3300,35 @@ Element.prototype.__defineSetter__('rbottom', function(val) {
Element.prototype.__defineGetter__('ileft', function() {
return (this.border ? 1 : 0) + this.padding.left;
// return (this.border && this.border.left ? 1 : 0) + this.padding.left;
});
Element.prototype.__defineGetter__('itop', function() {
return (this.border ? 1 : 0) + this.padding.top;
// return (this.border && this.border.top ? 1 : 0) + this.padding.top;
});
Element.prototype.__defineGetter__('iright', function() {
return (this.border ? 1 : 0) + this.padding.right;
// return (this.border && this.border.right ? 1 : 0) + this.padding.right;
});
Element.prototype.__defineGetter__('ibottom', function() {
return (this.border ? 1 : 0) + this.padding.bottom;
// return (this.border && this.border.bottom ? 1 : 0) + this.padding.bottom;
});
Element.prototype.__defineGetter__('iwidth', function() {
// return (this.border
// ? ((this.border.left ? 1 : 0) + (this.border.right ? 1 : 0)) : 0)
// + this.padding.left + this.padding.right;
return (this.border ? 2 : 0) + this.padding.left + this.padding.right;
});
Element.prototype.__defineGetter__('iheight', function() {
// return (this.border
// ? ((this.border.top ? 1 : 0) + (this.border.bottom ? 1 : 0)) : 0)
// + this.padding.top + this.padding.bottom;
return (this.border ? 2 : 0) + this.padding.top + this.padding.bottom;
});
@ -3749,6 +3771,22 @@ Element.prototype.render = function() {
this.lpos = coords;
if (this.border && this.border.type === 'line') {
this.screen._borderStops[coords.yi] = true;
this.screen._borderStops[coords.yl - 1] = true;
// if (!this.screen._borderStops[coords.yi]) {
// this.screen._borderStops[coords.yi] = { xi: coords.xi, xl: coords.xl };
// } else {
// if (this.screen._borderStops[coords.yi].xi > coords.xi) {
// this.screen._borderStops[coords.yi].xi = coords.xi;
// }
// if (this.screen._borderStops[coords.yi].xl < coords.xl) {
// this.screen._borderStops[coords.yi].xl = coords.xl;
// }
// }
// this.screen._borderStops[coords.yl - 1] = this.screen._borderStops[coords.yi];
}
dattr = this.sattr(this.style);
attr = dattr;
@ -3914,64 +3952,47 @@ Element.prototype.render = function() {
if (this.border.type === 'line') {
if (x === xi) {
ch = '\u250c'; // '┌'
if (this.screen.dockBorders || this.dockBorders) {
if (lines[y][x][1] === '\u2510') { // '┐'
ch = '\u252c'; // '┬'
} else if (lines[y][x][1] === '\u2534') { // '┴'
ch = '\u253c'; // '┼'
} else if (lines[y][x][1] === '\u2514') { // '└'
ch = '\u251c'; // '├'
} else if (lines[y][x][1] === '\u2518') { // '┘'
ch = '\u253c'; // '┼'
} else if (lines[y][x][1] === '\u2524') { // '┤'
ch = '\u253c'; // '┼'
} else if (lines[y][x][1] === '\u253c') { // '┼'
ch = '\u253c'; // '┼'
if (!this.border.left) {
if (this.border.top) {
ch = '\u2500'; // '─'
} else {
continue;
}
} else {
if (!this.border.top) {
ch = '\u2502'; // '│'
}
}
} else if (x === xl - 1) {
ch = '\u2510'; // '┐'
if (this.screen.dockBorders || this.dockBorders) {
if (lines[y][x][1] === '\u250c') { // '┌'
ch = '\u252c'; // '┬'
} else if (lines[y][x][1] === '\u2534') { // '┴'
ch = '\u253c'; // '┼'
} else if (lines[y][x][1] === '\u2518') { // '┘'
ch = '\u2524'; // '┤'
} else if (lines[y][x][1] === '\u2514') { // '└'
ch = '\u253c'; // '┼'
} else if (lines[y][x][1] === '\u251c') { // '├'
ch = '\u253c'; // '┼'
} else if (lines[y][x][1] === '\u253c') { // '┼'
ch = '\u253c'; // '┼'
if (!this.border.right) {
if (this.border.top) {
ch = '\u2500'; // '─'
} else {
continue;
}
} else {
if (!this.border.top) {
ch = '\u2502'; // '│'
}
}
} else {
// if (!this.border.top) continue;
ch = '\u2500'; // '─'
if (this.screen.dockBorders || this.dockBorders) {
if (lines[y][x][1] === '\u2502') { // '│'
ch = '\u253c'; // '┼'
} else if (lines[y][x][1] === '\u253c') { // '┼'
ch = '\u253c'; // '┼'
}
// else if (lines[y][x][1] === '\u250c') { // '┌'
// ch = '\u252c'; // '┬'
// } else if (lines[y][x][1] === '\u2514') { // '└'
// ch = '\u2534'; // '┴'
// else if (lines[y][x][1] === '\u2510') { // '┐'
// ch = '\u252c'; // '┬'
// } else if (lines[y][x][1] === '\u2518') { // '┘'
// ch = '\u2534'; // '┴'
// } else if (lines[y][x][1] === '\u252c') { // '┬'
// ch = '\u252c'; // '┬'
// } else if (lines[y][x][1] === '\u2534') { // '┴'
// ch = '\u2534'; // '┴'
// }
}
}
} else if (this.border.type === 'bg') {
// if (!this.border.top) break;
ch = this.border.ch;
}
if (!this.border.top && x !== xi && x !== xl - 1) {
ch = ' ';
if (dattr !== cell[0] || ch !== cell[1]) {
lines[y][x][0] = dattr;
lines[y][x][1] = ch;
lines[y].dirty = true;
continue;
}
}
if (battr !== cell[0] || ch !== cell[1]) {
lines[y][x][0] = battr;
lines[y][x][1] = ch;
@ -3983,56 +4004,47 @@ Element.prototype.render = function() {
if (!lines[y]) continue;
cell = lines[y][xi];
if (!cell) continue;
if (this.border.type === 'line') {
ch = '\u2502'; // '│'
if (this.screen.dockBorders || this.dockBorders) {
if (lines[y][xi][1] === '\u2500') { // '─'
ch = '\u253c'; // '┼'
} else if (lines[y][xi][1] === '\u253c') { // '┼'
ch = '\u253c'; // '┼'
}
if (this.border.left) {
if (this.border.type === 'line') {
ch = '\u2502'; // '│'
} else if (this.border.type === 'bg') {
ch = this.border.ch;
}
if (!coords.noleft)
if (battr !== cell[0] || ch !== cell[1]) {
lines[y][xi][0] = battr;
lines[y][xi][1] = ch;
lines[y].dirty = true;
}
} else {
ch = ' ';
if (dattr !== cell[0] || ch !== cell[1]) {
lines[y][xi][0] = dattr;
lines[y][xi][1] = ch;
lines[y].dirty = true;
}
} else if (this.border.type === 'bg') {
ch = this.border.ch;
}
if (!coords.noleft)
if (battr !== cell[0] || ch !== cell[1]) {
lines[y][xi][0] = battr;
lines[y][xi][1] = ch;
lines[y].dirty = true;
}
cell = lines[y][xl - 1];
if (!cell) continue;
if (this.border.type === 'line') {
ch = '\u2502'; // '│'
if (this.screen.dockBorders || this.dockBorders) {
if (lines[y][xl - 1][1] === '\u2500') { // '─'
ch = '\u253c'; // '┼'
} else if (lines[y][xl - 1][1] === '\u253c') { // '┼'
ch = '\u253c'; // '┼'
}
// else if (lines[y][x][1] === '\u250c') { // '┌'
// ch = '\u251c'; // '├'
// } else if (lines[y][x][1] === '\u2510') { // '┐'
// ch = '\u2524'; // '┤'
// } else if (lines[y][x][1] === '\u2514') { // '└'
// ch = '\u251c'; // '├'
// } else if (lines[y][x][1] === '\u2518') { // '┘'
// ch = '\u2524'; // '┤'
// } else if (lines[y][x][1] === '\u252c') { // '┬'
// ch = '\u253c'; // '┼'
// } else if (lines[y][x][1] === '\u2534') { // '┴'
// ch = '\u253c'; // '┼'
// }
if (this.border.right) {
if (this.border.type === 'line') {
ch = '\u2502'; // '│'
} else if (this.border.type === 'bg') {
ch = this.border.ch;
}
if (!coords.noright)
if (battr !== cell[0] || ch !== cell[1]) {
lines[y][xl - 1][0] = battr;
lines[y][xl - 1][1] = ch;
lines[y].dirty = true;
}
} else {
ch = ' ';
if (dattr !== cell[0] || ch !== cell[1]) {
lines[y][xl - 1][0] = dattr;
lines[y][xl - 1][1] = ch;
lines[y].dirty = true;
}
} else if (this.border.type === 'bg') {
ch = this.border.ch;
}
if (!coords.noright)
if (battr !== cell[0] || ch !== cell[1]) {
lines[y][xl - 1][0] = battr;
lines[y][xl - 1][1] = ch;
lines[y].dirty = true;
}
}
y = yl - 1;
@ -4046,66 +4058,47 @@ Element.prototype.render = function() {
if (this.border.type === 'line') {
if (x === xi) {
ch = '\u2514'; // '└'
if (this.screen.dockBorders || this.dockBorders) {
if (lines[y][x][1] === '\u2518') { // '┘'
ch = '\u2534'; // '┴'
} else if (lines[y][x][1] === '\u252c') { // '┬'
ch = '\u253c'; // '┼'
} else if (lines[y][x][1] === '\u250c') { // '┌'
ch = '\u251c'; // '├'
// XXX Not necessary?
//} else if (lines[y][x][1] === '\u2518') { // '┘'
// ch = '\u253c'; // '┼'
} else if (lines[y][x][1] === '\u2524') { // '┤'
ch = '\u253c'; // '┼'
} else if (lines[y][x][1] === '\u253c') { // '┼'
ch = '\u253c'; // '┼'
if (!this.border.left) {
if (this.border.bottom) {
ch = '\u2500'; // '─'
} else {
continue;
}
} else {
if (!this.border.bottom) {
ch = '\u2502'; // '│'
}
}
} else if (x === xl - 1) {
ch = '\u2518'; // '┘'
if (this.screen.dockBorders || this.dockBorders) {
if (lines[y][x][1] === '\u2514') { // '└'
ch = '\u2534'; // '┴'
} else if (lines[y][x][1] === '\u252c') { // '┬'
ch = '\u253c'; // '┼'
} else if (lines[y][x][1] === '\u2510') { // '┐'
ch = '\u2524'; // '┤'
// XXX Not necessary?
//} else if (lines[y][x][1] === '\u2514') { // '└'
// ch = '\u253c'; // '┼'
} else if (lines[y][x][1] === '\u251c') { // '├'
ch = '\u253c'; // '┼'
} else if (lines[y][x][1] === '\u253c') { // '┼'
ch = '\u253c'; // '┼'
if (!this.border.right) {
if (this.border.bottom) {
ch = '\u2500'; // '─'
} else {
continue;
}
} else {
if (!this.border.bottom) {
ch = '\u2502'; // '│'
}
}
} else {
// if (!this.border.bottom) continue;
ch = '\u2500'; // '─'
if (this.screen.options.dockBorders) {
if (lines[y][x][1] === '\u2502') { // '│'
ch = '\u253c'; // '┼'
} else if (lines[y][x][1] === '\u253c') { // '┼'
ch = '\u253c'; // '┼'
}
// else if (lines[y][x][1] === '\u250c') { // '┌'
// ch = '\u252c'; // '┬'
// } else if (lines[y][x][1] === '\u2514') { // '└'
// ch = '\u2534'; // '┴'
// else if (lines[y][x][1] === '\u2510') { // '┐'
// ch = '\u252c'; // '┬'
// } else if (lines[y][x][1] === '\u2518') { // '┘'
// ch = '\u2534'; // '┴'
// } else if (lines[y][x][1] === '\u252c') { // '┬'
// ch = '\u252c'; // '┬'
// } else if (lines[y][x][1] === '\u2534') { // '┴'
// ch = '\u2534'; // '┴'
// }
}
}
} else if (this.border.type === 'bg') {
// if (!this.border.bottom) break;
ch = this.border.ch;
}
if (!this.border.bottom && x !== xi && x !== xl - 1) {
ch = ' ';
if (dattr !== cell[0] || ch !== cell[1]) {
lines[y][x][0] = dattr;
lines[y][x][1] = ch;
lines[y].dirty = true;
}
continue;
}
if (battr !== cell[0] || ch !== cell[1]) {
lines[y][x][0] = battr;
lines[y][x][1] = ch;
@ -4132,6 +4125,135 @@ Element.prototype.render = function() {
return coords;
};
Screen.prototype._dockBorders = function() {
var lines = this.lines
, stops = this._borderStops
, i
, y
, x
, ch;
// var keys, stop;
//
// keys = Object.keys(this._borderStops)
// .map(function(k) { return +k; })
// .sort(function(a, b) { return a - b; });
//
// for (i = 0; i < keys.length; i++) {
// y = keys[i];
// if (!lines[y]) continue;
// stop = this._borderStops[y];
// for (x = stop.xi; x < stop.xl; x++) {
stops = Object.keys(stops)
.map(function(k) { return +k; })
.sort(function(a, b) { return a - b; });
for (i = 0; i < stops.length; i++) {
y = stops[i];
if (!lines[y]) continue;
for (x = 0; x < this.width; x++) {
ch = lines[y][x][1];
if (angles[ch]) {
lines[y][x][1] = getAngle(x, y, lines);
continue;
}
if (ch === '┘') {
if (lines[y][x + 1] && lines[y][x + 1][1] === '─') {
if (lines[y + 1] && lines[y + 1][x][1] === '│') {
lines[y][x][1] = '┼';
} else {
lines[y][x][1] = '┴';
}
} else if (lines[y + 1] && lines[y + 1][x][1] === '│') {
if (lines[y][x + 1] && lines[y][x + 1][1] === '─') {
lines[y][x][1] = '┼';
} else {
lines[y][x][1] = '┤';
}
}
} else if (ch === '┐') {
if (lines[y][x + 1] && lines[y][x + 1][1] === '─') {
if (lines[y - 1] && lines[y - 1][x][1] === '│') {
lines[y][x][1] = '┼';
} else {
lines[y][x][1] = '┬';
}
} else if (lines[y - 1] && lines[y - 1][x][1] === '│') {
if (lines[y][x + 1] && lines[y][x + 1][1] === '─') {
lines[y][x][1] = '┼';
} else {
lines[y][x][1] = '┤';
}
}
} else if (ch === '┌') {
if (lines[y][x - 1] && lines[y][x - 1][1] === '─') {
if (lines[y - 1] && lines[y - 1][x][1] === '│') {
lines[y][x][1] = '┼';
} else {
lines[y][x][1] = '┬';
}
} else if (lines[y - 1] && lines[y - 1][x][1] === '│') {
if (lines[y][x - 1] && lines[y][x - 1][1] === '─') {
lines[y][x][1] = '┼';
} else {
lines[y][x][1] = '├';
}
}
} else if (ch === '└') {
if (lines[y][x - 1] && lines[y][x - 1][1] === '─') {
if (lines[y + 1] && lines[y + 1][x][1] === '│') {
lines[y][x][1] = '┼';
} else {
lines[y][x][1] = '┴';
}
} else if (lines[y + 1] && lines[y + 1][x][1] === '│') {
if (lines[y][x - 1] && lines[y][x - 1][1] === '─') {
lines[y][x][1] = '┼';
} else {
lines[y][x][1] = '├';
}
}
} else if (ch === '─') {
lines[y][x][1] = getAngle(x, y, lines);
} else if (ch === '│') {
lines[y][x][1] = getAngle(x, y, lines);
// XXX For tables without top or bottom borders:
// } else if (ch === '┬') {
// if (lines[y][x + 1] && lines[y][x + 1][1] !== '─') {
// if (lines[y][x - 1] && lines[y][x - 1][1] !== '─') {
// lines[y][x][1] = '│';
// } else {
// lines[y][x][1] = '┐';
// }
// }
// if (lines[y][x - 1] && lines[y][x - 1][1] !== '─') {
// if (lines[y][x + 1] && lines[y][x + 1][1] !== '─') {
// lines[y][x][1] = '│';
// } else {
// lines[y][x][1] = '┌';
// }
// }
// } else if (ch === '┴') {
// if (lines[y][x + 1] && lines[y][x + 1][1] !== '─') {
// if (lines[y][x - 1] && lines[y][x - 1][1] !== '─') {
// lines[y][x][1] = '│';
// } else {
// lines[y][x][1] = '┘';
// }
// }
// if (lines[y][x - 1] && lines[y][x - 1][1] !== '─') {
// if (lines[y][x + 1] && lines[y][x + 1][1] !== '─') {
// lines[y][x][1] = '│';
// } else {
// lines[y][x][1] = '└';
// }
// }
}
}
}
};
Element.prototype._render = Element.prototype.render;
Element.prototype.insertLine = function(i, line) {
@ -7295,17 +7417,17 @@ Table.prototype.render = function() {
, cattr = this.sattr(this.style.cell)
, battr = this.sattr(this.style.border);
var width = coords.xl - coords.xi - this.iwidth / 2
, height = coords.yl - coords.yi - this.iheight / 2;
var width = coords.xl - coords.xi - this.iwidth / 2 // this.iright
, height = coords.yl - coords.yi - this.iheight / 2; // this.ibottom
// Apply attributes to header cells and cells.
for (var y = this.iheight / 2; y < height; y++) {
for (var y = this.iheight / 2; y < height; y++) { // this.itop
if (!lines[yi + y]) break;
for (var x = this.iwidth / 2; x < width; x++) {
for (var x = this.iwidth / 2; x < width; x++) { // this.ileft
if (!lines[yi + y][xi + x]) break;
// Check to see if it's not the default attr. Allows for tags:
if (lines[yi + y][xi + x][0] !== dattr) continue;
if (y === this.iheight / 2) {
if (y === this.iheight / 2) { // this.itop
lines[yi + y][xi + x][0] = hattr;
} else {
lines[yi + y][xi + x][0] = cattr;
@ -7337,6 +7459,10 @@ Table.prototype.render = function() {
// middle
lines[yi + ry][xi + 0][0] = battr;
lines[yi + ry][xi + 0][1] = '\u251c'; // '├'
// XXX If we alter iwidth and ileft for no borders - nothing should be written here
if (!self.border.left) {
lines[yi + ry][xi + 0][1] = '\u2500'; // '─'
}
}
} else if (i === self._maxes.length - 1) {
if (!lines[yi + ry][xi + rx + 1]) return;
@ -7353,6 +7479,10 @@ Table.prototype.render = function() {
// middle
lines[yi + ry][xi + ++rx][0] = battr;
lines[yi + ry][xi + rx][1] = '\u2524'; // '┤'
// XXX If we alter iwidth and iright for no borders - nothing should be written here
if (!self.border.right) {
lines[yi + ry][xi + rx][1] = '\u2500'; // '─'
}
}
return;
}
@ -7362,10 +7492,18 @@ Table.prototype.render = function() {
// top
lines[yi + ry][xi + ++rx][0] = battr;
lines[yi + ry][xi + rx][1] = '\u252c'; // '┬'
// XXX If we alter iheight and itop for no borders - nothing should be written here
if (!self.border.top) {
lines[yi + ry][xi + rx][1] = '\u2502'; // '│'
}
} else if (ry / 2 === self.rows.length) {
// bottom
lines[yi + ry][xi + ++rx][0] = battr;
lines[yi + ry][xi + rx][1] = '\u2534'; // '┴'
// XXX If we alter iheight and ibottom for no borders - nothing should be written here
if (!self.border.bottom) {
lines[yi + ry][xi + rx][1] = '\u2502'; // '│'
}
} else {
// middle
if (self.options.fillCellBorders) {
@ -7585,8 +7723,8 @@ ListTable.prototype.render = function() {
var battr = this.sattr(this.style.border);
var width = coords.xl - coords.xi - this.iwidth / 2
, height = coords.yl - coords.yi - this.iheight / 2;
var width = coords.xl - coords.xi - this.iwidth / 2 // this.iright
, height = coords.yl - coords.yi - this.iheight / 2; // this.ibottom
if (!this.border || this.options.noCellBorders) return coords;
@ -7603,10 +7741,18 @@ ListTable.prototype.render = function() {
// top
lines[yi + ry][xi + ++rx][0] = battr;
lines[yi + ry][xi + rx][1] = '\u252c'; // '┬'
// XXX If we alter iheight and itop for no borders - nothing should be written here
if (!self.border.top) {
lines[yi + ry][xi + rx][1] = '\u2502'; // '│'
}
} else if (ry === height) {
// bottom
lines[yi + ry][xi + ++rx][0] = battr;
lines[yi + ry][xi + rx][1] = '\u2534'; // '┴'
// XXX If we alter iheight and ibottom for no borders - nothing should be written here
if (!self.border.bottom) {
lines[yi + ry][xi + rx][1] = '\u2502'; // '│'
}
} else {
// middle
++rx;
@ -8473,6 +8619,119 @@ function findFile(start, target) {
})(start);
}
var angles = {
'┘': true,
'┐': true,
'┌': true,
'└': true,
'┼': true,
'⎺': true,
'⎻': true,
'⎼': true,
'⎽': true,
'├': true,
'┤': true,
'┴': true,
'┬': true,
'│': true,
'─': true
};
var langles = {
'┌': true,
'└': true,
'┼': true,
'├': true,
'┴': true,
'┬': true,
'─': true
};
var uangles = {
'┐': true,
'┌': true,
'┼': true,
'├': true,
'┤': true,
'┬': true,
'│': true
};
var rangles = {
'┘': true,
'┐': true,
'┼': true,
'┤': true,
'┴': true,
'┬': true,
'─': true
};
var dangles = {
'┘': true,
'└': true,
'┼': true,
'├': true,
'┤': true,
'┴': true,
'│': true
};
// Every ACS angle character can be
// represented by 4 bits ordered like this:
// [langle][uangle][rangle][dangle]
var angleTable = {
'0000': '', // ?
'0001': '│', // ?
'0010': '─', // ??
'0011': '┌',
'0100': '│', // ?
'0101': '│',
'0110': '└',
'0111': '├',
'1000': '─', // ??
'1001': '┐',
'1010': '─', // ??
'1011': '┬',
'1100': '┘',
'1101': '┤',
'1110': '┴',
'1111': '┼'
};
Object.keys(angleTable).forEach(function(key) {
angleTable[parseInt(key, 2)] = angleTable[key];
delete angleTable[key];
});
function getAngle(x, y, lines) {
var angle = 0
, attr = lines[y][x][0]
, ch = lines[y][x][1];
if (lines[y][x - 1] && langles[lines[y][x - 1][1]]) {
if (lines[y][x - 1][0] !== attr) return ch;
angle |= 1 << 3;
}
if (lines[y - 1] && uangles[lines[y - 1][x][1]]) {
if (lines[y - 1][x][0] !== attr) return ch;
angle |= 1 << 2;
}
if (lines[y][x + 1] && rangles[lines[y][x + 1][1]]) {
if (lines[y][x + 1][0] !== attr) return ch;
angle |= 1 << 1;
}
if (lines[y + 1] && dangles[lines[y + 1][x][1]]) {
if (lines[y + 1][x][0] !== attr) return ch;
angle |= 1 << 0;
}
return angleTable[angle] || ch;
}
/**
* Helpers
*/

View File

@ -7,43 +7,71 @@ screen = blessed.screen({
dockBorders: true
});
blessed.box({
var topleft = blessed.box({
parent: screen,
left: 0,
top: 0,
width: '50%',
height: '50%',
border: 'line',
border: {
type: 'line',
left: false,
top: false,
right: true,
bottom: false
},
// border: 'line',
content: 'Foo'
});
blessed.box({
var topright = blessed.box({
parent: screen,
left: '50%-1',
top: 0,
width: '50%+1',
height: '50%',
content: 'Bar',
border: 'line'
border: {
type: 'line',
left: true,
top: false,
right: false,
bottom: false
},
// border: 'line',
content: 'Bar'
});
blessed.box({
var bottomleft = blessed.box({
parent: screen,
left: 0,
top: '50%-1',
width: '50%',
height: '50%+1',
border: {
type: 'line',
left: false,
top: true,
right: false,
bottom: false
},
border: 'line',
content: 'Foo'
});
blessed.listtable({
var bottomright = blessed.listtable({
parent: screen,
left: '50%-1',
top: '50%-1',
width: '50%+1',
height: '50%+1',
border: 'line',
border: {
type: 'line',
left: true,
top: true,
right: false,
bottom: false
},
// border: 'line',
align: 'center',
tags: true,
keys: true,
@ -68,17 +96,36 @@ blessed.listtable({
[ 'T-Rex', 'Taco', '8:45am', 'Three' ],
[ 'Mouse', 'Cheese', '9:05am', 'Four' ]
]
}).focus();
});
// blessed.box({
// parent: screen,
// left: '50%-1',
// top: '50%-1',
// width: '50%+1',
// height: '50%+1',
// border: 'line',
// content: 'Bar'
// });
bottomright.focus();
var over = blessed.box({
parent: screen,
hidden: true,
left: 'center',
top: 'center',
width: '50%',
height: '50%',
border: {
type: 'line',
left: false,
top: true,
right: true,
bottom: true
},
content: 'Foo'
});
screen.on('keypress', function() {
over.toggle();
screen.render();
});
screen.key('escape', function() {
over.hide();
screen.render();
});
screen.key('q', function() {
return process.exit(0);

View File

@ -5,6 +5,7 @@ screen = blessed.screen({
dump: __dirname + '/logs/widget.log',
title: 'widget test',
resizeTimeout: 300,
dockBorders: true,
cursor: {
artificial: true,
shape: 'line',