diff options
author | Blaž Hrastnik | 2020-12-13 04:29:34 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2020-12-13 04:30:19 +0000 |
commit | ef0d062b1fd202fe89bc4bbd33826c46f660ef70 (patch) | |
tree | 77c10da4a77557c358f440368ba6f5506a3b7c9f /helix-term/src/application.rs | |
parent | 8695415fbfe927250f68e93793660e3c4e4a70b4 (diff) |
Fix cursor positioning.
Diffstat (limited to 'helix-term/src/application.rs')
-rw-r--r-- | helix-term/src/application.rs | 30 |
1 files changed, 4 insertions, 26 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 7a74f8ba..c25871c7 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -9,7 +9,6 @@ use crate::prompt::Prompt; use log::{debug, info}; use std::{ - borrow::Cow, io::{self, stdout, Stdout, Write}, path::PathBuf, time::Duration, @@ -47,31 +46,9 @@ pub struct Application { // TODO: temp #[inline(always)] pub fn text_color() -> Style { - return Style::default().fg(Color::Rgb(219, 191, 239)); // lilac + Style::default().fg(Color::Rgb(219, 191, 239)) // lilac } -// pub fn render_cursor(&mut self, view: &View, prompt: Option<&Prompt>, viewport: Rect) { -// let mut stdout = stdout(); -// match view.doc.mode() { -// Mode::Insert => write!(stdout, "\x1B[6 q"), -// mode => write!(stdout, "\x1B[2 q"), -// }; -// let pos = if let Some(prompt) = prompt { -// Position::new(self.size.0 as usize, 2 + prompt.cursor) -// } else { -// let cursor = view.doc.state.selection().cursor(); - -// let mut pos = view -// .screen_coords_at_pos(&view.doc.text().slice(..), cursor) -// .expect("Cursor is out of bounds."); -// pos.col += viewport.x as usize; -// pos.row += viewport.y as usize; -// pos -// }; - -// execute!(stdout, cursor::MoveTo(pos.col as u16, pos.row as u16)); -// } - impl Application { pub fn new(mut args: Args, executor: &'static smol::Executor<'static>) -> Result<Self, Error> { let backend = CrosstermBackend::new(stdout()); @@ -106,13 +83,14 @@ impl Application { let editor = &mut self.editor; let compositor = &self.compositor; - // TODO: should be unnecessary - // self.terminal.autoresize(); let mut cx = crate::compositor::Context { editor, executor }; let area = self.terminal.size().unwrap(); + compositor.render(area, self.terminal.current_buffer_mut(), &mut cx); + let pos = compositor.cursor_position(area, &mut cx); self.terminal.draw(); + self.terminal.set_cursor(pos.col as u16, pos.row as u16); } pub async fn event_loop(&mut self) { |