added cursor rendering

pull/1/head
Jan Hrastnik 4 years ago
parent c3a23a1c09
commit 6ba082697d

@ -3,7 +3,7 @@ mod buffer;
pub mod commands; pub mod commands;
mod graphemes; mod graphemes;
mod selection; mod selection;
mod state; pub mod state;
mod transaction; mod transaction;
pub use ropey::{Rope, RopeSlice}; pub use ropey::{Rope, RopeSlice};

@ -3,8 +3,8 @@ use crate::{Buffer, Rope, RopeSlice, Selection, SelectionRange};
/// A state represents the current editor state of a single buffer. /// A state represents the current editor state of a single buffer.
pub struct State { pub struct State {
pub(crate) doc: Buffer, pub doc: Buffer,
pub(crate) selection: Selection, pub selection: Selection,
} }
#[derive(Copy, Clone, PartialEq, Eq)] #[derive(Copy, Clone, PartialEq, Eq)]

@ -14,7 +14,7 @@ use std::time::Duration;
use anyhow::Error; use anyhow::Error;
use crate::{keymap, Args}; use crate::{keymap, Args};
use helix_core::{Buffer, State}; use helix_core::{state::coords_at_pos, Buffer, State};
pub struct BufferComponent<'a> { pub struct BufferComponent<'a> {
x: u16, x: u16,
@ -37,8 +37,7 @@ impl BufferComponent<'_> {
SetForegroundColor(Color::Reset), SetForegroundColor(Color::Reset),
cursor::MoveTo(self.x + 2, self.y + line_count), cursor::MoveTo(self.x + 2, self.y + line_count),
Print(line) Print(line)
) );
.unwrap();
line_count += 1; line_count += 1;
} }
} }
@ -117,6 +116,16 @@ impl Editor {
// TODO: handle count other than 1 // TODO: handle count other than 1
command(state, 1); command(state, 1);
self.render(); 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)
);
} }
} }
} }

@ -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 helix_core::commands::{self, Command};
use std::collections::HashMap; use std::collections::HashMap;
use std::io::{stdout, Write};
// Kakoune-inspired: // Kakoune-inspired:
// mode = { // mode = {

Loading…
Cancel
Save