terminal_style
What it is
- A small set of terminal UI helpers for the Oxigraph Admin CLI.
- Uses the
richlibrary to render styled messages, panels, tables, and prompts.
Public API
set_terminal_title()- Attempts to set the terminal window title to
Oxigraph Adminusing an ANSI escape sequence.
- Attempts to set the terminal window title to
print_welcome_message()- Clears spacing and prints a centered welcome panel (title/subtitle) and sets terminal title.
print_divider()- Prints a dim horizontal divider sized to the current console width.
print_status_info(text)- Prints an informational message (blue).
print_success_message(text)- Prints a success message (green).
print_error_message(text)- Prints an error message (red).
print_warning_message(text)- Prints a warning message (yellow).
print_menu_options(options)- Prints a titled list of available operations.
get_user_input(prompt_text="Enter your choice")- Prompts the user for input via
rich.prompt.Prompt.ask. - Returns
"exit"onKeyboardInterruptorEOFError(also prints a message on Ctrl+C).
- Prompts the user for input via
clear_screen()- Clears the terminal via
richconsole.
- Clears the terminal via
print_health_status(healthy: bool, message: str)- Prints a green “Status” line if healthy, otherwise red.
print_container_info(container_data)- Renders a
rich.table.Tableof container details. - Expects an iterable of dict-like items with keys:
Name,State,Ports,Created(defaults provided).
- Renders a
print_performance_metrics(metrics)- Prints a formatted list of metrics with basic key-based categorization:
- time/latency →
ms - count/total → thousands-separated
- memory/size → printed as-is
- time/latency →
- Prints a formatted list of metrics with basic key-based categorization:
print_data_stats(stats)- Prints key/value stats; integers are thousands-separated.
confirmation_prompt(message: str, danger: bool = False) -> bool- If
danger=True: requires typingYESto confirm (defaultNO). - Else: asks to continue with choices
y/n(defaultn).
- If
Configuration/Dependencies
- Dependency:
rich(Console,Panel,Text,Align,Prompt, andTable). - Uses a module-level
console = Console()instance for all output.
Usage
from naas_abi.apps.oxigraph_admin import terminal_style as ui
ui.print_welcome_message()
ui.print_menu_options(["1) Health check", "2) List containers", "exit) Quit"])
choice = ui.get_user_input("Select an option")
if choice == "1":
ui.print_health_status(True, "Oxigraph is running")
elif choice == "2":
ui.print_container_info([
{"Name": "oxigraph", "State": "running", "Ports": "7878/tcp", "Created": "2026-04-01"},
])
elif choice == "exit":
ui.print_warning_message("Exiting...")
else:
ui.print_error_message(f"Unknown option: {choice}")
Caveats
set_terminal_title()relies on ANSI escape sequences and may not work in all terminals; failures are silently ignored.print_container_info()expectscontainer_dataentries to be dict-like; missing keys fall back to"Unknown"/"None".