Show More
@@ -1,93 +1,93 | |||||
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 | from __future__ import absolute_import |
|
14 | from __future__ import absolute_import | |
15 |
|
15 | |||
16 | from mercurial.i18n import _ |
|
16 | from mercurial.i18n import _ | |
17 | from mercurial import ( |
|
17 | from mercurial import ( | |
18 | encoding, |
|
18 | encoding, | |
19 | extensions, |
|
19 | extensions, | |
20 | graphmod, |
|
20 | graphmod, | |
21 | templatekw, |
|
21 | templatekw, | |
22 | ) |
|
22 | ) | |
23 |
|
23 | |||
24 | # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
|
24 | # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for | |
25 | # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
|
25 | # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should | |
26 | # be specifying the version(s) of Mercurial they are tested with, or |
|
26 | # be specifying the version(s) of Mercurial they are tested with, or | |
27 | # leave the attribute unspecified. |
|
27 | # leave the attribute unspecified. | |
28 | testedwith = 'ships-with-hg-core' |
|
28 | testedwith = 'ships-with-hg-core' | |
29 |
|
29 | |||
30 | def prettyedge(before, edge, after): |
|
30 | def prettyedge(before, edge, after): | |
31 | if edge == '~': |
|
31 | if edge == '~': | |
32 | return '\xE2\x95\xA7' # U+2567 ╧ |
|
32 | return '\xE2\x95\xA7' # U+2567 ╧ | |
33 | if edge == 'X': |
|
33 | if edge == 'X': | |
34 | return '\xE2\x95\xB3' # U+2573 ╳ |
|
34 | return '\xE2\x95\xB3' # U+2573 ╳ | |
35 | if edge == '/': |
|
35 | if edge == '/': | |
36 | return '\xE2\x95\xB1' # U+2571 ╱ |
|
36 | return '\xE2\x95\xB1' # U+2571 ╱ | |
37 | if edge == '-': |
|
37 | if edge == '-': | |
38 | return '\xE2\x94\x80' # U+2500 ─ |
|
38 | return '\xE2\x94\x80' # U+2500 ─ | |
39 | if edge == '|': |
|
39 | if edge == '|': | |
40 | return '\xE2\x94\x82' # U+2502 │ |
|
40 | return '\xE2\x94\x82' # U+2502 │ | |
41 | if edge == ':': |
|
41 | if edge == ':': | |
42 | return '\xE2\x94\x86' # U+2506 ┆ |
|
42 | return '\xE2\x94\x86' # U+2506 ┆ | |
43 | if edge == '\\': |
|
43 | if edge == '\\': | |
44 | return '\xE2\x95\xB2' # U+2572 ╲ |
|
44 | return '\xE2\x95\xB2' # U+2572 ╲ | |
45 | if edge == '+': |
|
45 | if edge == '+': | |
46 | if before == ' ' and not after == ' ': |
|
46 | if before == ' ' and not after == ' ': | |
47 | return '\xE2\x94\x9C' # U+251C ├ |
|
47 | return '\xE2\x94\x9C' # U+251C ├ | |
48 | if after == ' ' and not before == ' ': |
|
48 | if after == ' ' and not before == ' ': | |
49 | return '\xE2\x94\xA4' # U+2524 ┤ |
|
49 | return '\xE2\x94\xA4' # U+2524 ┤ | |
50 | return '\xE2\x94\xBC' # U+253C ┼ |
|
50 | return '\xE2\x94\xBC' # U+253C ┼ | |
51 | return edge |
|
51 | return edge | |
52 |
|
52 | |||
53 | def convertedges(line): |
|
53 | def convertedges(line): | |
54 | line = ' %s ' % line |
|
54 | line = ' %s ' % line | |
55 | pretty = [] |
|
55 | pretty = [] | |
56 | for idx in xrange(len(line) - 2): |
|
56 | for idx in xrange(len(line) - 2): | |
57 | pretty.append(prettyedge(line[idx], line[idx + 1], line[idx + 2])) |
|
57 | pretty.append(prettyedge(line[idx], line[idx + 1], line[idx + 2])) | |
58 | return ''.join(pretty) |
|
58 | return ''.join(pretty) | |
59 |
|
59 | |||
60 | def getprettygraphnode(orig, *args, **kwargs): |
|
60 | def getprettygraphnode(orig, *args, **kwargs): | |
61 | node = orig(*args, **kwargs) |
|
61 | node = orig(*args, **kwargs) | |
62 | if node == 'o': |
|
62 | if node == 'o': | |
63 | return '\xE2\x97\x8B' # U+25CB ○ |
|
63 | return '\xE2\x97\x8B' # U+25CB ○ | |
64 | if node == '@': |
|
64 | if node == '@': | |
65 | return '\xE2\x97\x8D' # U+25CD ◍ |
|
65 | return '\xE2\x97\x8D' # U+25CD ◍ | |
66 | if node == '*': |
|
66 | if node == '*': | |
67 | return '\xE2\x88\x97' # U+2217 ∗ |
|
67 | return '\xE2\x88\x97' # U+2217 ∗ | |
68 | if node == 'x': |
|
68 | if node == 'x': | |
69 | return '\xE2\x97\x8C' # U+25CC ◌ |
|
69 | return '\xE2\x97\x8C' # U+25CC ◌ | |
70 | if node == '_': |
|
70 | if node == '_': | |
71 | return '\xE2\x95\xA4' # U+2564 ╤ |
|
71 | return '\xE2\x95\xA4' # U+2564 ╤ | |
72 | return node |
|
72 | return node | |
73 |
|
73 | |||
74 | def outputprettygraph(orig, ui, graph, *args, **kwargs): |
|
74 | def outputprettygraph(orig, ui, graph, *args, **kwargs): | |
75 | (edges, text) = zip(*graph) |
|
75 | (edges, text) = zip(*graph) | |
76 | graph = zip([convertedges(e) for e in edges], text) |
|
76 | graph = zip([convertedges(e) for e in edges], text) | |
77 | return orig(ui, graph, *args, **kwargs) |
|
77 | return orig(ui, graph, *args, **kwargs) | |
78 |
|
78 | |||
79 | def extsetup(ui): |
|
79 | def extsetup(ui): | |
|
80 | if ui.plain('graph'): | |||
|
81 | return | |||
|
82 | ||||
80 | if encoding.encoding != 'UTF-8': |
|
83 | if encoding.encoding != 'UTF-8': | |
81 | ui.warn(_('beautifygraph: unsupported encoding, UTF-8 required\n')) |
|
84 | ui.warn(_('beautifygraph: unsupported encoding, UTF-8 required\n')) | |
82 | return |
|
85 | return | |
83 |
|
86 | |||
84 | if 'A' in encoding._wide: |
|
87 | if 'A' in encoding._wide: | |
85 | ui.warn(_('beautifygraph: unsupported terminal settings, ' |
|
88 | ui.warn(_('beautifygraph: unsupported terminal settings, ' | |
86 | 'monospace narrow text required\n')) |
|
89 | 'monospace narrow text required\n')) | |
87 | return |
|
90 | return | |
88 |
|
91 | |||
89 | if ui.plain('graph'): |
|
|||
90 | return |
|
|||
91 |
|
||||
92 | extensions.wrapfunction(graphmod, 'outputgraph', outputprettygraph) |
|
92 | extensions.wrapfunction(graphmod, 'outputgraph', outputprettygraph) | |
93 | extensions.wrapfunction(templatekw, 'getgraphnode', getprettygraphnode) |
|
93 | extensions.wrapfunction(templatekw, 'getgraphnode', getprettygraphnode) |
General Comments 0
You need to be logged in to leave comments.
Login now