diff --git a/src/main.rs b/src/main.rs index 5d22585..612c838 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,7 @@ struct Nuudel { cursorx: u16, cursory: u16, buffer: Buffer, + filename: String, } #[derive(Default)] @@ -31,7 +32,13 @@ fn main() -> Result<()> { // Basic stuff let mut nuudel = Nuudel::default(); Nuudel::init_terminal()?; - nuudel.open_file("Cargo.toml")?; + + // Handle args + let args: Vec = std::env::args().collect(); + if let Some(arg) = args.get(1) { + nuudel.open_file(arg)?; + } + nuudel.run(&mut stdout())?; Nuudel::restore_terminal()?; @@ -68,12 +75,9 @@ impl Nuudel { fn handle_events(&mut self) -> Result<()> { match read()? { Event::Key(event) => match event.code { - KeyCode::Char('q') => { + KeyCode::Esc => { self.quit(); }, - KeyCode::Char('a') => { - print!("█"); - }, KeyCode::Left => { if self.cursorx > 0 { self.cursorx -= 1; @@ -94,6 +98,11 @@ impl Nuudel { self.cursory += 1; self.cursory = self.cursory.clamp(0, terminal::size()?.1-1); }, + KeyCode::Char(_) => { + self.buffer.lines[usize::try_from(self.cursory).unwrap()].insert(self.cursorx.into(), 'A'); + self.cursorx += 1; + + }, _ => {} }, _ => {} @@ -120,7 +129,7 @@ impl Nuudel { stdout.execute(cursor::MoveToNextLine(1))?; y += 1; } - print!("Press Q to quit"); + print!("Press ESC to quit"); //stdout.execute(terminal::EndSynchronizedUpdate)?; stdout.execute(cursor::MoveTo(self.cursorx, self.cursory))?; @@ -136,6 +145,7 @@ impl Nuudel { .lines() .map(String::from) .collect(); - Ok(()) + self.filename = filename.to_string(); + Ok(()) } }