First commit
This commit is contained in:
commit
ad0b0c5db2
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "hecto"
|
||||
version = "0.1.0"
|
||||
authors = ["Timothy J. Warren <tim@timshomepage.net>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
termion = "1"
|
34
src/main.rs
Normal file
34
src/main.rs
Normal file
@ -0,0 +1,34 @@
|
||||
use std::io::{self, stdout, Read};
|
||||
use termion::raw::IntoRawMode;
|
||||
|
||||
fn to_ctrl_byte(c: char) -> u8 {
|
||||
let byte = c as u8;
|
||||
byte & 0b0001_1111
|
||||
}
|
||||
|
||||
fn die(e: std::io::Error) {
|
||||
panic!(e);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _stdout = stdout().into_raw_mode().unwrap();
|
||||
|
||||
for b in io::stdin().bytes() {
|
||||
match b {
|
||||
Ok(b) => {
|
||||
let b = b.unwrap();
|
||||
let c = b as char;
|
||||
if c.is_control() {
|
||||
println!("{:?} \r", b);
|
||||
} else {
|
||||
println!("{:?} ({})\r", b, c);
|
||||
}
|
||||
|
||||
if b == to_ctrl_byte('q') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Err(err) => die(err),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user