tuiserial_core/
notification.rs1use std::time::Instant;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum NotificationLevel {
11 Info,
12 Warning,
13 Error,
14 Success,
15}
16
17#[derive(Debug, Clone)]
19pub struct Notification {
20 pub message: String,
21 pub level: NotificationLevel,
22 pub created_at: Instant,
23 pub duration_ms: u64,
24}
25
26impl Notification {
27 pub fn new(message: String, level: NotificationLevel) -> Self {
29 Self {
30 message,
31 level,
32 created_at: Instant::now(),
33 duration_ms: 3000, }
35 }
36
37 pub fn info(message: String) -> Self {
39 Self::new(message, NotificationLevel::Info)
40 }
41
42 pub fn warning(message: String) -> Self {
44 Self::new(message, NotificationLevel::Warning)
45 }
46
47 pub fn error(message: String) -> Self {
49 Self::new(message, NotificationLevel::Error)
50 }
51
52 pub fn success(message: String) -> Self {
54 Self::new(message, NotificationLevel::Success)
55 }
56
57 pub fn is_expired(&self) -> bool {
59 self.created_at.elapsed().as_millis() as u64 > self.duration_ms
60 }
61}