$ show rgwood/systemctl-tui
systemctl-tui is a terminal user interface for managing systemd services, written in Rust. It provides a fast, interactive alternative to the `systemctl` command-line tool, allowing users to browse, search, filter, and control systemd units (start/stop/restart/enable/mask/kill) and view live journal logs. The application supports both local operation and remote hosts over SSH, using D-Bus over a systemd-stdio-bridge connection on the remote side. Architecturally, the project is a Cargo workspace with three crates: `systemctl-ui-core` (shared library containing systemd D-Bus proxy, SSH helper, journal log parsing, formatting utilities, and a baked-in unit descriptions database), `systemctl-tui` (the main TUI binary built with ratatui, crossterm, and tokio), and `systemctl-gui` (an optional GTK4 frontend, not built by default). The TUI follows a single-component pattern with a large `Home` struct (~3000 lines) that implements a `Component` trait for initialization, event handling, and rendering. The event loop is asynchronous, with debounced journalctl calls and a spinner for service actions. Key features include fuzzy search, status filtering, context-sensitive action menus, a command palette, mouse support (drag to select log text), dark/light theme auto-detection, toast notifications for clipboard copies, and a pager for unit file editing. The project includes snapshot tests for the TUI, unit tests for core logic, and a comprehensive integration test matrix that runs against containers with systemd versions from 239 to current, as well as hostile hosts (no systemd).
The LLM identified 4 files worth highlighting for reuse:
Provides an `SshHost` struct that wraps SSH ControlMaster multiplexing for efficient connections to remote hosts. Includes `host_command` and `host_tokio_command` functions that abstract over local vs. remote command execution, allowing the rest of the application to invoke systemd commands uniformly. The module handles shell quoting, bridge argument construction for D-Bus over SSH, and connection lifecycle. This is a clean, self-contained utility that could be extracted and reused in any Rust project needing remote command execution with SSH.
Contains pure formatting functions: `format_systemd_timestamp` (converts systemd timestamp strings to human-readable absolute and relative times), `format_duration` (e.g., '1h 23m 45s'), and `format_bytes` (e.g., '12.5 MiB'). These functions have no side effects, no external dependencies beyond standard Rust, and are used by both TUI and GUI frontends. They could be easily extracted into a standalone utility crate for any application needing similar formatting.
Implements parsing of `journalctl --output=json` lines into structured `LogEntry` structs, including handling multi-line messages and mapping syslog priority codes to colored log levels. The `parse_json_log_line` function is a focused, well-tested parser that could be reused in any Rust project needing to parse journald JSON output, independent of the rest of the systemd integration.
The main TUI component encapsulating all application state, user interaction, and rendering. While large (~3000 lines) and tightly coupled to the specific application, it demonstrates a disciplined pattern of separating modes (Search, ServiceList, ActionMenu, Help, etc.) and using a `Component` trait. The use of `StatefulList<T>` for scrollable lists, debounced journalctl calls, and asynchronous dispatch via channels are patterns that could inspire similar architectures in other TUI applications. The file is not directly reusable without significant extraction, but the architectural patterns are noteworthy.