fix: Truncate all info table value cells and add debug logging

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:45:22 -03:00
parent d15ba05a44
commit 762fdfd876
2 changed files with 25 additions and 10 deletions

View File

@@ -3,7 +3,7 @@ use crate::compression_engine::CompressionType;
use crate::meta_plugin::MetaPluginType; use crate::meta_plugin::MetaPluginType;
use clap::Command; use clap::Command;
use clap::error::ErrorKind; use clap::error::ErrorKind;
use log::debug; use log::{debug, log_enabled, Level};
use prettytable::format::TableFormat; use prettytable::format::TableFormat;
use regex::Regex; use regex::Regex;
use std::collections::HashMap; use std::collections::HashMap;
@@ -247,17 +247,22 @@ pub fn calculate_last_column_width(column_widths: &[usize], terminal_width: usiz
/// Truncate a string to fit within a maximum width, adding an ellipsis if truncated /// Truncate a string to fit within a maximum width, adding an ellipsis if truncated
pub fn truncate_with_ellipsis(s: &str, max_width: usize) -> String { pub fn truncate_with_ellipsis(s: &str, max_width: usize) -> String {
debug!("Truncating '{}' to max_width: {}", s, max_width);
if max_width == 0 { if max_width == 0 {
debug!("Max width is 0, returning empty string");
return String::new(); return String::new();
} }
if s.chars().count() <= max_width { let char_count = s.chars().count();
if char_count <= max_width {
debug!("String fits within max_width ({} <= {}), returning original", char_count, max_width);
return s.to_string(); return s.to_string();
} }
// We need to truncate and add an ellipsis // We need to truncate and add an ellipsis
// The ellipsis takes 1 character, so we can show max_width-1 characters // The ellipsis takes 1 character, so we can show max_width-1 characters
if max_width == 1 { if max_width == 1 {
debug!("Max width is 1, returning ellipsis only");
return "".to_string(); return "".to_string();
} }
@@ -273,5 +278,6 @@ pub fn truncate_with_ellipsis(s: &str, max_width: usize) -> String {
} }
result.push('…'); result.push('…');
debug!("Truncated result: '{}'", result);
result result
} }

View File

@@ -136,6 +136,7 @@ fn show_item(
// Calculate the maximum width for the last column if we're in a terminal // Calculate the maximum width for the last column if we're in a terminal
let terminal_width = crate::modes::common::get_terminal_width(); let terminal_width = crate::modes::common::get_terminal_width();
debug!("Terminal width: {}", terminal_width);
if std::io::stdout().is_terminal() && terminal_width > 0 { if std::io::stdout().is_terminal() && terminal_width > 0 {
// For the info table, we always have exactly 2 columns // For the info table, we always have exactly 2 columns
// Find the maximum width of the first column (labels) // Find the maximum width of the first column (labels)
@@ -143,16 +144,24 @@ fn show_item(
.map(|row| row.get_cell(0).map(|c| c.get_content().chars().count()).unwrap_or(0)) .map(|row| row.get_cell(0).map(|c| c.get_content().chars().count()).unwrap_or(0))
.max() .max()
.unwrap_or(0); .unwrap_or(0);
debug!("Max label width: {}", max_label_width);
// Each row has: // Total width used: 1 (left border) + (max_label_width + 2) + 1 (middle separator) + (value_width + 2) + 1 (right border)
// 1. Label cell: max_label_width + 2 padding // We want: max_label_width + value_width + 7 <= terminal_width
// 2. Border character: '│' (1 character) // So max value width is: terminal_width - max_label_width - 7
// 3. Value cell: ? + 2 padding let max_value_width = terminal_width.saturating_sub(max_label_width + 7);
// Total width used: (max_label_width + 2) + 1 + (value_width + 2) debug!("Max value width: {}", max_value_width);
// We want this to be <= terminal_width
// So max value width is: terminal_width - (max_label_width + 2 + 1 + 2) // Process all existing rows to truncate their value cells
let max_value_width = terminal_width.saturating_sub(max_label_width + 5); for row in &mut rows {
if let Some(value_cell) = row.get_mut_cell(1) {
let content = value_cell.get_content();
if content.chars().count() > max_value_width {
let truncated = crate::modes::common::truncate_with_ellipsis(&content, max_value_width);
*value_cell = Cell::new(&truncated);
}
}
}
// Process meta rows to truncate values if necessary // Process meta rows to truncate values if necessary
for (meta_name, meta_value) in meta_rows { for (meta_name, meta_value) in meta_rows {