rtlibs-tui 0.1.4

rtools library: ratatui widgets
Documentation
use ratatui::layout::Position;

use crate::widgets::CommanderState;

use super::AppCommanderCommand;

#[derive(Debug)]
pub struct AppCommanderState<T>
where
    T: AppCommanderCommand,
{
    pub(crate) commander: CommanderState,
    pub(crate) commands: Vec<T>,
}

impl<T> AppCommanderState<T>
where
    T: AppCommanderCommand,
{
    pub fn new(commands: Vec<T>) -> Self
    {
        let exported = commands
            .iter()
            .map(|c| c.command())
            .collect::<Vec<_>>();

        let commander = CommanderState::new(exported);

        Self {
            commander,
            commands,
        }
    }

    pub fn height(
        &self,
        width: u16,
    ) -> u16
    {
        self.commander
            .height(width)
    }

    pub fn cursor(&self) -> Option<Position>
    {
        self.commander
            .cursor()
    }

    pub fn set_message<S>(
        &mut self,
        message: S,
    ) where
        S: AsRef<str>,
    {
        self.commander
            .set_message(message)
    }

    pub fn clear_message(&mut self)
    {
        self.commander
            .clear_message()
    }
}