use std::io::{self, IsTerminal};
use crate::GraphicalTheme;
#[derive(Debug, Clone)]
pub struct GraphicalReportHandler {
pub(crate) links: LinkStyle,
pub(crate) termwidth: usize,
pub(crate) theme: GraphicalTheme,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[expect(clippy::redundant_pub_crate, reason = "prevents accidental glob re-export")]
pub(crate) enum LinkStyle {
Link,
Text,
}
impl GraphicalReportHandler {
#[must_use]
pub fn new() -> Self {
let is_terminal = io::stdout().is_terminal() && io::stderr().is_terminal();
Self {
links: if is_terminal { LinkStyle::Link } else { LinkStyle::Text },
termwidth: 400,
theme: GraphicalTheme::new(is_terminal),
}
}
#[must_use]
pub fn new_themed(theme: GraphicalTheme) -> Self {
Self { links: LinkStyle::Link, termwidth: 200, theme }
}
#[must_use]
pub fn with_links(mut self, links: bool) -> Self {
self.links = if links { LinkStyle::Link } else { LinkStyle::Text };
self
}
#[must_use]
pub fn with_theme(mut self, theme: GraphicalTheme) -> Self {
self.theme = theme;
self
}
#[must_use]
pub fn with_width(mut self, width: usize) -> Self {
self.termwidth = width;
self
}
}
impl Default for GraphicalReportHandler {
fn default() -> Self {
Self::new()
}
}