Skip to content

Add alt-screen and key bindings to live mode#28

Merged
Tairesh merged 2 commits intomainfrom
live-mode-alt-screen
May 5, 2026
Merged

Add alt-screen and key bindings to live mode#28
Tairesh merged 2 commits intomainfrom
live-mode-alt-screen

Conversation

@Tairesh
Copy link
Copy Markdown
Owner

@Tairesh Tairesh commented May 5, 2026

Summary

Live mode now uses the terminal's alternate screen buffer with non-blocking key handling, so the user's existing terminal contents are preserved and they can quit or refresh interactively.

  • Alt screen: enters via crossterm on first successful fetch, restored on exit (clean exit, Ctrl+C, error path, panic) by a TerminalGuard RAII type.
  • Keys: q / Esc / Ctrl+C quit immediately; r forces an immediate refresh.
  • Footer: optional one-line footer with key hints + last-update timestamp ([q] quit [r] refresh • last update: HH:MM:SS). Configurable via live_mode_footer = true|false in TOML and --no-footer on the CLI.
  • First fetch outside alt screen: keeps the user's normal terminal visible while the initial API call loads instead of showing a blank alt screen.
  • Provider-fallback refactor: App::fetch_with_fallback is now a method, used by both one-shot and live paths. The live path can now return Result so TerminalGuard runs before any error exit (previously display_error called process::exit, skipping destructors).

Test plan

  • just check passes — 104 tests, clippy -D pedantic clean
  • New regression tests for live_mode_footer config field (defaults, explicit false, CLI override, CLI absent preserves config value)
  • New tests for format_footer (color on/off) and write_payload (CRLF translation, 5 edge cases)
  • New tests for WeatherFormatter::render_to_string (full text + one-line modes)
  • Manual smoke test on Linux: cargo run -- -c "<city>" --live -i 10 — verify alt-screen restore, key bindings, footer
  • Manual smoke test with --no-footer
  • Manual smoke test on macOS / Windows (nice-to-have)

Notes

  • Adds a single dependency: crossterm = "0.28" (cross-platform alt-screen + raw mode + key events; no separate ctrlc crate needed since Ctrl+C arrives as a regular KeyEvent in raw mode).
  • One-shot path (rustormy -c <city>) is byte-for-byte identical to before — only the live path changed.
  • \n → \r\n translation is required because raw mode disables the kernel's ONLCR line-discipline; verified to behave the same on Linux, macOS, and Windows console.

@Tairesh Tairesh added enhancement New feature or request dependencies Pull requests that update a dependency file rust Pull requests that update rust code labels May 5, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements a robust live mode for the weather application using the crossterm library, featuring an alternate screen buffer, an interactive event loop, and a customizable footer with update timestamps. The core application logic was refactored to separate weather data fetching and rendering, allowing for continuous updates and better error handling with provider fallbacks. Review feedback highlights opportunities to optimize performance by passing weather data by reference instead of by value and suggests improving the event loop to handle terminal resize events to prevent display corruption.

Comment thread src/display/formatter.rs Outdated
Comment thread src/live.rs Outdated
Comment thread src/live.rs Outdated
- Live mode now uses the terminal's alternate screen buffer via crossterm
  and restores the original screen on exit (clean exit, Ctrl+C, or panic)
  through a TerminalGuard RAII type.
- Add interactive keys: q / Esc / Ctrl+C to quit, r to force refresh.
- Add footer with key hints and last-update timestamp; suppressible via
  live_mode_footer = false in config or --no-footer on the CLI.
- Initial fetch runs before entering the alt screen so the user's existing
  terminal contents stay visible during the first API call.
- Refactor provider fallback into App::fetch_with_fallback method so the
  live path can return Result and let the guard restore the terminal
  before display_error's process::exit fires.
@Tairesh Tairesh force-pushed the live-mode-alt-screen branch from f933050 to 7976997 Compare May 5, 2026 16:36
- Handle Event::Resize in the live mode event loop instead
  of dropping it via a let-chain — raw mode resize was
  corrupting the display until the next refresh tick
- Take &Weather in formatter and render fns so the cached
  weather can be re-rendered without re-fetching or cloning
@Tairesh Tairesh merged commit a5de93a into main May 5, 2026
8 of 9 checks passed
@Tairesh Tairesh deleted the live-mode-alt-screen branch May 5, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file enhancement New feature or request rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant