**CRITICAL BUG FIX**: When using -l (loop), the outer loop in main.rs was restarting the animation even after user pressed exit keys. Changes: - render() now returns Result<bool> instead of Result<()> - Returns true when user presses exit key (q/ESC/Ctrl+C) - Returns false when animation completes naturally - main.rs checks return value and breaks loop on user exit This fixes the infinite loop issue where pressing q/ESC/Ctrl+C had no effect when using the -l flag. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
59 lines
1.5 KiB
Rust
59 lines
1.5 KiB
Rust
pub mod easing;
|
|
pub mod effects;
|
|
pub mod renderer;
|
|
pub mod timeline;
|
|
|
|
use crate::color::ColorEngine;
|
|
use crate::utils::{ascii::AsciiArt, terminal::TerminalManager};
|
|
use anyhow::Result;
|
|
|
|
pub struct AnimationEngine {
|
|
ascii_art: AsciiArt,
|
|
duration_ms: u64,
|
|
fps: u32,
|
|
effect: Box<dyn effects::Effect>,
|
|
easing: Box<dyn easing::EasingFunction>,
|
|
color_engine: ColorEngine,
|
|
}
|
|
|
|
impl AnimationEngine {
|
|
pub fn new(ascii_text: String, duration_ms: u64, fps: u32) -> Self {
|
|
Self {
|
|
ascii_art: AsciiArt::new(ascii_text),
|
|
duration_ms,
|
|
fps,
|
|
effect: Box::new(effects::FadeIn),
|
|
easing: Box::new(easing::Linear),
|
|
color_engine: ColorEngine::new(),
|
|
}
|
|
}
|
|
|
|
pub fn with_effect(mut self, effect_name: &str) -> Result<Self> {
|
|
self.effect = effects::get_effect(effect_name)?;
|
|
Ok(self)
|
|
}
|
|
|
|
pub fn with_easing(mut self, easing_name: &str) -> Result<Self> {
|
|
self.easing = easing::get_easing_function(easing_name)?;
|
|
Ok(self)
|
|
}
|
|
|
|
pub fn with_color_engine(mut self, color_engine: ColorEngine) -> Self {
|
|
self.color_engine = color_engine;
|
|
self
|
|
}
|
|
|
|
pub async fn run(&self, terminal: &mut TerminalManager) -> Result<bool> {
|
|
let renderer = renderer::Renderer::new(
|
|
&self.ascii_art,
|
|
self.duration_ms,
|
|
self.fps,
|
|
&*self.effect,
|
|
&*self.easing,
|
|
&self.color_engine,
|
|
);
|
|
|
|
renderer.render(terminal).await
|
|
}
|
|
}
|