Start of lines for editing

This commit is contained in:
Timothy Warren 2021-03-08 10:21:06 -05:00
parent 3c9b18fcb4
commit d9ed5c631a
4 changed files with 20 additions and 3 deletions

6
src/document.rs Normal file
View File

@ -0,0 +1,6 @@
use crate::Row;
#[derive(Default)]
pub struct Document {
rows: Vec<Row>,
}

View File

@ -1,8 +1,10 @@
use crate::Document;
use crate::Terminal; use crate::Terminal;
use termion::event::Key; use termion::event::Key;
const VERSION: &str = env!("CARGO_PKG_VERSION"); const VERSION: &str = env!("CARGO_PKG_VERSION");
#[derive(Default)]
pub struct Position { pub struct Position {
pub x: usize, pub x: usize,
pub y: usize, pub y: usize,
@ -12,6 +14,7 @@ pub struct Editor {
should_quit: bool, should_quit: bool,
terminal: Terminal, terminal: Terminal,
cursor_position: Position, cursor_position: Position,
document: Document,
} }
impl Editor { impl Editor {
@ -33,13 +36,14 @@ impl Editor {
Self { Self {
should_quit: false, should_quit: false,
terminal: Terminal::default().expect("Failed to initialize terminal"), terminal: Terminal::default().expect("Failed to initialize terminal"),
cursor_position: Position { x: 0, y: 0 } document: Document::default(),
cursor_position: Position::default(),
} }
} }
fn refresh_screen(&self) -> Result<(), std::io::Error> { fn refresh_screen(&self) -> Result<(), std::io::Error> {
Terminal::cursor_hide(); Terminal::cursor_hide();
Terminal::cursor_position(&Position { x: 0, y: 0}); Terminal::cursor_position(&Position::default());
if self.should_quit { if self.should_quit {
Terminal::clear_screen(); Terminal::clear_screen();
println!("Goodbye.\r"); println!("Goodbye.\r");

View File

@ -1,10 +1,14 @@
#![warn(clippy::all, clippy::pedantic)] #![warn(clippy::all, clippy::pedantic)]
mod document;
mod editor; mod editor;
mod row;
mod terminal; mod terminal;
pub use document::Document;
use editor::Editor; use editor::Editor;
pub use terminal::Terminal;
pub use editor::Position; pub use editor::Position;
pub use row::Row;
pub use terminal::Terminal;
fn main() { fn main() {
Editor::default().run(); Editor::default().run();

3
src/row.rs Normal file
View File

@ -0,0 +1,3 @@
pub struct Row {
string: String,
}