use instant::Instant; use std::time::Duration; use crate::constants::*; pub enum FlashingMessageIntent { Start, Quit, Save, Restore, Restart, } pub struct FlashingMessage { pub message: String, pub color: usize, pub last_changed_color: Instant, pub intent: Option, } impl FlashingMessage { pub fn new(message: &str, intent: Option) -> Self { Self { message: message.to_string(), color: 14, last_changed_color: Instant::now(), intent, } } pub fn next_color(&mut self) { let now = Instant::now(); if now - self.last_changed_color > Duration::from_secs_f32(FLASHING_PERIOD) { self.color += 1; if self.color > 15 { self.color = 13 } self.last_changed_color = now; } } } impl From<&str> for FlashingMessage { fn from(message: &str) -> Self { Self::new(message, None) } }