How to use the ansi2html.style function in ansi2html

To help you get started, we’ve selected a few ansi2html examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jhrmnn / knitj / knitj / convert.py View on Github external
def render_index(
    title: str, cells: str, client: bool = True, template: Path = None
) -> str:
    if template:
        index = template.read_text()
    else:
        index = resource_string('knitj', 'client/templates/index.html').decode()
    templ = jinja2.Template(index)
    styles = '\n'.join(
        chain(
            [HtmlFormatter(style=get_style_by_name('trac')).get_style_defs()],
            map(str, ansi2html.style.get_styles()),
        )
    )
    return templ.render(title=title, cells=cells, styles=styles, client=client)
github wookayin / gpustat-web / gpustat_web / app.py View on Github external
name_length = max(len(host) for host in hosts)

    # launch all clients parallel
    await asyncio.gather(*[
        run_client(host, exec_cmd, verbose=verbose, name_length=name_length) for host in hosts
    ])


###############################################################################
# webserver handlers.
###############################################################################

# monkey-patch ansi2html scheme. TODO: better color codes
import ansi2html
scheme = 'solarized'
ansi2html.style.SCHEME[scheme] = list(ansi2html.style.SCHEME[scheme])
ansi2html.style.SCHEME[scheme][0] = '#555555'
ansi_conv = ansi2html.Ansi2HTMLConverter(dark_bg=True, scheme=scheme)


def render_gpustat_body():
    body = ''
    for host, status in context.host_status.items():
        if not status:
            continue
        body += status
    return ansi_conv.convert(body, full=False)


async def handler(request):
    '''Renders the html page.'''