[Pgp-tools-commit] r626 - trunk/keyart

Aaron Toponce atoponce-guest at moszumanska.debian.org
Fri May 16 19:00:49 UTC 2014


Author: atoponce-guest
Date: 2014-05-16 19:00:49 +0000 (Fri, 16 May 2014)
New Revision: 626

Modified:
   trunk/keyart/keyart
Log:
Many updates.

* ANSI color is now supported, and detects if the terminal supports ANSI,
  or falls back to plain text.
* Removed support for multiple keys.
* Removed printing the 'S' and 'E' markers for start and end respectively
  until bug can be worked out with ANSI printing.


Modified: trunk/keyart/keyart
===================================================================
--- trunk/keyart/keyart	2014-05-15 17:17:51 UTC (rev 625)
+++ trunk/keyart/keyart	2014-05-16 19:00:49 UTC (rev 626)
@@ -5,6 +5,20 @@
 import subprocess
 import sys
 
+def supports_color():
+    """
+    Returns True if the running system's terminal supports color, and False
+    otherwise.
+    """
+    plat = sys.platform
+    supported_platform = plat != 'Pocket PC' and (plat != 'win32' or
+                                                  'ANSICON' in os.environ)
+    # isatty is not always implemented, #6223.
+    is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
+    if not supported_platform or not is_a_tty:
+        return False
+    return True
+
 def draw_art(keyfile):
     if not os.path.isfile(keyfile):
         print "No such file or directory: {0}".format(keyfile)
@@ -60,20 +74,35 @@
     pos = 104
     walk = [pos]
     visits = [0]*209
-    coins = [' ','.','^',':','l','i','?','{','f','x','X','Z','#','M','W','&','8','%','@']
+    if supports_color():
+        # shades of blue, green, yellow, orange, red, pink
+        b1 = '\033[38;5;21m'; b2 = '\033[38;5;33m'; b3 = '\033[38;5;45m'; b4 = '\033[38;5;50m'
+        g1 = '\033[38;5;48m'; g2 = '\033[38;5;46m'; g3 = '\033[38;5;118m'
+        y1 = '\033[38;5;190m'; y2 = '\033[38;5;226m'; y3 = '\033[38;5;220m'
+        o1 = '\033[38;5;214m'; o2 = '\033[38;5;208m'; o3 = '\033[38;5;202m'
+        r1 = '\033[38;5;196m'; r2 = '\033[38;5;203m'; r3 = '\033[38;5;210m'
+        p1 = '\033[38;5;217m'; p2 = '\033[38;5;224m'
+        reset = '\033[0m'
 
+        coins = [' ', '%s%s%s' % (b1,'.',reset), '%s%s%s' % (b2,'^',reset),
+                      '%s%s%s' % (b3,':',reset), '%s%s%s' % (b4,'l',reset),
+                      '%s%s%s' % (g1,'i',reset), '%s%s%s' % (g2,'?',reset),
+                      '%s%s%s' % (g3,'{',reset), '%s%s%s' % (y1,'f',reset),
+                      '%s%s%s' % (y2,'x',reset), '%s%s%s' % (y3,'X',reset),
+                      '%s%s%s' % (o1,'Z',reset), '%s%s%s' % (o2,'#',reset),
+                      '%s%s%s' % (o3,'M',reset), '%s%s%s' % (r1,'W',reset),
+                      '%s%s%s' % (r2,'&',reset), '%s%s%s' % (r3,'8',reset),
+                      '%s%s%s' % (p1,'%',reset), '%s%s%s' % (p2,'@',reset)]
+        markers = ['%s%s' % (reset,'S'), '%s%s' % (reset,'E')]
+    else:
+        coins = [' ','.','^',':','l','i','?','{','f','x','X','Z','#','M','W','&','8','%','@']
+
     zfill = str.zfill
 
     for c in key_fpr:
         f_bytes.append(zfill(bin(int(c,16))[2:],4)[:2]) # last 2 bits
         f_bytes.append(zfill(bin(int(c,16))[2:],4)[2:]) # first 2 bits
-            
-            
 
-    # I break from the OpenSSH implementation here. Rather than reading the
-    # bytes in little endian, the code is simpler reading in big endian. I
-    # don't see the point in complicating the code for little endian reading,
-    # when the fingerprint is SHA1 output, and should provide random output.
     for d in f_bytes:
         if (20 <= pos <=  36 or  39 <= pos <=  55 or  58 <= pos <=  74 or
             77 <= pos <=  93 or  96 <= pos <= 112 or 115 <= pos <= 131 or
@@ -165,10 +194,10 @@
         coin += coins[v]
         if i % 19 == 0:
             coin = "|%s" % coin
-        if i == 104:
-            coin = "%sS" % coin[:10]
-        if i == walk[len(walk)-1]:
-            coin = "%sE" % coin[:len(coin)-1]
+        #if i == 104:
+        #    coin = "%s%s" % (coin[:10], markers[0])
+        #if i == walk[len(walk)-1]:
+        #    coin = "%s%s" % (coin[:len(coin)-1], markers[1])
         if i % 19 == 18:
             art += "%s|\n" % coin
             coin = ''
@@ -176,10 +205,5 @@
     art += '+----[{0}]-----+'.format(key_fpr[-8:])
     return art
 
-arts = []
-
-for key in sys.argv[1:]:
-    arts.append(draw_art(key))
-
-for art in arts:
-    print art
+key = sys.argv[1]
+print draw_art(key)




More information about the Pgp-tools-commit mailing list