Add keyboard input handling to allow exiting animations

Fixed issue where Ctrl+C did not work to exit looping animations.
In raw terminal mode, signals are not automatically handled, so we
need to manually poll for keyboard events.

Changes:
- Added crossterm event polling in render loop
- Check for Ctrl+C, 'q', or ESC key to exit animation
- Polls with 0ms timeout to avoid blocking animation frames

Users can now exit with:
- Ctrl+C
- Press 'q'
- Press ESC

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-09 06:29:02 +01:00
parent 4035f2dc23
commit 5a0ff3f5cc

View File

@@ -2,6 +2,7 @@ use crate::animation::{easing::EasingFunction, effects::Effect, timeline::Timeli
use crate::color::{apply, ColorEngine};
use crate::utils::{ansi, ascii::AsciiArt, terminal::TerminalManager};
use anyhow::Result;
use crossterm::event::{self, Event, KeyCode, KeyModifiers};
use tokio::time::sleep;
pub struct Renderer<'a> {
@@ -37,6 +38,18 @@ impl<'a> Renderer<'a> {
loop {
let frame_start = std::time::Instant::now();
// Check for Ctrl+C or 'q' to exit
if event::poll(std::time::Duration::from_millis(0))? {
if let Event::Key(key) = event::read()? {
if key.code == KeyCode::Char('c') && key.modifiers.contains(KeyModifiers::CONTROL) {
break;
}
if key.code == KeyCode::Char('q') || key.code == KeyCode::Esc {
break;
}
}
}
// Calculate progress with easing
let linear_progress = timeline.progress();
let eased_progress = self.easing.ease(linear_progress);