From 1c6681e99da7430c15d26a52a2b72c6048fc1693 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 13 Jun 2013 05:30:21 -0500 Subject: [PATCH] different border drawing. --- example/ping | 5 ++- lib/widget.js | 111 ++++++++++++++++++++++++++++++++++---------------- 2 files changed, 79 insertions(+), 37 deletions(-) diff --git a/example/ping b/example/ping index 3defe2c..3e7afeb 100755 --- a/example/ping +++ b/example/ping @@ -79,11 +79,12 @@ var score = new blessed.Box({ top: 0, left: 4, height: 3, - width: 26, + //width: 26, border: { type: 'ascii' }, - align: 'center', + shrink: true, + //align: 'center', bold: true }); diff --git a/lib/widget.js b/lib/widget.js index 13d55e7..020d29e 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -986,7 +986,8 @@ Box.prototype.render = function(stop) { , xi_ = this.left , xi , xl = this.screen.cols - this.right - , yi = this.top + , yi_ = this.top + , yi , yl = this.screen.rows - this.bottom , cell , attr @@ -1003,14 +1004,14 @@ Box.prototype.render = function(stop) { } if (this.position.height) { - yl = yi + this.height; + yl = yi_ + this.height; } if (this.parent.childBase != null && ~this.parent.items.indexOf(this)) { var rtop = this.rtop - (this.parent.border ? 1 : 0) , visible = this.parent.height - (this.parent.border ? 2 : 0); - yi -= this.parent.childBase; + yi_ -= this.parent.childBase; yl = Math.min(yl, this.screen.rows - this.parent.bottom - (this.parent.border ? 1 : 0)); if (rtop - this.parent.childBase < 0) { @@ -1040,7 +1041,7 @@ Box.prototype.render = function(stop) { var ret = { xi: xi_, xl: xl, - yi: yi, + yi: yi_, yl: yl }; @@ -1050,7 +1051,6 @@ Box.prototype.render = function(stop) { ? sattr(this.border, this.border.fg, this.border.bg) : 0; - //if (this.escapes) dattr = this.screen.dattr; dattr = sattr(this, this.fg, this.bg); attr = dattr; @@ -1067,42 +1067,22 @@ Box.prototype.render = function(stop) { } } - for (; yi < yl; yi++) { + if (this.border) yi_++, yl--, xi_++, xl--; + +outer: + for (yi = yi_; yi < yl; yi++) { if (!lines[yi]) break; for (xi = xi_; xi < xl; xi++) { cell = lines[yi][xi]; if (!cell) break; - if (this.border && (yi === this.top || xi === this.left || yi === yl - 1 || xi === xl - 1)) { - if (this.border.type === 'ascii') { - if (yi === this.top) { - if (xi === this.left) ch = '┌'; - else if (xi === xl - 1) ch = '┐'; - else ch = '─'; - } else if (yi === yl - 1) { - if (xi === this.left) ch = '└'; - else if (xi === xl - 1) ch = '┘'; - else ch = '─'; - } else if (xi === this.left || xi === xl - 1) { - ch = '│'; - } - } else if (this.border.type === 'bg') { - ch = this.border.ch; - } - if (battr !== cell[0] || ch !== cell[1]) { - lines[yi][xi][0] = battr; - lines[yi][xi][1] = ch; - lines[yi].dirty = true; - } - continue; + if (this.shrink && !content[ci] && yi === yi_) { + xl = xi + 1 - 1; + break outer; } ch = content[ci++] || ' '; - if (this.shrink && !content[ci - 1]) { - if (this.border) continue; else break; - } - // Handle escape codes. while (ch === '\x1b') { if (c = /^\x1b\[(?:\d+(?:;\d+)*)?m/.exec(content.substring(ci - 1))) { @@ -1117,8 +1097,7 @@ Box.prototype.render = function(stop) { if (ch === '\t') ch = ' '; if (ch === '\n' || ch === '\r') { ch = ' '; - var xxl = xl - (this.border ? 1 : 0); - for (; xi < xxl; xi++) { + for (; xi < xl; xi++) { cell = lines[yi][xi]; if (!cell) break; if (attr !== cell[0] || ch !== cell[1]) { @@ -1127,7 +1106,6 @@ Box.prototype.render = function(stop) { lines[yi].dirty = true; } } - if (this.border) xi--; continue; } @@ -1139,6 +1117,69 @@ Box.prototype.render = function(stop) { } } + if (this.border) { + yi_--, yl++, xi_--, xl++; + yi = yi_; + for (xi = xi_; xi < xl; xi++) { + if (!lines[yi]) break; + if (this.border.type === 'ascii') { + if (xi === xi_) ch = '┌'; + else if (xi === xl - 1) ch = '┐'; + else ch = '─'; + } else if (this.border.type === 'bg') { + ch = this.border.ch; + } + cell = lines[yi][xi]; + if (!cell) break; + if (battr !== cell[0] || ch !== cell[1]) { + lines[yi][xi][0] = battr; + lines[yi][xi][1] = ch; + lines[yi].dirty = true; + } + } + yi = yi_ + 1; + for (; yi < yl; yi++) { + if (!lines[yi]) break; + if (this.border.type === 'ascii') { + ch = '│'; + } else if (this.border.type === 'bg') { + ch = this.border.ch; + } + cell = lines[yi][xi_]; + if (!cell) break; + if (battr !== cell[0] || ch !== cell[1]) { + lines[yi][xi_][0] = battr; + lines[yi][xi_][1] = ch; + lines[yi].dirty = true; + } + cell = lines[yi][xl - 1]; + if (!cell) break; + if (battr !== cell[0] || ch !== cell[1]) { + lines[yi][xl - 1][0] = battr; + lines[yi][xl - 1][1] = ch; + lines[yi].dirty = true; + } + } + yi = yl - 1; + for (xi = xi_; xi < xl; xi++) { + if (!lines[yi]) break; + if (this.border.type === 'ascii') { + if (xi === xi_) ch = '└'; + else if (xi === xl - 1) ch = '┘'; + else ch = '─'; + } else if (this.border.type === 'bg') { + ch = this.border.ch; + } + cell = lines[yi][xi]; + if (!cell) break; + if (battr !== cell[0] || ch !== cell[1]) { + lines[yi][xi][0] = battr; + lines[yi][xi][1] = ch; + lines[yi].dirty = true; + } + } + } + this.children.forEach(function(el) { el.render(); });