on master help sign in
added cursor rendering
commit6ba082697d4a930d4114e950a212f115bace47e9 authorJan Hrastnik <jan.hrastnik2@gmail.com> dateWed 24 Jun 2020, 20:59 (6 years ago) parentc3a23a1
4 files changed+21−7
helix-core/src/lib.rs+1−1 helix-core/src/state.rs+2−2 helix-term/src/editor.rs+12−3 helix-term/src/keymap.rs+6−1
helix-core/src/lib.rs+1−1
@@ -3,7 +3,7 @@ mod buffer;
33pub mod commands;
44mod graphemes;
55mod selection;
6−mod state;
6+pub mod state;
77mod transaction;
88
99pub use ropey::{Rope, RopeSlice};
helix-core/src/state.rs+2−2
@@ -3,8 +3,8 @@ use crate::{Buffer, Rope, RopeSlice, Selection, SelectionRange};
33
44/// A state represents the current editor state of a single buffer.
55pub struct State {
6− pub(crate) doc: Buffer,
7− pub(crate) selection: Selection,
6+ pub doc: Buffer,
7+ pub selection: Selection,
88}
99
1010#[derive(Copy, Clone, PartialEq, Eq)]
helix-term/src/editor.rs+12−3
@@ -14,7 +14,7 @@ use std::time::Duration;
1414use anyhow::Error;
1515
1616use crate::{keymap, Args};
17−use helix_core::{Buffer, State};
17+use helix_core::{state::coords_at_pos, Buffer, State};
1818
1919pub struct BufferComponent<'a> {
2020 x: u16,
@@ -37,8 +37,7 @@ impl BufferComponent<'_> {
3737 SetForegroundColor(Color::Reset),
3838 cursor::MoveTo(self.x + 2, self.y + line_count),
3939 Print(line)
40− )
41− .unwrap();
40+ );
4241 line_count += 1;
4342 }
4443 }
@@ -117,6 +116,16 @@ impl Editor {
117116 // TODO: handle count other than 1
118117 command(state, 1);
119118 self.render();
119+ // render the cursor
120+ let pos = self.state.as_ref().unwrap().selection.primary().head;
121+ let coords = coords_at_pos(
122+ &self.state.as_ref().unwrap().doc.contents.slice(..),
123+ pos,
124+ );
125+ execute!(
126+ stdout(),
127+ cursor::MoveTo((coords.1 + 2) as u16, coords.0 as u16)
128+ );
120129 }
121130 }
122131 }
helix-term/src/keymap.rs+6−1
@@ -1,6 +1,11 @@
1−use crossterm::event::{KeyCode, KeyEvent as Key, KeyModifiers as Modifiers};
1+use crossterm::{
2+ event::{KeyCode, KeyEvent as Key, KeyModifiers as Modifiers},
3+ execute,
4+ style::Print,
5+};
26use helix_core::commands::{self, Command};
37use std::collections::HashMap;
8+use std::io::{stdout, Write};
49
510// Kakoune-inspired:
611// mode = {