Skip to content

Commit

Permalink
Tweak updated display style (#372)
Browse files Browse the repository at this point in the history
For things to look better in nteract in particular.
  • Loading branch information
alexarchambault authored May 20, 2019
1 parent bb3848e commit 6762203
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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\"");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 6762203

Please sign in to comment.