Flash
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use ratatui::style::Color;
|
||||
|
||||
use crate::state::Modal;
|
||||
|
||||
pub struct Sparkle {
|
||||
@@ -13,6 +15,7 @@ pub struct UiState {
|
||||
pub sparkles: Vec<Sparkle>,
|
||||
pub status_message: Option<String>,
|
||||
pub flash_until: Option<Instant>,
|
||||
pub flash_color: Color,
|
||||
pub modal: Modal,
|
||||
pub doc_topic: usize,
|
||||
pub doc_scroll: usize,
|
||||
@@ -28,6 +31,7 @@ impl Default for UiState {
|
||||
sparkles: Vec::new(),
|
||||
status_message: None,
|
||||
flash_until: None,
|
||||
flash_color: Color::Green,
|
||||
modal: Modal::None,
|
||||
doc_topic: 0,
|
||||
doc_scroll: 0,
|
||||
@@ -40,9 +44,14 @@ impl Default for UiState {
|
||||
}
|
||||
|
||||
impl UiState {
|
||||
pub fn flash(&mut self, msg: &str, duration_ms: u64) {
|
||||
pub fn flash(&mut self, msg: &str, duration_ms: u64, color: Color) {
|
||||
self.status_message = Some(msg.to_string());
|
||||
self.flash_until = Some(Instant::now() + Duration::from_millis(duration_ms));
|
||||
self.flash_color = color;
|
||||
}
|
||||
|
||||
pub fn flash_color(&self) -> Option<Color> {
|
||||
if self.is_flashing() { Some(self.flash_color) } else { None }
|
||||
}
|
||||
|
||||
pub fn set_status(&mut self, msg: String) {
|
||||
|
||||
Reference in New Issue
Block a user