pub struct Terminal { /* private fields */ }Expand description
Actor that manages the connection to the terminal
Implementations§
Source§impl Terminal
impl Terminal
Sourcepub fn init(
cx: &mut Cx<'_, Self>,
sizer: Sizer,
resize: Fwd<Option<TermShare>>,
input: Fwd<Key>,
) -> Option<Self>
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.
Sourcepub fn check(&mut self, _cx: &mut Cx<'_, Self>, enable: bool)
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.
Sourcepub fn bell(&mut self, cx: &mut Cx<'_, Self>)
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.
Sourcepub fn pause(&mut self, cx: &mut Cx<'_, Self>)
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.