diff --git a/lib/widget.js b/lib/widget.js index d9bf83a..020d29e 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -540,19 +540,6 @@ Screen.prototype.fillRegion = function(attr, ch, xi, xl, yi, yl) { } }; -Screen.prototype.setCell = function(yi, xi, attr, ch) { - var lines = this.lines; - if (!lines[yi]) return; - var cell = lines[yi][xi]; - if (!cell) return; - if (attr !== cell[0] || ch !== cell[1]) { - lines[yi][xi][0] = attr; - lines[yi][xi][1] = ch; - lines[yi].dirty = true; - } - return true; -}; - /** * Element */ @@ -1086,6 +1073,9 @@ 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.shrink && !content[ci] && yi === yi_) { xl = xi + 1 - 1; break outer; @@ -1108,41 +1098,85 @@ outer: if (ch === '\n' || ch === '\r') { ch = ' '; for (; xi < xl; xi++) { - if (!this.screen.setCell(yi, xi, attr, ch)) break; + cell = lines[yi][xi]; + if (!cell) break; + if (attr !== cell[0] || ch !== cell[1]) { + lines[yi][xi][0] = attr; + lines[yi][xi][1] = ch; + lines[yi].dirty = true; + } } continue; } - if (!this.screen.setCell(yi, xi, attr, ch)) break; + if (attr !== cell[0] || ch !== cell[1]) { + lines[yi][xi][0] = attr; + lines[yi][xi][1] = ch; + lines[yi].dirty = true; + } } } if (this.border) { yi_--, yl++, xi_--, xl++; - if (this.border.type === 'bg') ch = this.border.ch; 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; } - if (!this.screen.setCell(yi, xi, battr, ch)) break; } yi = yi_ + 1; - if (this.border.type === 'ascii') ch = '│'; for (; yi < yl; yi++) { - if (!this.screen.setCell(yi, xi_, battr, ch)) break; - if (!this.screen.setCell(yi, xl - 1, battr, ch)) break; + 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; } - if (!this.screen.setCell(yi, xi, battr, ch)) break; } }