Buffer line styling

This commit is contained in:
mars 2023-04-12 17:54:22 -04:00
parent 742ed97819
commit 83872583e0
1 changed files with 5 additions and 2 deletions

View File

@ -74,7 +74,7 @@ impl Buffer {
cols: u16,
rows: u16,
scroll: Cursor,
out: &mut impl QueueableCommand,
out: &mut impl Write,
) -> crossterm::Result<u32> {
self.parse();
@ -86,6 +86,7 @@ impl Buffer {
out.queue(cursor::MoveTo(0, 0))?;
let mut line_buf = Vec::<u8>::with_capacity(text_width);
for (row, line) in (0..rows).zip(self.text.lines_at(scroll.line)) {
// only the last line is empty and should be skipped
if line.len_chars() == 0 {
@ -98,6 +99,7 @@ impl Buffer {
let lhs = scroll.column;
let width = line.len_chars();
line_buf.clear();
if lhs < width {
let window = text_width.min(width - lhs);
let rhs = lhs + window;
@ -107,7 +109,7 @@ impl Buffer {
if range.start < range.end {
// this range is in view so display
let content = line.slice(range.clone());
style.print_styled(out, content)?;
style.print_styled(&mut line_buf, content)?;
}
if range.end >= rhs {
@ -117,6 +119,7 @@ impl Buffer {
}
}
out.write_all(&line_buf)?;
out.queue(cursor::MoveToNextLine(1))?;
}