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

htmlui: use new special labels to know when to escape / markup

Changeset d3f7a37ae41b

Parent 053cafeb5ba0

by Steve Borho

Changes to one file · Browse files at d3f7a37ae41b Showing diff from parent 053cafeb5ba0 Diff from another changeset...

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
59
60
61
62
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
59
60
61
62
63
64
 # 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 PyQt4 import QtCore  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.append(self.label(''.join(args), label))     def write_err(self, *args, **opts):   label = opts.get('label', 'ui.error')   self.error.append(self.label(''.join(args), label))     def label(self, msg, label):   msg = hglib.tounicode(msg) - if label: + if label != 'ui.labeled':   msg = QtCore.Qt.escape(msg)   msg = msg.replace('\n', '<br />') + if label == 'ui.plain': + return msg   style = qtlib.geteffect(label)   return '<span style="%s">%s</span>' % (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 = ''.join(self.output), ''.join(self.error)   self.output, self.error = [], []   return d, e    if __name__ == "__main__":   from mercurial import hg   u = htmlui()   repo = hg.repository(u)   repo.status()   print u.getdata()[0]