use crate::Color;
#[derive(Debug, Clone, Copy)]
pub struct DefaultProcessor;
impl TextProcessor for DefaultProcessor {
fn process(&self, processables: Vec<Processable>) -> Vec<ProcessedChar> {
let mut list = Vec::new();
let none_style = OptTextStyle {
fg_color: None,
bg_color: None,
shakiness: None,
};
for processable in processables {
let text = match processable {
Processable::ToProcess(text) => text,
Processable::NoProcess(text) => text,
};
for c in text.chars() {
list.push(ProcessedChar {
character: c,
style: none_style.clone(),
});
}
}
list
}
}
pub enum Processable {
ToProcess(String),
NoProcess(String),
}
impl From<String> for Processable {
fn from(item: String) -> Processable {
Processable::ToProcess(item)
}
}
impl From<&'static str> for Processable {
fn from(item: &'static str) -> Processable {
Processable::ToProcess(item.to_owned())
}
}
pub trait TextProcessor {
fn process(&self, processables: Vec<Processable>) -> Vec<ProcessedChar>;
}
#[derive(Debug, Clone)]
pub struct ProcessedChar {
pub character: char,
pub(crate) style: OptTextStyle,
}
#[derive(Debug, Clone)]
pub(crate) struct OptTextStyle {
pub fg_color: Option<Color>,
pub bg_color: Option<Color>,
pub shakiness: Option<f32>,
}