rtlibs-tui 0.1.4

rtools library: ratatui widgets
Documentation
#[derive(Debug, Default)]
pub enum StatusBarPosition
{
    Right,
    #[default]
    Left,
}

#[derive(Debug)]
pub struct StatusBarItem
{
    pub key: String,
    pub position: StatusBarPosition,
    pub max_width: Option<usize>,
    pub value: Option<String>,
}

impl StatusBarItem
{
    pub fn new<S>(key: S) -> Self
    where
        S: AsRef<str>,
    {
        let inner = move |key: &str| Self {
            key: key.to_string(),
            position: StatusBarPosition::Left,
            max_width: None,
            value: None,
        };

        inner(key.as_ref())
    }

    pub fn with_value<S>(
        mut self,
        value: S,
    ) -> Self
    where
        S: AsRef<str>,
    {
        self.set_value(value);
        self
    }

    pub fn set_value<S>(
        &mut self,
        value: S,
    ) where
        S: AsRef<str>,
    {
        let mut inner = |value: &str| {
            self.value = Some(value.to_string());
        };

        inner(value.as_ref())
    }

    pub fn clear_value(&mut self)
    {
        self.value = None;
    }

    pub fn right_aligned(mut self) -> Self
    {
        self.position = StatusBarPosition::Right;
        self
    }

    pub fn left_aligned(mut self) -> Self
    {
        self.position = StatusBarPosition::Left;
        self
    }

    pub fn with_max_width(
        mut self,
        width: usize,
    ) -> Self
    {
        self.max_width = Some(width);
        self
    }
}