~testdoc-dev/testdoc/trunk.git

« back to all changes in this revision

Viewing changes to testdoc/formatter.py

  • Committer: Andrew Bennetts
  • Date: 2010-09-07 07:16:54 UTC
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: git-v1:3294910faf1c5563848d8b4d0bd05c02de11cf76
Clearer implementation of ShinyFormatter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
        self.stream = stream
88
88
        self._last_indent = 0
89
89
 
90
 
    def write(self, line, indent, colour):
 
90
    def writeln(self, line, indent, colour):
91
91
        if indent is None:
92
92
            indent = self._last_indent + 2
93
93
        else:
94
94
            self._last_indent = indent
95
95
        line = ' ' * indent + line
96
96
        if colour is None:
97
 
            self.stream.write(line)
 
97
            self.stream.write(line + '\n')
98
98
        else:
99
99
            colour = self._colours[colour]
100
 
            self.stream.write('\x1b[%sm%s\x1b[0m' % (colour, line))
 
100
            self.stream.write('\x1b[%sm%s\x1b[0m\n' % (colour, line))
101
101
 
102
102
    def title(self, name):
103
 
        self.write(name + '\n', 0, 'bright green')
 
103
        self.writeln(name, 0, 'bright green')
104
104
 
105
105
    def section(self, name):
106
 
        self.write(name + '\n', 2, 'bright yellow')
 
106
        self.writeln(name, 2, 'bright yellow')
107
107
 
108
108
    def subsection(self, name):
109
 
        self.write(name + '\n', 4, 'bright white')
 
109
        self.writeln(name, 4, 'bright white')
110
110
 
111
111
    def paragraph(self, text):
112
112
        colour = None
117
117
            # section
118
118
            colour = 'yellow'
119
119
        for line in text.strip().splitlines(True):
120
 
            self.write(line, None, colour)
121
 
        if not line.endswith('\n'):
122
 
            self.write('\n', None, colour)
123
 
 
124
 
 
 
120
            self.writeln(line.rstrip('\n'), None, colour)