예제 #1
0
class ConsoleFormatter(object):
    def __init__(self, stream, theme, tab=8, showgutter=True):
        self._c = Console(stream)
        self._theme = theme
        self._tabstop = u' ' * tab
        self._lineno = 1

        self._showgutter = showgutter
        self._gutter = (
            Color(theme.gutter[u'foreground']), 
            Color(theme.gutter[u'background']), 
            Color(theme.gutter[u'divider'])
        )

    def start_document(self, name):
        theme = self._theme.theme_for_scope(u'')
        fg = Color(theme[u'foreground'])
        bg = Color(theme[u'background'])
        self._c.pset(fg=fg, bg=bg).clear_line()
        self.gutter()

    def end_document(self):
        self._c.pop()
        self._c.reset().write(u'\n')

    def start_scope(self, name, off, line):
        theme = self._theme.theme_for_scope(name)
        fg = None
        if u'foreground' in theme:
            fg = Color(theme[u'foreground'])
        bg = None
        if u'background' in theme:
            bg = Color(theme[u'background'])
        self._c.pset(fg=fg, bg=bg)

    def end_scope(self, off, line):
        self._c.pop()

    def characters(self, str):
        last = 0
        str = str.replace(u'\t', self._tabstop)
        idx = str.find('\n', last)
        while idx != -1:
            self._c.write(str[last:idx+1])
            self._c.clear_line()
            self.gutter()
            last = idx+1
            idx = str.find(u'\n', last)
        self._c.write(str[last:])

    def gutter(self):
        if self._showgutter == True:
            self._c.pset(fg=self._gutter[0], bg=self._gutter[1])
            self._c.write(u'%4u' % self._lineno).set(fg=self._gutter[2]).write(u'│')
            self._c.pop().write(u' ')
        self._lineno += 1
예제 #2
0
class ConsoleFormatter(object):
    def __init__(self, stream, theme, tab=8, showgutter=True):
        self._c = Console(stream)
        self._theme = theme
        self._tabstop = u' ' * tab
        self._lineno = 1

        self._showgutter = showgutter
        self._gutter = (Color(theme.gutter[u'foreground']),
                        Color(theme.gutter[u'background']),
                        Color(theme.gutter[u'divider']))

    def start_document(self, name):
        theme = self._theme.theme_for_scope(u'')
        fg = Color(theme[u'foreground'])
        bg = Color(theme[u'background'])
        self._c.pset(fg=fg, bg=bg).clear_line()
        self.gutter()

    def end_document(self):
        self._c.pop()
        self._c.reset().write(u'\n')

    def start_scope(self, name, off, line):
        theme = self._theme.theme_for_scope(name)
        fg = None
        if u'foreground' in theme:
            fg = Color(theme[u'foreground'])
        bg = None
        if u'background' in theme:
            bg = Color(theme[u'background'])
        self._c.pset(fg=fg, bg=bg)

    def end_scope(self, off, line):
        self._c.pop()

    def characters(self, str):
        last = 0
        str = str.replace(u'\t', self._tabstop)
        idx = str.find('\n', last)
        while idx != -1:
            self._c.write(str[last:idx + 1])
            self._c.clear_line()
            self.gutter()
            last = idx + 1
            idx = str.find(u'\n', last)
        self._c.write(str[last:])

    def gutter(self):
        if self._showgutter == True:
            self._c.pset(fg=self._gutter[0], bg=self._gutter[1])
            self._c.write(u'%4u' %
                          self._lineno).set(fg=self._gutter[2]).write(u'│')
            self._c.pop().write(u' ')
        self._lineno += 1
예제 #3
0
class DebugFormatter(object):
    def __init__(self, stream, tab=8, theme=None):
        self._stream = stream
        self._c = None
        self._tabstop = u' ' * tab
        self._content = u''
        if theme is not None:
            self._c = Console(sys.stdout)
            self._theme = theme
            self._lineno = 1

            self._gutter = (Color(theme.gutter[u'foreground']),
                            Color(theme.gutter[u'background']),
                            Color(theme.gutter[u'divider']))

    @property
    def content(self):
        return self._content

    def start_document(self, name):
        if self._c is not None:
            theme = self._theme.theme_for_scope(u'')
            fg = Color(theme[u'foreground'])
            bg = Color(theme[u'background'])
            self._c.pset(fg=fg, bg=bg)
            self._c.clear_line()
            self.gutter()
            self._c.write(u'@%s{' % name)
        self._stream.write(u'@%s{' % name)

    def end_document(self):
        if self._c is not None:
            self._c.write(u'}')
            self._c.pop()
            self._c.reset()
            self._c.write(u'\n')
        self._stream.write(u'}')

    def start_scope(self, name, off, line):
        if self._c is not None:
            theme = self._theme.theme_for_scope(name)
            fg = None
            if u'foreground' in theme:
                fg = Color(theme[u'foreground'])
            bg = None
            if u'background' in theme:
                bg = Color(theme[u'background'])
            self._c.pset(fg=fg, bg=bg)
            self._c.write(u'@%s(%u,%u){' % (name, off, line))
        self._stream.write(u'@%s(%u,%u){' % (name, off, line))

    def end_scope(self, off, line):
        if self._c is not None:
            self._c.write(u'}(%u,%u)' % (off, line))
            self._c.pop()
        self._stream.write(u'}(%u,%u)' % (off, line))

    def characters(self, str):
        self._content += str
        last = 0
        str = str.replace(u'\t', self._tabstop)
        idx = str.find('\n', last)
        while idx != -1:
            self._stream.write(str[last:idx + 1])
            if self._c is not None:
                self._c.write(str[last:idx + 1])
                self._c.clear_line()
                self.gutter()
            last = idx + 1
            idx = str.find(u'\n', last)
        self._stream.write(str[last:])
        if self._c is not None:
            self._c.write(str[last:])

    def gutter(self):
        self._c.pset(fg=self._gutter[0], bg=self._gutter[1])
        self._c.write(u'%4u' %
                      self._lineno).set(fg=self._gutter[2]).write(u'│')
        self._c.pop().write(u' ')
        self._lineno += 1
예제 #4
0
class DebugFormatter(object):
    def __init__(self, stream, tab=8, theme=None):
        self._stream = stream
        self._c = None
        self._tabstop = u' ' * tab
        self._content = u''
        if theme is not None:
            self._c = Console(sys.stdout)
            self._theme = theme
            self._lineno = 1

            self._gutter = (
                Color(theme.gutter[u'foreground']), 
                Color(theme.gutter[u'background']), 
                Color(theme.gutter[u'divider'])
            )

    @property
    def content(self):
        return self._content

    def start_document(self, name):
        if self._c is not None:
            theme = self._theme.theme_for_scope(u'')
            fg = Color(theme[u'foreground'])
            bg = Color(theme[u'background'])
            self._c.pset(fg=fg, bg=bg)
            self._c.clear_line()
            self.gutter()
            self._c.write(u'@%s{' % name)
        self._stream.write(u'@%s{' % name)

    def end_document(self):
        if self._c is not None:
            self._c.write(u'}')
            self._c.pop()
            self._c.reset()
            self._c.write(u'\n')
        self._stream.write(u'}')

    def start_scope(self, name, off, line):
        if self._c is not None:
            theme = self._theme.theme_for_scope(name)
            fg = None
            if u'foreground' in theme:
                fg = Color(theme[u'foreground'])
            bg = None
            if u'background' in theme:
                bg = Color(theme[u'background'])
            self._c.pset(fg=fg, bg=bg)
            self._c.write(u'@%s(%u,%u){' % (name, off, line))
        self._stream.write(u'@%s(%u,%u){' % (name, off, line))

    def end_scope(self, off, line):
        if self._c is not None:
            self._c.write(u'}(%u,%u)' % (off, line))
            self._c.pop()
        self._stream.write(u'}(%u,%u)' % (off, line))

    def characters(self, str):
        self._content += str
        last = 0
        str = str.replace(u'\t', self._tabstop)
        idx = str.find('\n', last)
        while idx != -1:
            self._stream.write(str[last:idx+1])
            if self._c is not None:
                self._c.write(str[last:idx+1])
                self._c.clear_line()
                self.gutter()
            last = idx+1
            idx = str.find(u'\n', last)
        self._stream.write(str[last:])
        if self._c is not None:
            self._c.write(str[last:])

    def gutter(self):
        self._c.pset(fg=self._gutter[0], bg=self._gutter[1])
        self._c.write(u'%4u' % self._lineno).set(fg=self._gutter[2]).write(u'│')
        self._c.pop().write(u' ')
        self._lineno += 1