diff options
Diffstat (limited to 'src/line/mod.rs')
| -rw-r--r-- | src/line/mod.rs | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/line/mod.rs b/src/line/mod.rs index 75a4508..c6c2f34 100644 --- a/src/line/mod.rs +++ b/src/line/mod.rs @@ -2,12 +2,16 @@ mod buf; use std::io::{self, Write}; -use crate::cursor::{self, Direction}; +use crate::{ + cursor::{self, CursorPos, Direction}, + syntax_highlighting::Highlighter, +}; pub use buf::LineBuf; pub struct Line { buf: LineBuf, dirty: bool, + line_start: CursorPos, } impl std::ops::Deref for Line { @@ -23,9 +27,38 @@ impl Line { Self { buf: LineBuf::new(), dirty: false, + line_start: CursorPos::default(), } } + pub fn set_begin_of_line(&mut self, pos: CursorPos) { + self.line_start = pos; + } + + pub fn highlight_syntax(&mut self, h: &mut Highlighter) -> std::io::Result<()> { + if !self.is_dirty() { + return Ok(()); + } + + self.mark_clean(); + + if !h.enabled { + return Ok(()); + } + + use crate::parse::{self, Parse}; + + let buf = self.into_bytes(); + let mut parser = parse::Cursor::new(&buf, parse::ParseMode::Completion); + let _ = parse::Ast::parse(&mut parser); + let mut stdout = io::stdout().lock(); + self.line_start.f_go_to(&mut stdout)?; + h.pretty_print(&buf, parser.highlights, &mut stdout)?; + stdout.flush()?; + + Ok(()) + } + pub fn mark_clean(&mut self) { self.dirty = false; } |
