D3665: graph: improve graph output by using Unicode characters

johnstiles (John Stiles) phabricator at mercurial-scm.org
Mon May 28 18:05:53 EDT 2018


johnstiles updated this revision to Diff 8918.
johnstiles added a comment.


  Converted non-ASCII characters to `\xNN' form for Python 3 compatibility.
  Converted sys.stdout.encoding to encoding.encoding.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3665?vs=8910&id=8918

REVISION DETAIL
  https://phab.mercurial-scm.org/D3665

AFFECTED FILES
  hgext/beautifygraph.py

CHANGE DETAILS

diff --git a/hgext/beautifygraph.py b/hgext/beautifygraph.py
--- a/hgext/beautifygraph.py
+++ b/hgext/beautifygraph.py
@@ -8,7 +8,7 @@
 
 from __future__ import absolute_import
 
-import sys
+from mercurial import encoding
 from mercurial import extensions
 from mercurial import templatekw
 from mercurial import graphmod
@@ -22,17 +22,17 @@
 def extsetup(ui):
   def convertedges(line):
     def prettyedge(before, edge, after):
-      if edge == '~':  return '╧'
-      if edge == 'X':  return '╳'
-      if edge == '/':  return '╱'
-      if edge == '-':  return '─'
-      if edge == '|':  return '│'
-      if edge == ':':  return '┆'
-      if edge == '\\': return '╲'
+      if edge == '~':  return '\xE2\x95\xA7' # U+2567 ╧
+      if edge == 'X':  return '\xE2\x95\xB3' # U+2573 ╳
+      if edge == '/':  return '\xE2\x95\xB1' # U+2571 ╱
+      if edge == '-':  return '\xE2\x94\x80' # U+2500 ─
+      if edge == '|':  return '\xE2\x94\x82' # U+2502 │
+      if edge == ':':  return '\xE2\x94\x86' # U+2506 ┆
+      if edge == '\\': return '\xE2\x95\xB2' # U+2572 ╲
       if edge == '+':
-        if before == ' ' and not after  == ' ': return '├'
-        if after  == ' ' and not before == ' ': return '┤'
-        return '┼'
+        if before == ' ' and not after  == ' ': return '\xE2\x94\x9C' # U+251C ├
+        if after  == ' ' and not before == ' ': return '\xE2\x94\xA4' # U+2524 ┤
+        return '\xE2\x94\xBC' # U+253C ┼
       return edge
     line = ' %s ' % line
     pretty = [];
@@ -42,15 +42,15 @@
   
   def getprettygraphnode(orig, *args, **kwargs):
     node = orig(*args, **kwargs)
-    if node == 'o': return '◯'
-    if node == '@': return '⌾'
-    if node == '*': return '∗'
-    if node == 'x': return '◌'
-    if node == '_': return '╤'
+    if node == 'o': return '\xE2\x97\xAF' # U+25EF ◯
+    if node == '@': return '\xE2\x8C\xBE' # U+233E ⌾
+    if node == '*': return '\xE2\x88\x97' # U+2217 ∗
+    if node == 'x': return '\xE2\x97\x8C' # U+25CC ◌
+    if node == '_': return '\xE2\x95\xA4' # U+2564 ╤
     return node
 
   def outputprettygraph(orig, ui, graph, *args, **kwargs):
-    if not ui.plain('graph') and sys.stdout.encoding == "UTF-8":
+    if not ui.plain('graph') and encoding.encoding == "UTF-8":
       (edges, text) = zip(*graph)
       graph = zip([convertedges(e) for e in edges], text)
     return orig(ui, graph, *args, **kwargs)



To: johnstiles, #hg-reviewers
Cc: yuja, mercurial-devel


More information about the Mercurial-devel mailing list