use core::fmt::{self, Write};
use super::ANSIFmt;
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash)]
pub struct ANSIStr<'a> {
prefix: &'a str,
suffix: &'a str,
}
impl<'a> ANSIStr<'a> {
pub const fn new(prefix: &'a str, suffix: &'a str) -> Self {
Self { prefix, suffix }
}
pub const fn empty() -> Self {
Self::new("", "")
}
pub const fn is_empty(&self) -> bool {
self.prefix.is_empty() && self.suffix.is_empty()
}
pub const fn get_prefix(&self) -> &'a str {
self.prefix
}
pub const fn get_suffix(&self) -> &'a str {
self.suffix
}
}
impl ANSIFmt for ANSIStr<'_> {
fn fmt_ansi_prefix<W: Write>(&self, f: &mut W) -> fmt::Result {
f.write_str(self.prefix)
}
fn fmt_ansi_suffix<W: Write>(&self, f: &mut W) -> fmt::Result {
f.write_str(self.suffix)
}
}