Add devterm tools and TUI menu
Some checks failed
CI / test (3.10) (push) Failing after 12s
CI / test (3.11) (push) Failing after 21s
CI / test (3.12) (push) Failing after 25s
CI / test (3.8) (push) Failing after 30s
CI / lint (push) Has been cancelled
CI / typecheck (push) Has been cancelled
CI / build-package (push) Has been cancelled
CI / test (3.9) (push) Has been cancelled
Some checks failed
CI / test (3.10) (push) Failing after 12s
CI / test (3.11) (push) Failing after 21s
CI / test (3.12) (push) Failing after 25s
CI / test (3.8) (push) Failing after 30s
CI / lint (push) Has been cancelled
CI / typecheck (push) Has been cancelled
CI / build-package (push) Has been cancelled
CI / test (3.9) (push) Has been cancelled
This commit is contained in:
63
devterm/tui/menu.py
Normal file
63
devterm/tui/menu.py
Normal file
@@ -0,0 +1,63 @@
|
||||
from rich.console import Console
|
||||
from rich.panel import Panel
|
||||
from rich.prompt import Prompt
|
||||
from rich.table import Table
|
||||
|
||||
|
||||
class DevtermMenu:
|
||||
def __init__(self):
|
||||
self.console = Console()
|
||||
self.tools = [
|
||||
("json", "JSON Formatter/Validator"),
|
||||
("jwt", "JWT Decoder"),
|
||||
("cron", "Cron Validator"),
|
||||
("base64", "Base64 Encoder/Decoder"),
|
||||
("url", "URL Encoder/Decoder"),
|
||||
]
|
||||
|
||||
def display_welcome(self):
|
||||
welcome_text = """
|
||||
[bold cyan]╔════════════════════════════════════════════════════════════╗
|
||||
║ [yellow]Devterm[/yellow] - Developer Tools ║
|
||||
║ ║
|
||||
║ A browser-based developer utilities suite ║
|
||||
║ Running at: http://{host}:{port} ║
|
||||
╚════════════════════════════════════════════════════════════╝[/bold cyan]"""
|
||||
self.console.print(welcome_text)
|
||||
|
||||
def display_menu(self):
|
||||
table = Table(title="Available Tools", show_header=True, header_style="bold magenta")
|
||||
table.add_column("#", justify="right", style="cyan")
|
||||
table.add_column("Tool", justify="left", style="green")
|
||||
table.add_column("Description", justify="left", style="white")
|
||||
|
||||
for idx, (tool_id, description) in enumerate(self.tools, 1):
|
||||
table.add_row(str(idx), f"[bold]{tool_id}[/bold]", description)
|
||||
|
||||
self.console.print(Panel(table, title="[bold]Devterm Menu[/bold]", expand=False))
|
||||
|
||||
def get_user_choice(self):
|
||||
self.display_welcome()
|
||||
self.console.print()
|
||||
self.display_menu()
|
||||
self.console.print()
|
||||
|
||||
choices = [str(i) for i in range(1, len(self.tools) + 1)]
|
||||
choice = Prompt.ask(
|
||||
"Select a tool to launch (or press Enter to open all in browser)",
|
||||
choices=choices + [""],
|
||||
default="",
|
||||
)
|
||||
|
||||
if choice == "":
|
||||
return None
|
||||
return self.tools[int(choice) - 1][0]
|
||||
|
||||
def show_starting_message(self, host: str, port: int):
|
||||
self.console.print(Panel(
|
||||
f"[green]Devterm is starting...[/green]\n\n"
|
||||
f"Access tools at: [bold]http://{host}:{port}[/bold]\n\n"
|
||||
f"Press [cyan]Ctrl+C[/cyan] to stop the server",
|
||||
title="[bold]Devterm[/bold]",
|
||||
expand=False
|
||||
))
|
||||
Reference in New Issue
Block a user