This repository was archived by the owner on Sep 4, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdemo_beam.py
More file actions
71 lines (61 loc) · 2.02 KB
/
Copy pathdemo_beam.py
File metadata and controls
71 lines (61 loc) · 2.02 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
66
67
68
69
70
71
#!/usr/bin/env python3
"""
demo_beam.py — ターミナル間を飛ぶデータパケット表示
==============================================================================
demo_stage がウィンドウ bounds を移動させ、このプロセスは中身だけ描く。
"""
from __future__ import annotations
import argparse
import os
import sys
import time
YELLOW = "\033[93m"
BOLD = "\033[1m"
RST = "\033[0m"
CYAN = "\033[96m"
def clear():
sys.stdout.write("\033[2J\033[H")
sys.stdout.flush()
def frame(lines):
pkt = lines[0] if lines else "⟦···⟧"
route = lines[1] if len(lines) > 1 else ""
art = [
YELLOW + BOLD + "╔════════════════════╗" + RST,
YELLOW + BOLD + "║ ✦ DATA IN FLIGHT ║" + RST,
YELLOW + "║" + RST + f" {CYAN}{pkt[:16]:16s}{RST} " + YELLOW + "║" + RST,
YELLOW + "║" + RST + f" {route[:16]:16s} " + YELLOW + "║" + RST,
YELLOW + BOLD + "╚════════════════════╝" + RST,
]
return "\n".join(art)
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--log", required=True)
a = ap.parse_args()
open(a.log, "a").close()
pos = 0
lines = ["⟦standby⟧", "parked"]
clear()
print(frame(lines))
try:
while True:
try:
size = os.path.getsize(a.log)
except OSError:
size = 0
if size < pos:
pos = 0
if size > pos:
with open(a.log, "r", encoding="utf-8", errors="replace") as f:
f.seek(pos)
chunk = f.read()
pos = f.tell()
got = [ln for ln in chunk.splitlines() if ln.strip()]
if got:
lines = got[-2:] if len(got) >= 2 else got + [""]
clear()
print(frame(lines))
time.sleep(0.08)
except KeyboardInterrupt:
pass
if __name__ == "__main__":
main()