On long spans, trim the middle of them to make them fit in the terminal width

When encountering a single line span that is wider than the terminal, we keep context at the start and end of the span but otherwise remove the code from the middle. This is somewhat independent from whether the left and right margins of the output have been trimmed as well.

```
error[E0308]: mismatched types
  --> $DIR/long-span.rs:6:15
   |
LL | ... = [0, 0, 0, 0, ..., 0, 0];
   |       ^^^^^^^^^^^^^...^^^^^^^ expected `u8`, found `[{integer}; 1681]`
```

Address part of #137680 (missing handling of the long suggestion). Fix #125581.
This commit is contained in:
Esteban Küber
2025-02-27 21:11:22 +00:00
parent d975bd3a67
commit 72326bfe40
9 changed files with 86 additions and 4 deletions

View File

@@ -89,6 +89,16 @@ impl StyledBuffer {
}
}
pub(crate) fn replace(&mut self, line: usize, start: usize, end: usize, string: &str) {
if start == end {
return;
}
let _ = self.lines[line].drain(start..(end - string.chars().count()));
for (i, c) in string.chars().enumerate() {
self.lines[line][start + i] = StyledChar::new(c, Style::LineNumber);
}
}
/// For given `line` inserts `string` with `style` before old content of that line,
/// adding lines if needed
pub(crate) fn prepend(&mut self, line: usize, string: &str, style: Style) {