aboutsummaryrefslogtreecommitdiff
path: root/helix-tui/src
diff options
context:
space:
mode:
authorIvan Tham2021-06-15 05:03:56 +0000
committerIvan Tham2021-06-15 15:46:21 +0000
commit124514aa7024b0cf40bf01def54d280fcc86897c (patch)
treee4fa3e9566755d40bd322578fd25f7de99b28377 /helix-tui/src
parent6bdf609caaf4eb1c137f503f147d1e4e4f3e8676 (diff)
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.
Diffstat (limited to 'helix-tui/src')
-rw-r--r--helix-tui/src/terminal.rs32
1 files changed, 25 insertions, 7 deletions
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