fix: use default disk.columns when only other disk.* configs exist (#1776)

I configured `[disk.name_filter]` and after upgrading to v0.11.0, the
disk widget became empty since `disk.columns` was parsed as an empty
vector unless I added `disk.columns` to my config as well.
This commit is contained in:
Frederick Zhang 2025-08-09 01:01:48 +10:00 committed by GitHub
parent c17110caf2
commit 9fe558183b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View File

@ -407,7 +407,7 @@ pub(crate) fn init_app(args: BottomArgs, config: Config) -> Result<(App, BottomL
DiskTableWidget::new(
&app_config_fields,
&styling,
config.disk.as_ref().map(|cfg| cfg.columns.as_slice()),
config.disk.as_ref().and_then(|cfg| cfg.columns.as_deref()),
),
);
}

View File

@ -16,7 +16,7 @@ pub(crate) struct DiskConfig {
/// A list of disk widget columns.
#[serde(default)]
pub(crate) columns: Vec<DiskColumn>, // TODO: make this more composable(?) in the future, we might need to rethink how it's done for custom widgets
pub(crate) columns: Option<Vec<DiskColumn>>, // TODO: make this more composable(?) in the future, we might need to rethink how it's done for custom widgets
}
#[cfg(test)]
@ -24,10 +24,17 @@ mod test {
use super::DiskConfig;
#[test]
fn empty_column_setting() {
fn none_column_setting() {
let config = "";
let generated: DiskConfig = toml_edit::de::from_str(config).unwrap();
assert!(generated.columns.is_empty());
assert!(generated.columns.is_none());
}
#[test]
fn empty_column_setting() {
let config = r#"columns = []"#;
let generated: DiskConfig = toml_edit::de::from_str(config).unwrap();
assert!(generated.columns.unwrap().is_empty());
}
#[test]