pub struct AltuiInit { /* private fields */ }Expand description
Crossterm terminal initialization helper which restores the original terminal state on drop.
AltuiInit provides a minimal RAII wrapper around a Crossterm-based
Terminal. It is designed to eliminate repetitive setup and teardown
code while keeping full control over rendering and event handling.
§Responsibilities
- enable raw mode
- enter the alternate screen
- optionally enable mouse capture
- restore the terminal state on drop
§What AltuiInit does not do
- manage an event loop
- handle input
- hide the underlying
TerminalAPI
§Full control
If you need full control over terminal initialization or teardown
(for example, skipping LeaveAlternateScreen or managing cursor state
manually), you can always bypass AltuiInit and use Crossterm directly.
AltuiInit is a convenience layer, not a restriction.
Implementations§
Source§impl AltuiInit
impl AltuiInit
Sourcepub fn new(mouse: bool) -> Result<Self>
pub fn new(mouse: bool) -> Result<Self>
Creates a new AltuiInit instance and initializes the terminal.
This method:
- enables raw mode
- enters the alternate screen
- optionally enables mouse capture
- constructs a Crossterm-backed
Terminal
The original terminal state is restored automatically when the
returned AltuiInit value is dropped.
§Parameters
mouse: enables mouse capture iftrue
§Errors
Returns an error if any of the terminal initialization steps fail.
§Notes
This function assumes ownership of the terminal state. If your application
requires custom or partial terminal initialization, consider using
Crossterm directly instead of AltuiInit.
Sourcepub fn set_panic_hook(self) -> Self
pub fn set_panic_hook(self) -> Self
Installs the default panic hook used by AltuiInit.
The installed hook performs a best-effort restoration of the terminal state if a panic occurs, even if the panic originates from another thread.
This method is optional. It is provided as a convenience for applications that want a safe default panic behavior without installing a global panic hook manually.
§Notes
- The panic hook is global and affects the entire process.
- Calling this method does not suppress panics.
- Terminal cleanup via
Dropremains the primary cleanup mechanism.
§See also
- [
install_panic_hook]
Sourcepub fn terminal(&mut self) -> &mut Terminal<CrosstermBackend<Stdout>>
pub fn terminal(&mut self) -> &mut Terminal<CrosstermBackend<Stdout>>
Returns a mutable reference to the underlying Terminal.
This allows full access to the rendering API without abstraction or
restriction. AltuiInit does not attempt to hide or wrap the terminal
interface.
§Notes
The returned reference is valid for the lifetime of AltuiInit. Terminal
state will still be restored when AltuiInit is dropped.
Sourcepub fn run<F>(&mut self, f: F) -> Result<()>
pub fn run<F>(&mut self, f: F) -> Result<()>
Executes the provided closure with a mutable reference to the terminal.
This method serves as a convenience entry point that scopes terminal usage to the lifetime of the closure.
§Parameters
f: a closure that receives a mutable reference to the terminal
§Errors
Propagates any error returned by the closure.
§Notes
- This method does not implement an event loop.
- It does not catch panics; panic handling is delegated to
Dropand the optional panic hook. - Calling this method is equivalent to manually borrowing the terminal
via
AltuiInit::terminal.