update files

This commit is contained in:
nuintun 2015-12-02 12:20:06 +08:00
parent b1179a94fa
commit 6b58997ec1
2 changed files with 25 additions and 2 deletions

View File

@ -94,7 +94,7 @@
].forEach(function (line){ xterm.write(line + '\r\n'); });
xterm.write('\033[41;32m红底绿字\033[0m');
xterm.toString('html');
console.log(xterm.toString('html'));
</script>
</body>
</html>

View File

@ -1031,6 +1031,7 @@ AnsiTerminal.prototype.toString = function (type){
if (type === 'html') {
var styleBuffer;
var attrCache = null;
var stylesBuffer = this.stylesBuffer || [];
stylesBuffer = stylesBuffer.slice(0, rows);
@ -1039,9 +1040,12 @@ AnsiTerminal.prototype.toString = function (type){
stylesBuffer[i] = stylesBuffer[i] || [];
cols = this.screen.buffer[i].cells.length;
s += '<div>';
for (j = 0; j < cols; ++j) {
node = this.screen.buffer[i].cells[j];
styleBuffer = stylesBuffer[i][j] || styles(node);
attrCache = j === 0 ? null : attrCache;
if (styleBuffer.value !== node.value || styleBuffer.attr !== node.attr) {
stylesBuffer[i][j] = styles(node);
@ -1050,9 +1054,28 @@ AnsiTerminal.prototype.toString = function (type){
}
if (node.value) {
console.log(node.value, ': ', stylesBuffer[i][j]);
if (attrCache !== null && node.attr === attrCache) {
s += node.value;
} else {
if (attrCache === null) {
s += '<span>';
} else {
s += node.value;
if (j === cols - 1) {
s += '</span>';
} else {
s += '</span><span>';
}
}
attrCache = node.attr;
}
}
}
s += '</div>';
}
this.stylesBuffer = stylesBuffer;