use std::env;
use std::result::Result;
#[allow(unused)] use crate::View;
use crate::{ansi, width};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Destination {
Stdout,
Stderr,
Capture,
}
impl Destination {
pub(crate) fn initalize(&self) -> Result<(), ()> {
if match self {
Destination::Stdout => {
atty::is(atty::Stream::Stdout) && !is_dumb_term() && ansi::enable_windows_ansi()
}
Destination::Stderr => {
atty::is(atty::Stream::Stderr) && !is_dumb_term() && ansi::enable_windows_ansi()
}
Destination::Capture => true,
} {
Ok(())
} else {
Err(())
}
}
pub(crate) fn width(&self) -> Option<usize> {
match self {
Destination::Stdout => width::stdout_width(),
Destination::Stderr => width::stderr_width(),
Destination::Capture => Some(80),
}
}
}
fn is_dumb_term() -> bool {
env::var("TERM").is_ok_and(|s| s.eq_ignore_ascii_case("dumb"))
}