Browse Source

First commit

master
Timothy Warren 8 months ago
commit
ad0b0c5db2
  1. 1
      .gitignore
  2. 10
      Cargo.toml
  3. 34
      src/main.rs

1
.gitignore

@ -0,0 +1 @@
/target

10
Cargo.toml

@ -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

@ -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…
Cancel
Save