terminal_style
What it is
A small set of terminal UI helpers for the Oxigraph Admin CLI, built on top of the rich library. It provides consistent styled output (welcome panel, dividers, status messages, tables) and interactive prompts.
Public API
-
console: rich.console.Console- Shared
Consoleinstance used by all helpers.
- Shared
-
set_terminal_title()- Attempts to set the terminal window title to
"Oxigraph Admin"using an ANSI escape sequence.
- Attempts to set the terminal window title to
-
print_welcome_message()- Sets the terminal title and prints a centered welcome
Panelwith title/subtitle.
- Sets the terminal title and prints a centered welcome
-
print_divider()- Prints a horizontal divider line sized to
console.width.
- Prints a horizontal divider line sized to
-
print_status_info(text)- Prints an informational line (styled, prefixed with ℹ️).
-
print_success_message(text)- Prints a success line (styled, prefixed with ✅).
-
print_error_message(text)- Prints an error line (styled, prefixed with ❌).
-
print_warning_message(text)- Prints a warning line (styled, prefixed with ⚠️).
-
print_menu_options(options)- Prints a menu header and each option from
options(iterable of strings).
- Prints a menu header and each option from
-
get_user_input(prompt_text="Enter your choice") -> str- Prompts the user using
rich.prompt.Prompt.ask. - Returns
"exit"onKeyboardInterruptorEOFError(Ctrl+C prints an exit message).
- Prompts the user using
-
clear_screen()- Clears the terminal via
console.clear().
- Clears the terminal via
-
print_health_status(healthy: bool, message: str)- Prints a green “healthy” or red “unhealthy” status line.
-
print_container_info(container_data)- Renders a
rich.table.Tableof container info. - Expects an iterable of dict-like objects with keys:
Name,State,Ports,Created(defaults to"Unknown"/"None"). - Adds a colored status emoji based on
State(running,exited, other).
- Renders a
-
print_performance_metrics(metrics)- Prints key/value metrics with simple key-based formatting:
- keys containing
time/latency→...ms - keys containing
count/total→ formatted with thousands separators - keys containing
memory/size→ printed as-is - otherwise generic display
- keys containing
- Prints key/value metrics with simple key-based formatting:
-
print_data_stats(stats)- Prints data stats; integers are formatted with thousands separators.
-
confirmation_prompt(message: str, danger: bool = False) -> bool- Asks for confirmation:
danger=True: user must typeYES(defaultNO)danger=False: user choosesy/n(defaultn)
- Asks for confirmation:
Configuration/Dependencies
- Requires
rich:rich.console.Console,rich.panel.Panel,rich.text.Text,rich.align.Align,rich.prompt.Promptrich.table.Table(imported insideprint_container_info)
- No additional configuration; uses a module-level
Console()instance.
Usage
from naas_abi.apps.oxigraph_admin import terminal_style as ts
ts.print_welcome_message()
ts.print_divider()
ts.print_status_info("Checking services...")
ts.print_health_status(True, "Oxigraph is responding")
ts.print_menu_options(["1) Show containers", "2) Restart service", "exit) Quit"])
choice = ts.get_user_input("Select an option")
if choice == "exit":
raise SystemExit
containers = [
{"Name": "oxigraph", "State": "running", "Ports": "7878/tcp", "Created": "2026-03-01"},
]
ts.print_container_info(containers)
if ts.confirmation_prompt("Restart Oxigraph?", danger=True):
ts.print_success_message("Restart confirmed")
else:
ts.print_warning_message("Restart cancelled")Caveats
set_terminal_title()uses an ANSI escape sequence; some terminals may ignore it.get_user_input()returns the literal string"exit"on Ctrl+C/EOF; callers should handle this sentinel.- Emoji characters are used in output; display depends on terminal font/encoding support.