use super::Color;
#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TextUi {
pub text: String,
pub color: Option<Color>,
}
impl TextUi {
#[inline]
pub fn new(text: impl Into<String>) -> Self {
let text = text.into();
Self { text, color: None }
}
#[inline]
#[must_use]
pub fn with_color(mut self, color: impl Into<Color>) -> Self {
self.color = Some(color.into());
self
}
}
impl<'a> From<&'a str> for TextUi {
#[inline]
fn from(text: &str) -> Self {
Self::new(text)
}
}
impl<'a> From<&'a String> for TextUi {
#[inline]
fn from(text: &String) -> Self {
Self::new(text)
}
}
impl From<String> for TextUi {
#[inline]
fn from(text: String) -> Self {
Self::new(text)
}
}
impl<'a, C> From<(&'a str, C)> for TextUi
where
C: Into<Color>,
{
#[inline]
fn from((text, color): (&str, C)) -> Self {
Self::new(text).with_color(color)
}
}
impl<'a, C> From<(&'a String, C)> for TextUi
where
C: Into<Color>,
{
#[inline]
fn from((text, color): (&String, C)) -> Self {
Self::new(text).with_color(color)
}
}
impl<C> From<(String, C)> for TextUi
where
C: Into<Color>,
{
#[inline]
fn from((text, color): (String, C)) -> Self {
Self::new(text).with_color(color)
}
}