use std::borrow::Cow;
#[derive(Debug, Clone)]
pub struct Frame {
ascii: Cow<'static, str>,
ticks: usize,
}
impl Frame {
pub fn new<S>(ascii: S) -> Self
where
S: Into<Cow<'static, str>>,
{
Self {
ascii: ascii.into(),
ticks: 0,
}
}
pub fn new_ticks<S>(ascii: S, ticks: usize) -> Self
where
S: Into<Cow<'static, str>>,
{
Self {
ascii: ascii.into(),
ticks,
}
}
pub fn content(&self) -> &str {
&self.ascii
}
pub fn ticks(&self) -> usize {
self.ticks
}
pub fn get_lines(&self) -> Vec<String> {
self.ascii.lines().map(|line| line.to_string()).collect()
}
pub fn get_height(&self) -> u32 {
self.get_lines().len() as u32
}
pub fn get_width(&self) -> u32 {
self.ascii
.lines()
.map(|line| line.chars().count())
.max()
.unwrap_or(0) as u32
}
}