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:
@@ -2,6 +2,7 @@ use crate::animation::{easing::EasingFunction, effects::Effect, timeline::Timeli
|
|||||||
use crate::color::{apply, ColorEngine};
|
use crate::color::{apply, ColorEngine};
|
||||||
use crate::utils::{ansi, ascii::AsciiArt, terminal::TerminalManager};
|
use crate::utils::{ansi, ascii::AsciiArt, terminal::TerminalManager};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use crossterm::event::{self, Event, KeyCode, KeyModifiers};
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
|
|
||||||
pub struct Renderer<'a> {
|
pub struct Renderer<'a> {
|
||||||
@@ -37,6 +38,18 @@ impl<'a> Renderer<'a> {
|
|||||||
loop {
|
loop {
|
||||||
let frame_start = std::time::Instant::now();
|
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
|
// Calculate progress with easing
|
||||||
let linear_progress = timeline.progress();
|
let linear_progress = timeline.progress();
|
||||||
let eased_progress = self.easing.ease(linear_progress);
|
let eased_progress = self.easing.ease(linear_progress);
|
||||||
|
|||||||
Reference in New Issue
Block a user