feat(cmdline): improve rich output and add mise tasks
- Add box-drawing characters for nicer header - Add response formatting with success/error indicators - Add mise tasks: cmd (interactive) and cmd-stats (monitoring)
This commit is contained in:
50
cmdline.py
50
cmdline.py
@@ -122,9 +122,27 @@ def print_header():
|
|||||||
print(CLR, end="")
|
print(CLR, end="")
|
||||||
print(CURSOR_OFF, end="")
|
print(CURSOR_OFF, end="")
|
||||||
print(f"\033[1;1H", end="")
|
print(f"\033[1;1H", end="")
|
||||||
print(f" \033[1;38;5;231mMAINLINE COMMAND CENTER\033[0m")
|
print(f" \033[1;38;5;231m╔{'═' * (w - 6)}╗\033[0m")
|
||||||
print(f" \033[2;38;5;37m{'─' * (w - 4)}\033[0m")
|
print(
|
||||||
print(f" \033[38;5;245mTopic: {TOPIC}\033[0m")
|
f" \033[1;38;5;231m║\033[0m \033[1;38;5;82mMAINLINE\033[0m \033[3;38;5;245mCommand Center\033[0m \033[1;38;5;231m ║\033[0m"
|
||||||
|
)
|
||||||
|
print(f" \033[1;38;5;231m╚{'═' * (w - 6)}╝\033[0m")
|
||||||
|
print(f" \033[2;38;5;37mTopic: {TOPIC}\033[0m")
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
def print_response(response: str, is_error: bool = False) -> None:
|
||||||
|
"""Print response with nice formatting."""
|
||||||
|
print()
|
||||||
|
if is_error:
|
||||||
|
print(f" \033[1;38;5;196m✗ Error\033[0m")
|
||||||
|
print(f" \033[38;5;196m{'─' * 40}\033[0m")
|
||||||
|
else:
|
||||||
|
print(f" \033[1;38;5;82m✓ Response\033[0m")
|
||||||
|
print(f" \033[38;5;37m{'─' * 40}\033[0m")
|
||||||
|
|
||||||
|
for line in response.split("\n"):
|
||||||
|
print(f" {line}")
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
|
||||||
@@ -135,12 +153,12 @@ def interactive_mode():
|
|||||||
print_header()
|
print_header()
|
||||||
poller = NtfyResponsePoller(TOPIC)
|
poller = NtfyResponsePoller(TOPIC)
|
||||||
|
|
||||||
print(f"{G_DIM}Type /help for available commands, /quit to exit{RST}")
|
print(f" \033[38;5;245mType /help for commands, /quit to exit\033[0m")
|
||||||
print()
|
print()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
cmd = input(f"{G_HI}> {RST}").strip()
|
cmd = input(f" \033[1;38;5;82m❯\033[0m {G_HI}").strip()
|
||||||
except (EOFError, KeyboardInterrupt):
|
except (EOFError, KeyboardInterrupt):
|
||||||
print()
|
print()
|
||||||
break
|
break
|
||||||
@@ -150,19 +168,18 @@ def interactive_mode():
|
|||||||
|
|
||||||
if cmd.startswith("/"):
|
if cmd.startswith("/"):
|
||||||
if cmd == "/quit" or cmd == "/exit":
|
if cmd == "/quit" or cmd == "/exit":
|
||||||
print(f"{G_DIM}Goodbye!{RST}")
|
print(f"\n \033[1;38;5;245mGoodbye!{RST}\n")
|
||||||
break
|
break
|
||||||
|
|
||||||
if cmd == "/help":
|
if cmd == "/help":
|
||||||
print(f"\n{AVAILABLE_COMMANDS}\n")
|
print(f"\n{AVAILABLE_COMMANDS}\n")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
print(f"{G_DIM}Sending to mainline...{RST}")
|
print(f" \033[38;5;245m⟳ Sending to mainline...{RST}")
|
||||||
result = poller.send_and_wait(cmd)
|
result = poller.send_and_wait(cmd)
|
||||||
print(f"\n{result}\n")
|
print_response(result, is_error=result.startswith("Error"))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print(f"{G_DIM}Commands must start with / - type /help{RST}\n")
|
print(f"\n \033[1;38;5;196m⚠ Commands must start with /{RST}\n")
|
||||||
|
|
||||||
print(CURSOR_ON, end="")
|
print(CURSOR_ON, end="")
|
||||||
|
|
||||||
@@ -196,17 +213,20 @@ def main():
|
|||||||
|
|
||||||
if args.watch and "/effects stats" in args.command:
|
if args.watch and "/effects stats" in args.command:
|
||||||
print_header()
|
print_header()
|
||||||
print(f"{G_DIM}Watching /effects stats (Ctrl+C to exit)...{RST}\n")
|
print(f" \033[38;5;245mWatching /effects stats (Ctrl+C to exit)...{RST}\n")
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
result = poller.send_and_wait(args.command)
|
result = poller.send_and_wait(args.command)
|
||||||
print(f"\033[2J\033[1;1H", end="")
|
print(f"\033[2J\033[1;1H", end="")
|
||||||
print(f"{G_HI}Performance Stats - {time.strftime('%H:%M:%S')}{RST}")
|
print(
|
||||||
print(f"{G_DIM}{'─' * 40}{RST}")
|
f" \033[1;38;5;82m❯\033[0m Performance Stats - \033[1;38;5;245m{time.strftime('%H:%M:%S')}{RST}"
|
||||||
print(result)
|
)
|
||||||
|
print(f" \033[38;5;37m{'─' * 44}{RST}")
|
||||||
|
for line in result.split("\n"):
|
||||||
|
print(f" {line}")
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print(f"\n{G_DIM}Stopped watching{RST}")
|
print(f"\n \033[1;38;5;245mStopped watching{RST}")
|
||||||
return
|
return
|
||||||
|
|
||||||
result = poller.send_and_wait(args.command)
|
result = poller.send_and_wait(args.command)
|
||||||
|
|||||||
@@ -25,6 +25,13 @@ run = "uv run mainline.py"
|
|||||||
run-poetry = "uv run mainline.py --poetry"
|
run-poetry = "uv run mainline.py --poetry"
|
||||||
run-firehose = "uv run mainline.py --firehose"
|
run-firehose = "uv run mainline.py --firehose"
|
||||||
|
|
||||||
|
# =====================
|
||||||
|
# Command & Control
|
||||||
|
# =====================
|
||||||
|
|
||||||
|
cmd = "uv run cmdline.py"
|
||||||
|
cmd-stats = "uv run cmdline.py -w /effects stats"
|
||||||
|
|
||||||
# =====================
|
# =====================
|
||||||
# Environment
|
# Environment
|
||||||
# =====================
|
# =====================
|
||||||
|
|||||||
Reference in New Issue
Block a user