-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: support default selection of average CPU graph (#1353)
* feature: support default selection of average CPU graph * test
- Loading branch information
1 parent
300f667
commit b6f92c2
Showing
11 changed files
with
152 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# CPU | ||
|
||
## Default CPU Graph Selection | ||
|
||
You can configure which CPU graph is shown by default when starting up bottom by setting `cpu.default`. | ||
|
||
```toml | ||
[cpu] | ||
# One of "all" (default), "average"/"avg" | ||
default = "average" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use serde::Deserialize; | ||
|
||
/// 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 struct CpuConfig { | ||
#[serde(default)] | ||
pub default: CpuDefault, | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn default_cpu_default() { | ||
let config = ""; | ||
let generated: CpuConfig = toml_edit::de::from_str(config).unwrap(); | ||
match generated.default { | ||
CpuDefault::All => {} | ||
CpuDefault::Average => { | ||
panic!("the default should be all") | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn all_cpu_default() { | ||
let config = r#" | ||
default = "all" | ||
"#; | ||
let generated: CpuConfig = toml_edit::de::from_str(config).unwrap(); | ||
match generated.default { | ||
CpuDefault::All => {} | ||
CpuDefault::Average => { | ||
panic!("the default should be all") | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn avg_cpu_default() { | ||
let config = r#" | ||
default = "avg" | ||
"#; | ||
|
||
let generated: CpuConfig = toml_edit::de::from_str(config).unwrap(); | ||
match generated.default { | ||
CpuDefault::All => { | ||
panic!("the avg should be set") | ||
} | ||
CpuDefault::Average => {} | ||
} | ||
} | ||
|
||
#[test] | ||
fn average_cpu_default() { | ||
let config = r#" | ||
default = "average" | ||
"#; | ||
|
||
let generated: CpuConfig = toml_edit::de::from_str(config).unwrap(); | ||
match generated.default { | ||
CpuDefault::All => { | ||
panic!("the avg should be set") | ||
} | ||
CpuDefault::Average => {} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters