use std::time::Duration;
use nutype::nutype;
pub(super) const ACTIVITY_FRAME_INTERVAL: Duration = Duration::from_millis(100);
const ACTIVITY_FRAMES: [&str; 10] = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
#[nutype(derive(Debug, Clone, Copy, PartialEq, Eq))]
pub(crate) struct ActivityFrame(usize);
impl ActivityFrame {
pub(super) fn initial() -> Self {
Self::new(0)
}
pub(super) fn next(self) -> Self {
Self::new((self.into_inner() + 1) % ACTIVITY_FRAMES.len())
}
pub(super) fn glyph(self) -> &'static str {
ACTIVITY_FRAMES[self.into_inner()]
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn spinner_wraps_after_its_last_frame() {
let mut frame = ActivityFrame::initial();
for _ in ACTIVITY_FRAMES {
frame = frame.next();
}
assert_eq!(frame, ActivityFrame::initial());
}
}