Fix loading of asciicast v1

This commit is contained in:
Marcin Kulik
2025-05-06 17:01:22 +02:00
parent e4b888178f
commit dd6b9a3008
3 changed files with 10 additions and 10 deletions

View File

@@ -193,10 +193,10 @@ mod tests {
assert_eq!(events[0].time, 1);
assert!(matches!(events[0].data, EventData::Output(ref s) if s == "ż"));
assert_eq!(events[1].time, 1000000);
assert_eq!(events[1].time, 10000001);
assert!(matches!(events[1].data, EventData::Output(ref s) if s == "ółć"));
assert_eq!(events[2].time, 10500000);
assert_eq!(events[2].time, 10500001);
assert!(matches!(events[2].data, EventData::Output(ref s) if s == "\r\n"));
}

View File

@@ -50,12 +50,12 @@ pub fn load(json: String) -> Result<Asciicast<'static>> {
env: asciicast.env.clone(),
};
let events = Box::new(
asciicast
.stdout
.into_iter()
.map(|e| Ok(Event::output(e.time, e.data))),
);
let events = Box::new(asciicast.stdout.into_iter().scan(0, |prev_time, event| {
let time = *prev_time + event.time;
*prev_time = time;
Some(Ok(Event::output(time, event.data)))
}));
Ok(Asciicast { header, events })
}

View File

@@ -15,11 +15,11 @@
"ż"
],
[
1.000000,
10.00,
"ółć"
],
[
10.500000,
0.5,
"\r\n"
]
]