Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

htmlui: introduce a UI subclass which emits HTML/Rich Text output

Use this class when calling Mercurial synchronously for output. The
first customer for this will likely be a wrapper for patch.diff()

Changeset 6e72e090ea24

Parent 7fa4e363ff1d

by Steve Borho

Changes to one file · Browse files at 6e72e090ea24 Showing diff from parent 7fa4e363ff1d Diff from another changeset...

Change 1 of 1 Show Entire File tortoisehg/​hgqt/​htmlui.py Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
@@ -0,0 +1,58 @@
+# htmlui.py - mercurial.ui.ui class which emits HTML/Rich Text +# +# Copyright 2010 Steve Borho <steve@borho.org> +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2, incorporated herein by reference. + +import os + +from mercurial import ui +from tortoisehg.hgqt import qtlib +from tortoisehg.util import hglib + +class htmlui(ui.ui): + def __init__(self, src=None): + super(htmlui, self).__init__(src) + self.setconfig('ui', 'interactive', 'off') + self.setconfig('progress', 'disable', 'True') + self.output = '' + self.error = '' + os.environ['TERM'] = 'dumb' + qtlib.configstyles(self) + + def write(self, *args, **opts): + label = opts.get('label', '') + if self._buffers: + self._buffers[-1].extend([(str(a), label) for a in args]) + else: + self.output += self.label(''.join(args), label) + + def write_err(self, *args, **opts): + label = opts.get('label', 'ui.error') + self.error += self.label(''.join(args), label) + + def label(self, msg, label): + msg = hglib.tounicode(msg) + style = qtlib.geteffect(label) + return '<pre style="%s">%s</pre>' % (style, msg) + + def popbuffer(self, labeled=False): + b = self._buffers.pop() + if labeled: + return ''.join(self.label(a, label) for a, label in b) + return ''.join(a for a, label in b) + + def plain(self): + return True + + def getdata(self): + d, e = self.output, self.error + self.output, self.error = '', '' + return d, e + +if __name__ == "__main__": + from mercurial import hg + u = htmlui() + repo = hg.repository(u) + repo.status()