pub struct Terminal<I, O> { /* private fields */ }Expand description
Implementations§
Source§impl Terminal<Stdin, Stdout>
impl Terminal<Stdin, Stdout>
Sourcepub fn stdio() -> Self
pub fn stdio() -> Self
Create a terminal over inherited standard input and output.
The returned handle uses stdin for input, stdout for output, and
Env::from_process for its environment snapshot. Use this when the
process is expected to be connected directly to the terminal.
§Returns
A Terminal<Stdin, Stdout> with no saved raw-mode state.
§Errors and panics
This constructor does not fail or intentionally panic.
§Usage note
If stdin or stdout may be redirected, prefer Terminal::open to open
the controlling terminal directly.
Source§impl Terminal<TtyInput, TtyOutput>
impl Terminal<TtyInput, TtyOutput>
Sourcepub fn open() -> Result<Self>
pub fn open() -> Result<Self>
Open the controlling terminal directly.
On Unix this opens /dev/tty for both input and output. On Windows it
opens CONIN$ for input and CONOUT$ for output. The returned
Terminal snapshots the process environment with Env::from_process.
§Returns
A Terminal<TtyInput, TtyOutput> backed by the controlling terminal.
§Errors
Returns the error from open_tty if the process has no controlling
terminal or if the platform device cannot be opened.
§Panics
This function does not intentionally panic.
Source§impl<I, O> Terminal<I, O>
impl<I, O> Terminal<I, O>
Sourcepub fn input(&self) -> Iwhere
I: Copy,
pub fn input(&self) -> Iwhere
I: Copy,
Return a copy of the input half.
This is available only when I: Copy, which is true for the standard
and controlling-terminal handle types provided by this module. Use it to
pass input to EventSource::new while
retaining the Terminal for raw-mode restoration.
§Returns
A copy of the input handle.
§Errors and panics
This method does not fail or intentionally panic.
Sourcepub fn output(&self) -> Owhere
O: Copy,
pub fn output(&self) -> Owhere
O: Copy,
Return a copy of the output half.
This is available only when O: Copy, which is true for the standard
and controlling-terminal output types provided by this module. Use it to
pass output to a renderer such as TextBuffer while
retaining the Terminal for raw-mode restoration.
§Returns
A copy of the output handle.
§Errors and panics
This method does not fail or intentionally panic.
Sourcepub fn into_halves(self) -> (I, O)
pub fn into_halves(self) -> (I, O)
Source§impl<I: AsFd, O: AsFd> Terminal<I, O>
impl<I: AsFd, O: AsFd> Terminal<I, O>
Sourcepub fn new(input: I, output: O, env: Env) -> Self
pub fn new(input: I, output: O, env: Env) -> Self
Build a terminal from input and output descriptors plus an Env.
The environment is stored exactly as provided and is not required to
describe the given descriptors. Use Terminal::stdio or
Terminal::open to snapshot the process environment automatically.
§Parameters
input— readable terminal descriptor.output— writable terminal descriptor.env— environment snapshot associated with this terminal.
§Returns
A Terminal with no saved raw-mode state.
§Errors and panics
This constructor does not fail or intentionally panic.
Sourcepub fn make_raw(&mut self) -> Result<State>
pub fn make_raw(&mut self) -> Result<State>
Put the terminal into raw mode and save the previous state.
This calls make_raw_mode with the terminal’s input and output
descriptors. The returned pre-raw State is cloned into the terminal
so restore can later apply it without an argument.
§Returns
The state that was active before raw mode was applied.
§Errors
Returns any error from reading the current state or applying the raw state.
§Panics
This method does not intentionally panic.
Sourcepub fn restore(&mut self) -> Result<()>
pub fn restore(&mut self) -> Result<()>
Restore the state cached by the most recent make_raw.
If a state is cached, it is applied with set_state and then
cleared. If no state is cached, this is a no-op.
§Returns
Ok(()) when no state was cached or restoration succeeded.
§Errors
Returns any error from applying the cached state.
§Panics
This method does not intentionally panic.
Sourcepub fn set_state(&self, state: &State) -> Result<()>
pub fn set_state(&self, state: &State) -> Result<()>
Apply a previously snapshotted terminal mode.
This does not update or clear the state cached by
make_raw. Use it for manual state management; use
restore for the terminal-owned raw-mode lifecycle.
§Parameters
state— state to apply to the terminal.
§Returns
Ok(()) when the state was applied.
§Errors
Returns any error from set_state.
§Panics
This method does not intentionally panic.
Sourcepub fn is_terminal(&self) -> (bool, bool)
pub fn is_terminal(&self) -> (bool, bool)
Sourcepub fn get_window_size(&self) -> Result<Winsize>
pub fn get_window_size(&self) -> Result<Winsize>
Query the current terminal window size.
On Unix this tries the output descriptor first and falls back to the input descriptor if the output query fails. If both fail, the output descriptor’s error is returned.
§Returns
The current window size in cells and, when reported by the platform, pixels.
§Errors
Returns an OS error if the size cannot be queried from either half.
§Panics
This method does not intentionally panic.
Trait Implementations§
Source§impl<I: AsFd, O> AsFd for Terminal<I, O>
Available on Unix only.
impl<I: AsFd, O> AsFd for Terminal<I, O>
Source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
Borrow the input descriptor.
This exposes the input half, not the output half. Use
output and borrow that handle when an output
descriptor is required.
Source§impl<I: Read, O> Read for Terminal<I, O>
impl<I: Read, O> Read for Terminal<I, O>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Source§impl<I, O: Write> Write for Terminal<I, O>
impl<I, O: Write> Write for Terminal<I, O>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)