setCell function.

This commit is contained in:
Christopher Jeffrey 2013-06-13 14:57:46 -05:00
parent 1c6681e99d
commit 34b7520c44

View File

@ -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 * Element
*/ */
@ -1073,9 +1086,6 @@ outer:
for (yi = yi_; yi < yl; yi++) { for (yi = yi_; yi < yl; yi++) {
if (!lines[yi]) break; if (!lines[yi]) break;
for (xi = xi_; xi < xl; xi++) { for (xi = xi_; xi < xl; xi++) {
cell = lines[yi][xi];
if (!cell) break;
if (this.shrink && !content[ci] && yi === yi_) { if (this.shrink && !content[ci] && yi === yi_) {
xl = xi + 1 - 1; xl = xi + 1 - 1;
break outer; break outer;
@ -1098,85 +1108,41 @@ outer:
if (ch === '\n' || ch === '\r') { if (ch === '\n' || ch === '\r') {
ch = ' '; ch = ' ';
for (; xi < xl; xi++) { for (; xi < xl; xi++) {
cell = lines[yi][xi]; if (!this.screen.setCell(yi, xi, attr, ch)) break;
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; continue;
} }
if (attr !== cell[0] || ch !== cell[1]) { if (!this.screen.setCell(yi, xi, attr, ch)) break;
lines[yi][xi][0] = attr;
lines[yi][xi][1] = ch;
lines[yi].dirty = true;
}
} }
} }
if (this.border) { if (this.border) {
yi_--, yl++, xi_--, xl++; yi_--, yl++, xi_--, xl++;
if (this.border.type === 'bg') ch = this.border.ch;
yi = yi_; yi = yi_;
for (xi = xi_; xi < xl; xi++) { for (xi = xi_; xi < xl; xi++) {
if (!lines[yi]) break;
if (this.border.type === 'ascii') { if (this.border.type === 'ascii') {
if (xi === xi_) ch = '┌'; if (xi === xi_) ch = '┌';
else if (xi === xl - 1) ch = '┐'; else if (xi === xl - 1) ch = '┐';
else 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; yi = yi_ + 1;
if (this.border.type === 'ascii') ch = '│';
for (; yi < yl; yi++) { for (; yi < yl; yi++) {
if (!lines[yi]) break; if (!this.screen.setCell(yi, xi_, battr, ch)) break;
if (this.border.type === 'ascii') { if (!this.screen.setCell(yi, xl - 1, battr, ch)) break;
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; yi = yl - 1;
for (xi = xi_; xi < xl; xi++) { for (xi = xi_; xi < xl; xi++) {
if (!lines[yi]) break;
if (this.border.type === 'ascii') { if (this.border.type === 'ascii') {
if (xi === xi_) ch = '└'; if (xi === xi_) ch = '└';
else if (xi === xl - 1) ch = '┘'; else if (xi === xl - 1) ch = '┘';
else 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;
} }
} }