mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-22 04:03:06 +00:00
other: switch to toml_edit (#1034)
This commit is contained in:
parent
f02bd21948
commit
e8ae1a265a
7 changed files with 53 additions and 24 deletions
39
Cargo.lock
generated
39
Cargo.lock
generated
|
@ -246,7 +246,7 @@ dependencies = [
|
|||
"sysinfo",
|
||||
"thiserror",
|
||||
"time",
|
||||
"toml",
|
||||
"toml_edit",
|
||||
"tui",
|
||||
"typed-builder",
|
||||
"unicode-segmentation",
|
||||
|
@ -1550,6 +1550,15 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_spanned"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0efd8caf556a6cebd3b285caf480045fcc1ac04f6bd786b09a6f11af30c4fcf4"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook"
|
||||
version = "0.3.13"
|
||||
|
@ -1777,14 +1786,27 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.10"
|
||||
name = "toml_datetime"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f"
|
||||
checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622"
|
||||
dependencies = [
|
||||
"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]]
|
||||
name = "tui"
|
||||
version = "0.19.0"
|
||||
|
@ -2024,6 +2046,15 @@ version = "0.42.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "faf09497b8f8b5ac5d3bb4d05c0a99be20f26fd3d5f2db7b0716e946d5103658"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wrapcenum-derive"
|
||||
version = "0.4.0"
|
||||
|
|
|
@ -98,7 +98,7 @@ starship-battery = { version = "0.7.9", optional = true }
|
|||
sysinfo = "0.26.7"
|
||||
thiserror = "1.0.38"
|
||||
time = { version = "0.3.20", features = ["formatting", "macros"] }
|
||||
toml = "0.5.10"
|
||||
toml_edit = { version = "0.19.4", features = ["serde"] }
|
||||
tui = "0.19.0"
|
||||
typed-builder = "0.10.0"
|
||||
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 Ok(config_string) = fs::read_to_string(path) {
|
||||
// We found a config file!
|
||||
Ok(toml::from_str(config_string.as_str())?)
|
||||
Ok(toml_edit::de::from_str(config_string.as_str())?)
|
||||
} else {
|
||||
// Config file DNE...
|
||||
if let Some(parent_path) = path.parent() {
|
||||
|
|
|
@ -115,7 +115,7 @@ pub struct ConfigColours {
|
|||
impl ConfigColours {
|
||||
/// Returns `true` if there is a [`ConfigColours`] that is empty or there isn't one at all.
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -442,7 +442,7 @@ pub fn get_widget_layout(
|
|||
Some(r) => r,
|
||||
None => {
|
||||
// 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
|
||||
} else {
|
||||
DEFAULT_LAYOUT
|
||||
|
|
|
@ -69,8 +69,8 @@ impl From<std::string::String> for BottomError {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<toml::de::Error> for BottomError {
|
||||
fn from(err: toml::de::Error) -> Self {
|
||||
impl From<toml_edit::de::Error> for BottomError {
|
||||
fn from(err: toml_edit::de::Error) -> Self {
|
||||
BottomError::ConfigError(err.to_string())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ fn test_duplicate_temp_type() {
|
|||
.arg("./tests/invalid_configs/duplicate_temp_type.toml")
|
||||
.assert()
|
||||
.failure()
|
||||
.stderr(predicate::str::contains("duplicate field"));
|
||||
.stderr(predicate::str::contains("duplicate key"));
|
||||
}
|
||||
|
||||
/// 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")
|
||||
.assert()
|
||||
.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::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##"
|
||||
[[row]]
|
||||
[[row.child]]
|
||||
|
@ -57,10 +61,7 @@ fn test_create_layout(
|
|||
#[test]
|
||||
/// Tests the default setup.
|
||||
fn test_default_movement() {
|
||||
let rows = toml::from_str::<Config>(DEFAULT_LAYOUT)
|
||||
.unwrap()
|
||||
.row
|
||||
.unwrap();
|
||||
let rows = from_str::<Config>(DEFAULT_LAYOUT).unwrap().row.unwrap();
|
||||
let ret_bottom_layout = test_create_layout(&rows, DEFAULT_WIDGET_ID, None, 1, false);
|
||||
|
||||
// Simple tests for the top CPU widget
|
||||
|
@ -132,7 +133,7 @@ fn test_default_movement() {
|
|||
#[test]
|
||||
/// Tests battery movement in the default setup.
|
||||
fn test_default_battery_movement() {
|
||||
let rows = toml::from_str::<Config>(DEFAULT_BATTERY_LAYOUT)
|
||||
let rows = from_str::<Config>(DEFAULT_BATTERY_LAYOUT)
|
||||
.unwrap()
|
||||
.row
|
||||
.unwrap();
|
||||
|
@ -178,10 +179,7 @@ fn test_default_battery_movement() {
|
|||
#[test]
|
||||
/// Tests using left_legend.
|
||||
fn test_left_legend() {
|
||||
let rows = toml::from_str::<Config>(DEFAULT_LAYOUT)
|
||||
.unwrap()
|
||||
.row
|
||||
.unwrap();
|
||||
let rows = from_str::<Config>(DEFAULT_LAYOUT).unwrap().row.unwrap();
|
||||
let ret_bottom_layout = test_create_layout(&rows, DEFAULT_WIDGET_ID, None, 1, true);
|
||||
|
||||
// Legend
|
||||
|
@ -240,7 +238,7 @@ fn test_default_widget_in_layout() {
|
|||
[[row.child]]
|
||||
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 total_height_ratio = 0;
|
||||
let mut default_widget_count = 1;
|
||||
|
@ -273,7 +271,7 @@ fn test_default_widget_in_layout() {
|
|||
#[test]
|
||||
/// Tests default widget by setting type and count.
|
||||
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 total_height_ratio = 0;
|
||||
let mut default_widget_count = 3;
|
||||
|
@ -305,7 +303,7 @@ fn test_default_widget_by_option() {
|
|||
|
||||
#[test]
|
||||
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);
|
||||
|
||||
// First proc widget
|
||||
|
|
Loading…
Reference in a new issue