diff options
| author | Jonas Maier <> | 2026-05-24 18:02:04 +0200 |
|---|---|---|
| committer | Jonas Maier <> | 2026-05-24 18:02:04 +0200 |
| commit | 01a198b8ad42680c9333039c75317d1787120c78 (patch) | |
| tree | 96fac6e66a4f454ba0d6a4fc6d61226346c3258a /src/line | |
| parent | 52e97864d483f1f442e96058a17c159c5be10db3 (diff) | |
| download | pish-01a198b8ad42680c9333039c75317d1787120c78.tar.gz | |
better multiline handling
Diffstat (limited to 'src/line')
| -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; } |
