Skip to content

Commit

Permalink
Add initial blank frame (fixes #45)
Browse files Browse the repository at this point in the history
  • Loading branch information
ku1ik committed Jun 11, 2023
1 parent 65110c6 commit 6e33da7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<I: Iterator<Item = Event>> Iterator for Batch<I> {
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);
Expand Down Expand Up @@ -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::<Vec<_>>();

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]
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -124,6 +124,7 @@ pub fn run<I: BufRead, O: Write + Send>(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);
Expand Down

0 comments on commit 6e33da7

Please sign in to comment.