-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmess.py
More file actions
65 lines (52 loc) · 1.98 KB
/
Copy pathmess.py
File metadata and controls
65 lines (52 loc) · 1.98 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
# x-tools:file[update]
"""
Displays an animated, random text character mess.
The mess can be made faster and displayed in color.
"""
import random as rnd
import time
import xulbux as xx
from xulbux import ArgumentParser
from xulbux.ansi import AnyStyle, S
digits: list[str] = ["0", "1"]
styles: list[AnyStyle] = [S.DIM, S.BOLD, S.INVERSE, S.UNDERLINE, S.STRIKETHROUGH, S.DOUBLE_UNDERLINE]
def binary_line() -> S:
return S(*(rnd.choice(styles)(rnd.choice(digits)) for _ in range(xx.console.get_width())))
def main() -> None:
# fmt: off
if ARGS.color_mode.exists:
styles.extend([
S.BLACK, S.RED, S.GREEN, S.YELLOW, S.BLUE, S.MAGENTA, S.CYAN, S.WHITE,
S.BR.BLACK, S.BR.RED, S.BR.GREEN, S.BR.YELLOW, S.BR.BLUE, S.BR.MAGENTA, S.BR.CYAN, S.BR.WHITE,
S.BG.BLACK, S.BG.RED, S.BG.GREEN, S.BG.YELLOW, S.BG.BLUE, S.BG.MAGENTA, S.BG.CYAN, S.BG.WHITE,
S.BG.BR.BLACK, S.BG.BR.RED, S.BG.BR.GREEN, S.BG.BR.YELLOW, S.BG.BR.BLUE, S.BG.BR.MAGENTA, S.BG.BR.CYAN, S.BG.BR.WHITE, # ruff:ignore[line-too-long]
])
# fmt: on
if ARGS.fast_mode.exists:
while True:
binary_line().print()
else:
while True:
binary_line().print()
time.sleep(0.025)
if __name__ == "__main__":
args = ArgumentParser(
title="Mess",
subtitle="Display a random binary mess",
controls=[("Ctrl+C", "Stop the animation")],
examples=[
("{cmd}", "Show binary mess at normal speed"),
("{cmd} -c -f", "Show colorful binary mess at maximum speed"),
],
)
args.add_opt({"-c", "--color"}, "color_mode", help="Color the mess in random colors")
args.add_opt({"-f", "--fast"}, "fast_mode", help="Display the mess at maximum speed")
global ARGS
ARGS = args.parse()
try:
main()
except KeyboardInterrupt:
print()
except Exception as exc:
xx.console.fail(exc, start="\n", end="\n\n", exit_code=1)