-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
31 lines (26 loc) 路 904 Bytes
/
main.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
import random
import string
import time
import click
random.seed()
ALL_CHARS = string.digits + string.ascii_letters + string.punctuation
COLS, _ = click.get_terminal_size()
def echo(message: str, charset: str = ALL_CHARS, speed: float = 0.05,
iterations: int = 2) -> None:
"""Scrmbl print the given message."""
if not charset:
charset = ALL_CHARS
for line in message.split('\n'):
echoed = ''
for char in line:
for _ in range(iterations):
ran_char = random.choice(charset)
click.echo('\r{0}{1}'.format(echoed, ran_char), nl=False)
time.sleep(speed)
echoed += char
# wrap if line longer than console cols
if len(echoed) >= COLS - 1:
click.echo('\r' + echoed)
echoed = ''
if echoed:
click.echo('\r' + echoed)