From 5f3d7f10b082843d3112dfdac720499753a8dfec Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 6 Apr 2015 19:31:04 -0700 Subject: [PATCH] clean up border and table code. --- lib/widget.js | 111 ++++---------------------------------------------- 1 file changed, 7 insertions(+), 104 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index 9f995c3..443f003 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -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;