pub struct TerminalGuard { /* private fields */ }Expand description
An RAII guard that turns on terminal mouse capture (and optionally the
keyboard-enhancement protocol) for as long as it is alive, and guarantees
the terminal is put back the way it was — both on the normal exit path
(via Drop) and on any panic (via a wrapped panic hook).
Create it after your terminal has been put into raw mode / the alternate
screen (e.g. after ratatui::init()), and drop it before you tear that
down (e.g. before ratatui::restore()):
use tui_panel_select::TerminalGuard;
let mut terminal = ratatui::init();
let guard = TerminalGuard::install(true)?;
let enhanced = guard.keyboard_enhancement_active();
// ... run your event loop, using `enhanced` to decide whether modifier
// combinations like Ctrl+Enter are reported distinctly ...
drop(guard); // restore mouse capture / keyboard flags
ratatui::restore();Implementations§
Source§impl TerminalGuard
impl TerminalGuard
Sourcepub fn install(keyboard_enhancement: bool) -> Result<Self>
pub fn install(keyboard_enhancement: bool) -> Result<Self>
Enable mouse capture and install the panic-safe restore hook.
When keyboard_enhancement is true and the terminal advertises
support, the keyboard-enhancement (disambiguate-escape-codes) protocol
is pushed as well, so modifier combinations such as Ctrl+Enter are
reported distinctly from a plain Enter. Use
keyboard_enhancement_active to
learn whether it actually took effect.
The current panic hook is taken and wrapped: on any panic the wrapper disables mouse capture (and pops the keyboard-enhancement flags, if they were pushed) before delegating to the previous hook.
Sourcepub fn keyboard_enhancement_active(&self) -> bool
pub fn keyboard_enhancement_active(&self) -> bool
Whether the keyboard-enhancement protocol was actually enabled (it is only enabled when requested and supported by the terminal).
Trait Implementations§
Source§impl Debug for TerminalGuard
impl Debug for TerminalGuard
Source§impl Drop for TerminalGuard
impl Drop for TerminalGuard
Auto Trait Implementations§
impl Freeze for TerminalGuard
impl RefUnwindSafe for TerminalGuard
impl Send for TerminalGuard
impl Sync for TerminalGuard
impl Unpin for TerminalGuard
impl UnsafeUnpin for TerminalGuard
impl UnwindSafe for TerminalGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more