First commit

This commit is contained in:
Timothy Warren 2021-01-22 19:36:11 -05:00
commit ad0b0c5db2
3 changed files with 45 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

10
Cargo.toml Normal file
View 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
View 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),
}
}
}