Skip to main content

Encoder

Struct Encoder 

Source
pub struct Encoder<'alloc>(/* private fields */);
Expand description

Key encoder that converts key events into terminal escape sequences.

Implementations§

Source§

impl<'alloc> Encoder<'alloc>

Source

pub fn new() -> Result<Self>

Create a new key encoder instance.

Source

pub fn new_with_alloc<'ctx: 'alloc, Ctx>( alloc: &'alloc Allocator<'ctx, Ctx>, ) -> Result<Self>

Create a new key encoder instance with a custom allocator.

See the crate-level documentation regarding custom memory management and lifetimes.

Source

pub fn encode_to_vec( &mut self, event: &Event<'_>, vec: &mut Vec<u8>, ) -> Result<()>

Encode a key event into a terminal escape sequence.

Converts a key event into the appropriate terminal escape sequence based on the encoder’s current options.

Not all key events produce output. For example, unmodified modifier keys typically don’t generate escape sequences. Check the returned Vec to determine if any data was written.

Source

pub fn encode(&mut self, event: &Event<'_>, buf: &mut [u8]) -> Result<usize>

Encode a key event into a terminal escape sequence.

Converts a key event into the appropriate terminal escape sequence based on the encoder’s current options. The sequence is written to the provided buffer.

Not all key events produce output. For example, unmodified modifier keys typically don’t generate escape sequences. Check the returned usize to determine if any data was written.

If the output buffer is too small, this returns Err(Error::OutOfSpace { required }) where required is the required buffer size. The caller can then allocate a larger buffer and call the method again.

Source

pub fn set_options_from_terminal( &mut self, terminal: &Terminal<'_, '_>, ) -> &mut Self

Set encoder options from a terminal’s current state.

Reads the terminal’s current modes and flags and applies them to the encoder’s options. This sets cursor key application mode, keypad mode, alt escape prefix, modifyOtherKeys state, and Kitty keyboard protocol flags from the terminal state.

Note that the macos_option_as_alt option cannot be determined from terminal state and is reset to OptionAsAlt::False by this call. Use Encoder::set_macos_option_as_alt to set it afterward if needed.

Source

pub fn set_cursor_key_application(&mut self, value: bool) -> &mut Self

Set terminal DEC mode 1: cursor key application mode.

Source

pub fn set_keypad_key_application(&mut self, value: bool) -> &mut Self

Set terminal DEC mode 66: keypad key application mode.

Source

pub fn set_ignore_keypad_with_numlock(&mut self, value: bool) -> &mut Self

Set terminal DEC mode 1035: ignore keypad with numlock.

Source

pub fn set_alt_esc_prefix(&mut self, value: bool) -> &mut Self

Set terminal DEC mode 1036: alt sends escape prefix.

Source

pub fn set_modify_other_keys_state_2(&mut self, value: bool) -> &mut Self

Set xterm modifyOtherKeys mode 2.

Source

pub fn set_kitty_flags(&mut self, value: KittyKeyFlags) -> &mut Self

Set Kitty keyboard protocol flags.

Source

pub fn set_macos_option_as_alt(&mut self, value: OptionAsAlt) -> &mut Self

Set macOS option-as-alt setting.

Trait Implementations§

Source§

impl<'alloc> Debug for Encoder<'alloc>

Source§

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

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

impl Drop for Encoder<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'alloc> Freeze for Encoder<'alloc>

§

impl<'alloc> RefUnwindSafe for Encoder<'alloc>

§

impl<'alloc> !Send for Encoder<'alloc>

§

impl<'alloc> !Sync for Encoder<'alloc>

§

impl<'alloc> Unpin for Encoder<'alloc>

§

impl<'alloc> UnsafeUnpin for Encoder<'alloc>

§

impl<'alloc> UnwindSafe for Encoder<'alloc>

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, 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.