vmm_sys_util::terminal

Trait Terminal

Source
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

Trait for file descriptors that are TTYs, according to isatty.

§Safety

This is marked unsafe because the implementation must ensure that the returned RawFd is a valid fd and that the lifetime of the returned fd is at least that of the trait object.

Required Methods§

Source

fn tty_fd(&self) -> RawFd

Get the file descriptor of the TTY.

Provided Methods§

Source

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.

Source

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.

Source

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.

Source

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);

Implementations on Foreign Types§

Source§

impl<'a> Terminal for StdinLock<'a>

Source§

fn tty_fd(&self) -> RawFd

Implementors§