Skip to content
Permalink
Browse files

Tweak updated display style (#372)

For things to look better in nteract in particular.
  • Loading branch information...
alexarchambault committed May 20, 2019
1 parent bb3848e commit 67622033816dabc22bd14d61ea0b32733ba07c35
@@ -22,6 +22,8 @@ public void close() throws IOException {

private static final String[] ANSI_COLOR_MAP = {"black", "red",
"green", "yellow", "blue", "magenta", "cyan", "white",};
private static final String[] RGB_COLOR_MAP = {"black", "red",
"rgb(0, 187, 0)", "yellow", "blue", "magenta", "rgb(0, 187, 187)", "white",};

private static final byte[] BYTES_QUOT = """.getBytes();
private static final byte[] BYTES_AMP = "&".getBytes();
@@ -118,11 +120,18 @@ protected void processDefaultTextColor() throws IOException {

@Override
protected void processSetForegroundColor(int color, boolean bright) throws IOException {
// hard-coded color are for nteract (where the ansi-* classes are defined), and it might be useful from nbviewer too
// ansi-* classes are for jupyterlab (and classic too I think)
writeAttribute("span style=\"color: " + RGB_COLOR_MAP[color] + "\"");
writeAttribute("span class=\"ansi-" + ANSI_COLOR_MAP[color] + "-fg\"");
}

@Override
protected void processSetBackgroundColor(int color, boolean bright) throws IOException {
String extra = "";
if (color == 7)
extra = "; color: rgb(255, 255, 255);";
writeAttribute("span style=\"background-color: " + RGB_COLOR_MAP[color] + extra + "\"");
writeAttribute("span class=\"ansi-" + ANSI_COLOR_MAP[color] + "-bg\"");
}
}
@@ -255,7 +255,7 @@ final class Execute(
haos.close()
val html =
s"""<div class="jp-RenderedText">
|<pre>${baos.toString("UTF-8")}</pre>
|<pre><code>${baos.toString("UTF-8")}</code></pre>
|</div>""".stripMargin
log.debug(s"HTML: $html")
val d = r.add(
@@ -45,13 +45,14 @@ final class PrettyPrint private(
"""<style>@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }</style><div style="animation: fadein 2s;">"""
else
""
extra + """<div class="jp-RenderedText"><pre>"""
// pre and div are for jupyterlab, code is for nteract
extra + """<div class="jp-RenderedText"><pre><code>"""
}
private def suffix = {
val extra =
if (fadeIn0) "</div>"
else ""
"</pre></div>" + extra
"</code></pre></div>" + extra
}

private def html: String =

0 comments on commit 6762203

Please sign in to comment.
You can’t perform that action at this time.