resq-tui
Version:v0.1.8· License:Apache-2.0· Crate: crates.io · API docs: docs.rs
Overview
resq-tui ensures every ResQ tool (resq-logs, resq-perf, resq-flame, resq-health, etc.) shares a consistent visual identity and interaction model. It provides two tiers of output:
- Full-screen TUI — Ratatui-based widgets (header, footer, tabs, popups) with a standardized theme for interactive terminal applications.
- Non-TUI CLI — Styled console formatters, tables, progress bars, and spinners for traditional command-line output that gracefully degrade when piped or redirected.
Architecture
Module dependency flow
Installation
Add to yourCargo.toml:
Module Reference
lib.rs — Core Widgets and Utilities
The root module re-exports crossterm and ratatui for convenience and provides the original Theme struct alongside shared TUI drawing functions.
Theme (root)
The original hardcoded dark-palette theme struct, retained for backward compatibility. For new code, prefer theme::Theme::adaptive() (see below).
Widget Functions
draw_header
Renders a standardized header bar with service name, status badge, PID, and URL.
draw_footer
Renders a keyboard-shortcut footer bar.
draw_tabs
Renders a tab bar with selection highlight. Uses the default theme internally.
draw_popup
Renders a centered modal overlay for help dialogs or error messages.
centered_rect
Helper that computes a centered Rect given percentage dimensions. Used internally by draw_popup.
Utility Functions
format_bytes
Converts a byte count to a human-readable string using binary units (KiB, MiB, GiB).
format_duration
Converts seconds to a human-readable duration string.
SPINNER_FRAMES
Braille animation frames for TUI spinner widgets:
theme — Adaptive Color System
The theme module provides a Dracula-inspired adaptive color palette that switches between light and dark variants based on terminal environment detection.
AdaptiveColor
A color pair with light and dark variants that resolves at runtime via detect_color_mode().
Palette Constants
Theme (theme module)
Extended theme struct with adaptive color support.
detect — Terminal Environment Detection
Detects TTY status, color support, and accessibility mode. All detection is cached per-process via OnceLock.
Environment Variables
ColorMode
Public Functions
console — Styled Message Formatters
TTY-gated console formatters for non-TUI CLI output. Diagnostics go to stderr, structured data to stdout. All styling respects detect::should_style().
Format Functions (return String)
Print Functions (write to stderr)
Convenience wrappers that call the correspondingformat_* function and print to stderr:
table — CLI Table Renderer
Renders styled tables to stderr with zebra-striped rows, auto-computed column widths, and adaptive colors. Falls back to plain aligned text when styling is disabled.
Align
Column
Builder for table column definitions.
render_table
Renders a complete table to stderr.
progress — CLI Progress Bar
Non-TUI progress bar rendered to stderr with adaptive gradient colors. Falls back to plain ASCII in non-TTY mode.
ProgressBar
Downloading ████████████████░░░░░░░░░░░░░░░░░░░░░░░░ 40%
Non-TTY output: Downloading [################------------------------] 40%
spinner — Threaded CLI Spinner
Thread-safe stderr spinner that respects TTY and accessibility settings. Uses braille animation by default with a plain-dots fallback.
SPINNER_FRAMES
Braille frames used by both the TUI spinner constant and the non-TUI Spinner:
Spinner
The spinner is also stopped automatically on
Drop.
start() prints "Fetching service health..." once and returns immediately.
terminal — Terminal Lifecycle Management
Manages raw mode, alternate screen, and provides a standard event loop for Ratatui applications.
Type Alias
init() -> anyhow::Result<Term>
Enables raw mode, enters the alternate screen, and returns an initialized Term.
restore()
Leaves the alternate screen and disables raw mode. Safe to call even in a partially-initialized state.
TuiApp Trait
Implement this trait on your application state to use run_loop.
false from handle_key to exit the event loop. Ctrl+C always exits.
run_loop
Runs a standard TUI event loop. poll_ms controls input polling frequency.
Integration Guide
Building a new ResQ TUI tool
- Add the dependency to your crate’s
Cargo.toml:
- Implement
TuiAppon your application state:
- Run the event loop in
main:
Using non-TUI console output
For CLI tools that do not need a full-screen TUI:Accessibility
resq-tui respects the following standards:
NO_COLOR(no-color.org) — disables all ANSI color codesTERM=dumb— plain text output onlyACCESSIBLE— activates screen-reader-friendly output (plain dot spinners, no animation)- Non-TTY pipes and redirects receive unstyled output automatically