diff --git a/src/modes/list.rs b/src/modes/list.rs index 11b1881..f533882 100644 --- a/src/modes/list.rs +++ b/src/modes/list.rs @@ -120,122 +120,135 @@ pub fn mode_list( let cell = match column_type { ColumnType::Id => { + let mut cell = Cell::new(&string_column(item.id.unwrap_or(0).to_string(), column_width)); match column.align { - crate::config::ColumnAlignment::Right => Cell::new(&string_column(item.id.unwrap_or(0).to_string(), column_width)).align(Alignment::RIGHT), - crate::config::ColumnAlignment::Left => Cell::new(&string_column(item.id.unwrap_or(0).to_string(), column_width)).align(Alignment::LEFT), + crate::config::ColumnAlignment::Right => { cell.align(Alignment::RIGHT); }, + crate::config::ColumnAlignment::Left => { cell.align(Alignment::LEFT); }, } + cell }, ColumnType::Time => { + let mut cell = Cell::new(&string_column( + item.ts + .with_timezone(&chrono::Local) + .format("%F %T") + .to_string(), + column_width, + )); match column.align { - crate::config::ColumnAlignment::Right => Cell::new(&string_column( - item.ts - .with_timezone(&chrono::Local) - .format("%F %T") - .to_string(), - column_width, - )).align(Alignment::RIGHT), - crate::config::ColumnAlignment::Left => Cell::new(&string_column( - item.ts - .with_timezone(&chrono::Local) - .format("%F %T") - .to_string(), - column_width, - )).align(Alignment::LEFT), + crate::config::ColumnAlignment::Right => { cell.align(Alignment::RIGHT); }, + crate::config::ColumnAlignment::Left => { cell.align(Alignment::LEFT); }, } + cell }, ColumnType::Size => { - match column.align { - crate::config::ColumnAlignment::Right => match item.size { - Some(size) => Cell::new(&size_column(size as u64, settings.human_readable, column_width)).align(Alignment::RIGHT), - None => match item_path.metadata() { + let cell = match item.size { + Some(size) => { + let mut cell = Cell::new(&size_column(size as u64, settings.human_readable, column_width)); + match column.align { + crate::config::ColumnAlignment::Right => { cell.align(Alignment::RIGHT); }, + crate::config::ColumnAlignment::Left => { cell.align(Alignment::LEFT); }, + } + cell + }, + None => { + let mut cell = match item_path.metadata() { Ok(_) => Cell::new("Unknown") .with_style(Attr::ForegroundColor(color::YELLOW)) - .with_style(Attr::Bold) - .align(Alignment::RIGHT), + .with_style(Attr::Bold), Err(_) => Cell::new("Missing") .with_style(Attr::ForegroundColor(color::RED)) - .with_style(Attr::Bold) - .align(Alignment::RIGHT), - }, + .with_style(Attr::Bold), + }; + match column.align { + crate::config::ColumnAlignment::Right => { cell.align(Alignment::RIGHT); }, + crate::config::ColumnAlignment::Left => { cell.align(Alignment::LEFT); }, + } + cell }, - crate::config::ColumnAlignment::Left => match item.size { - Some(size) => Cell::new(&size_column(size as u64, settings.human_readable, column_width)).align(Alignment::LEFT), - None => match item_path.metadata() { - Ok(_) => Cell::new("Unknown") - .with_style(Attr::ForegroundColor(color::YELLOW)) - .with_style(Attr::Bold) - .align(Alignment::LEFT), - Err(_) => Cell::new("Missing") - .with_style(Attr::ForegroundColor(color::RED)) - .with_style(Attr::Bold) - .align(Alignment::LEFT), - }, - }, - } + }; + cell }, ColumnType::Compression => { + let mut cell = Cell::new(&string_column(item.compression.to_string(), column_width)); match column.align { - crate::config::ColumnAlignment::Right => Cell::new(&string_column(item.compression.to_string(), column_width)).align(Alignment::RIGHT), - crate::config::ColumnAlignment::Left => Cell::new(&string_column(item.compression.to_string(), column_width)).align(Alignment::LEFT), + crate::config::ColumnAlignment::Right => { cell.align(Alignment::RIGHT); }, + crate::config::ColumnAlignment::Left => { cell.align(Alignment::LEFT); }, } + cell }, ColumnType::FileSize => { - match column.align { - crate::config::ColumnAlignment::Right => match item_path.metadata() { - Ok(metadata) => Cell::new(&size_column(metadata.len(), settings.human_readable, column_width)).align(Alignment::RIGHT), - Err(_) => Cell::new("Missing") - .with_style(Attr::ForegroundColor(color::RED)) - .with_style(Attr::Bold) - .align(Alignment::RIGHT), + let cell = match item_path.metadata() { + Ok(metadata) => { + let mut cell = Cell::new(&size_column(metadata.len(), settings.human_readable, column_width)); + match column.align { + crate::config::ColumnAlignment::Right => { cell.align(Alignment::RIGHT); }, + crate::config::ColumnAlignment::Left => { cell.align(Alignment::LEFT); }, + } + cell }, - crate::config::ColumnAlignment::Left => match item_path.metadata() { - Ok(metadata) => Cell::new(&size_column(metadata.len(), settings.human_readable, column_width)).align(Alignment::LEFT), - Err(_) => Cell::new("Missing") + Err(_) => { + let mut cell = Cell::new("Missing") .with_style(Attr::ForegroundColor(color::RED)) - .with_style(Attr::Bold) - .align(Alignment::LEFT), + .with_style(Attr::Bold); + match column.align { + crate::config::ColumnAlignment::Right => { cell.align(Alignment::RIGHT); }, + crate::config::ColumnAlignment::Left => { cell.align(Alignment::LEFT); }, + } + cell }, - } + }; + cell }, ColumnType::FilePath => { + let mut cell = Cell::new(&string_column( + item_path.clone().into_os_string().into_string().unwrap(), + column_width, + )); match column.align { - crate::config::ColumnAlignment::Right => Cell::new(&string_column( - item_path.clone().into_os_string().into_string().unwrap(), - column_width, - )).align(Alignment::RIGHT), - crate::config::ColumnAlignment::Left => Cell::new(&string_column( - item_path.clone().into_os_string().into_string().unwrap(), - column_width, - )).align(Alignment::LEFT), + crate::config::ColumnAlignment::Right => { cell.align(Alignment::RIGHT); }, + crate::config::ColumnAlignment::Left => { cell.align(Alignment::LEFT); }, } + cell }, ColumnType::Tags => { + let mut cell = Cell::new(&string_column(tags.join(" "), column_width)); match column.align { - crate::config::ColumnAlignment::Right => Cell::new(&string_column(tags.join(" "), column_width)).align(Alignment::RIGHT), - crate::config::ColumnAlignment::Left => Cell::new(&string_column(tags.join(" "), column_width)).align(Alignment::LEFT), + crate::config::ColumnAlignment::Right => { cell.align(Alignment::RIGHT); }, + crate::config::ColumnAlignment::Left => { cell.align(Alignment::LEFT); }, } + cell }, ColumnType::Meta => { - match column.align { - crate::config::ColumnAlignment::Right => match meta_name { - Some(meta_name) => match meta.get(meta_name) { - Some(meta_value) => { - Cell::new(&string_column(meta_value.to_string(), column_width)).align(Alignment::RIGHT) + let cell = match meta_name { + Some(meta_name) => match meta.get(meta_name) { + Some(meta_value) => { + let mut cell = Cell::new(&string_column(meta_value.to_string(), column_width)); + match column.align { + crate::config::ColumnAlignment::Right => { cell.align(Alignment::RIGHT); }, + crate::config::ColumnAlignment::Left => { cell.align(Alignment::LEFT); }, } - None => Cell::new("").align(Alignment::RIGHT), - }, - None => Cell::new("").align(Alignment::RIGHT), - }, - crate::config::ColumnAlignment::Left => match meta_name { - Some(meta_name) => match meta.get(meta_name) { - Some(meta_value) => { - Cell::new(&string_column(meta_value.to_string(), column_width)).align(Alignment::LEFT) + cell + } + None => { + let mut cell = Cell::new(""); + match column.align { + crate::config::ColumnAlignment::Right => { cell.align(Alignment::RIGHT); }, + crate::config::ColumnAlignment::Left => { cell.align(Alignment::LEFT); }, } - None => Cell::new("").align(Alignment::LEFT), + cell }, - None => Cell::new("").align(Alignment::LEFT), }, - } + None => { + let mut cell = Cell::new(""); + match column.align { + crate::config::ColumnAlignment::Right => { cell.align(Alignment::RIGHT); }, + crate::config::ColumnAlignment::Left => { cell.align(Alignment::LEFT); }, + } + cell + }, + }; + cell }, }; table_row.add_cell(cell);