forked from mars/breed
Buffer line styling
This commit is contained in:
parent
742ed97819
commit
83872583e0
|
@ -74,7 +74,7 @@ impl Buffer {
|
||||||
cols: u16,
|
cols: u16,
|
||||||
rows: u16,
|
rows: u16,
|
||||||
scroll: Cursor,
|
scroll: Cursor,
|
||||||
out: &mut impl QueueableCommand,
|
out: &mut impl Write,
|
||||||
) -> crossterm::Result<u32> {
|
) -> crossterm::Result<u32> {
|
||||||
self.parse();
|
self.parse();
|
||||||
|
|
||||||
|
@ -86,6 +86,7 @@ impl Buffer {
|
||||||
|
|
||||||
out.queue(cursor::MoveTo(0, 0))?;
|
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)) {
|
for (row, line) in (0..rows).zip(self.text.lines_at(scroll.line)) {
|
||||||
// only the last line is empty and should be skipped
|
// only the last line is empty and should be skipped
|
||||||
if line.len_chars() == 0 {
|
if line.len_chars() == 0 {
|
||||||
|
@ -98,6 +99,7 @@ impl Buffer {
|
||||||
|
|
||||||
let lhs = scroll.column;
|
let lhs = scroll.column;
|
||||||
let width = line.len_chars();
|
let width = line.len_chars();
|
||||||
|
line_buf.clear();
|
||||||
if lhs < width {
|
if lhs < width {
|
||||||
let window = text_width.min(width - lhs);
|
let window = text_width.min(width - lhs);
|
||||||
let rhs = lhs + window;
|
let rhs = lhs + window;
|
||||||
|
@ -107,7 +109,7 @@ impl Buffer {
|
||||||
if range.start < range.end {
|
if range.start < range.end {
|
||||||
// this range is in view so display
|
// this range is in view so display
|
||||||
let content = line.slice(range.clone());
|
let content = line.slice(range.clone());
|
||||||
style.print_styled(out, content)?;
|
style.print_styled(&mut line_buf, content)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if range.end >= rhs {
|
if range.end >= rhs {
|
||||||
|
@ -117,6 +119,7 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out.write_all(&line_buf)?;
|
||||||
out.queue(cursor::MoveToNextLine(1))?;
|
out.queue(cursor::MoveToNextLine(1))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue