aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Villalovos <john@sodarock.com>2018-02-07 14:28:41 -0800
committerGeoff Gustafson <geoff@linux.intel.com>2018-02-07 14:28:41 -0800
commit29857cb6f28c49a6c9da781b08326471deb7a3e6 (patch)
treec3624199d94ab391b06d16b8ea214b769236c3da
parent976966fe4f4645c70fd24c6b97a32acd5c9b150a (diff)
[zjsbanner] Simplify code for readability (#1830)
Use a dict to make the zjsbanner code simpler and hopefully easier to understand. Signed-off-by: John L. Villalovos <john@sodarock.com>
-rwxr-xr-xscripts/zjsbanner49
1 files changed, 20 insertions, 29 deletions
diff --git a/scripts/zjsbanner b/scripts/zjsbanner
index ace98b1..85bfc54 100755
--- a/scripts/zjsbanner
+++ b/scripts/zjsbanner
@@ -6,43 +6,32 @@
import sys
-alphabet = ['4avhh', 'uhuhu', 'fgggf', 'uhhhu', 'vgugv', 'vgugg', 'fgjhe',
- 'hhvhh', 'v444v', 'v22ic', 'hisih', 'ggggv', 'hrlhh',
- 'hpljh', 'ehhhe', 'uhugg', 'ehhjf', 'uhuih', 'fge1u', 'v4444',
- 'hhhhe', 'hhha4', 'hhlrh', 'ha4ah', 'ha444', 'v248v']
-digits = ['ejlpe', '4c44v', 'u116v', 'u1e1u', 'hhv11',
- 'vgu1u', 'fguhe', 'v248g', 'ehehe', 'ehf11']
-
-other = {
- ' ': '00000',
- '?': 'e1c04',
- '.': '00004',
- '-': '00e00',
+banner_font = {
+ '0': 'ejlpe', '1': '4c44v', '2': 'u116v', '3': 'u1e1u', '4': 'hhv11',
+ '5': 'vgu1u', '6': 'fguhe', '7': 'v248g', '8': 'ehehe', '9': 'ehf11',
+ 'A': '4avhh', 'B': 'uhuhu', 'C': 'fgggf', 'D': 'uhhhu', 'E': 'vgugv',
+ 'F': 'vgugg', 'G': 'fgjhe', 'H': 'hhvhh', 'I': 'v444v', 'J': 'v22ic',
+ 'K': 'hisih', 'L': 'ggggv', 'M': 'hrlhh', 'N': 'hpljh', 'O': 'ehhhe',
+ 'P': 'uhugg', 'Q': 'ehhjf', 'R': 'uhuih', 'S': 'fge1u', 'T': 'v4444',
+ 'U': 'hhhhe', 'V': 'hhha4', 'W': 'hhlrh', 'X': 'ha4ah', 'Y': 'ha444',
+ 'Z': 'v248v', '?': 'e1c04', ' ': '00000', '-': '00e00', '.': '00004',
'_': '0000v',
}
-def find_pattern(char, line):
- # returns: five character string
- if char.isalpha():
- char = char.upper()
- index = ord(char) - ord('A')
- ptnchr = alphabet[index][line]
- elif char.isdigit():
- index = ord(char) - ord('0')
- ptnchr = digits[index][line]
- else:
- if char not in other:
- char = '?'
- ptnchr = other.get(char)[line]
- if ptnchr.isalpha():
- mask = ord(ptnchr) - ord('a') + 10
+def find_pattern(char, line):
+ char = char.upper()
+ if char not in banner_font:
+ char = '?'
+ print_character = banner_font[char][line]
+ if print_character.isalpha():
+ mask = ord(print_character) - ord('a') + 10
else:
- mask = ord(ptnchr) - ord('0')
-
+ mask = ord(print_character) - ord('0')
return "{0:5b}".format(mask).replace('1', '#').replace('0', ' ')
+
def banner(message):
while len(message) > 0:
print("")
@@ -55,6 +44,7 @@ def banner(message):
out += (find_pattern(line[j], i) + ' ')
print(out)
+
def main():
if len(sys.argv) <= 1:
print("usage: zjsbanner <text>")
@@ -62,5 +52,6 @@ def main():
banner(' '.join(sys.argv[1:]))
+
if __name__ == "__main__":
main()