Proper rendering of inverse data in default colors

Fix #57
This commit is contained in:
Paris
2016-05-30 16:03:26 +00:00
parent ff7d0e58dc
commit 1a3846161a
+42 -17
View File
@@ -968,6 +968,17 @@
};
/**
* Flags used to render terminal text properly
*/
Terminal.flags = {
BOLD: 0b00001,
UNDERLINE: 0b00010,
BLINK: 0b00100,
INVERSE: 0b01000,
INVISIBLE: 0b10000
}
/*
* Rendering Engine
*
@@ -1035,8 +1046,7 @@
fg = (data >> 9) & 0x1ff;
flags = data >> 18;
// bold
if (flags & 1) {
if (flags & Terminal.flags.BOLD) {
if (!Terminal.brokenBold) {
out += ' xterm-bold ';
}
@@ -1044,35 +1054,50 @@
if (fg < 8) fg += 8;
}
// underline
if (flags & 2) {
if (flags & Terminal.flags.UNDERLINE) {
out += ' xterm-underline ';
}
// blink
if (flags & 4) {
if (flags & Terminal.flags.BLINK) {
out += ' xterm-blink ';
}
// inverse
if (flags & 8) {
bg = (data >> 9) & 0x1ff;
fg = data & 0x1ff;
// Should inverse just be before the
// above boldColors effect instead?
if ((flags & 1) && fg < 8) fg += 8;
/**
* If inverse flag is on, then swap the foreground and background variables.
*/
if (flags & Terminal.flags.INVERSE) {
/* One-line variable swap in JavaScript: http://stackoverflow.com/a/16201730 */
bg = [fg, fg = bg][0];
// Should inverse just be before the
// above boldColors effect instead?
if ((flags & 1) && fg < 8) fg += 8;
}
// invisible
if (flags & 16) {
if (flags & Terminal.flags.INVISIBLE) {
out += ' xterm-hidden ';
}
if (bg !== 256) {
/**
* Weird situation: Invert flag used black foreground and white background results
* in invalid background color, positioned at the 256 index of the 256 terminal
* color map. Pin the colors manually in such a case.
*
* Source: https://github.com/sourcelair/xterm.js/issues/57
*/
if (flags & Terminal.flags.INVERSE) {
if (bg == 257) {
bg = 15;
}
if (fg == 256) {
fg = 0;
}
}
if (bg < 256) {
out += ' xterm-bg-color-' + bg + ' ';
}
if (fg !== 257) {
if (fg < 256) {
out += ' xterm-color-' + fg + ' ';
}