diff --git a/src/config.rs b/src/config.rs index 7e7c530..c7f55af 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,6 +11,8 @@ pub struct ColumnConfig { pub label: String, #[serde(default)] pub align: ColumnAlignment, + #[serde(default)] + pub max_len: Option, } #[derive(Debug, Clone, Serialize, Deserialize, Default)] @@ -32,6 +34,8 @@ impl<'de> serde::Deserialize<'de> for ColumnConfig { label: Option, #[serde(default)] align: ColumnAlignment, + #[serde(default)] + max_len: Option, } let helper = Helper::deserialize(deserializer)?; @@ -41,6 +45,7 @@ impl<'de> serde::Deserialize<'de> for ColumnConfig { name: helper.name, label, align: helper.align, + max_len: helper.max_len, }) } } @@ -198,11 +203,36 @@ impl Settings { if settings.list_format.is_empty() { debug!("CONFIG: Setting default list_format"); settings.list_format = vec![ - ColumnConfig { name: "id".to_string(), label: "id".to_string(), align: ColumnAlignment::Left }, - ColumnConfig { name: "time".to_string(), label: "time".to_string(), align: ColumnAlignment::Left }, - ColumnConfig { name: "size".to_string(), label: "size".to_string(), align: ColumnAlignment::Left }, - ColumnConfig { name: "tags".to_string(), label: "tags".to_string(), align: ColumnAlignment::Left }, - ColumnConfig { name: "meta:hostname".to_string(), label: "hostname".to_string(), align: ColumnAlignment::Left }, + ColumnConfig { + name: "id".to_string(), + label: "id".to_string(), + align: ColumnAlignment::Left, + max_len: Some(8), + }, + ColumnConfig { + name: "time".to_string(), + label: "time".to_string(), + align: ColumnAlignment::Left, + max_len: Some(19), + }, + ColumnConfig { + name: "size".to_string(), + label: "size".to_string(), + align: ColumnAlignment::Left, + max_len: Some(10), + }, + ColumnConfig { + name: "tags".to_string(), + label: "tags".to_string(), + align: ColumnAlignment::Left, + max_len: Some(20), + }, + ColumnConfig { + name: "meta:hostname".to_string(), + label: "hostname".to_string(), + align: ColumnAlignment::Left, + max_len: Some(15), + }, ]; } diff --git a/src/modes/list.rs b/src/modes/list.rs index c2c12a7..7ee6ad9 100644 --- a/src/modes/list.rs +++ b/src/modes/list.rs @@ -84,7 +84,7 @@ pub fn mode_list( .unwrap_or_else(|_| panic!("Unknown column {:?}", column.name)); let mut meta_name: Option<&str> = None; - let column_width = 0; // We're not supporting width in the new format + let column_width = column.max_len.unwrap_or(0); if let ColumnType::Meta = column_type { let parts: Vec<&str> = column.name.split(':').collect();