diff --git a/src/editor.rs b/src/editor.rs index c983406..7f71a57 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -6,6 +6,10 @@ use std::io; use std::io::prelude::*; use std::io::BufReader; +pub struct EditorRow { + row_chars: String, +} + /// Main structure for the editor /// /// impl blocks are split similarly to the original C implementation @@ -13,6 +17,8 @@ use std::io::BufReader; pub struct Editor { cursor_x: usize, cursor_y: usize, + row: EditorRow, + num_rows: usize, screen_cols: usize, screen_rows: usize, output_buffer: String, @@ -123,15 +129,13 @@ impl Editor { } } - - return Some(output); } fn get_window_size(&mut self) -> TermSize { match get_term_size() { Some(size) => size, - None => unimplemented!("The easy way usually works") + None => unimplemented!("The easy way usually works"), } } } @@ -144,22 +148,22 @@ impl Editor { if self.cursor_x != 0 { self.cursor_x -= 1; } - }, + } ArrowRight => { if self.cursor_x != self.screen_cols - 1 { self.cursor_x += 1; } - }, + } ArrowUp => { if self.cursor_y != 0 { self.cursor_y -= 1; } - }, + } ArrowDown => { if self.cursor_y != self.screen_rows - 1 { self.cursor_y += 1; } - }, + } _ => (), }; } @@ -182,13 +186,13 @@ impl Editor { // Break out of the input loop return None; } - }, + } HomeKey => { self.cursor_x = 0; - }, + } EndKey => { self.cursor_x = self.screen_cols - 1; - }, + } PageUp => self.page_up_or_down(PageUp), PageDown => self.page_up_or_down(PageDown), ArrowUp => self.move_cursor(&ArrowUp), @@ -204,7 +208,7 @@ impl Editor { } fn page_up_or_down(&mut self, key: EditorKey) { - let mut times = self.screen_rows; + let mut times = self.screen_rows; while times > 1 { times -= 1; @@ -243,7 +247,7 @@ impl Editor { } while padding > 0 { self.append_out(" "); - padding -=1; + padding -= 1; } self.append_out(&welcome); @@ -279,3 +283,8 @@ impl Editor { handle.write_all(&self.output_buffer.as_bytes()) } } + +// File I/O +impl Editor { + pub fn open(&mut self) {} +}