mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-22 13:14:40 +02:00
other: switch to toml_edit (#1034)
This commit is contained in:
parent
f02bd21948
commit
e8ae1a265a
39
Cargo.lock
generated
39
Cargo.lock
generated
@ -246,7 +246,7 @@ dependencies = [
|
|||||||
"sysinfo",
|
"sysinfo",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"time",
|
"time",
|
||||||
"toml",
|
"toml_edit",
|
||||||
"tui",
|
"tui",
|
||||||
"typed-builder",
|
"typed-builder",
|
||||||
"unicode-segmentation",
|
"unicode-segmentation",
|
||||||
@ -1550,6 +1550,15 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_spanned"
|
||||||
|
version = "0.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0efd8caf556a6cebd3b285caf480045fcc1ac04f6bd786b09a6f11af30c4fcf4"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "signal-hook"
|
name = "signal-hook"
|
||||||
version = "0.3.13"
|
version = "0.3.13"
|
||||||
@ -1777,14 +1786,27 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml"
|
name = "toml_datetime"
|
||||||
version = "0.5.10"
|
version = "0.6.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f"
|
checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml_edit"
|
||||||
|
version = "0.19.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a1eb0622d28f4b9c90adc4ea4b2b46b47663fde9ac5fafcb14a1369d5508825"
|
||||||
|
dependencies = [
|
||||||
|
"indexmap",
|
||||||
|
"serde",
|
||||||
|
"serde_spanned",
|
||||||
|
"toml_datetime",
|
||||||
|
"winnow",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tui"
|
name = "tui"
|
||||||
version = "0.19.0"
|
version = "0.19.0"
|
||||||
@ -2024,6 +2046,15 @@ version = "0.42.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
|
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winnow"
|
||||||
|
version = "0.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "faf09497b8f8b5ac5d3bb4d05c0a99be20f26fd3d5f2db7b0716e946d5103658"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wrapcenum-derive"
|
name = "wrapcenum-derive"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
|
@ -98,7 +98,7 @@ starship-battery = { version = "0.7.9", optional = true }
|
|||||||
sysinfo = "0.26.7"
|
sysinfo = "0.26.7"
|
||||||
thiserror = "1.0.38"
|
thiserror = "1.0.38"
|
||||||
time = { version = "0.3.20", features = ["formatting", "macros"] }
|
time = { version = "0.3.20", features = ["formatting", "macros"] }
|
||||||
toml = "0.5.10"
|
toml_edit = { version = "0.19.4", features = ["serde"] }
|
||||||
tui = "0.19.0"
|
tui = "0.19.0"
|
||||||
typed-builder = "0.10.0"
|
typed-builder = "0.10.0"
|
||||||
unicode-segmentation = "1.10.1"
|
unicode-segmentation = "1.10.1"
|
||||||
|
@ -241,7 +241,7 @@ pub fn create_or_get_config(config_path: &Option<PathBuf>) -> error::Result<Conf
|
|||||||
if let Some(path) = config_path {
|
if let Some(path) = config_path {
|
||||||
if let Ok(config_string) = fs::read_to_string(path) {
|
if let Ok(config_string) = fs::read_to_string(path) {
|
||||||
// We found a config file!
|
// We found a config file!
|
||||||
Ok(toml::from_str(config_string.as_str())?)
|
Ok(toml_edit::de::from_str(config_string.as_str())?)
|
||||||
} else {
|
} else {
|
||||||
// Config file DNE...
|
// Config file DNE...
|
||||||
if let Some(parent_path) = path.parent() {
|
if let Some(parent_path) = path.parent() {
|
||||||
|
@ -115,7 +115,7 @@ pub struct ConfigColours {
|
|||||||
impl ConfigColours {
|
impl ConfigColours {
|
||||||
/// Returns `true` if there is a [`ConfigColours`] that is empty or there isn't one at all.
|
/// Returns `true` if there is a [`ConfigColours`] that is empty or there isn't one at all.
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
if let Ok(serialized_string) = toml::to_string(self) {
|
if let Ok(serialized_string) = toml_edit::ser::to_string(self) {
|
||||||
return serialized_string.is_empty();
|
return serialized_string.is_empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -442,7 +442,7 @@ pub fn get_widget_layout(
|
|||||||
Some(r) => r,
|
Some(r) => r,
|
||||||
None => {
|
None => {
|
||||||
// This cannot (like it really shouldn't) fail!
|
// This cannot (like it really shouldn't) fail!
|
||||||
ref_row = toml::from_str::<Config>(if get_use_battery(matches, config) {
|
ref_row = toml_edit::de::from_str::<Config>(if get_use_battery(matches, config) {
|
||||||
DEFAULT_BATTERY_LAYOUT
|
DEFAULT_BATTERY_LAYOUT
|
||||||
} else {
|
} else {
|
||||||
DEFAULT_LAYOUT
|
DEFAULT_LAYOUT
|
||||||
|
@ -69,8 +69,8 @@ impl From<std::string::String> for BottomError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<toml::de::Error> for BottomError {
|
impl From<toml_edit::de::Error> for BottomError {
|
||||||
fn from(err: toml::de::Error) -> Self {
|
fn from(err: toml_edit::de::Error) -> Self {
|
||||||
BottomError::ConfigError(err.to_string())
|
BottomError::ConfigError(err.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ fn test_duplicate_temp_type() {
|
|||||||
.arg("./tests/invalid_configs/duplicate_temp_type.toml")
|
.arg("./tests/invalid_configs/duplicate_temp_type.toml")
|
||||||
.assert()
|
.assert()
|
||||||
.failure()
|
.failure()
|
||||||
.stderr(predicate::str::contains("duplicate field"));
|
.stderr(predicate::str::contains("duplicate key"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks for if a hex is valid
|
/// Checks for if a hex is valid
|
||||||
@ -139,5 +139,5 @@ fn test_invalid_default_widget_count() {
|
|||||||
.arg("./tests/invalid_configs/invalid_default_widget_count.toml")
|
.arg("./tests/invalid_configs/invalid_default_widget_count.toml")
|
||||||
.assert()
|
.assert()
|
||||||
.failure()
|
.failure()
|
||||||
.stderr(predicate::str::contains("invalid number"));
|
.stderr(predicate::str::contains("number too large"));
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,10 @@ use bottom::constants::{DEFAULT_LAYOUT, DEFAULT_WIDGET_ID};
|
|||||||
use bottom::options::{layout_options::Row, Config};
|
use bottom::options::{layout_options::Row, Config};
|
||||||
use bottom::utils::error;
|
use bottom::utils::error;
|
||||||
|
|
||||||
|
use toml_edit::de::from_str;
|
||||||
|
|
||||||
|
// TODO: Could move these into the library files rather than external tbh.
|
||||||
|
|
||||||
const PROC_LAYOUT: &str = r##"
|
const PROC_LAYOUT: &str = r##"
|
||||||
[[row]]
|
[[row]]
|
||||||
[[row.child]]
|
[[row.child]]
|
||||||
@ -57,10 +61,7 @@ fn test_create_layout(
|
|||||||
#[test]
|
#[test]
|
||||||
/// Tests the default setup.
|
/// Tests the default setup.
|
||||||
fn test_default_movement() {
|
fn test_default_movement() {
|
||||||
let rows = toml::from_str::<Config>(DEFAULT_LAYOUT)
|
let rows = from_str::<Config>(DEFAULT_LAYOUT).unwrap().row.unwrap();
|
||||||
.unwrap()
|
|
||||||
.row
|
|
||||||
.unwrap();
|
|
||||||
let ret_bottom_layout = test_create_layout(&rows, DEFAULT_WIDGET_ID, None, 1, false);
|
let ret_bottom_layout = test_create_layout(&rows, DEFAULT_WIDGET_ID, None, 1, false);
|
||||||
|
|
||||||
// Simple tests for the top CPU widget
|
// Simple tests for the top CPU widget
|
||||||
@ -132,7 +133,7 @@ fn test_default_movement() {
|
|||||||
#[test]
|
#[test]
|
||||||
/// Tests battery movement in the default setup.
|
/// Tests battery movement in the default setup.
|
||||||
fn test_default_battery_movement() {
|
fn test_default_battery_movement() {
|
||||||
let rows = toml::from_str::<Config>(DEFAULT_BATTERY_LAYOUT)
|
let rows = from_str::<Config>(DEFAULT_BATTERY_LAYOUT)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.row
|
.row
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -178,10 +179,7 @@ fn test_default_battery_movement() {
|
|||||||
#[test]
|
#[test]
|
||||||
/// Tests using left_legend.
|
/// Tests using left_legend.
|
||||||
fn test_left_legend() {
|
fn test_left_legend() {
|
||||||
let rows = toml::from_str::<Config>(DEFAULT_LAYOUT)
|
let rows = from_str::<Config>(DEFAULT_LAYOUT).unwrap().row.unwrap();
|
||||||
.unwrap()
|
|
||||||
.row
|
|
||||||
.unwrap();
|
|
||||||
let ret_bottom_layout = test_create_layout(&rows, DEFAULT_WIDGET_ID, None, 1, true);
|
let ret_bottom_layout = test_create_layout(&rows, DEFAULT_WIDGET_ID, None, 1, true);
|
||||||
|
|
||||||
// Legend
|
// Legend
|
||||||
@ -240,7 +238,7 @@ fn test_default_widget_in_layout() {
|
|||||||
[[row.child]]
|
[[row.child]]
|
||||||
type="proc"
|
type="proc"
|
||||||
"##;
|
"##;
|
||||||
let rows = toml::from_str::<Config>(proc_layout).unwrap().row.unwrap();
|
let rows = from_str::<Config>(proc_layout).unwrap().row.unwrap();
|
||||||
let mut iter_id = 0; // A lazy way of forcing unique IDs *shrugs*
|
let mut iter_id = 0; // A lazy way of forcing unique IDs *shrugs*
|
||||||
let mut total_height_ratio = 0;
|
let mut total_height_ratio = 0;
|
||||||
let mut default_widget_count = 1;
|
let mut default_widget_count = 1;
|
||||||
@ -273,7 +271,7 @@ fn test_default_widget_in_layout() {
|
|||||||
#[test]
|
#[test]
|
||||||
/// Tests default widget by setting type and count.
|
/// Tests default widget by setting type and count.
|
||||||
fn test_default_widget_by_option() {
|
fn test_default_widget_by_option() {
|
||||||
let rows = toml::from_str::<Config>(PROC_LAYOUT).unwrap().row.unwrap();
|
let rows = from_str::<Config>(PROC_LAYOUT).unwrap().row.unwrap();
|
||||||
let mut iter_id = 0; // A lazy way of forcing unique IDs *shrugs*
|
let mut iter_id = 0; // A lazy way of forcing unique IDs *shrugs*
|
||||||
let mut total_height_ratio = 0;
|
let mut total_height_ratio = 0;
|
||||||
let mut default_widget_count = 3;
|
let mut default_widget_count = 3;
|
||||||
@ -305,7 +303,7 @@ fn test_default_widget_by_option() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_proc_custom_layout() {
|
fn test_proc_custom_layout() {
|
||||||
let rows = toml::from_str::<Config>(PROC_LAYOUT).unwrap().row.unwrap();
|
let rows = from_str::<Config>(PROC_LAYOUT).unwrap().row.unwrap();
|
||||||
let ret_bottom_layout = test_create_layout(&rows, DEFAULT_WIDGET_ID, None, 1, false);
|
let ret_bottom_layout = test_create_layout(&rows, DEFAULT_WIDGET_ID, None, 1, false);
|
||||||
|
|
||||||
// First proc widget
|
// First proc widget
|
||||||
|
Loading…
x
Reference in New Issue
Block a user