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