Skip to content

html

html #

html — a log as a static tree of <details>, and the assets a live renderer needs.

The fragment carries its own stylesheet, so it reads the same in a notebook cell, a stored page and an email. script is the browser side of the same picture: it builds the identical tree from the JSON entries and upserts them as they stream in. error is the one way an error is shown, in the tree or beside it: the text with a button that copies it. An entry's kind picks how its message reads: prose, a shell command as code, or a program's output as a terminal block with its ANSI colours (ansi_html).

error(text) #

text as an error block with a button that copies it to the clipboard.

Source code in capturegraph-ui/capturegraph_ui/log/html.py
def error(text: str) -> str:
    """``text`` as an error block with a button that copies it to the clipboard."""
    return (
        f'<div class="cg-error"><button type="button" onclick="{escape(_COPY)}">Copy</button>'
        f"<pre>{escape(text)}</pre></div>"
    )

html(log) #

log as one self-contained fragment.

Source code in capturegraph-ui/capturegraph_ui/log/html.py
def html(log: cg.logging.Log) -> str:
    """``log`` as one self-contained fragment."""
    return f'<div class="cg-log"><style>{stylesheet()}</style>{_children(log, log.root, 0)}</div>'

script() #

The browser renderer: window.cgLog.mount(container, entries) and upsert.

Source code in capturegraph-ui/capturegraph_ui/log/html.py
def script() -> str:
    """The browser renderer: ``window.cgLog.mount(container, entries)`` and ``upsert``."""
    return _asset("log.js")

stale(entry, parent) #

Whether entry was last logged in an earlier iteration than parent is on.

Source code in capturegraph-ui/capturegraph_ui/log/html.py
def stale(entry: cg.logging.Entry, parent: cg.logging.Entry) -> bool:
    """Whether ``entry`` was last logged in an earlier iteration than ``parent`` is on."""
    return (
        entry.iteration is not None
        and parent.iteration is not None
        and entry.iteration < parent.iteration
    )

stylesheet() #

The stylesheet every rendering of a log shares.

Source code in capturegraph-ui/capturegraph_ui/log/html.py
def stylesheet() -> str:
    """The stylesheet every rendering of a log shares."""
    return _asset("log.css")