Skip to main content

AltuiInit

Struct AltuiInit 

Source
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 Terminal API

§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

Source

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 if true
§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.

Source

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 Drop remains the primary cleanup mechanism.
§See also
  • [install_panic_hook]
Source

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.

Source

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 Drop and the optional panic hook.
  • Calling this method is equivalent to manually borrowing the terminal via AltuiInit::terminal.

Trait Implementations§

Source§

impl Drop for AltuiInit

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more