run

Function run 

Source
pub async fn run(dry_run_flag: bool) -> Result<(), Box<dyn Error + Send + Sync>>
Expand description

What: Run the Pacsea TUI application end-to-end.

This function initializes terminal and state, spawns background workers (index, search, details, status/news), drives the event loop, persists caches, and restores the terminal on exit.

Inputs:

  • dry_run_flag: When true, install/remove/downgrade actions are displayed but not executed (overrides the config default for the session).

Output:

  • Ok(()) when the UI exits cleanly; Err on unrecoverable terminal or runtime errors.

ยงErrors

  • Returns Err when terminal setup fails (e.g., unable to initialize terminal backend)
  • Returns Err when terminal restoration fails on exit
  • Returns Err when critical runtime errors occur during initialization or event loop execution

Details:

  • Config/state: Migrates legacy configs, loads settings (layout, keymap, sort), and reads persisted files (details cache, recent queries, install list, on-disk official index).
  • Background tasks: Spawns channels and tasks for batched details fetch, AUR/official search, PKGBUILD retrieval, official index refresh/enrichment, Arch status text, and Arch news.
  • Event loop: Renders UI frames and handles keyboard, mouse, tick, and channel messages to update results, details, ring-prefetch, PKGBUILD viewer, installed-only mode, and modals.
  • Persistence: Debounces and periodically writes recent, details cache, and install list.
  • Cleanup: Flushes pending writes and restores terminal modes before returning.