clean up border and table code.

This commit is contained in:
Christopher Jeffrey 2015-04-06 19:31:04 -07:00
parent 8a62f5e633
commit 5f3d7f10b0
1 changed files with 7 additions and 104 deletions

View File

@ -3977,11 +3977,9 @@ Element.prototype.render = function() {
}
}
} else {
// if (!this.border.top) continue;
ch = '\u2500'; // '─'
}
} else if (this.border.type === 'bg') {
// if (!this.border.top) break;
ch = this.border.ch;
}
if (!this.border.top && x !== xi && x !== xl - 1) {
@ -4083,11 +4081,9 @@ Element.prototype.render = function() {
}
}
} else {
// if (!this.border.bottom) continue;
ch = '\u2500'; // '─'
}
} else if (this.border.type === 'bg') {
// if (!this.border.bottom) break;
ch = this.border.ch;
}
if (!this.border.bottom && x !== xi && x !== xl - 1) {
@ -4180,99 +4176,6 @@ Screen.prototype._dockBorders = function() {
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] = '└';
// }
// }
}
}
}
@ -7441,17 +7344,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 // this.iright
, height = coords.yl - coords.yi - this.iheight / 2; // this.ibottom
var width = coords.xl - coords.xi - this.iright
, height = coords.yl - coords.yi - this.ibottom;
// Apply attributes to header cells and cells.
for (var y = this.iheight / 2; y < height; y++) { // this.itop
for (var y = this.itop; y < height; y++) {
if (!lines[yi + y]) break;
for (var x = this.iwidth / 2; x < width; x++) { // this.ileft
for (var x = this.ileft; x < width; x++) {
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) { // this.itop
if (y === this.itop) {
lines[yi + y][xi + x][0] = hattr;
} else {
lines[yi + y][xi + x][0] = cattr;
@ -7747,8 +7650,8 @@ ListTable.prototype.render = function() {
var battr = this.sattr(this.style.border);
var width = coords.xl - coords.xi - this.iwidth / 2 // this.iright
, height = coords.yl - coords.yi - this.iheight / 2; // this.ibottom
var width = coords.xl - coords.xi - this.iright
, height = coords.yl - coords.yi - this.ibottom;
if (!this.border || this.options.noCellBorders) return coords;