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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user