Skip to main content

Terminal

Struct Terminal 

Source
pub struct Terminal { /* private fields */ }
Expand description

Actor that manages the connection to the terminal

Implementations§

Source§

impl Terminal

Source

pub fn init( cx: &mut Cx<'_, Self>, sizer: Sizer, resize: Fwd<Option<TermShare>>, input: Fwd<Key>, ) -> Option<Self>

Set up the terminal. Sends a message back to resize immediately, which provides a TermShare which is used to access various means of outputting data to the terminal.

Whenever the window size changes, a new resize message is sent. When the terminal output is paused, None is sent to resize to let the app know that there is no output available right now.

Input keys received are sent to input once decoded.

In case of an error that can’t be handled, cleans up the terminal state and terminates the actor with ActorDied::Failed. The actor that created the terminal can catch that and do whatever cleanup is necessary before aborting the process.

sizer is the Sizer that will be used for measuring glyphs. It is passed through to TermShare, and can be retrieved from there using Output::sizer.

§Panic handling

When Rust panics, the terminal must be restored to its normal state otherwise things would be left in a bad state for the user (in cooked mode with no echo, requiring the user to blindly type reset on the command-line). So this code saves a copy of the current panic handler (using std::panic::take_hook), and then installs its own handler that does terminal cleanup before calling on to the saved panic handler. This mean that if any custom panic handler is needed by the application, then it must be set up before the call to Terminal::init.

Source

pub fn check(&mut self, _cx: &mut Cx<'_, Self>, enable: bool)

Enable or disable generation of the Key::Check keypress, which occurs in a gap in typing, 300ms after the last key pressed. This may be used to do validation if that’s too expensive to do on every keypress.

Source

pub fn bell(&mut self, cx: &mut Cx<'_, Self>)

Ring the bell (i.e. beep) immediately. Doesn’t wait for the buffered terminal data to be flushed. Will output even when paused.

Source

pub fn pause(&mut self, cx: &mut Cx<'_, Self>)

Pause terminal input and output handling. Sends the cleanup sequence to the terminal, and switches to cooked mode. Sends a resize message with None to tell the app that output is disabled.

This call should be used before forking off a process which might prompt the user and receive user input, otherwise this process would compete with the sub-process for user input. Resume after the subprocess has finished with the resume call.

Source

pub fn resume(&mut self, cx: &mut Cx<'_, Self>)

Resume terminal output and input handling. Switches to raw mode and sends a resize message to trigger a full redraw.

Trait Implementations§

Source§

impl Drop for Terminal

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.