cetus-utils 0.1.0

The utils of cetus clmmpool
Documentation
use colored::Colorize;
use tabled::{
    object::Segment, style::Color, Alignment, Modify, Panel, Rotate, Style, Table, Tabled,
};

// Colors
#[allow(dead_code)]
pub fn blue() -> Option<Color> {
    Some(Color::try_from(" ".blue().to_string()).unwrap())
}

#[allow(dead_code)]
pub fn cyan() -> Option<Color> {
    Some(Color::try_from(" ".cyan().to_string()).unwrap())
}

#[allow(dead_code)]
pub fn green() -> Option<Color> {
    Some(Color::try_from(" ".green().to_string()).unwrap())
}

#[allow(dead_code)]
pub fn red() -> Option<Color> {
    Some(Color::try_from(" ".red().to_string()).unwrap())
}

#[allow(dead_code)]
pub fn render_list<I, T>(iter: I, panel: &str, color: Option<Color>) -> String
where
    I: IntoIterator<Item = T>,
    T: Tabled,
{
    let color = if color.is_some() {
        color.unwrap()
    } else {
        cyan().unwrap()
    };
    let style = Style::rounded()
        .top_left_corner('')
        .top_right_corner('')
        .bottom_left_corner('')
        .bottom_right_corner('');
    let data = Table::new(iter)
        .with(style)
        .with(color)
        .with(Modify::new(Segment::all()).with(Alignment::center()))
        .to_string();
    if !panel.is_empty() {
        format!("- {}\n{}", panel, data)
    } else {
        data
    }
}

#[allow(dead_code)]
pub fn render_object<I>(object: I, panel: &str, color: Option<Color>) -> String
where
    I: Tabled,
{
    let color = if color.is_some() {
        color.unwrap()
    } else {
        cyan().unwrap()
    };
    let panel = format!(" {}", panel);
    Table::new(vec![object])
        .with(Rotate::Left)
        .with(Rotate::Bottom)
        .with(Style::modern().off_horizontal())
        .with(color)
        .with(Panel(panel.as_str(), 0))
        .with(Modify::new(Segment::all()).with(Alignment::left()))
        .to_string()
}