Skip to content

Commit

Permalink
new fn repl added
Browse files Browse the repository at this point in the history
  • Loading branch information
Znackt committed Jul 7, 2024
1 parent 225626a commit 8f1e5c6
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,31 @@ use crossterm::event::{read, Event::Key, KeyCode::Char};
use crossterm::terminal::{disable_raw_mode, enable_raw_mode};
use std::io::{self, Read};

Check warning on line 3 in src/editor.rs

View workflow job for this annotation

GitHub Actions / Check

unused imports: `Read`, `self`

Check warning on line 3 in src/editor.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused imports: `Read`, `self`
pub struct Editor {}

impl Editor {
pub fn default() -> Self {
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: {b:08b} ASCII: {b:#03} \r");
} else {
println!("Binary: {b:08b} ASCII: {b:#03} Character: {c:#?}\r");
}
if c == 'q' {
break;
}
}
Err(err) => println!("Error: {err}"),
}
if let Err(err) = self.repl() {
panic!("{err:#?}");
}

loop {
match read() {
Ok(Key(event)) => {
print!("Goodbye.\r\n");
}

pub fn repl(&self) -> Result<(), std::io::Error> {
enable_raw_mode()?;
loop {
if let Key(event) = read()? {
println!("{event:?} \r");
if let Char(c) = event.code {
if c == 'q' {
if c == 'q'{
break;
}
}
}
Err(err) => println!("Error: {err}"),
_ => (),
}
}
disable_raw_mode().unwrap();
disable_raw_mode()?;
Ok(())
}
}
}

0 comments on commit 8f1e5c6

Please sign in to comment.