-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
use crossterm::event::{read, Event::Key, KeyCode::Char}; | ||
use crossterm::terminal::{disable_raw_mode, enable_raw_mode}; | ||
|
||
|
||
pub struct Editor { | ||
|
||
} | ||
pub struct Editor {} | ||
|
||
impl Editor { | ||
pub fn default() -> Self { | ||
Editor{} | ||
pub fn default() -> Self { | ||
Editor {} | ||
} | ||
pub fn run(&self) { | ||
if let Err(err) = self.repl() { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
panic!("{err:#?}"); | ||
This comment has been minimized.
Sorry, something went wrong.
pflenker
Author
Owner
|
||
} | ||
print!("Goodbye.\r\n"); | ||
} | ||
pub fn run(&self){ | ||
enable_raw_mode().unwrap(); | ||
fn repl(&self) -> Result<(), std::io::Error> { | ||
This comment has been minimized.
Sorry, something went wrong.
pflenker
Author
Owner
|
||
enable_raw_mode()?; | ||
This comment has been minimized.
Sorry, something went wrong.
pflenker
Author
Owner
|
||
loop { | ||
match read() { | ||
Ok(Key(event)) => { | ||
println!("{event:?} \r"); | ||
if let Char(c) = event.code { | ||
if c == 'q' { | ||
break; | ||
} | ||
if let Key(event) = read()? { | ||
This comment has been minimized.
Sorry, something went wrong.
pflenker
Author
Owner
|
||
println!("{event:?} \r"); | ||
if let Char(c) = event.code { | ||
if c == 'q' { | ||
break; | ||
} | ||
}, | ||
Err(err) => println!("Error: {err}"), | ||
_ => () | ||
} | ||
} | ||
} | ||
disable_raw_mode().unwrap(); | ||
disable_raw_mode()?; | ||
Ok(()) | ||
This comment has been minimized.
Sorry, something went wrong.
pflenker
Author
Owner
|
||
} | ||
} |
repl
will soon hold our read-eval-print` loop. The function will return nothing if everything went well, and returns an error if something we couldn't recover from happened.