diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2023-12-24 22:19:11 +1300 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2023-12-24 22:19:11 +1300 |
commit | 77067f6e244a9cf4a6ef59df2e3d735b4f172c35 (patch) | |
tree | 74eb1a226da5b367f65e2f9012dc8d440e1ccce5 /src/devices/stream.rs | |
download | bedrock-pc-78f08203e7c759ced9825b1baccaca8b9c4edc05.zip |
First commitv0.1.0
Diffstat (limited to 'src/devices/stream.rs')
-rw-r--r-- | src/devices/stream.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/devices/stream.rs b/src/devices/stream.rs new file mode 100644 index 0000000..3d376b6 --- /dev/null +++ b/src/devices/stream.rs @@ -0,0 +1,46 @@ +use std::io::{Read, Write, Stdin, Stdout}; + +pub struct StreamDevice { + pub wake_flag: bool, + + pub input_control: bool, + pub output_control: bool, + pub read_queue: Vec<u8>, + + pub stdin: Stdin, + pub stdout: Stdout, +} + +impl StreamDevice { + pub fn new() -> Self { + Self { + wake_flag: false, + + input_control: true, + output_control: true, + read_queue: Vec::with_capacity(256), + + stdin: std::io::stdin(), + stdout: std::io::stdout(), + } + } + + // pub fn fetch_stdin(&mut self) { + // match self.stdin.read(&mut self.read_queue) { + // Ok() => (), + // Err() => (), + // } + // } + + pub fn read_stdin(&mut self) -> u8 { + let mut buffer = [0; 1]; + match self.stdin.read_exact(&mut buffer) { + Ok(()) => buffer[0], + Err(_) => 0, + } + } + + pub fn write_stdout(&mut self, val: u8) { + self.stdout.write_all(&[val]).unwrap(); + } +} |