From 3154d626ff4c12d9c9a29e9fa304430da8755965 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Sun, 14 Dec 2014 23:11:13 -0800 Subject: [PATCH] Escape quits, return inserts a new line. --- src/main.rs | 35 +++++++++++++++++------------------ todo.md | 4 +++- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/main.rs b/src/main.rs index 26fa589..233fca6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ mod buffer; // Usage documentation string static USAGE: &'static str = " -Usage: led +Usage: led [] led --help Options: @@ -23,7 +23,7 @@ Options: // Struct for storing command-line arguments #[deriving(Decodable, Show)] struct Args { - arg_file: String, + arg_file: Option, flag_help: bool, } @@ -54,7 +54,7 @@ fn main() { column = 0; continue; } - rustbox::print(column, line, Style::Bold, Color::White, Color::Black, c.to_string()); + rustbox::print(column, line, Style::Normal, Color::White, Color::Black, c.to_string()); column += 1; } else { @@ -76,21 +76,20 @@ fn main() { // Handle events match rustbox::poll_event() { - rustbox::Event::KeyEvent(_, _, ch) => { - match char::from_u32(ch) { - Some('q') => { break; }, - - Some('w') => { - let p = tb.len(); - tb.insert_text("\n", p); - }, - - Some(c) => { - let p = tb.len(); - tb.insert_text(c.to_string().as_slice(), p); - }, - - _ => {} + rustbox::Event::KeyEvent(modifier, key, character) => { + // Return + if key == 13 { + let p = tb.len(); + tb.insert_text("\n", p); + } + // Esc + else if key == 27 { + break; + } + // Some key + else if let Option::Some(c) = char::from_u32(character) { + let p = tb.len(); + tb.insert_text(c.to_string().as_slice(), p); } }, diff --git a/todo.md b/todo.md index 3152cfd..16cf2bd 100644 --- a/todo.md +++ b/todo.md @@ -1 +1,3 @@ -- Implement useful iterators for the Text Rope. \ No newline at end of file +- "Editor" class that has cursors. +- Some way of scrolling the view...? +- File loading. \ No newline at end of file