From 124514aa7024b0cf40bf01def54d280fcc86897c Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Tue, 15 Jun 2021 13:03:56 +0800 Subject: Add cursor kind to separate hidden cursor from pos Now IME cursor position should be correct since we can still set cursor position without drawing the cursor. --- helix-tui/src/terminal.rs | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'helix-tui') diff --git a/helix-tui/src/terminal.rs b/helix-tui/src/terminal.rs index ad1e8da3..e8f8f359 100644 --- a/helix-tui/src/terminal.rs +++ b/helix-tui/src/terminal.rs @@ -8,6 +8,19 @@ enum ResizeBehavior { Auto, } +#[derive(Debug)] +/// UNSTABLE +pub enum CursorKind { + /// █ + Block, + /// | + // Bar, + /// _ + // Underline, + /// Hidden cursor, can set cursor position with this to let IME have correct cursor position. + Hidden, +} + #[derive(Debug, Clone, PartialEq)] /// UNSTABLE pub struct Viewport { @@ -147,7 +160,11 @@ where /// Synchronizes terminal size, calls the rendering closure, flushes the current internal state /// and prepares for the next draw call. - pub fn draw(&mut self, cursor_position: Option<(u16, u16)>) -> io::Result<()> { + pub fn draw( + &mut self, + cursor_position: Option<(u16, u16)>, + cursor_kind: CursorKind, + ) -> io::Result<()> { // // Autoresize - otherwise we get glitches if shrinking or potential desync between widgets // // and the terminal (if growing), which may OOB. // self.autoresize()?; @@ -162,12 +179,13 @@ where // Draw to stdout self.flush()?; - match cursor_position { - None => self.hide_cursor()?, - Some((x, y)) => { - self.show_cursor()?; - self.set_cursor(x, y)?; - } + if let Some((x, y)) = cursor_position { + self.set_cursor(x, y)?; + } + + match cursor_kind { + CursorKind::Block => self.show_cursor()?, + CursorKind::Hidden => self.hide_cursor()?, } // Swap buffers -- cgit v1.2.3-70-g09d2