Skip to main content

CrosstermOptions

Struct CrosstermOptions 

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

Options controlling which optional terminal protocol features Crossterm::with_options enables.

All features default to true; mouse capture, the kitty keyboard protocol, entering the alternate screen, and raw mode all match the unconditional behavior of Crossterm::new prior to this type’s introduction. Use CrosstermOptions::mouse_capture, CrosstermOptions::kitty_protocol, CrosstermOptions::focus_change, CrosstermOptions::bracketed_paste, CrosstermOptions::alt_screen, or CrosstermOptions::raw_mode to disable a feature entirely, e.g. when running on a terminal (or through a pipe/CI harness/tmux/SSH session) where the feature is unwanted.

This is also the type returned by Crossterm::builder, the preferred entry point for constructing one of these: Crossterm::builder() reads better at a call site than CrosstermOptions::new() but the two are otherwise identical (builder() just calls Self::new()).

This crate does not attempt to auto-detect terminal capabilities (no TERM parsing, no supports_keyboard_enhancement() query): those queries can block for seconds on terminals that never respond. CrosstermOptions is the opt-out mechanism instead: callers who know their environment don’t support a feature can disable it explicitly.

use retroglyph_crossterm::Crossterm;

let options = Crossterm::builder().mouse_capture(false).kitty_protocol(false);

Implementations§

Source§

impl CrosstermOptions

Source

pub fn new() -> Self

Creates a new set of options with every feature enabled.

Source

pub const fn mouse_capture(self, enabled: bool) -> Self

Sets whether to enable mouse capture (crossterm::event::EnableMouseCapture).

Source

pub const fn kitty_protocol(self, enabled: bool) -> Self

Sets whether to push the kitty keyboard protocol’s enhancement flags (crossterm::event::PushKeyboardEnhancementFlags).

Source

pub const fn focus_change(self, enabled: bool) -> Self

Sets whether to report focus gained/lost as [Event::FocusGained]/[Event::FocusLost] (crossterm::event::EnableFocusChange).

See the crate-level “Focus and lifecycle events” docs for the pause/resume contract this implies (e.g. on Wayland, where a terminal can lose and regain focus independent of any resize).

Source

pub const fn bracketed_paste(self, enabled: bool) -> Self

Sets whether to report bracketed paste as [Event::Paste] (crossterm::event::EnableBracketedPaste).

Source

pub const fn alt_screen(self, enabled: bool) -> Self

Sets whether to enter the alternate screen (crossterm::terminal::EnterAlternateScreen).

Disabling this keeps rendering on the caller’s normal scrollback buffer instead of switching to a dedicated full-screen surface; on exit, Crossterm only leaves the alternate screen (LeaveAlternateScreen) if it entered it, so disabling this doesn’t risk leaving the caller’s real terminal buffer in an unexpected state.

Source

pub const fn raw_mode(self, enabled: bool) -> Self

Sets whether to enable raw mode (crossterm::terminal::enable_raw_mode).

Disabling this leaves the terminal in cooked mode, so the OS/shell keep handling line buffering, echo, and signal-generating keys (Ctrl-C, Ctrl-Z) itself instead of forwarding every keystroke as an [Event::Key]. Restore only disables raw mode if this backend is the one that enabled it.

Source

pub const fn color_support(self, color_support: ColorSupport) -> Self

Overrides the ColorSupport level, skipping this crate’s own $NO_COLOR/$TERM auto-detection (see Crossterm::color_support for the auto-detected default and how it’s chosen). Use this when a caller knows the receiving terminal’s actual color depth (or wants to force it) rather than trusting the environment.

Source

pub fn build(self) -> Result<Crossterm, Error>

Builds the Crossterm backend with these options, rendering to standard output.

Equivalent to Crossterm::with_options; this is the terminal step of the Crossterm::builder().<options>().build() chain started by Crossterm::builder. Use build_with_writer to render to a different sink (a file, a pipe, an in-memory buffer for tests) instead of stdout.

§Errors

Returns an std::io::Error if raw mode or terminal commands fail. Also returns an std::io::Error with std::io::ErrorKind::ResourceBusy if another Crossterm instance is already live in this process: see the concurrency contract documented on Crossterm.

Source

pub fn build_with_writer<W: Write>( self, writer: W, ) -> Result<Crossterm<W>, Error>

Builds the Crossterm backend with these options, rendering to writer instead of stdout.

writer only receives the rendered cell content ([Output::draw]/[Output::flush] output, plus the runtime [Output::clear]/[Cursor::set_cursor_visible]/ [Cursor::set_cursor_position] escapes). Terminal-protocol setup/teardown (raw mode, the alternate screen, the initial cursor hide, mouse capture, focus-change reporting, bracketed paste, and the kitty keyboard protocol) always targets the real process stdout regardless of writer, since those are properties of the actual controlling terminal, not of an arbitrary byte sink. Callers rendering to a non-terminal writer (a file, a pipe, an in-memory buffer) should disable the features they don’t want touching the real terminal via CrosstermOptions::raw_mode, CrosstermOptions::alt_screen, CrosstermOptions::mouse_capture, etc.

§Errors

Returns an std::io::Error if raw mode or terminal commands fail. Also returns an std::io::Error with std::io::ErrorKind::ResourceBusy if another Crossterm instance is already live in this process: see the concurrency contract documented on Crossterm.

Trait Implementations§

Source§

impl Clone for CrosstermOptions

Source§

fn clone(&self) -> CrosstermOptions

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CrosstermOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CrosstermOptions

Source§

fn default() -> Self

Every feature enabled; matches Crossterm::new’s historical behavior. color_support defaults to None (auto-detect from the environment at build time; see CrosstermOptions::color_support).

Source§

impl PartialEq for CrosstermOptions

Source§

fn eq(&self, other: &CrosstermOptions) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for CrosstermOptions

Source§

impl Eq for CrosstermOptions

Source§

impl StructuralPartialEq for CrosstermOptions

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<C> WithAlpha for C
where C: Copy,

§

fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>

Wraps self with alpha, storing alpha before the color in memory (see [AlphaFirst]).
§

fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>

Wraps self with alpha, storing alpha after the color in memory (see [AlphaLast]).
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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