How to use the ansi2html.converter 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 elad661 / curlbus / curlbus / server.py View on Github external
from aiohttp import web
from aiohttp import client_exceptions
from gino.ext.aiohttp import Gino
from .operators import operators, operators_by_id, operator_names, operator_logos
from .render import render_station_arrivals, render_operator_index, render_route_alternatives, render_route_map, render_station_list
from .siri import SIRIClient
from .gtfs.utils import (get_stop_info, get_routes, get_route_route,
                         get_arrival_gtfs_info, translate_route_name,
                         count_routes, get_rail_stations, get_nearby_stops)
from .gtfs import model as gtfs_model
from .html import html_template, relative_linkify
from aiocache import SimpleMemoryCache
import os.path
import ansi2html
# monkey-patch ansi2html to get a more modern HTML document structure and a footer
ansi2html.converter._html_template = html_template
ansi2html.converter.linkify = relative_linkify
CACHE_TTL = 30
ANSI_RESET = "\033[0m\033[39m\033[49m"


def parse_accept_header(request):
    """ Returns `json`, `html`, or `text` according to the accept header """
    # This doesn't care for priorities, it'll take the first guess
    accept = request.headers.getall('ACCEPT', [])
    for item in accept:
        for sub_item in item.lower().split(','):
            if "text/html" in sub_item:
                return 'html'
            if "application/json" in sub_item:
                return 'json'
            if "*/*" in sub_item:
github svn2github / chromium-depot-tools / man / src / filter_demo_output.py View on Github external
def main():
  ansi2html.converter.SCHEME['custom'] = (
      "#000000", "#e42e16", "#19c518", "#e7e71c", "#492ee1",
      "#d338d3", "#33d6e5", "#ffffff",
  )

  backend = sys.argv[1]
  output = sys.stdin.read().rstrip()

  callout_re = re.compile('\x1b\[(\d+)c\n')
  callouts = collections.defaultdict(int)
  for i, line in enumerate(output.splitlines(True)):
    m = callout_re.match(line)
    if m:
      callouts[i + int(m.group(1)) - len(callouts)] += 1

  output = callout_re.sub('', output)