rtlibs-tui 0.1.4

rtools library: ratatui widgets
Documentation
use super::NotificationItem;
use super::NotificationKind;

#[derive(Debug)]
pub struct NotificationService
{
    pub default_timer: usize,
    pub items: Vec<NotificationItem>,
}

impl Default for NotificationService
{
    fn default() -> Self
    {
        Self::new()
    }
}

impl NotificationService
{
    pub fn new() -> Self
    {
        Self {
            default_timer: 300,
            items: Vec::new(),
        }
    }

    // pub fn items_mut(&mut self) -> &mut Vec<NotificationItem>
    // {
    //     &mut self.items
    // }

    pub fn with_default_timer(
        mut self,
        timer: usize,
    ) -> Self
    {
        self.default_timer = timer;
        self
    }

    pub fn error<S>(
        &mut self,
        message: S,
    ) where
        S: AsRef<str>,
    {
        self.items
            .push(
                NotificationItem::new(
                    message,
                    NotificationKind::Error,
                    self.default_timer,
                ),
            );
    }

    pub fn success<S>(
        &mut self,
        message: S,
    ) where
        S: AsRef<str>,
    {
        self.items
            .push(
                NotificationItem::new(
                    message,
                    NotificationKind::Success,
                    self.default_timer,
                ),
            );
    }

    pub fn info<S>(
        &mut self,
        message: S,
    ) where
        S: AsRef<str>,
    {
        self.items
            .push(
                NotificationItem::new(
                    message,
                    NotificationKind::Info,
                    self.default_timer,
                ),
            );
    }

    pub fn warning<S>(
        &mut self,
        message: S,
    ) where
        S: AsRef<str>,
    {
        self.items
            .push(
                NotificationItem::new(
                    message,
                    NotificationKind::Warning,
                    self.default_timer,
                ),
            );
    }
}