use std::time::Duration;
use clap::Parser;
#[derive(Debug, Clone, Parser)]
#[command(name = "crabtop", version, about = "Linux TUI system monitor")]
pub struct CliArgs {
#[arg(short, long, default_value_t = 1500)]
pub interval: u64,
#[arg(long, default_value_t = 120)]
pub history: usize,
#[arg(short, long)]
pub detailed: bool,
#[arg(long)]
pub cpu_cores: bool,
#[arg(long)]
pub mem_detailed: bool,
#[arg(long)]
pub gpu_detailed: bool,
#[arg(long)]
pub temp_detailed: bool,
}
#[derive(Debug, Clone, Copy)]
pub struct Detail {
pub cpu: bool,
pub mem: bool,
pub gpu: bool,
pub temp: bool,
}
#[derive(Debug, Clone)]
pub struct Config {
pub interval: Duration,
pub history: usize,
pub detail: Detail,
}
impl From<CliArgs> for Config {
fn from(a: CliArgs) -> Self {
let all = a.detailed;
Self {
interval: Duration::from_millis(a.interval.max(50)),
history: a.history.max(8),
detail: Detail {
cpu: all || a.cpu_cores,
mem: all || a.mem_detailed,
gpu: all || a.gpu_detailed,
temp: all || a.temp_detailed,
},
}
}
}