-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
16 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use std::io::{self, Read}; | ||
use crossterm::event::{read, Event::Key, KeyCode::Char}; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
use crossterm::terminal::{disable_raw_mode, enable_raw_mode}; | ||
|
||
|
||
pub struct Editor { | ||
|
||
} | ||
|
@@ -11,20 +12,21 @@ impl Editor { | |
} | ||
pub fn run(&self){ | ||
enable_raw_mode().unwrap(); | ||
for b in io::stdin().bytes() { | ||
match b { | ||
Ok(b) => { | ||
let c = b as char; | ||
if c.is_control() { | ||
println!("Binary: {0:08b} ASCII: {0:#03} \r", b); | ||
} else { | ||
println!("Binary: {0:08b} ASCII: {0:#03} Character: {1:#?}\r", b, c); | ||
} | ||
if c == 'q' { | ||
break; | ||
} | ||
} | ||
loop { | ||
This comment has been minimized.
Sorry, something went wrong.
pflenker
Author
Owner
|
||
match read() { | ||
Ok(Key(event)) => { | ||
This comment has been minimized.
Sorry, something went wrong.
pflenker
Author
Owner
|
||
println!("{:?} \r", event); | ||
This comment has been minimized.
Sorry, something went wrong.
pflenker
Author
Owner
|
||
match (event.code) { | ||
Char(c) => { | ||
if c == 'q' { | ||
break; | ||
} | ||
}, | ||
_ => (), | ||
} | ||
}, | ||
Err(err) => println!("Error: {}", err), | ||
_ => () | ||
} | ||
} | ||
disable_raw_mode().unwrap(); | ||
|
We need a bit more from Crossterm now, especially the ability to deal with "events". Crossterm exposes anything that happens to the terminal - like a keypress, but also more - to us via an Event. For now, we're only interested in Key events (as opposed to e.g. an event that is fired when someone pastes something into the terminal).