on master help sign in
added cursor rendering
6ba0826Jan Hrastnik
helix-core/src/lib.rs+1−1
@@ -3,7 +3,7 @@ mod buffer;
3pub mod commands;
3pub mod commands;
4mod graphemes;
4mod graphemes;
5mod selection;
5mod selection;
6−mod state;
6+pub mod state;
7mod transaction;
7mod transaction;
8
8
9pub use ropey::{Rope, RopeSlice};
9pub use ropey::{Rope, RopeSlice};
helix-core/src/state.rs+2−2
@@ -3,8 +3,8 @@ use crate::{Buffer, Rope, RopeSlice, Selection, SelectionRange};
3
3
4/// A state represents the current editor state of a single buffer.
4/// A state represents the current editor state of a single buffer.
5pub struct State {
5pub struct State {
6− pub(crate) doc: Buffer,
6+ pub doc: Buffer,
7− pub(crate) selection: Selection,
7+ pub selection: Selection,
8}
8}
9
9
10#[derive(Copy, Clone, PartialEq, Eq)]
10#[derive(Copy, Clone, PartialEq, Eq)]
helix-term/src/editor.rs+12−3
@@ -14,7 +14,7 @@ use std::time::Duration;
14use anyhow::Error;
14use anyhow::Error;
15
15
16use crate::{keymap, Args};
16use crate::{keymap, Args};
17−use helix_core::{Buffer, State};
17+use helix_core::{state::coords_at_pos, Buffer, State};
18
18
19pub struct BufferComponent<'a> {
19pub struct BufferComponent<'a> {
20 x: u16,
20 x: u16,
@@ -37,8 +37,7 @@ impl BufferComponent<'_> {
37 SetForegroundColor(Color::Reset),
37 SetForegroundColor(Color::Reset),
38 cursor::MoveTo(self.x + 2, self.y + line_count),
38 cursor::MoveTo(self.x + 2, self.y + line_count),
39 Print(line)
39 Print(line)
40− )
40+ );
41− .unwrap();
42 line_count += 1;
41 line_count += 1;
43 }
42 }
44 }
43 }
@@ -117,6 +116,16 @@ impl Editor {
117 // TODO: handle count other than 1
116 // TODO: handle count other than 1
118 command(state, 1);
117 command(state, 1);
119 self.render();
118 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+ );
120 }
129 }
121 }
130 }
122 }
131 }
helix-term/src/keymap.rs+6−1
@@ -1,6 +1,11 @@
1+use crossterm::{
1−use crossterm::event::{KeyCode, KeyEvent as Key, KeyModifiers as Modifiers};
2+ event::{KeyCode, KeyEvent as Key, KeyModifiers as Modifiers},
3+ execute,
4+ style::Print,
5+};
2use helix_core::commands::{self, Command};
6use helix_core::commands::{self, Command};
3use std::collections::HashMap;
7use std::collections::HashMap;
8+use std::io::{stdout, Write};
4
9
5// Kakoune-inspired:
10// Kakoune-inspired:
6// mode = {
11// mode = {