Mercurial > hg
comparison hgext/beautifygraph.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | c2a0bc6412db |
children | 687b865b95ad |
comparison
equal
deleted
inserted
replaced
43075:57875cf423c9 | 43076:2372284d9457 |
---|---|
26 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should | 26 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
27 # be specifying the version(s) of Mercurial they are tested with, or | 27 # be specifying the version(s) of Mercurial they are tested with, or |
28 # leave the attribute unspecified. | 28 # leave the attribute unspecified. |
29 testedwith = 'ships-with-hg-core' | 29 testedwith = 'ships-with-hg-core' |
30 | 30 |
31 | |
31 def prettyedge(before, edge, after): | 32 def prettyedge(before, edge, after): |
32 if edge == '~': | 33 if edge == '~': |
33 return '\xE2\x95\xA7' # U+2567 ╧ | 34 return '\xE2\x95\xA7' # U+2567 ╧ |
34 if edge == '/': | 35 if edge == '/': |
35 return '\xE2\x95\xB1' # U+2571 ╱ | 36 return '\xE2\x95\xB1' # U+2571 ╱ |
36 if edge == '-': | 37 if edge == '-': |
37 return '\xE2\x94\x80' # U+2500 ─ | 38 return '\xE2\x94\x80' # U+2500 ─ |
38 if edge == '|': | 39 if edge == '|': |
39 return '\xE2\x94\x82' # U+2502 │ | 40 return '\xE2\x94\x82' # U+2502 │ |
40 if edge == ':': | 41 if edge == ':': |
41 return '\xE2\x94\x86' # U+2506 ┆ | 42 return '\xE2\x94\x86' # U+2506 ┆ |
42 if edge == '\\': | 43 if edge == '\\': |
43 return '\xE2\x95\xB2' # U+2572 ╲ | 44 return '\xE2\x95\xB2' # U+2572 ╲ |
44 if edge == '+': | 45 if edge == '+': |
45 if before == ' ' and not after == ' ': | 46 if before == ' ' and not after == ' ': |
46 return '\xE2\x94\x9C' # U+251C ├ | 47 return '\xE2\x94\x9C' # U+251C ├ |
47 if after == ' ' and not before == ' ': | 48 if after == ' ' and not before == ' ': |
48 return '\xE2\x94\xA4' # U+2524 ┤ | 49 return '\xE2\x94\xA4' # U+2524 ┤ |
49 return '\xE2\x94\xBC' # U+253C ┼ | 50 return '\xE2\x94\xBC' # U+253C ┼ |
50 return edge | 51 return edge |
52 | |
51 | 53 |
52 def convertedges(line): | 54 def convertedges(line): |
53 line = ' %s ' % line | 55 line = ' %s ' % line |
54 pretty = [] | 56 pretty = [] |
55 for idx in pycompat.xrange(len(line) - 2): | 57 for idx in pycompat.xrange(len(line) - 2): |
56 pretty.append(prettyedge(line[idx:idx + 1], | 58 pretty.append( |
57 line[idx + 1:idx + 2], | 59 prettyedge( |
58 line[idx + 2:idx + 3])) | 60 line[idx : idx + 1], |
61 line[idx + 1 : idx + 2], | |
62 line[idx + 2 : idx + 3], | |
63 ) | |
64 ) | |
59 return ''.join(pretty) | 65 return ''.join(pretty) |
66 | |
60 | 67 |
61 def getprettygraphnode(orig, *args, **kwargs): | 68 def getprettygraphnode(orig, *args, **kwargs): |
62 node = orig(*args, **kwargs) | 69 node = orig(*args, **kwargs) |
63 if node == 'o': | 70 if node == 'o': |
64 return '\xE2\x97\x8B' # U+25CB ○ | 71 return '\xE2\x97\x8B' # U+25CB ○ |
65 if node == '@': | 72 if node == '@': |
66 return '\xE2\x97\x8D' # U+25CD ◍ | 73 return '\xE2\x97\x8D' # U+25CD ◍ |
67 if node == '*': | 74 if node == '*': |
68 return '\xE2\x88\x97' # U+2217 ∗ | 75 return '\xE2\x88\x97' # U+2217 ∗ |
69 if node == 'x': | 76 if node == 'x': |
70 return '\xE2\x97\x8C' # U+25CC ◌ | 77 return '\xE2\x97\x8C' # U+25CC ◌ |
71 if node == '_': | 78 if node == '_': |
72 return '\xE2\x95\xA4' # U+2564 ╤ | 79 return '\xE2\x95\xA4' # U+2564 ╤ |
73 return node | 80 return node |
81 | |
74 | 82 |
75 def outputprettygraph(orig, ui, graph, *args, **kwargs): | 83 def outputprettygraph(orig, ui, graph, *args, **kwargs): |
76 (edges, text) = zip(*graph) | 84 (edges, text) = zip(*graph) |
77 graph = zip([convertedges(e) for e in edges], text) | 85 graph = zip([convertedges(e) for e in edges], text) |
78 return orig(ui, graph, *args, **kwargs) | 86 return orig(ui, graph, *args, **kwargs) |
87 | |
79 | 88 |
80 def extsetup(ui): | 89 def extsetup(ui): |
81 if ui.plain('graph'): | 90 if ui.plain('graph'): |
82 return | 91 return |
83 | 92 |
84 if encoding.encoding != 'UTF-8': | 93 if encoding.encoding != 'UTF-8': |
85 ui.warn(_('beautifygraph: unsupported encoding, UTF-8 required\n')) | 94 ui.warn(_('beautifygraph: unsupported encoding, UTF-8 required\n')) |
86 return | 95 return |
87 | 96 |
88 if r'A' in encoding._wide: | 97 if r'A' in encoding._wide: |
89 ui.warn(_('beautifygraph: unsupported terminal settings, ' | 98 ui.warn( |
90 'monospace narrow text required\n')) | 99 _( |
100 'beautifygraph: unsupported terminal settings, ' | |
101 'monospace narrow text required\n' | |
102 ) | |
103 ) | |
91 return | 104 return |
92 | 105 |
93 extensions.wrapfunction(graphmod, 'outputgraph', outputprettygraph) | 106 extensions.wrapfunction(graphmod, 'outputgraph', outputprettygraph) |
94 extensions.wrapfunction(templatekw, 'getgraphnode', getprettygraphnode) | 107 extensions.wrapfunction(templatekw, 'getgraphnode', getprettygraphnode) |