Top

goulash.ansi module

goulash.ansi

""" goulash.ansi
"""

from ansi2html.style import get_styles
from ansi2html import Ansi2HTMLConverter as _Ansi2HTMLConverter

class Ansi2HTMLConverter(_Ansi2HTMLConverter):
    """ Subclassed from ansi2html.Ans2HTMLConverter to prevent
        every convert() call redundantly rendering the style
    """
    def get_style(self):
        return ''

    def convert(self, *args, **kargs):
        kargs.update(full=False)
        return super(Ansi2HTMLConverter, self).convert(*args, **kargs)
Ansi2HtmlConverter=Ansi2HTMLConverter

Classes

class Ansi2HTMLConverter

Subclassed from ansi2html.Ans2HTMLConverter to prevent every convert() call redundantly rendering the style

class Ansi2HTMLConverter(_Ansi2HTMLConverter):
    """ Subclassed from ansi2html.Ans2HTMLConverter to prevent
        every convert() call redundantly rendering the style
    """
    def get_style(self):
        return ''

    def convert(self, *args, **kargs):
        kargs.update(full=False)
        return super(Ansi2HTMLConverter, self).convert(*args, **kargs)

Ancestors (in MRO)

Methods

def __init__(

self, latex=False, inline=False, dark_bg=True, font_size='normal', linkify=False, escaped=True, markup_lines=False, output_encoding='utf-8', scheme='ansi2html', title='')

def __init__(self,
             latex=False,
             inline=False,
             dark_bg=True,
             font_size='normal',
             linkify=False,
             escaped=True,
             markup_lines=False,
             output_encoding='utf-8',
             scheme='ansi2html',
             title=''
            ):
    self.latex = latex
    self.inline = inline
    self.dark_bg = dark_bg
    self.font_size = font_size
    self.linkify = linkify
    self.escaped = escaped
    self.markup_lines = markup_lines
    self.output_encoding = output_encoding
    self.scheme = scheme
    self.title = title
    self._attrs = None
    if inline:
        self.styles = dict([(item.klass.strip('.'), item) for item in get_styles(self.dark_bg, self.scheme)])
    self.ansi_codes_prog = re.compile('\033\\[' '([\\d;]*)' '([a-zA-z])')

def apply_regex(

self, ansi)

def apply_regex(self, ansi):
    parts = self._apply_regex(ansi)
    parts = self._collapse_cursor(parts)
    parts = list(parts)
    if self.linkify:
        parts = [linkify(part, self.latex) for part in parts]
    combined = "".join(parts)
    if self.markup_lines and not self.latex:
        combined = "\n".join([
            """%s""" % (i, line)
            for i, line in enumerate(combined.split('\n'))
        ])
    return combined

def attrs(

self)

Prepare attributes for the template

def attrs(self):
    """ Prepare attributes for the template """
    if not self._attrs:
        raise Exception("Method .prepare not yet called.")
    return self._attrs

def convert(

self, *args, **kargs)

def convert(self, *args, **kargs):
    kargs.update(full=False)
    return super(Ansi2HTMLConverter, self).convert(*args, **kargs)

def get_style(

self)

def get_style(self):
    return ''

def prepare(

self, ansi='', ensure_trailing_newline=False)

Load the contents of 'ansi' into this object

def prepare(self, ansi='', ensure_trailing_newline=False):
    """ Load the contents of 'ansi' into this object """
    body = self.apply_regex(ansi)
    if ensure_trailing_newline and _needs_extra_newline(body):
        body += '\n'
    self._attrs = {
        'dark_bg': self.dark_bg,
        'font_size': self.font_size,
        'body': body,
    }
    return self._attrs

def produce_headers(

self)

def produce_headers(self):
    return '\n' % {
        'style' : "\n".join(map(str, get_styles(self.dark_bg, self.scheme)))
    }

class Ansi2HtmlConverter

Subclassed from ansi2html.Ans2HTMLConverter to prevent every convert() call redundantly rendering the style

class Ansi2HTMLConverter(_Ansi2HTMLConverter):
    """ Subclassed from ansi2html.Ans2HTMLConverter to prevent
        every convert() call redundantly rendering the style
    """
    def get_style(self):
        return ''

    def convert(self, *args, **kargs):
        kargs.update(full=False)
        return super(Ansi2HTMLConverter, self).convert(*args, **kargs)

Ancestors (in MRO)

Methods

def __init__(

self, latex=False, inline=False, dark_bg=True, font_size='normal', linkify=False, escaped=True, markup_lines=False, output_encoding='utf-8', scheme='ansi2html', title='')

Inheritance: Ansi2HTMLConverter.__init__

def __init__(self,
             latex=False,
             inline=False,
             dark_bg=True,
             font_size='normal',
             linkify=False,
             escaped=True,
             markup_lines=False,
             output_encoding='utf-8',
             scheme='ansi2html',
             title=''
            ):
    self.latex = latex
    self.inline = inline
    self.dark_bg = dark_bg
    self.font_size = font_size
    self.linkify = linkify
    self.escaped = escaped
    self.markup_lines = markup_lines
    self.output_encoding = output_encoding
    self.scheme = scheme
    self.title = title
    self._attrs = None
    if inline:
        self.styles = dict([(item.klass.strip('.'), item) for item in get_styles(self.dark_bg, self.scheme)])
    self.ansi_codes_prog = re.compile('\033\\[' '([\\d;]*)' '([a-zA-z])')

def apply_regex(

self, ansi)

Inheritance: Ansi2HTMLConverter.apply_regex

def apply_regex(self, ansi):
    parts = self._apply_regex(ansi)
    parts = self._collapse_cursor(parts)
    parts = list(parts)
    if self.linkify:
        parts = [linkify(part, self.latex) for part in parts]
    combined = "".join(parts)
    if self.markup_lines and not self.latex:
        combined = "\n".join([
            """%s""" % (i, line)
            for i, line in enumerate(combined.split('\n'))
        ])
    return combined

def attrs(

self)

Inheritance: Ansi2HTMLConverter.attrs

Prepare attributes for the template

def attrs(self):
    """ Prepare attributes for the template """
    if not self._attrs:
        raise Exception("Method .prepare not yet called.")
    return self._attrs

def convert(

self, *args, **kargs)

Inheritance: Ansi2HTMLConverter.convert

def convert(self, *args, **kargs):
    kargs.update(full=False)
    return super(Ansi2HTMLConverter, self).convert(*args, **kargs)

def get_style(

self)

Inheritance: Ansi2HTMLConverter.get_style

def get_style(self):
    return ''

def prepare(

self, ansi='', ensure_trailing_newline=False)

Inheritance: Ansi2HTMLConverter.prepare

Load the contents of 'ansi' into this object

def prepare(self, ansi='', ensure_trailing_newline=False):
    """ Load the contents of 'ansi' into this object """
    body = self.apply_regex(ansi)
    if ensure_trailing_newline and _needs_extra_newline(body):
        body += '\n'
    self._attrs = {
        'dark_bg': self.dark_bg,
        'font_size': self.font_size,
        'body': body,
    }
    return self._attrs

def produce_headers(

self)

Inheritance: Ansi2HTMLConverter.produce_headers

def produce_headers(self):
    return '\n' % {
        'style' : "\n".join(map(str, get_styles(self.dark_bg, self.scheme)))
    }