diff --git a/src/modes/list.rs b/src/modes/list.rs index cb76824..f24eed1 100644 --- a/src/modes/list.rs +++ b/src/modes/list.rs @@ -91,51 +91,72 @@ pub fn mode_list( } } - let mut cell = match column_type { - ColumnType::Id => Cell::new(item.id.unwrap_or(0).to_string()), - ColumnType::Time => Cell::new( - item.ts - .with_timezone(&chrono::Local) - .format("%F %T") - .to_string(), - ), + let cell_content = match column_type { + ColumnType::Id => item.id.unwrap_or(0).to_string(), + ColumnType::Time => item.ts + .with_timezone(&chrono::Local) + .format("%F %T") + .to_string(), ColumnType::Size => match item.size { - Some(size) => Cell::new(format_size( - size as u64, - settings.human_readable, - )), + Some(size) => format_size(size as u64, settings.human_readable), None => match item_path.metadata() { - Ok(_) => Cell::new("Unknown") - .fg(Color::Yellow) - .add_attribute(Attribute::Bold), - Err(_) => Cell::new("Missing") - .fg(Color::Red) - .add_attribute(Attribute::Bold), + Ok(_) => "Unknown".to_string(), + Err(_) => "Missing".to_string(), }, }, - ColumnType::Compression => Cell::new(item.compression.to_string()), + ColumnType::Compression => item.compression.to_string(), ColumnType::FileSize => match item_path.metadata() { - Ok(metadata) => Cell::new(format_size( - metadata.len(), - settings.human_readable, - )), - Err(_) => Cell::new("Missing") - .fg(Color::Red) - .add_attribute(Attribute::Bold), + Ok(metadata) => format_size(metadata.len(), settings.human_readable), + Err(_) => "Missing".to_string(), }, - ColumnType::FilePath => Cell::new( - item_path.clone().into_os_string().into_string().unwrap(), - ), - ColumnType::Tags => Cell::new(tags.join(" ")), + ColumnType::FilePath => item_path.clone().into_os_string().into_string().unwrap(), + ColumnType::Tags => tags.join(" "), ColumnType::Meta => match meta_name { Some(meta_name) => match meta.get(meta_name) { - Some(meta_value) => Cell::new(meta_value.to_string()), - None => Cell::new(""), + Some(meta_value) => meta_value.to_string(), + None => "".to_string(), }, - None => Cell::new(""), + None => "".to_string(), }, }; + // Truncate content to max 3 lines + let mut cell_lines: Vec<&str> = cell_content.split('\n').collect(); + if cell_lines.len() > 3 { + cell_lines.truncate(3); + // Add ellipsis to the last line if we truncated + if let Some(last_line) = cell_lines.last_mut() { + let mut last_line = (*last_line).to_string(); + if last_line.len() > 3 { + last_line.truncate(last_line.len() - 3); + } + last_line.push_str("..."); + cell_lines[2] = Box::leak(last_line.into_boxed_str()); + } + } + let truncated_content = cell_lines.join("\n"); + + let mut cell = Cell::new(truncated_content); + + // Apply styling for specific cases + match column_type { + ColumnType::Size => { + if item.size.is_none() { + if item_path.metadata().is_ok() { + cell = cell.fg(Color::Yellow).add_attribute(Attribute::Bold); + } else { + cell = cell.fg(Color::Red).add_attribute(Attribute::Bold); + } + } + } + ColumnType::FileSize => { + if item_path.metadata().is_err() { + cell = cell.fg(Color::Red).add_attribute(Attribute::Bold); + } + } + _ => {} + } + // Apply alignment and max height cell = match column.align { crate::config::ColumnAlignment::Right => cell.set_alignment(CellAlignment::Right),