-
Notifications
You must be signed in to change notification settings - Fork 0
/
lineprinter.py
executable file
·52 lines (45 loc) · 1.08 KB
/
lineprinter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
from time import sleep
import sys
import random
DELAY = 0.005 # s
def lprint(text):
codes = [ord(c) for c in text if c != ' ']
start = ord('A')
last = max(codes)
stop = min(last, 255) + 1
chars = set(text)
seen = {' '}
for code in range(start, stop):
current = chr(code)
seen.add(current)
for char in text:
if char in seen:
out = char
chars.discard(char)
else:
out = current
print(out, end='', flush=True)
if not chars:
break
if out != ' ':
sleep(DELAY)
print('\r', end='', flush=True)
print('\r' + text)
def demo():
names = [
'Alan Turing',
'Grace Hopper',
'Barbara Liskov',
'Alan Kay',
'Edsger Dijkstra',
'John Backus',
]
random.shuffle(names)
for name in names:
lprint(name)
if __name__ == '__main__':
if len(sys.argv) > 1:
lprint(' '.join(sys.argv[1:]))
else:
demo()