diff --git a/src/events.rs b/src/events.rs index 149d2f8..0d0466e 100644 --- a/src/events.rs +++ b/src/events.rs @@ -20,7 +20,7 @@ impl> Iterator for Batch { self.prev_data.push_str(&data); self.next() - } else if !self.prev_data.is_empty() { + } else if !self.prev_data.is_empty() || self.prev_time == 0.0 { let prev_time = self.prev_time; self.prev_time = time; let prev_data = std::mem::replace(&mut self.prev_data, data); @@ -125,6 +125,18 @@ mod tests { assert_eq!(&stdout[0], &(0.0, "foobar".to_owned())); assert_eq!(&stdout[1], &(0.066, "baz".to_owned())); assert_eq!(&stdout[2], &(1.0, "qux".to_owned())); + + let stdout = [ + (0.0, "".to_owned()), + (1.0, "foo".to_owned()), + (2.0, "bar".to_owned()), + ]; + + let stdout = super::batch(stdout.into_iter(), 30).collect::>(); + + assert_eq!(&stdout[0], &(0.0, "".to_owned())); + assert_eq!(&stdout[1], &(1.0, "foo".to_owned())); + assert_eq!(&stdout[2], &(2.0, "bar".to_owned())); } #[test] diff --git a/src/lib.rs b/src/lib.rs index cc62fb1..b46f9ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,7 @@ use clap::ArgEnum; use log::info; use std::fmt::{Debug, Display}; use std::io::{BufRead, Write}; -use std::{thread, time::Instant}; +use std::{iter, thread, time::Instant}; mod asciicast; mod events; mod fonts; @@ -124,6 +124,7 @@ pub fn run(input: I, output: O, config: Config) -> .unwrap_or(5.0); let stdout = asciicast::stdout(events); + let stdout = iter::once((0.0, "".to_owned())).chain(stdout); let stdout = events::limit_idle_time(stdout, itl); let stdout = events::accelerate(stdout, config.speed); let stdout = events::batch(stdout, config.fps_cap);