use std::{borrow::Cow, fmt::Display};
use colored::Color;
#[derive(Debug, Default)]
pub enum BoxType {
Classic,
#[default]
Single,
DoubleHorizontal,
DoubleVertical,
Double,
Bold,
Rounded,
BoldCorners,
Empty,
}
impl Display for BoxType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = match &self {
BoxType::Classic => "classic".to_string(),
BoxType::Single => "single".to_string(),
BoxType::DoubleHorizontal => "double_horizontal".to_string(),
BoxType::DoubleVertical => "double_vertical".to_string(),
BoxType::Double => "double".to_string(),
BoxType::Bold => "bold".to_string(),
BoxType::Rounded => "rounded".to_string(),
BoxType::BoldCorners => "bold_corners".to_string(),
BoxType::Empty => "empty".to_string(),
};
write!(f, "{}", str)
}
}
#[derive(Debug, Default)]
pub enum BoxAlign {
Left,
#[default]
Center,
Right,
}
impl Display for BoxAlign {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = match self {
BoxAlign::Left => "left".to_string(),
BoxAlign::Center => "center".to_string(),
BoxAlign::Right => "right".to_string(),
};
write!(f, "{}", str)
}
}
#[derive(Debug)]
pub struct BoxPad {
pub top: usize,
pub down: usize,
pub left: usize,
pub right: usize,
}
impl Default for BoxPad {
fn default() -> Self {
Self::new()
}
}
impl BoxPad {
pub fn new() -> Self {
BoxPad {
top: 0,
down: 0,
left: 0,
right: 0,
}
}
pub fn from_tldr(top: usize, left: usize, down: usize, right: usize) -> Self {
BoxPad {
top,
down,
left,
right,
}
}
pub fn uniform(pad: usize) -> Self {
BoxPad {
top: pad,
down: pad,
left: pad,
right: pad,
}
}
pub fn vh(vertical: usize, horizontal: usize) -> Self {
BoxPad {
top: vertical,
down: vertical,
left: horizontal,
right: horizontal,
}
}
pub fn lr(&self) -> usize {
self.right + self.left
}
}
#[allow(dead_code)]
#[derive(Debug)]
pub enum SegType<'a> {
Single(Vec<Cow<'a, str>>),
Columnar(Vec<Vec<Cow<'a, str>>>),
}
#[allow(dead_code)]
impl<'a> SegType<'a> {
pub(crate) fn push(&mut self, p0: Cow<'a, str>) {
match self {
SegType::Single(vec) => vec.push(p0),
SegType::Columnar(vec) => {
if let Some(vec) = vec.last_mut() {
vec.push(p0);
}
}
}
}
pub(crate) fn get_single(&self, index: usize) -> Option<&Cow<'a, str>> {
match self {
SegType::Single(vec) => vec.get(index),
_ => None,
}
}
pub(crate) fn get_columnar(&self, index: usize) -> Option<&Vec<Cow<'a, str>>> {
match self {
SegType::Columnar(vec) => vec.get(index),
_ => None,
}
}
}
#[derive(Debug, Clone)]
pub enum SegColor {
Single(Vec<Color>),
Columnar(Vec<Vec<Color>>),
}
use hex_color::HexColor;
impl SegColor {
pub(crate) fn parse_hexcolor(hex: &str) -> Color {
let box_col = match HexColor::parse(hex) {
Ok(color) => Color::TrueColor {
r: color.r,
g: color.g,
b: color.b,
},
Err(e) => {
eprintln!("Error parsing box color '{}': {}", hex, e);
Color::White }
};
box_col
}
}