syntax-highlight bash lines (#3142)

i'm not yet convinced i have the best heuristics for what to highlight,
but this feels like a useful step towards something a bit easier to
read, esp. when the model is producing large commands.

<img width="669" height="589" alt="Screenshot 2025-09-03 at 8 21 56 PM"
src="https://github.com/user-attachments/assets/b9cbcc43-80e8-4d41-93c8-daa74b84b331"
/>

also a fairly significant refactor of our line wrapping logic.
This commit is contained in:
Jeremy Rose
2025-09-05 07:10:32 -07:00
committed by GitHub
parent 323a5cb7e7
commit d6182becbe
16 changed files with 786 additions and 305 deletions

View File

@@ -832,25 +832,10 @@ impl TextArea {
None => true,
};
if needs_recalc {
let mut lines: Vec<Range<usize>> = Vec::new();
for line in textwrap::wrap(
let lines = crate::wrapping::wrap_ranges(
&self.text,
Options::new(width as usize).wrap_algorithm(textwrap::WrapAlgorithm::FirstFit),
)
.iter()
{
match line {
std::borrow::Cow::Borrowed(slice) => {
let start =
unsafe { slice.as_ptr().offset_from(self.text.as_ptr()) as usize };
let end = start + slice.len();
let trailing_spaces =
self.text[end..].chars().take_while(|c| *c == ' ').count();
lines.push(start..end + trailing_spaces + 1);
}
std::borrow::Cow::Owned(_) => unreachable!(),
}
}
);
*cache = Some(WrapCache { width, lines });
}
}