display

Provide some helpers to get formatted data back to the kernel. Most people will probably just use the templates, the procs are implementations.

Types

DisplayKind = enum
  dkPng, dkPlot, dkFile, dkTextFile, dkImageFile, dkHtml
Kind of data to be shown

Procs

proc showBinaryFile(what: string): JsonNode {...}{.raises: [IOError], tags: [ReadIOEffect].}
For dkFile. Reads the file to a string and encode it as base64.
proc showImgFile(what: string; w: int = 480; h: int = 320): JsonNode {...}{.raises: [IOError],
    tags: [ReadIOEffect].}
For dkImageFile. Reads the file to a string and encode it as base64. Can set width and height of the output.
proc showTextFile(what: string): JsonNode {...}{.raises: [IOError], tags: [ReadIOEffect].}
For dkTextFile. Reads the file to a string and tries to match it with a mimetype by the extension. Since mimetype support varies by jupyter frontend, the plain text is also sent back.
proc showInMemPng(what: PNG[string]; w: int = 480; h: int = 320): JsonNode {...}{.
    raises: [IOError, OSError, PNGError, NZError],
    tags: [WriteIOEffect, ReadIOEffect].}
For dkPng. Encode a png loaded from nimPNG in memory.
proc showBase64StringPng(what: string; w: int = 480; h: int = 320): JsonNode {...}{.raises: [],
    tags: [].}
For dkPlot. Expects what to be an already base64-encoded png.
proc showHtml(what: string): JsonNode {...}{.raises: [], tags: [].}

Templates

template show(kind: DisplayKind; size: array[2, int]; what: untyped)
Send back something to display. Also expects an array with [width, height] values.
template show(kind: DisplayKind; what: untyped)
Send back something to display.
template latex(str: varargs[string, `$`])
Send back a string as latex expression to display. Wraps the string in $$. Remember to escape \. Mimics echo so eg. latex "x =", x works.
template md(str: varargs[string, `$`])
Send back a string as markdown to display. Can use it instead of echo.
template html(str: varargs[string, `$`])
Send back a string as html to display. Can use it instead of echo.