rtlibs-tui 0.1.5

rtools library: ratatui widgets
Documentation
mod service;
mod state;
mod widget;

pub use service::*;
pub use state::*;
pub use widget::*;

use ratatui::style::Style;

#[derive(Debug)]
pub enum NotificationKind
{
    Success,
    Error,
    Info,
    Warning,
}

#[derive(Debug)]
pub struct NotificationItem
{
    message: String,
    timer: usize,
    kind: NotificationKind,
}

impl NotificationItem
{
    pub fn new<S>(
        message: S,
        kind: NotificationKind,
        starting_timer: usize,
    ) -> Self
    where
        S: AsRef<str>,
    {
        let inner = move |message: &str| Self {
            message: message.to_string(),
            timer: starting_timer,
            kind,
        };

        inner(message.as_ref())
    }

    fn get_color(
        &self,
        style: &NotificationWidgetStyle,
    ) -> (
        String,
        Style,
    )
    {
        match self.kind
        {
            NotificationKind::Success => (
                "SUCCESS".to_string(),
                style.success,
            ),
            NotificationKind::Error => (
                "ERROR".to_string(),
                style.error,
            ),
            NotificationKind::Info => (
                "INFO".to_string(),
                style.info,
            ),
            NotificationKind::Warning => (
                "WARNING".to_string(),
                style.warning,
            ),
        }
    }
}