use crate::fmt::{Display, Formatter};
use crate::{markup, Markup};
use std::io;
pub struct DebugDisplay<T>(pub T);
impl<T> Display for DebugDisplay<T>
where
T: std::fmt::Debug,
{
fn fmt(&self, f: &mut Formatter<'_>) -> io::Result<()> {
write!(f, "{:?}", self.0)
}
}
pub struct DebugDisplayOption<T>(pub Option<T>);
impl<T> Display for DebugDisplayOption<T>
where
T: std::fmt::Debug,
{
fn fmt(&self, fmt: &mut Formatter) -> io::Result<()> {
use crate as biome_console;
if let Some(value) = &self.0 {
markup!({ DebugDisplay(value) }).fmt(fmt)?;
} else {
markup!(<Dim>"unset"</Dim>).fmt(fmt)?;
}
Ok(())
}
}
pub struct HorizontalLine {
width: usize,
}
impl HorizontalLine {
pub fn new(width: usize) -> Self {
Self { width }
}
}
impl Display for HorizontalLine {
fn fmt(&self, fmt: &mut Formatter) -> io::Result<()> {
fmt.write_str(&"\u{2501}".repeat(self.width))
}
}
pub struct Softline;
pub const SOFT_LINE: Softline = Softline;
impl Display for Softline {
fn fmt(&self, fmt: &mut Formatter) -> io::Result<()> {
fmt.write_str("\n")
}
}
pub struct Hardline;
pub const HARD_LINE: Hardline = Hardline;
impl Display for Hardline {
fn fmt(&self, fmt: &mut Formatter) -> io::Result<()> {
fmt.write_str("\n\n")
}
}
pub struct Padding {
width: usize,
}
impl Padding {
pub fn new(width: usize) -> Self {
Self { width }
}
}
impl Display for Padding {
fn fmt(&self, fmt: &mut Formatter) -> io::Result<()> {
for _ in 0..self.width {
fmt.write_str(" ")?;
}
Ok(())
}
}
pub struct KeyValuePair<'a>(pub &'a str, pub Markup<'a>);
impl Display for KeyValuePair<'_> {
fn fmt(&self, fmt: &mut Formatter) -> io::Result<()> {
let KeyValuePair(key, value) = self;
write!(fmt, " {key}:")?;
let padding_width = 30usize.saturating_sub(key.len() + 1);
for _ in 0..padding_width {
fmt.write_str(" ")?;
}
value.fmt(fmt)?;
fmt.write_str("\n")
}
}