tuigui 0.23.0

An easy-to-use, highly extensible, and speedy TUI library.
Documentation
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Effect {
    Bold,
    Dimmed,
    Italic,
    Underline,
    Blink,
    BlinkFast,
    Reversed,
    Hidden,
    Strikethrough,
}

#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum AnsiColor {
    Black,
    BrightBlack,

    Red,
    BrightRed,

    Green,
    BrightGreen,

    Yellow,
    BrightYellow,

    Blue,
    BrightBlue,

    Magenta,
    BrightMagenta,

    Cyan,
    BrightCyan,

    White,
    BrightWhite,
}

impl Into<Color> for AnsiColor {
    fn into(self) -> Color {
        Color::Ansi(self)
    }
}

impl Into<StyleGround> for Color {
    fn into(self) -> StyleGround {
        StyleGround::Color(self)
    }
}

impl<T: Into<Color>> Into<StyleGround> for Option<T> {
    fn into(self) -> StyleGround {
        match self {
            Some(s) => StyleGround::Color(s.into()),
            None => StyleGround::Clear,
        }
    }
}

#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Color {
    Custom {
        r: u8,
        g: u8,
        b: u8,
    },
    Ansi(AnsiColor),
}

impl Color {
    pub fn rgb(r: u8, g: u8, b: u8) -> Self {
        Self::Custom {
            r,
            g,
            b,
        }
    }

    pub fn ansi(color: AnsiColor) -> Self {
        Self::Ansi(color)
    }
}

#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum StylePullLayer {
    /// Pull from foreground
    Foreground,
    /// Pull from background
    Background,
    /// Pull from same layer
    Same,
    /// Pull something from any layer if possible
    Any,
    /// Pull color from any layer if possible
    AnyColor,
}

#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum StyleGround {
    /// Nothing (terminal background)
    Clear,
    /// Color
    Color(Color),
    /// Based on the widget behind
    Transparent(StylePullLayer),
    /// Based on the context filler (x-ray)
    Filler(StylePullLayer),
}

impl StyleGround {
    #[inline(always)]
    /// Returns 'true' if the style ground
    /// is not a variant that eventually gets
    /// finalized like transparency or filler
    /// but instead is a final variant like
    /// a color or a clear
    pub fn is_final(&self) -> bool {
        return match self {
            Self::Clear => true,
            Self::Color(_) => true,
            Self::Transparent(_) => false,
            Self::Filler(_) => false,
        };
    }

    #[inline(always)]
    pub fn is_color(&self) -> bool {
        return match self {
            Self::Color(_) => true,
            _ => false,
        };
    }

    #[inline(always)]
    pub fn is_clear(&self) -> bool {
        return match self {
            Self::Clear => true,
            _ => false,
        };
    }
}

#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
/// Style for content that appears in the frame buffer
pub struct Style {
    pub fg: StyleGround,
    pub bg: StyleGround,
    pub effects: Vec<Effect>,
}

impl Style {
    pub fn new() -> Self {
        Self {
            fg: StyleGround::Clear,
            bg: StyleGround::Clear,
            effects: Vec::new(),
        }
    }

    pub fn fg(mut self, foreground: impl Into<StyleGround>) -> Self {
        self.fg = foreground.into();

        return self;
    }

    pub fn bg(mut self, background: impl Into<StyleGround>) -> Self {
        self.bg = background.into();

        return self;
    }

    pub fn effect(mut self, effect: Effect) -> Self {
        self.effects.push(effect);

        return self;
    }

    pub fn effects(mut self, effects: &[Effect]) -> Self {
        for i in effects {
            self.effects.push(*i);
        }

        return self;
    }

    pub fn has_effect(&self, effect: Effect) -> bool {
        return self.effects.contains(&effect);
    }
}