aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/editor.rs
diff options
context:
space:
mode:
authorJan Hrastnik2020-06-19 00:14:29 +0000
committerJan Hrastnik2020-06-19 00:14:29 +0000
commite93b15cef3d9274a95ac4342e777d240856e5803 (patch)
tree4f2ab662d75d21511a71c5246c197c1542422455 /helix-term/src/editor.rs
parent8958f06f0824965d030adc7522303129da014315 (diff)
created view struct
Diffstat (limited to 'helix-term/src/editor.rs')
-rw-r--r--helix-term/src/editor.rs43
1 files changed, 40 insertions, 3 deletions
diff --git a/helix-term/src/editor.rs b/helix-term/src/editor.rs
index 3df84d6e..1ce5c8f6 100644
--- a/helix-term/src/editor.rs
+++ b/helix-term/src/editor.rs
@@ -16,13 +16,35 @@ use anyhow::Error;
use crate::{keymap, Args};
use helix_core::{Buffer, State};
+pub struct View<'a> {
+ x: u16,
+ y: u16,
+ contents: &'a str,
+}
+
+impl View<'_> {
+ pub fn render(&self) {
+ execute!(
+ stdout(),
+ cursor::MoveTo(self.x, self.y),
+ Print(self.contents)
+ );
+ }
+}
+
pub struct Editor {
state: Option<State>,
+ current_line: u16,
+ size: (u16, u16),
}
impl Editor {
pub fn new(mut args: Args) -> Result<Self, Error> {
- let mut editor = Editor { state: None };
+ let mut editor = Editor {
+ state: None,
+ current_line: 0,
+ size: terminal::size().unwrap(),
+ };
if let Some(file) = args.files.pop() {
editor.open(file)?;
@@ -38,10 +60,25 @@ impl Editor {
Ok(())
}
- fn render(&self) {
+ fn render(&mut self) {
// TODO:
+
match &self.state {
- Some(s) => execute!(stdout(), cursor::MoveTo(0, 0), Print(s.file())).unwrap(),
+ Some(s) => {
+ for line in s
+ .file()
+ .lines_at(self.current_line as usize)
+ .take(self.size.1 as usize)
+ {
+ let view = View {
+ x: 0,
+ y: self.current_line,
+ contents: line.as_str().unwrap(),
+ };
+ view.render();
+ self.current_line += 1;
+ }
+ }
None => (),
}
}