Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ANSI inverse #2967

Merged
merged 3 commits into from
Nov 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 60 additions & 46 deletions notebook/static/base/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,59 @@ define([
"ansi-white-intense",
];

function _pushColoredChunk(chunk, fg, bg, bold, underline, inverse, out) {
if (chunk) {
var classes = [];
var styles = [];

if (bold && typeof fg === "number" && 0 <= fg && fg < 8) {
fg += 8; // Bold text uses "intense" colors
}
if (inverse) {
[fg, bg] = [bg, fg];
}

if (typeof fg === "number") {
classes.push(_ANSI_COLORS[fg] + "-fg");
} else if (fg.length) {
styles.push("color: rgb(" + fg + ")");
} else if (inverse) {
classes.push("ansi-default-inverse-fg");
}

if (typeof bg === "number") {
classes.push(_ANSI_COLORS[bg] + "-bg");
} else if (bg.length) {
styles.push("background-color: rgb(" + bg + ")");
} else if (inverse) {
classes.push("ansi-default-inverse-bg");
}

if (bold) {
classes.push("ansi-bold");
}

if (underline) {
classes.push("ansi-underline");
}

if (classes.length || styles.length) {
out.push("<span");
if (classes.length) {
out.push(' class="' + classes.join(" ") + '"');
}
if (styles.length) {
out.push(' style="' + styles.join("; ") + '"');
}
out.push(">");
out.push(chunk);
out.push("</span>");
} else {
out.push(chunk);
}
}
}

function _getExtendedColors(numbers) {
var r, g, b;
var n = numbers.shift();
Expand Down Expand Up @@ -309,52 +362,7 @@ define([
// Ignored: Not a color code
}
var chunk = str.substring(start, match.index);
if (chunk) {
if (bold && typeof fg === "number" && 0 <= fg && fg < 8) {
fg += 8; // Bold text uses "intense" colors
}
var classes = [];
var styles = [];

if (typeof fg === "number") {
classes.push(_ANSI_COLORS[fg] + "-fg");
} else if (fg.length) {
styles.push("color: rgb(" + fg + ")");
}

if (typeof bg === "number") {
classes.push(_ANSI_COLORS[bg] + "-bg");
} else if (bg.length) {
styles.push("background-color: rgb(" + bg + ")");
}

if (bold) {
classes.push("ansi-bold");
}

if (underline) {
classes.push("ansi-underline");
}

if (inverse) {
classes.push("ansi-inverse");
}

if (classes.length || styles.length) {
out.push("<span");
if (classes.length) {
out.push(' class="' + classes.join(" ") + '"');
}
if (styles.length) {
out.push(' style="' + styles.join("; ") + '"');
}
out.push(">");
out.push(chunk);
out.push("</span>");
} else {
out.push(chunk);
}
}
_pushColoredChunk(chunk, fg, bg, bold, underline, inverse, out);
start = ansi_re.lastIndex;

while (numbers.length) {
Expand All @@ -380,6 +388,12 @@ define([
case 22:
bold = false;
break;
case 24:
underline = false;
break;
case 27:
inverse = false;
break;
case 30:
case 31:
case 32:
Expand Down
5 changes: 4 additions & 1 deletion notebook/static/notebook/less/ansicolors.less
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
.ansicolors(cyan, #60C6C8, #258F8F);
.ansicolors(white, #C5C1B4, #A1A6B2);

.ansi-default-inverse-fg { color: #FFFFFF; }
.ansi-default-inverse-bg { background-color: #000000; }

.ansi-bold { font-weight: bold; }
.ansi-underline { text-decoration: underline; }
.ansi-inverse { outline: 0.5px dotted; }

/* The following styles are deprecated an will be removed in a future version */

.ansibold {font-weight: bold;}
.ansi-inverse { outline: 0.5px dotted; }

/* use dark versions for foreground, to improve visibility */
.ansiblack {color: black;}
Expand Down