pub unsafe trait Terminal {
// Required method
fn tty_fd(&self) -> RawFd;
// Provided methods
fn set_canon_mode(&self) -> Result<()> { ... }
fn set_raw_mode(&self) -> Result<()> { ... }
fn set_non_block(&self, non_block: bool) -> Result<()> { ... }
fn read_raw(&self, out: &mut [u8]) -> Result<usize> { ... }
}
Expand description
Required Methods§
Provided Methods§
Sourcefn set_canon_mode(&self) -> Result<()>
fn set_canon_mode(&self) -> Result<()>
Set this terminal to canonical mode (ICANON | ECHO | ISIG
).
Enable canonical mode with ISIG
that generates signal when receiving
any of the characters INTR, QUIT, SUSP, or DSUSP, and with ECHO
that echo
the input characters. Refer to
termios
.
Sourcefn set_raw_mode(&self) -> Result<()>
fn set_raw_mode(&self) -> Result<()>
Set this terminal to raw mode.
Unset the canonical mode with (!(ICANON | ECHO | ISIG)
) which means
input is available character by character, echoing is disabled and special
signal of receiving characters INTR, QUIT, SUSP, or DSUSP is disabled.
Sourcefn set_non_block(&self, non_block: bool) -> Result<()>
fn set_non_block(&self, non_block: bool) -> Result<()>
Set this terminal to non-blocking mode.
If non_block
is true
, then read_raw
will not block.
If non_block
is false
, then read_raw
may block if
there is nothing to read.
Sourcefn read_raw(&self, out: &mut [u8]) -> Result<usize>
fn read_raw(&self, out: &mut [u8]) -> Result<usize>
Read from a Terminal
.
Read up to out.len()
bytes from this terminal without any buffering.
This may block, depending on if non-blocking was enabled with set_non_block
or if there are any bytes to read.
If there is at least one byte that is readable, this will not block.
§Examples
extern crate vmm_sys_util;
use vmm_sys_util::terminal::Terminal;
let stdin_handle = io::stdin();
let stdin = stdin_handle.lock();
assert!(stdin.set_non_block(true).is_ok());
let mut out = [0u8; 0];
assert_eq!(stdin.read_raw(&mut out[..]).unwrap(), 0);