mirror of
https://github.com/nuintun/command-manager.git
synced 2025-06-07 19:44:35 +08:00
update files
This commit is contained in:
parent
5866d94577
commit
84c3f92511
@ -81,7 +81,7 @@
|
|||||||
' \u001b[36;1mgulp-cmd \u001b[0mconcat: \u001b[35mAssets/js/util/ztree/3.5.0/css/img/diy/8.png\u001b[39m ...ok\u001b[36m +0ms\u001b[0m\r\n'
|
' \u001b[36;1mgulp-cmd \u001b[0mconcat: \u001b[35mAssets/js/util/ztree/3.5.0/css/img/diy/8.png\u001b[39m ...ok\u001b[36m +0ms\u001b[0m\r\n'
|
||||||
].forEach(function (line){ xterm.write(line + '\n'); });
|
].forEach(function (line){ xterm.write(line + '\n'); });
|
||||||
|
|
||||||
xterm.write('\033[41;32m红底绿字\033[0m\r\n' + new Date().toISOString());
|
xterm.write('\033[4;41;32m红底绿字\033[0m\r\n' + new Date().toISOString());
|
||||||
|
|
||||||
document.getElementById('term').innerHTML = xterm.toString('html');
|
document.getElementById('term').innerHTML = xterm.toString('html');
|
||||||
|
|
||||||
@ -92,9 +92,11 @@
|
|||||||
|
|
||||||
var canvasXTerm = new CanvasXTerm();
|
var canvasXTerm = new CanvasXTerm();
|
||||||
|
|
||||||
canvasXTerm.draw(xterm.stylesBuffer);
|
canvasXTerm.draw(xterm.getStyles());
|
||||||
|
|
||||||
console.log(canvasXTerm.canvas);
|
console.log(canvasXTerm.canvas);
|
||||||
|
|
||||||
|
document.getElementById('term').appendChild(canvasXTerm.canvas);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -13,15 +13,11 @@ function textRepeat(text, n){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function CanvasXTerm(font){
|
function CanvasXTerm(font){
|
||||||
this.font = font || { family: 'Consolas', lineHeight: 20, size: 13, color: '#fff' };
|
this.font = font || { family: 'Consolas', lineHeight: 23, size: 14, color: '#fff' };
|
||||||
this.canvas = document.createElement('canvas');
|
this.canvas = document.createElement('canvas');
|
||||||
this.canvas.style.backgroundColor = 'transparent';
|
this.canvas.style.backgroundColor = 'transparent';
|
||||||
this.brush = this.canvas.getContext('2d');
|
this.brush = this.canvas.getContext('2d');
|
||||||
this.brush.textAlign = 'start';
|
this.baseY = this.font.lineHeight / 2;
|
||||||
this.brush.textBaseline = 'bottom';
|
|
||||||
this.brush.font = this.font + ' ' + this.fontSize;
|
|
||||||
this.brush.fillStyle = this.font.color;
|
|
||||||
this.baseY = (this.font.lineHeight + this.font.size) / 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CanvasXTerm.prototype = {
|
CanvasXTerm.prototype = {
|
||||||
@ -37,7 +33,7 @@ CanvasXTerm.prototype = {
|
|||||||
|
|
||||||
this.canvas.width = this.measureWidth(
|
this.canvas.width = this.measureWidth(
|
||||||
textRepeat('A', cols),
|
textRepeat('A', cols),
|
||||||
'italic bold ' + ' ' + this.font.size + 'px' + this.font.family
|
'italic bold ' + this.font.size + 'px ' + this.font.family
|
||||||
);
|
);
|
||||||
|
|
||||||
this.canvas.height = rows * this.font.lineHeight;
|
this.canvas.height = rows * this.font.lineHeight;
|
||||||
@ -46,39 +42,40 @@ CanvasXTerm.prototype = {
|
|||||||
for (i = 0; i < rows; i++) {
|
for (i = 0; i < rows; i++) {
|
||||||
x = 0;
|
x = 0;
|
||||||
y = i * 20 + this.baseY;
|
y = i * 20 + this.baseY;
|
||||||
text = '';
|
|
||||||
|
|
||||||
for (j = 0; j < cols; j++) {
|
for (j = 0; j < cols; j++) {
|
||||||
node = screen[i][j];
|
node = screen[i][j];
|
||||||
|
|
||||||
//if (j = 0) {
|
if (j === 0) {
|
||||||
// attrCache = node.attr;
|
text = '';
|
||||||
// stylesCache = this.getStyles(node);
|
attrCache = node.attr;
|
||||||
//}
|
stylesCache = this.getStyles(node);
|
||||||
//
|
}
|
||||||
//if (node.value) {
|
|
||||||
// if (node.attr !== attrCache) {
|
if (node.value) {
|
||||||
// x = this.drawText(text, x, y, this.getStyles(stylesCache)).x;
|
if (node.attr !== attrCache) {
|
||||||
// attrCache = node.attr;
|
x = this.drawText(text, x, y, this.getStyles(stylesCache)).x;
|
||||||
// stylesCache = this.getStyles(node);
|
text = '';
|
||||||
// }
|
attrCache = node.attr;
|
||||||
//
|
stylesCache = this.getStyles(node);
|
||||||
// text += node.value;
|
}
|
||||||
//}
|
|
||||||
|
text += node.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//this.drawText(text, x, y, this.getStyles(stylesCache));
|
this.drawText(text, x, y, this.getStyles(stylesCache));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getStyles: function (node){
|
getStyles: function (node){
|
||||||
var styles = {};
|
var styles = {};
|
||||||
|
|
||||||
if (node.background) {
|
if (node.background) {
|
||||||
styles.background = background;
|
styles.background = node.background;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.foreground) {
|
if (node.foreground) {
|
||||||
styles.foreground = foreground;
|
styles.foreground = node.foreground;
|
||||||
} else {
|
} else {
|
||||||
styles.foreground = this.font.color;
|
styles.foreground = this.font.color;
|
||||||
}
|
}
|
||||||
@ -94,32 +91,34 @@ CanvasXTerm.prototype = {
|
|||||||
return styles;
|
return styles;
|
||||||
},
|
},
|
||||||
drawText: function (text, x, y, styles){
|
drawText: function (text, x, y, styles){
|
||||||
var font = styles.italic ? 'italic' : 'normal'
|
var font = (styles.italic ? 'italic ' : 'normal ')
|
||||||
+ ' ' + styles.bold ? 'bold' : 'normal'
|
+ (styles.bold ? 'bold ' : 'normal ')
|
||||||
+ ' ' + this.font.size + 'px'
|
+ this.font.size + 'px '
|
||||||
+ ' ' + this.font.family;
|
+ this.font.family;
|
||||||
|
|
||||||
var width = this.measureWidth(text, font);
|
var width = this.measureWidth(text, font);
|
||||||
|
|
||||||
if (styles.background) {
|
if (styles.background) {
|
||||||
this.brush.save();
|
this.brush.save();
|
||||||
|
|
||||||
this.fillStyle = styles.background;
|
this.brush.fillStyle = styles.background;
|
||||||
|
|
||||||
this.brush.fillRect(x, y - this.font.size, width, this.font.size);
|
this.brush.fillRect(x, y - this.font.size / 2, width, this.font.size);
|
||||||
this.brush.restore();
|
this.brush.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.brush.save();
|
this.brush.save();
|
||||||
|
|
||||||
this.font = font;
|
this.brush.font = font;
|
||||||
this.brush.fillStyle = styles.foreground;
|
this.brush.fillStyle = styles.foreground;
|
||||||
|
this.brush.textAlign = 'start';
|
||||||
|
this.brush.textBaseline = 'middle';
|
||||||
|
|
||||||
this.fillText(text, x, y);
|
this.brush.fillText(text, x, y);
|
||||||
this.brush.restore();
|
this.brush.restore();
|
||||||
|
|
||||||
if (styles.underline) {
|
if (styles.underline) {
|
||||||
underline.call(this.brush, x, x + width, y, styles.foreground);
|
underline(this.brush, x, x + width, y + this.font.size / 2, styles.foreground);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -140,14 +139,14 @@ CanvasXTerm.prototype = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function underline(fromX, toX, Y, foreground){
|
function underline(brush, fromX, toX, Y, foreground){
|
||||||
this.save();
|
brush.save();
|
||||||
this.translate(0, parseInt(Y) === Y ? 0 : 0.5);
|
brush.translate(0, parseInt(Y) === Y ? 0.5 : 0);
|
||||||
this.lineWidth = 1;
|
brush.lineWidth = 1;
|
||||||
this.strokeStyle = foreground;
|
brush.strokeStyle = foreground;
|
||||||
this.beginPath();
|
brush.beginPath();
|
||||||
this.moveTo(fromX, Y);
|
brush.moveTo(fromX, Y);
|
||||||
this.lineTo(toX, Y);
|
brush.lineTo(toX, Y);
|
||||||
this.stroke();
|
brush.stroke();
|
||||||
this.restore();
|
brush.restore();
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user