pub struct Encoder<'alloc>(/* private fields */);Expand description
Key encoder that converts key events into terminal escape sequences.
Implementations§
Source§impl<'alloc> Encoder<'alloc>
impl<'alloc> Encoder<'alloc>
Sourcepub fn new_with_alloc<'ctx: 'alloc, Ctx>(
alloc: &'alloc Allocator<'ctx, Ctx>,
) -> Result<Self>
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.
Sourcepub fn encode_to_vec(
&mut self,
event: &Event<'_>,
vec: &mut Vec<u8>,
) -> Result<()>
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.
Sourcepub fn encode(&mut self, event: &Event<'_>, buf: &mut [u8]) -> Result<usize>
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.
Sourcepub fn set_options_from_terminal(
&mut self,
terminal: &Terminal<'_, '_>,
) -> &mut Self
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.
Sourcepub fn set_cursor_key_application(&mut self, value: bool) -> &mut Self
pub fn set_cursor_key_application(&mut self, value: bool) -> &mut Self
Set terminal DEC mode 1: cursor key application mode.
Sourcepub fn set_keypad_key_application(&mut self, value: bool) -> &mut Self
pub fn set_keypad_key_application(&mut self, value: bool) -> &mut Self
Set terminal DEC mode 66: keypad key application mode.
Sourcepub fn set_ignore_keypad_with_numlock(&mut self, value: bool) -> &mut Self
pub fn set_ignore_keypad_with_numlock(&mut self, value: bool) -> &mut Self
Set terminal DEC mode 1035: ignore keypad with numlock.
Sourcepub fn set_alt_esc_prefix(&mut self, value: bool) -> &mut Self
pub fn set_alt_esc_prefix(&mut self, value: bool) -> &mut Self
Set terminal DEC mode 1036: alt sends escape prefix.
Sourcepub fn set_modify_other_keys_state_2(&mut self, value: bool) -> &mut Self
pub fn set_modify_other_keys_state_2(&mut self, value: bool) -> &mut Self
Set xterm modifyOtherKeys mode 2.
Sourcepub fn set_kitty_flags(&mut self, value: KittyKeyFlags) -> &mut Self
pub fn set_kitty_flags(&mut self, value: KittyKeyFlags) -> &mut Self
Set Kitty keyboard protocol flags.
Sourcepub fn set_macos_option_as_alt(&mut self, value: OptionAsAlt) -> &mut Self
pub fn set_macos_option_as_alt(&mut self, value: OptionAsAlt) -> &mut Self
Set macOS option-as-alt setting.