~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to colordiff.py

  • Committer: Michael Ellerman
  • Date: 2006-06-21 13:56:46 UTC
  • mto: This revision was merged to the branch mainline in revision 405.
  • Revision ID: michael@ellerman.id.au-20060621135646-87ecb4dafbcd8e62
Support for colordiff's 'plain', which colours the context text.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
 
43
43
    colors = {
44
44
        'modline' :     'darkyellow',
 
45
        'plain' :       None,
45
46
        'newtext' :     'darkgreen',
46
47
        'oldtext' :     'red',
47
48
        'diffstuff' :   'darkblue'
80
81
 
81
82
    def colorstring(self, type, string):
82
83
        color = self.colors[type]
83
 
        self.target.write(terminal.colorstring(str(string), color))
 
84
        if color is not None:
 
85
            string = terminal.colorstring(str(string), color)
 
86
        self.target.write(string)
84
87
 
85
88
    def write(self, text):
86
89
        newstuff = text.split('\n')
97
100
            self.colorstring('newtext', str(item))
98
101
        elif isinstance(item, RemoveLine):
99
102
            self.colorstring('oldtext', str(item))
100
 
        elif isinstance(item, basestring):
101
 
            if item.startswith('==='):
102
 
                self.colorstring('modline', str(item))
103
 
            else:
104
 
                self.target.write(item)
 
103
        elif isinstance(item, basestring) and item.startswith('==='):
 
104
            self.colorstring('modline', str(item))
105
105
        else:
106
 
            self.target.write(str(item))
 
106
            self.colorstring('plain', str(item))
107
107
 
108
108
    def flush(self):
109
109
        self.target.flush()