fix: Correctly calculate info table column width for truncation

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-09-08 17:38:56 -03:00
parent aa8b942f2d
commit d15ba05a44

View File

@@ -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),