mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
fix inverse. refactor charAttributes.
This commit is contained in:
@@ -15,6 +15,15 @@ var http = require('http')
|
||||
|
||||
process.title = 'term.js';
|
||||
|
||||
/**
|
||||
* Dump
|
||||
*/
|
||||
|
||||
var stream;
|
||||
if (process.argv[2] === '--dump') {
|
||||
stream = require('fs').createWriteStream(__dirname + '/dump.log');
|
||||
}
|
||||
|
||||
/**
|
||||
* Open Terminal
|
||||
*/
|
||||
@@ -33,6 +42,7 @@ term = pty.fork(process.env.SHELL || 'sh', [], {
|
||||
});
|
||||
|
||||
term.on('data', function(data) {
|
||||
if (stream) stream.write('OUT: ' + data + '\n-\n');
|
||||
return !socket
|
||||
? buff.push(data)
|
||||
: socket.emit('data', data);
|
||||
@@ -100,6 +110,7 @@ io.sockets.on('connection', function(sock) {
|
||||
socket = sock;
|
||||
|
||||
socket.on('data', function(data) {
|
||||
if (stream) stream.write('IN: ' + data + '\n-\n');
|
||||
term.write(data);
|
||||
});
|
||||
|
||||
|
||||
+62
-11
@@ -211,7 +211,8 @@ function Terminal(options) {
|
||||
this.readable = true;
|
||||
this.writable = true;
|
||||
|
||||
this.defAttr = (257 << 9) | 256;
|
||||
this.defAttr = (0 << 18) | (257 << 9) | (256 << 0);
|
||||
// this.defAttr = (0 << 18) | (0x1ff << 9) | (0x1ff << 0);
|
||||
this.curAttr = this.defAttr;
|
||||
|
||||
this.params = [];
|
||||
@@ -996,6 +997,7 @@ Terminal.prototype.refresh = function(start, end) {
|
||||
fgColor = (data >> 9) & 0x1ff;
|
||||
flags = data >> 18;
|
||||
|
||||
// bold
|
||||
if (flags & 1) {
|
||||
if (!Terminal.brokenBold) {
|
||||
out += 'font-weight:bold;';
|
||||
@@ -1004,16 +1006,43 @@ Terminal.prototype.refresh = function(start, end) {
|
||||
if (fgColor < 8) fgColor += 8;
|
||||
}
|
||||
|
||||
// underline
|
||||
if (flags & 2) {
|
||||
out += 'text-decoration:underline;';
|
||||
}
|
||||
|
||||
// blink
|
||||
if (flags & 4) {
|
||||
if (flags & 2) {
|
||||
out = out.slice(0, -1);
|
||||
out += ' blink;';
|
||||
} else {
|
||||
out += 'text-decoration:blink;';
|
||||
}
|
||||
}
|
||||
|
||||
// inverse
|
||||
if (flags & 8) {
|
||||
bgColor = (data >> 9) & 0x1ff;
|
||||
fgColor = data & 0x1ff;
|
||||
// Should inverse just be before the
|
||||
// above boldColors effect instead?
|
||||
if ((flags & 1) && fgColor < 8) fgColor += 8;
|
||||
}
|
||||
|
||||
// invisible
|
||||
if (flags & 16) {
|
||||
out += 'visibility:hidden;';
|
||||
}
|
||||
|
||||
// if (bgColor !== 0x1ff) {
|
||||
if (bgColor !== 256) {
|
||||
out += 'background-color:'
|
||||
+ Terminal.colors[bgColor]
|
||||
+ ';';
|
||||
}
|
||||
|
||||
// if (fgColor !== 0x1ff) {
|
||||
if (fgColor !== 257) {
|
||||
out += 'color:'
|
||||
+ Terminal.colors[fgColor]
|
||||
@@ -2845,6 +2874,12 @@ Terminal.prototype.eraseInLine = function(params) {
|
||||
// Ps = 4 8 ; 5 ; Ps -> Set background color to the second
|
||||
// Ps.
|
||||
Terminal.prototype.charAttributes = function(params) {
|
||||
// Optimize a single SGR0.
|
||||
if (params.length === 1 && params[0] === 0) {
|
||||
this.curAttr = this.defAttr;
|
||||
return;
|
||||
}
|
||||
|
||||
var l = params.length
|
||||
, i = 0
|
||||
, flags = this.curAttr >> 18
|
||||
@@ -2873,30 +2908,40 @@ Terminal.prototype.charAttributes = function(params) {
|
||||
flags = this.defAttr >> 18;
|
||||
fg = (this.defAttr >> 9) & 0x1ff;
|
||||
bg = this.defAttr & 0x1ff;
|
||||
// flags = 0;
|
||||
// fg = 0x1ff;
|
||||
// bg = 0x1ff;
|
||||
} else if (p === 1) {
|
||||
// bold text
|
||||
flags |= 1;
|
||||
} else if (p === 4) {
|
||||
// underlined text
|
||||
flags |= 2;
|
||||
} else if (p === 7 || p === 27) {
|
||||
} else if (p === 5) {
|
||||
// blink
|
||||
flags |= 4;
|
||||
} else if (p === 7) {
|
||||
// inverse and positive
|
||||
// test with: echo -e '\e[31m\e[42mhello\e[7mworld\e[27mhi\e[m'
|
||||
if (p === 7) {
|
||||
if (flags & 4) continue;
|
||||
flags |= 4;
|
||||
} else if (p === 27) {
|
||||
if (~flags & 4) continue;
|
||||
flags &= ~4;
|
||||
}
|
||||
// JAVASCRIPT, Y U NO XOR SWAP?
|
||||
p = bg, bg = fg, fg = p;
|
||||
flags |= 8;
|
||||
} else if (p === 8) {
|
||||
// invisible
|
||||
flags |= 16;
|
||||
} else if (p === 22) {
|
||||
// not bold
|
||||
flags &= ~1;
|
||||
} else if (p === 24) {
|
||||
// not underlined
|
||||
flags &= ~2;
|
||||
} else if (p === 25) {
|
||||
// not blink
|
||||
flags &= ~4;
|
||||
} else if (p === 27) {
|
||||
// not inverse
|
||||
flags &= ~8;
|
||||
} else if (p === 28) {
|
||||
// not invisible
|
||||
flags &= ~16;
|
||||
} else if (p === 39) {
|
||||
// reset fg
|
||||
fg = (this.defAttr >> 9) & 0x1ff;
|
||||
@@ -2933,6 +2978,12 @@ Terminal.prototype.charAttributes = function(params) {
|
||||
p = params[i] & 0xff;
|
||||
bg = p;
|
||||
}
|
||||
} else if (p === 100) {
|
||||
// reset fg/bg
|
||||
fg = (this.defAttr >> 9) & 0x1ff;
|
||||
bg = this.defAttr & 0x1ff;
|
||||
} else {
|
||||
this.error('Unknown SGR attribute: %d.', p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user