31
31
def paragraph(self, text):
32
32
self.writeln('%s\n' % (text.strip(),))
35
class ReSTFormatter(object):
38
def __init__(self, stream):
41
def writeln(self, line):
42
self.stream.write('%s\n' % (line,))
44
def title(self, name):
45
self.writeln('%s' % ('=' * len(name),))
46
self.writeln('%s' % (name,))
47
self.writeln('%s' % ('=' * len(name),))
49
self.writeln('.. contents::')
53
def section(self, name):
55
self.writeln('%s' % (name,))
56
self.writeln('%s' % ('=' * len(name),))
59
def subsection(self, name):
60
self.writeln('%s' % (name,))
61
self.writeln('%s' % ('-' * len(name),))
64
def paragraph(self, text):
65
self.writeln('%s\n' % (text.strip(),))
68
class ShinyFormatter(object):
69
"""Coloured, indented output.
71
For use on terminals that support ANSI colour sequences.
78
"bright green": "32;1",
80
"bright yellow": "33;1",
85
"bright white": "37;1",
88
def __init__(self, stream):
92
def writeln(self, line, indent, colour):
94
indent = self._last_indent + 2
96
self._last_indent = indent
97
line = ' ' * indent + line
99
self.stream.write(line + '\n')
101
colour = self._colours[colour]
102
self.stream.write('\x1b[%sm%s\x1b[0m\n' % (colour, line))
104
def title(self, name):
105
self.writeln(name, 0, 'bright green')
107
def section(self, name):
108
self.writeln(name, 2, 'bright yellow')
110
def subsection(self, name):
111
self.writeln(name, 4, 'bright white')
113
def paragraph(self, text):
115
if self._last_indent == 0:
118
elif self._last_indent == 2:
121
for line in text.strip().splitlines(True):
122
self.writeln(line.rstrip('\n'), None, colour)