feat: add ellipsis when truncating strings and only apply max_len for terminal output

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-26 08:45:48 -03:00
parent 2a233b3d43
commit a92c22b58c
2 changed files with 75 additions and 39 deletions

View File

@@ -46,7 +46,30 @@ pub fn string_column(s: String, column_width: usize) -> String {
if column_width > 0 {
match s.char_indices().nth(column_width) {
None => s.to_string(),
Some((idx, _)) => s[..idx].to_string(),
Some((idx, _)) => {
if column_width > 1 {
// Find where to cut to fit the ellipsis
let mut cut_idx = idx;
// We need to make room for the ellipsis character
// Find the character boundary before the cut index
for i in (0..idx).rev() {
if s.is_char_boundary(i) {
if idx - i >= 3 { // Make sure we have enough room
cut_idx = i;
break;
}
}
}
// If we can't find a good place, just truncate without ellipsis
if cut_idx >= 3 {
format!("{}", &s[..cut_idx - 1])
} else {
s[..idx].to_string()
}
} else {
s[..idx].to_string()
}
}
}
} else {
s.to_string()