diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-06-09 06:53:24 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-06-09 06:53:24 -0400 |
commit | 5cf20a142ef667b9664dd2a2dc3bb26c7562c9a0 (patch) | |
tree | 0bfea46547add38d6daeac47d7ccf383a079443f /examples | |
parent | e842fef74b21d74bf4b731f67c05a1192092ee50 (diff) | |
download | nbsh-old-5cf20a142ef667b9664dd2a2dc3bb26c7562c9a0.tar.gz nbsh-old-5cf20a142ef667b9664dd2a2dc3bb26c7562c9a0.zip |
pass input events through to the running process
Diffstat (limited to 'examples')
-rw-r--r-- | examples/cooked.rs | 19 | ||||
-rw-r--r-- | examples/raw.rs | 20 |
2 files changed, 39 insertions, 0 deletions
diff --git a/examples/cooked.rs b/examples/cooked.rs new file mode 100644 index 0000000..cf0384c --- /dev/null +++ b/examples/cooked.rs @@ -0,0 +1,19 @@ +use std::io::Read; + +fn main() { + loop { + let stdin = std::io::stdin(); + let mut stdin = stdin.lock(); + let mut buf = [0; 1]; + let n = stdin.read(&mut buf).unwrap(); + if n > 0 { + eprint!("got {}\r\n", buf[0]); + if buf[0] == 4 { + break; + } + } else { + eprint!("got no bytes\r\n"); + break; + } + } +} diff --git a/examples/raw.rs b/examples/raw.rs new file mode 100644 index 0000000..5890a99 --- /dev/null +++ b/examples/raw.rs @@ -0,0 +1,20 @@ +use std::io::Read; + +fn main() { + let _screen = crossterm::RawScreen::into_raw_mode().unwrap(); + loop { + let stdin = std::io::stdin(); + let mut stdin = stdin.lock(); + let mut buf = [0; 1]; + let n = stdin.read(&mut buf).unwrap(); + if n > 0 { + eprint!("got {}\r\n", buf[0]); + if buf[0] == 4 { + break; + } + } else { + eprint!("got no bytes\r\n"); + break; + } + } +} |