From d15ba05a4475d4dcbdd1045f8d0acd9d7ffc8923 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Mon, 8 Sep 2025 17:38:56 -0300 Subject: [PATCH] fix: Correctly calculate info table column width for truncation Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) --- src/modes/info.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/modes/info.rs b/src/modes/info.rs index 27db3c9..d78d5fb 100644 --- a/src/modes/info.rs +++ b/src/modes/info.rs @@ -137,22 +137,34 @@ fn show_item( // Calculate the maximum width for the last column if we're in a terminal let terminal_width = crate::modes::common::get_terminal_width(); if std::io::stdout().is_terminal() && terminal_width > 0 { - // Estimate widths of other columns (assuming first column is the longest label) - // This is a simplification, but should work for most cases + // For the info table, we always have exactly 2 columns + // Find the maximum width of the first column (labels) let max_label_width = rows.iter() .map(|row| row.get_cell(0).map(|c| c.get_content().chars().count()).unwrap_or(0)) .max() .unwrap_or(0); - // Calculate the maximum width for the value column - let max_value_width = crate::modes::common::calculate_last_column_width(&[max_label_width], terminal_width); + // Each row has: + // 1. Label cell: max_label_width + 2 padding + // 2. Border character: '│' (1 character) + // 3. Value cell: ? + 2 padding + // Total width used: (max_label_width + 2) + 1 + (value_width + 2) + // We want this to be <= terminal_width + + // So max value width is: terminal_width - (max_label_width + 2 + 1 + 2) + let max_value_width = terminal_width.saturating_sub(max_label_width + 5); // Process meta rows to truncate values if necessary for (meta_name, meta_value) in meta_rows { let truncated_value = if max_value_width > 0 { crate::modes::common::truncate_with_ellipsis(&meta_value, max_value_width) } else { - meta_value + // If max_value_width is 0, we can't show anything, but let's at least show something + if max_value_width == 0 { + "…".to_string() + } else { + meta_value + } }; rows.push(Row::new(vec![ Cell::new(&meta_name).with_style(Attr::Bold),