summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClementTsang <34804052+ClementTsang@users.noreply.github.com>2024-04-02 22:26:38 -0400
committerClementTsang <34804052+ClementTsang@users.noreply.github.com>2024-04-20 03:17:56 -0400
commit9a04ad542bc4a2c2b9ec1c61c953655b977b06d5 (patch)
treeab24b5ecac6cf5567340870ccf1522d17d590335
parent4453eaaa393988ba7920f52618190fc75f22fecf (diff)
-rw-r--r--src/options.rs2
-rw-r--r--src/options/args.rs59
-rw-r--r--src/options/config.rs1
-rw-r--r--src/options/config/cpu.rs37
-rw-r--r--src/options/config/process.rs27
-rw-r--r--src/options/config/temperature.rs8
-rw-r--r--src/options/config/versions.rs2
-rw-r--r--src/options/config/versions/v1.rs0
-rw-r--r--src/options/config/versions/v2.rs0
-rw-r--r--src/widgets/cpu_graph.rs2
-rw-r--r--tests/integration/valid_config_tests.rs2
11 files changed, 98 insertions, 42 deletions
diff --git a/src/options.rs b/src/options.rs
index 4844de6e..08270adb 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -186,7 +186,7 @@ pub fn init_app(
widget.widget_id,
CpuWidgetState::new(
&app_config_fields,
- config.cpu.default,
+ config.cpu.args.default_cpu_entry,
default_time_value,
autohide_timer,
styling,
diff --git a/src/options/args.rs b/src/options/args.rs
index 696ee9dd..54ca528f 100644
--- a/src/options/args.rs
+++ b/src/options/args.rs
@@ -319,17 +319,16 @@ pub(crate) struct ProcessArgs {
#[arg(
short = 'u',
long,
- help = "Sets process CPU% to be based on current CPU%.",
- long_help = "Sets process CPU% usage to be based on the current system CPU% usage rather than total CPU usage."
+ help = "Calculates process CPU usage as a percentage of current usage rather than total usage."
)]
pub(crate) current_usage: Option<bool>,
// TODO: Disable this on Windows?
#[arg(
long,
- help = "Hides advanced process killing options.",
- long_help = "Hides advanced options to stop a process on Unix-like systems. The only \
- option shown is 15 (TERM)."
+ help = "Hides additional stopping options Unix-like systems.",
+ long_help = "Hides additional stopping options Unix-like systems. Signal 15 (TERM) will be sent when \
+ stopping a process."
)]
pub(crate) disable_advanced_kill: Option<bool>,
@@ -347,7 +346,10 @@ pub(crate) struct ProcessArgs {
)]
pub(crate) mem_as_value: Option<bool>,
- #[arg(long, help = "Show processes as their commands by default.")]
+ #[arg(
+ long,
+ help = "Shows the full command name instead of just the process name by default."
+ )]
pub(crate) process_command: Option<bool>,
#[arg(short = 'R', long, help = "Enables regex by default while searching.")]
@@ -356,15 +358,14 @@ pub(crate) struct ProcessArgs {
#[arg(
short = 'T',
long,
- help = "Defaults the process widget be in tree mode."
+ help = "Makes the process widget use tree mode by default."
)]
pub(crate) tree: Option<bool>,
#[arg(
short = 'n',
long,
- help = "Show process CPU% usage without normalizing over the number of cores.",
- long_help = "Shows all process CPU% usage without averaging over the number of CPU cores in the system."
+ help = "Show process CPU% usage without averaging over the number of CPU cores."
)]
pub(crate) unnormalized_cpu: Option<bool>,
@@ -433,34 +434,56 @@ impl TemperatureArgs {
}
}
+/// The default selection of the CPU widget. If the given selection is invalid,
+/// we will fall back to all.
+#[derive(Clone, Copy, Debug, Default, Deserialize)]
+#[serde(rename_all = "lowercase")]
+pub enum CpuDefault {
+ #[default]
+ All,
+ #[serde(alias = "avg")]
+ Average,
+}
+
+impl From<&str> for CpuDefault {
+ fn from(value: &str) -> Self {
+ match value.to_ascii_lowercase().as_str() {
+ "all" => CpuDefault::All,
+ "avg" | "average" => CpuDefault::Average,
+ _ => CpuDefault::All,
+ }
+ }
+}
+
/// CPU arguments/config options.
#[derive(Args, Clone, Debug, Default, Deserialize)]
#[command(next_help_heading = "CPU Options", rename_all = "snake_case")]
pub(crate) struct CpuArgs {
- #[arg(long, help = "Defaults to selecting the average CPU entry.")]
- pub(crate) default_avg_cpu: Option<bool>,
-
#[arg(
- short = 'a',
long,
- help = "Hides the average CPU usage entry.",
- long = "Hides the average CPU usage entry from being shown."
+ help = "Sets which CPU entry is selected by default.",
+ value_name = "ENTRY",
+ value_parser = ["all", "avg"],
+ default_value = "all"
)]
+ #[serde(default)]
+ pub(crate) default_cpu_entry: CpuDefault,
+
+ #[arg(short = 'a', long, help = "Hides the average CPU usage entry.")]
pub(crate) hide_avg_cpu: Option<bool>,
// TODO: Maybe rename this or fix this? Should this apply to all "left legends"?
#[arg(
short = 'l',
long,
- help = "Puts the CPU chart legend to the left side.",
- long_help = "Puts the CPU chart legend to the left side rather than the right side."
+ help = "Puts the CPU chart legend on the left side."
)]
pub(crate) left_legend: Option<bool>,
}
impl CpuArgs {
pub(crate) fn merge(&mut self, other: &Self) {
- set_if_some!(default_avg_cpu, self, other);
+ // set_if_some!(default_cpu_entry, self, other);
set_if_some!(hide_avg_cpu, self, other);
set_if_some!(left_legend, self, other);
}
diff --git a/src/options/config.rs b/src/options/config.rs
index 7c2e3d5d..59a441e5 100644
--- a/src/options/config.rs
+++ b/src/options/config.rs
@@ -10,6 +10,7 @@ pub mod network;
pub mod process;
mod style;
pub mod temperature;
+mod versions;
use std::{fs, io::Write, path::PathBuf};
diff --git a/src/options/config/cpu.rs b/src/options/config/cpu.rs
index 0976dd6d..99330cba 100644
--- a/src/options/config/cpu.rs
+++ b/src/options/config/cpu.rs
@@ -5,30 +5,25 @@ use crate::args::CpuArgs;
use super::DefaultConfig;
-/// The default selection of the CPU widget. If the given selection is invalid, we will fall back to all.
-#[derive(Clone, Copy, Debug, Default, Deserialize)]
-#[serde(rename_all = "lowercase")]
-pub enum CpuDefault {
- #[default]
- All,
- #[serde(alias = "avg")]
- Average,
-}
-
/// Process column settings.
#[derive(Clone, Debug, Default, Deserialize)]
pub(crate) struct CpuConfig {
#[serde(flatten)]
pub(crate) args: CpuArgs,
- #[serde(default)]
- pub(crate) default: CpuDefault,
}
impl DefaultConfig for CpuConfig {
fn default_config() -> String {
let s = indoc! {r##"
-
+ # Sets which CPU entry is selected by default.
+ # default_cpu_entry = "all"
+
+ # Hides the average CPU usage entry from being shown.
+ # hide_avg_cpu = false
+
+ # Puts the CPU chart legend on the left side.
+ # left_legend = false
"##};
s.to_string()
@@ -37,13 +32,15 @@ impl DefaultConfig for CpuConfig {
#[cfg(test)]
mod test {
+ use crate::args::CpuDefault;
+
use super::*;
#[test]
fn default_cpu_default() {
let config = "";
let generated: CpuConfig = toml_edit::de::from_str(config).unwrap();
- match generated.default {
+ match generated.args.default_cpu_entry {
CpuDefault::All => {}
CpuDefault::Average => {
panic!("the default should be all")
@@ -54,10 +51,10 @@ mod test {
#[test]
fn all_cpu_default() {
let config = r#"
- default = "all"
+ default_cpu_entry = "all"
"#;
let generated: CpuConfig = toml_edit::de::from_str(config).unwrap();
- match generated.default {
+ match generated.args.default_cpu_entry {
CpuDefault::All => {}
CpuDefault::Average => {
panic!("the default should be all")
@@ -68,11 +65,11 @@ mod test {
#[test]
fn avg_cpu_default() {
let config = r#"
- default = "avg"
+ default_cpu_entry = "avg"
"#;
let generated: CpuConfig = toml_edit::de::from_str(config).unwrap();
- match generated.default {
+ match generated.args.default_cpu_entry {
CpuDefault::All => {
panic!("the avg should be set")
}
@@ -83,11 +80,11 @@ mod test {
#[test]
fn average_cpu_default() {
let config = r#"
- default = "average"
+ default_cpu_entry = "average"
"#;
let generated: CpuConfig = toml_edit::de::from_str(config).unwrap();
- match generated.default {
+ match generated.args.default_cpu_entry {
CpuDefault::All => {
panic!("the avg should be set")
}
diff --git a/src/options/config/process.rs b/src/options/config/process.rs
index c4ac66d4..878abc68 100644
--- a/src/options/config/process.rs
+++ b/src/options/config/process.rs
@@ -18,6 +18,33 @@ impl DefaultConfig for ProcessConfig {
let s = indoc! {r##"
# Enables case sensitivity by default when searching for a process.
# case_sensitive = false
+
+ # Calculates process CPU usage as a percentage of current usage rather than total usage.
+ # current_usage = false
+
+ # Hides advanced process stopping options on Unix-like systems. Signal 15 (TERM) will be sent when stopping a process.
+ # disable_advanced_kill = false
+
+ # Groups processes with the same name by default.
+ # group_processes = false
+
+ # Defaults to showing process memory usage by value. Otherwise, it defaults to showing it by percentage.
+ # mem_as_value = false
+
+ # Shows the full command name instead of just the process name by default.
+ # process_command = false
+
+ # Enables regex by default while searching.
+ # regex = false
+
+ # Makes the process widget use tree mode by default.
+ # tree = false
+
+ # Show process CPU% usage without averaging over the number of CPU cores.
+ # unnormalized_cpu = false
+
+ # Enables whole-word matching by default while searching.
+ # whole_word = false
"##};
s.to_string()
diff --git a/src/options/config/temperature.rs b/src/options/config/temperature.rs
index 6fce986f..5bd8c0ee 100644
--- a/src/options/config/temperature.rs
+++ b/src/options/config/temperature.rs
@@ -1,3 +1,4 @@
+use indoc::indoc;
use serde::Deserialize;
use crate::args::TemperatureArgs;
@@ -13,6 +14,11 @@ pub(crate) struct TemperatureConfig {
impl DefaultConfig for TemperatureConfig {
fn default_config() -> String {
- todo!()
+ let s = indoc! {r##"
+ # The temperature unit. Supported values are "[c]elsius", "[f]ahrenheit", and "[k]elvin".
+ # temperature_type = "celsius"
+ "##};
+
+ s.to_string()
}
}
diff --git a/src/options/config/versions.rs b/src/options/config/versions.rs
new file mode 100644
index 00000000..ae6adc7c
--- /dev/null
+++ b/src/options/config/versions.rs
@@ -0,0 +1,2 @@
+pub mod v1;
+pub mod v2;
diff --git a/src/options/config/versions/v1.rs b/src/options/config/versions/v1.rs
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/src/options/config/versions/v1.rs
diff --git a/src/options/config/versions/v2.rs b/src/options/config/versions/v2.rs
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/src/options/config/versions/v2.rs
diff --git a/src/widgets/cpu_graph.rs b/src/widgets/cpu_graph.rs
index 15f1f939..777876e5 100644
--- a/src/widgets/cpu_graph.rs
+++ b/src/widgets/cpu_graph.rs
@@ -5,6 +5,7 @@ use tui::{style::Style, text::Text, widgets::Row};
use crate::{
app::AppConfigFields,
+ args::CpuDefault,
canvas::{
components::data_table::{
Column, ColumnHeader, DataTable, DataTableColumn, DataTableProps, DataTableStyling,
@@ -15,7 +16,6 @@ use crate::{
},
data_collection::cpu::CpuDataType,
data_conversion::CpuWidgetData,
- options::config::cpu::CpuDefault,
utils::general::truncate_to_text,
};
diff --git a/tests/integration/valid_config_tests.rs b/tests/integration/valid_config_tests.rs
index f4334223..e949db0c 100644
--- a/tests/integration/valid_config_tests.rs
+++ b/tests/integration/valid_config_tests.rs
@@ -1,6 +1,6 @@
//! Tests config files that have sometimes caused issues despite being valid.
-use std::{io::Read, path::Path, thread, time::Duration};
+use std::{io::Read, thread, time::Duration};
use crate::util::spawn_btm_in_pty;