##// END OF EJS Templates
wrapfunction: use sysstr instead of bytes as argument in "beautifygraph"...
marmoute -
r51667:caa0a25f default
parent child Browse files
Show More
@@ -1,107 +1,107 b''
1 # -*- coding: UTF-8 -*-
1 # -*- coding: UTF-8 -*-
2 # beautifygraph.py - improve graph output by using Unicode characters
2 # beautifygraph.py - improve graph output by using Unicode characters
3 #
3 #
4 # Copyright 2018 John Stiles <johnstiles@gmail.com>
4 # Copyright 2018 John Stiles <johnstiles@gmail.com>
5 #
5 #
6 # This software may be used and distributed according to the terms of the
6 # This software may be used and distributed according to the terms of the
7 # GNU General Public License version 2 or any later version.
7 # GNU General Public License version 2 or any later version.
8
8
9 '''beautify log -G output by using Unicode characters (EXPERIMENTAL)
9 '''beautify log -G output by using Unicode characters (EXPERIMENTAL)
10
10
11 A terminal with UTF-8 support and monospace narrow text are required.
11 A terminal with UTF-8 support and monospace narrow text are required.
12 '''
12 '''
13
13
14
14
15 from mercurial.i18n import _
15 from mercurial.i18n import _
16 from mercurial import (
16 from mercurial import (
17 encoding,
17 encoding,
18 extensions,
18 extensions,
19 graphmod,
19 graphmod,
20 templatekw,
20 templatekw,
21 )
21 )
22
22
23 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
23 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
24 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
24 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
25 # be specifying the version(s) of Mercurial they are tested with, or
25 # be specifying the version(s) of Mercurial they are tested with, or
26 # leave the attribute unspecified.
26 # leave the attribute unspecified.
27 testedwith = b'ships-with-hg-core'
27 testedwith = b'ships-with-hg-core'
28
28
29
29
30 def prettyedge(before, edge, after):
30 def prettyedge(before, edge, after):
31 if edge == b'~':
31 if edge == b'~':
32 return b'\xE2\x95\xA7' # U+2567 ╧
32 return b'\xE2\x95\xA7' # U+2567 ╧
33 if edge == b'/':
33 if edge == b'/':
34 return b'\xE2\x95\xB1' # U+2571 β•±
34 return b'\xE2\x95\xB1' # U+2571 β•±
35 if edge == b'-':
35 if edge == b'-':
36 return b'\xE2\x94\x80' # U+2500 ─
36 return b'\xE2\x94\x80' # U+2500 ─
37 if edge == b'|':
37 if edge == b'|':
38 return b'\xE2\x94\x82' # U+2502 β”‚
38 return b'\xE2\x94\x82' # U+2502 β”‚
39 if edge == b':':
39 if edge == b':':
40 return b'\xE2\x94\x86' # U+2506 ┆
40 return b'\xE2\x94\x86' # U+2506 ┆
41 if edge == b'\\':
41 if edge == b'\\':
42 return b'\xE2\x95\xB2' # U+2572 β•²
42 return b'\xE2\x95\xB2' # U+2572 β•²
43 if edge == b'+':
43 if edge == b'+':
44 if before == b' ' and not after == b' ':
44 if before == b' ' and not after == b' ':
45 return b'\xE2\x94\x9C' # U+251C β”œ
45 return b'\xE2\x94\x9C' # U+251C β”œ
46 if after == b' ' and not before == b' ':
46 if after == b' ' and not before == b' ':
47 return b'\xE2\x94\xA4' # U+2524 ─
47 return b'\xE2\x94\xA4' # U+2524 ─
48 return b'\xE2\x94\xBC' # U+253C β”Ό
48 return b'\xE2\x94\xBC' # U+253C β”Ό
49 return edge
49 return edge
50
50
51
51
52 def convertedges(line):
52 def convertedges(line):
53 line = b' %s ' % line
53 line = b' %s ' % line
54 pretty = []
54 pretty = []
55 for idx in range(len(line) - 2):
55 for idx in range(len(line) - 2):
56 pretty.append(
56 pretty.append(
57 prettyedge(
57 prettyedge(
58 line[idx : idx + 1],
58 line[idx : idx + 1],
59 line[idx + 1 : idx + 2],
59 line[idx + 1 : idx + 2],
60 line[idx + 2 : idx + 3],
60 line[idx + 2 : idx + 3],
61 )
61 )
62 )
62 )
63 return b''.join(pretty)
63 return b''.join(pretty)
64
64
65
65
66 def getprettygraphnode(orig, *args, **kwargs):
66 def getprettygraphnode(orig, *args, **kwargs):
67 node = orig(*args, **kwargs)
67 node = orig(*args, **kwargs)
68 if node == b'o':
68 if node == b'o':
69 return b'\xE2\x97\x8B' # U+25CB β—‹
69 return b'\xE2\x97\x8B' # U+25CB β—‹
70 if node == b'@':
70 if node == b'@':
71 return b'\xE2\x97\x89' # U+25C9 β—‰
71 return b'\xE2\x97\x89' # U+25C9 β—‰
72 if node == b'%':
72 if node == b'%':
73 return b'\xE2\x97\x8D' # U+25CE β—Ž
73 return b'\xE2\x97\x8D' # U+25CE β—Ž
74 if node == b'*':
74 if node == b'*':
75 return b'\xE2\x88\x97' # U+2217 βˆ—
75 return b'\xE2\x88\x97' # U+2217 βˆ—
76 if node == b'x':
76 if node == b'x':
77 return b'\xE2\x97\x8C' # U+25CC β—Œ
77 return b'\xE2\x97\x8C' # U+25CC β—Œ
78 if node == b'_':
78 if node == b'_':
79 return b'\xE2\x95\xA4' # U+2564 β•€
79 return b'\xE2\x95\xA4' # U+2564 β•€
80 return node
80 return node
81
81
82
82
83 def outputprettygraph(orig, ui, graph, *args, **kwargs):
83 def outputprettygraph(orig, ui, graph, *args, **kwargs):
84 (edges, text) = zip(*graph)
84 (edges, text) = zip(*graph)
85 graph = zip([convertedges(e) for e in edges], text)
85 graph = zip([convertedges(e) for e in edges], text)
86 return orig(ui, graph, *args, **kwargs)
86 return orig(ui, graph, *args, **kwargs)
87
87
88
88
89 def extsetup(ui):
89 def extsetup(ui):
90 if ui.plain(b'graph'):
90 if ui.plain(b'graph'):
91 return
91 return
92
92
93 if encoding.encoding != b'UTF-8':
93 if encoding.encoding != b'UTF-8':
94 ui.warn(_(b'beautifygraph: unsupported encoding, UTF-8 required\n'))
94 ui.warn(_(b'beautifygraph: unsupported encoding, UTF-8 required\n'))
95 return
95 return
96
96
97 if 'A' in encoding._wide:
97 if 'A' in encoding._wide:
98 ui.warn(
98 ui.warn(
99 _(
99 _(
100 b'beautifygraph: unsupported terminal settings, '
100 b'beautifygraph: unsupported terminal settings, '
101 b'monospace narrow text required\n'
101 b'monospace narrow text required\n'
102 )
102 )
103 )
103 )
104 return
104 return
105
105
106 extensions.wrapfunction(graphmod, b'outputgraph', outputprettygraph)
106 extensions.wrapfunction(graphmod, 'outputgraph', outputprettygraph)
107 extensions.wrapfunction(templatekw, b'getgraphnode', getprettygraphnode)
107 extensions.wrapfunction(templatekw, 'getgraphnode', getprettygraphnode)
General Comments 0
You need to be logged in to leave comments. Login now