pumas/
config.rs

1//! Configuration.
2
3use clap::{Parser, Subcommand};
4use clap_complete::Shell;
5
6/// Power usage monitor for Apple Silicon.
7#[derive(Debug, Parser)]
8#[clap(author, about, version)]
9#[clap(propagate_version = true)]
10pub struct Config {
11    /// Selection of commands.
12    #[command(subcommand)]
13    pub command: Command,
14}
15
16/// Indicate whether to run or generate completions.
17#[derive(Debug, Subcommand)]
18pub enum Command {
19    /// Run the power usage monitor.
20    Run {
21        /// Configuration
22        #[command(flatten)]
23        args: RunConfig,
24    },
25
26    /// Print a shell completion script to stdout.
27    GenerateCompletion {
28        /// Shell for which you want completion.
29        #[arg(value_enum, value_parser = clap::value_parser!(Shell))]
30        shell: Shell,
31    },
32}
33
34/// UI configuration.
35#[derive(Debug, clap::Args)]
36pub struct RunConfig {
37    /// Update rate [ms], min=100.
38    ///
39    /// PowerMetrics samples at this rate.
40    #[arg(short='i', long="sample-rate", default_value = "1000",
41        value_parser = clap::value_parser!(u16).range(100..))]
42    pub sample_rate_ms: u16,
43
44    /// History buffer size.
45    ///
46    /// Number of recent samples to keep in history for each metric.
47    #[arg(long, default_value = "128")]
48    pub history_size: usize,
49
50    /// ASCII code for labels, max: 255, default: green.
51    #[arg(long, default_value = "2")]
52    pub accent_color: u8,
53
54    /// ASCII code, max=255, default: green.
55    #[arg(long, default_value = "2")]
56    pub gauge_fg_color: u8,
57
58    /// ASCII code, max=255, default: white.
59    #[arg(long, default_value = "7")]
60    pub gauge_bg_color: u8,
61
62    /// ASCII code, max=255, default: blue.
63    #[arg(long, default_value = "4")]
64    pub history_fg_color: u8,
65
66    /// ASCII code, max=255, default: white.
67    #[arg(long, default_value = "7")]
68    pub history_bg_color: u8,
69
70    /// Print metrics to stdout as JSON instead of running the UI.
71    #[arg(long, default_value = "false")]
72    pub json: bool,
73}
74
75impl RunConfig {
76    /// Return colors.
77    pub fn colors(&self) -> UiColors {
78        UiColors {
79            accent: self.accent_color,
80            gauge_fg: self.gauge_fg_color,
81            gauge_bg: self.gauge_bg_color,
82            history_fg: self.history_fg_color,
83            history_bg: self.history_bg_color,
84        }
85    }
86}
87
88/// Hold color configuration.
89#[derive(Debug)]
90pub struct UiColors {
91    /// Accent color: ASCII code in 0~255.
92    pub accent: u8,
93    /// Gauge foreground color: ASCII code in 0~255.
94    pub gauge_fg: u8,
95    /// Gauge background color: ASCII code in 0~255.
96    pub gauge_bg: u8,
97    /// History foreground color: ASCII code in 0~255.
98    pub history_fg: u8,
99    /// History background color: ASCII code in 0~255.
100    pub history_bg: u8,
101}