aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorJan Hrastnik2020-06-24 18:59:35 +0000
committerJan Hrastnik2020-06-24 18:59:35 +0000
commit6ba082697d4a930d4114e950a212f115bace47e9 (patch)
tree278c403c63a34899f8a175bf55deb035b0833c80 /helix-term
parentc3a23a1c0933900d795a1a5b67c3a305616ba8f2 (diff)
added cursor rendering
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/editor.rs15
-rw-r--r--helix-term/src/keymap.rs7
2 files changed, 18 insertions, 4 deletions
diff --git a/helix-term/src/editor.rs b/helix-term/src/editor.rs
index 65024374..7b3e215a 100644
--- a/helix-term/src/editor.rs
+++ b/helix-term/src/editor.rs
@@ -14,7 +14,7 @@ use std::time::Duration;
use anyhow::Error;
use crate::{keymap, Args};
-use helix_core::{Buffer, State};
+use helix_core::{state::coords_at_pos, Buffer, State};
pub struct BufferComponent<'a> {
x: u16,
@@ -37,8 +37,7 @@ impl BufferComponent<'_> {
SetForegroundColor(Color::Reset),
cursor::MoveTo(self.x + 2, self.y + line_count),
Print(line)
- )
- .unwrap();
+ );
line_count += 1;
}
}
@@ -117,6 +116,16 @@ impl Editor {
// TODO: handle count other than 1
command(state, 1);
self.render();
+ // render the cursor
+ let pos = self.state.as_ref().unwrap().selection.primary().head;
+ let coords = coords_at_pos(
+ &self.state.as_ref().unwrap().doc.contents.slice(..),
+ pos,
+ );
+ execute!(
+ stdout(),
+ cursor::MoveTo((coords.1 + 2) as u16, coords.0 as u16)
+ );
}
}
}
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs
index 25bffd2e..44f4fc95 100644
--- a/helix-term/src/keymap.rs
+++ b/helix-term/src/keymap.rs
@@ -1,6 +1,11 @@
-use crossterm::event::{KeyCode, KeyEvent as Key, KeyModifiers as Modifiers};
+use crossterm::{
+ event::{KeyCode, KeyEvent as Key, KeyModifiers as Modifiers},
+ execute,
+ style::Print,
+};
use helix_core::commands::{self, Command};
use std::collections::HashMap;
+use std::io::{stdout, Write};
// Kakoune-inspired:
// mode = {