comparison hgext/beautifygraph.py @ 43077:687b865b95ad

formatting: byteify all mercurial/ and hgext/ string literals Done with python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py') black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**') # skip-blame mass-reformatting only Differential Revision: https://phab.mercurial-scm.org/D6972
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:48:39 -0400
parents 2372284d9457
children 9f70512ae2cf
comparison
equal deleted inserted replaced
43076:2372284d9457 43077:687b865b95ad
24 24
25 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for 25 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
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 = b'ships-with-hg-core'
30 30
31 31
32 def prettyedge(before, edge, after): 32 def prettyedge(before, edge, after):
33 if edge == '~': 33 if edge == b'~':
34 return '\xE2\x95\xA7' # U+2567 ╧ 34 return b'\xE2\x95\xA7' # U+2567 ╧
35 if edge == '/': 35 if edge == b'/':
36 return '\xE2\x95\xB1' # U+2571 ╱ 36 return b'\xE2\x95\xB1' # U+2571 ╱
37 if edge == '-': 37 if edge == b'-':
38 return '\xE2\x94\x80' # U+2500 ─ 38 return b'\xE2\x94\x80' # U+2500 ─
39 if edge == '|': 39 if edge == b'|':
40 return '\xE2\x94\x82' # U+2502 │ 40 return b'\xE2\x94\x82' # U+2502 │
41 if edge == ':': 41 if edge == b':':
42 return '\xE2\x94\x86' # U+2506 ┆ 42 return b'\xE2\x94\x86' # U+2506 ┆
43 if edge == '\\': 43 if edge == b'\\':
44 return '\xE2\x95\xB2' # U+2572 ╲ 44 return b'\xE2\x95\xB2' # U+2572 ╲
45 if edge == '+': 45 if edge == b'+':
46 if before == ' ' and not after == ' ': 46 if before == b' ' and not after == b' ':
47 return '\xE2\x94\x9C' # U+251C ├ 47 return b'\xE2\x94\x9C' # U+251C ├
48 if after == ' ' and not before == ' ': 48 if after == b' ' and not before == b' ':
49 return '\xE2\x94\xA4' # U+2524 ┤ 49 return b'\xE2\x94\xA4' # U+2524 ┤
50 return '\xE2\x94\xBC' # U+253C ┼ 50 return b'\xE2\x94\xBC' # U+253C ┼
51 return edge 51 return edge
52 52
53 53
54 def convertedges(line): 54 def convertedges(line):
55 line = ' %s ' % line 55 line = b' %s ' % line
56 pretty = [] 56 pretty = []
57 for idx in pycompat.xrange(len(line) - 2): 57 for idx in pycompat.xrange(len(line) - 2):
58 pretty.append( 58 pretty.append(
59 prettyedge( 59 prettyedge(
60 line[idx : idx + 1], 60 line[idx : idx + 1],
61 line[idx + 1 : idx + 2], 61 line[idx + 1 : idx + 2],
62 line[idx + 2 : idx + 3], 62 line[idx + 2 : idx + 3],
63 ) 63 )
64 ) 64 )
65 return ''.join(pretty) 65 return b''.join(pretty)
66 66
67 67
68 def getprettygraphnode(orig, *args, **kwargs): 68 def getprettygraphnode(orig, *args, **kwargs):
69 node = orig(*args, **kwargs) 69 node = orig(*args, **kwargs)
70 if node == 'o': 70 if node == b'o':
71 return '\xE2\x97\x8B' # U+25CB ○ 71 return b'\xE2\x97\x8B' # U+25CB ○
72 if node == '@': 72 if node == b'@':
73 return '\xE2\x97\x8D' # U+25CD ◍ 73 return b'\xE2\x97\x8D' # U+25CD ◍
74 if node == '*': 74 if node == b'*':
75 return '\xE2\x88\x97' # U+2217 ∗ 75 return b'\xE2\x88\x97' # U+2217 ∗
76 if node == 'x': 76 if node == b'x':
77 return '\xE2\x97\x8C' # U+25CC ◌ 77 return b'\xE2\x97\x8C' # U+25CC ◌
78 if node == '_': 78 if node == b'_':
79 return '\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('graph'): 90 if ui.plain(b'graph'):
91 return 91 return
92 92
93 if encoding.encoding != 'UTF-8': 93 if encoding.encoding != b'UTF-8':
94 ui.warn(_('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 r'A' in encoding._wide: 97 if r'A' in encoding._wide:
98 ui.warn( 98 ui.warn(
99 _( 99 _(
100 'beautifygraph: unsupported terminal settings, ' 100 b'beautifygraph: unsupported terminal settings, '
101 '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, 'outputgraph', outputprettygraph) 106 extensions.wrapfunction(graphmod, b'outputgraph', outputprettygraph)
107 extensions.wrapfunction(templatekw, 'getgraphnode', getprettygraphnode) 107 extensions.wrapfunction(templatekw, b'getgraphnode', getprettygraphnode)