diff --git a/lib/widget.js b/lib/widget.js index 020d29e..d9bf83a 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -540,6 +540,19 @@ 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 */ @@ -1073,9 +1086,6 @@ 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; @@ -1098,85 +1108,41 @@ outer: if (ch === '\n' || ch === '\r') { ch = ' '; for (; xi < xl; xi++) { - 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; - } + if (!this.screen.setCell(yi, xi, attr, ch)) break; } continue; } - if (attr !== cell[0] || ch !== cell[1]) { - lines[yi][xi][0] = attr; - lines[yi][xi][1] = ch; - lines[yi].dirty = true; - } + if (!this.screen.setCell(yi, xi, attr, ch)) break; } } 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 (!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; - } + if (!this.screen.setCell(yi, xi_, battr, ch)) break; + if (!this.screen.setCell(yi, xl - 1, battr, ch)) break; } 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; } }