use clap::{Parser, ValueEnum};
use miette::Result;
use super::OPTSET_OUTPUT;
#[derive(Debug, Clone, Parser)]
pub struct OutputArgs {
#[arg(
short = 'c',
long = "clear",
help_heading = OPTSET_OUTPUT,
num_args = 0..=1,
default_missing_value = "clear",
value_name = "MODE",
display_order = 30,
)]
pub screen_clear: Option<ClearMode>,
#[arg(
short = 'N',
long,
help_heading = OPTSET_OUTPUT,
num_args = 0..=1,
default_missing_value = "both",
value_name = "WHEN",
display_order = 140,
)]
pub notify: Option<NotifyMode>,
#[arg(
long,
help_heading = OPTSET_OUTPUT,
default_value = "auto",
value_name = "MODE",
alias = "colour",
display_order = 31,
)]
pub color: ColourMode,
#[arg(
long,
help_heading = OPTSET_OUTPUT,
display_order = 200,
)]
pub timings: bool,
#[arg(
short,
long,
help_heading = OPTSET_OUTPUT,
display_order = 170,
)]
pub quiet: bool,
#[arg(
long,
help_heading = OPTSET_OUTPUT,
display_order = 20,
)]
pub bell: bool,
}
impl OutputArgs {
pub(crate) fn normalise(&mut self) -> Result<()> {
if self.color == ColourMode::Auto && std::env::var("NO_COLOR").is_ok() {
self.color = ColourMode::Never;
}
Ok(())
}
}
#[derive(Clone, Copy, Debug, Default, ValueEnum)]
pub enum ClearMode {
#[default]
Clear,
Reset,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
pub enum ColourMode {
Auto,
Always,
Never,
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, ValueEnum)]
pub enum NotifyMode {
#[default]
Both,
Start,
End,
}
impl NotifyMode {
pub fn on_start(self) -> bool {
matches!(self, Self::Both | Self::Start)
}
pub fn on_end(self) -> bool {
matches!(self, Self::Both | Self::End)
}
}