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