Skip to main content

Event

Enum Event 

Source
pub enum Event {
Show 43 variants KeyPress(Key), KeyRelease(Key), MouseClick(Mouse), MouseRelease(Mouse), MouseWheel(Mouse), MouseMove(Mouse), Resize(Winsize), WindowCellSize(Size), WindowPixelSize(Size), CellPixelSize(Size), FocusIn, FocusOut, PasteStart, PasteEnd { complete: bool, }, PasteChunk(Vec<u8>), CursorPosition { position: Position, page: u32, }, PrimaryDeviceAttributes(Vec<Option<u32>>), SecondaryDeviceAttributes(Vec<Option<u32>>), TertiaryDeviceAttributes(String), TerminalName(String), ModeReport { mode: Mode, setting: ModeSetting, }, ModifyOtherKeys(ModifyOtherKeysMode), KittyKeyboardEnhancements(KittyKeyboardFlags), WindowOp { op: u32, args: Vec<Option<u32>>, }, Termcap { recognized: bool, entries: Vec<(String, Option<String>)>, }, SettingReport(SettingReport), ForegroundColor(Color), BackgroundColor(Color), CursorColor(Color), PaletteColor { index: u8, color: Color, }, ColorScheme(ColorScheme), Visibility(Visibility), ProgramStatus(ProgramStatusCapabilities), ClipboardStart { selection: ClipboardSelection, }, ClipboardChunk(Vec<u8>), ClipboardEnd { complete: bool, }, KittyGraphics { options: Vec<(String, String)>, payload: Vec<u8>, }, Glyph(GlyphReply), DragDrop { options: Vec<(String, String)>, payload: Vec<u8>, }, Unknown { kind: SequenceKind, bytes: Vec<u8>, }, StringStart { kind: SequenceKind, }, StringChunk(Vec<u8>), StringEnd { complete: bool, },
}
Expand description

A terminal event.

Key events compare their Key identities. Inspect Key::repeat separately when repeat status matters.

Variants§

§

KeyPress(Key)

Key was pressed or repeated. Inspect Key::repeat for repeat status.

§

KeyRelease(Key)

Key was released. Decoder-generated releases have Key::repeat set to false.

§

MouseClick(Mouse)

Mouse button was pressed.

§

MouseRelease(Mouse)

Mouse button was released.

§

MouseWheel(Mouse)

Mouse wheel scrolled.

§

MouseMove(Mouse)

Mouse moved (with or without a button held).

§

Resize(Winsize)

The terminal surface changed size. Emitted only for genuine change notifications: kernel SIGWINCH (full Winsize), ReadConsoleInput window-buffer-size events on Windows (cells only), and in-band CSI 48 t reports under mode 2048 (full Winsize). Replies to explicit size queries are delivered as WindowCellSize / WindowPixelSize / CellPixelSize instead.

§

WindowCellSize(Size)

Reply to a CSI 18 t query: window size in columns by rows.

§

WindowPixelSize(Size)

Reply to a CSI 14 t query: text-area pixel dimensions (width by height).

§

CellPixelSize(Size)

Reply to a CSI 16 t query: one cell’s pixel width by pixel height.

§

FocusIn

Focus gained.

§

FocusOut

Focus lost.

§

PasteStart

Bracketed paste started.

§

PasteEnd

Bracketed paste ended.

Idle recovery, explicit recovery, and input read failures produce an incomplete end after any retained payload bytes.

Fields

§complete: bool

Whether the terminal sent the paste terminator.

§

PasteChunk(Vec<u8>)

Streaming chunk of pasted bytes emitted between Event::PasteStart and Event::PasteEnd. Pastes that exceed the source’s read buffer are split across multiple chunks; reassembly and any text decoding are the caller’s responsibility (terminals may paste arbitrary binary content, not just valid UTF-8).

§

CursorPosition

Cursor position report (CPR or DECXCPR). Coordinates are zero-based (the 1-based wire form is normalized when parsed).

A standard report on row 1, column 1 to 16, has the same bytes as legacy modified F3 (CSI 1 ; m R). For that report, the decoder emits a KeyPress for F3 first and this event second. The code that owns the cursor request drops that key.

DECXCPR replies use CSI ? row ; column R or CSI ? row ; column ; page R. The decoder retains the page number and ignores additional parameters after it. These private replies always produce a single cursor event.

Fields

§position: Position

Zero-based cell coordinates.

§page: u32

One-based page number, or zero when absent.

§

PrimaryDeviceAttributes(Vec<Option<u32>>)

Primary device attributes (DA1) — list of decoded numeric attributes.

§

SecondaryDeviceAttributes(Vec<Option<u32>>)

Secondary device attributes (DA2).

§

TertiaryDeviceAttributes(String)

Tertiary device attributes (DA3) — terminal ID string.

§

TerminalName(String)

Terminal name reply (XTVERSION). Carries the raw identifier string, which typically combines a name and version (e.g. "XTerm(380)").

§

ModeReport

DECRPM / RM mode report.

The setting distinguishes all five DECRPM states. A terminal can report a mode as permanently set or permanently reset, meaning it recognizes the mode but will not let the host toggle it. When deciding whether a feature is usable, prefer ModeSetting::is_available over is_recognized: a permanently reset mode is recognized yet can never be enabled.

Fields

§mode: Mode

Reported mode.

§setting: ModeSetting

Current mode setting.

§

ModifyOtherKeys(ModifyOtherKeysMode)

modifyOtherKeys report.

§

KittyKeyboardEnhancements(KittyKeyboardFlags)

Kitty keyboard protocol active-enhancements report (CSI ? <flags> u). The payload is the parsed crate::ansi::kitty::KittyKeyboardFlags bitset.

§

WindowOp

XTWINOPS reply (window operation).

Fields

§op: u32

Window operation number.

§args: Vec<Option<u32>>

Window operation arguments.

§

Termcap

XTGETTCAP / termcap capability reply. recognized is true for a successful reply (DCS 1 + r) and false for a failure (DCS 0 + r); the entries are decoded the same way in both cases (a failure echoes the requested, now known-unsupported, capability names).

Fields

§recognized: bool

Whether the requested capabilities were recognized.

§entries: Vec<(String, Option<String>)>

Decoded (name, value) pairs. The value is None when the entry carried no =: either a boolean capability, reported as a bare name, or a failure reply echoing a name it does not support. recognized is what tells those apart.

Kept as pairs because only the hex wire form is delimiter-safe: decoded values commonly contain ; and = (kf13 is \E[1;2P), so a joined string could not be split back apart.

§

SettingReport(SettingReport)

DECRPSS setting report (DCS 1 $ r on success, DCS 0 $ r on failure), reporting a current setting such as the active SGR attributes or cursor style. Sent in answer to write_decrqss.

§

ForegroundColor(Color)

OSC 10 default foreground color reply.

§

BackgroundColor(Color)

OSC 11 default background color reply.

§

CursorColor(Color)

OSC 12 cursor color reply.

§

PaletteColor

OSC 4 indexed palette color reply (OSC 4 ; index ; color).

Fields

§index: u8

Palette color index.

§color: Color

Reported palette color.

§

ColorScheme(ColorScheme)

Color-scheme report (DEC mode 2031): whether the terminal is in its dark or light scheme. Indicates only the dark/light preference, not the actual colors.

§

Visibility(Visibility)

Terminal visibility report (DEC mode 2033): whether the terminal view may be observed. Arrives unsolicited while Program::enable_visibility_reports is active, and as the reply to Program::request_visibility.

This is independent of focus: focus says which view receives keyboard input, visibility says whether output can be seen.

§

ProgramStatus(ProgramStatusCapabilities)

Supported program status states and kinds (OSC 7501).

Sent in reply to Program::request_program_status. Absent lists use the protocol’s fixed defaults. Names from future revisions are preserved; unknown pairs are ignored.

§

ClipboardStart

Start of an OSC 52 clipboard reply, after its header.

Every recognized reply starts with this event, including empty replies. Zero or more chunks follow with the wire payload, normally base64.

Fields

§selection: ClipboardSelection

Clipboard selection that was reported.

§

ClipboardChunk(Vec<u8>)

Raw OSC 52 payload bytes, excluding the header and terminator.

Chunk boundaries follow input availability, not base64 groups or text boundaries. Callers can consume chunks incrementally or assemble them.

§

ClipboardEnd

End of an OSC 52 clipboard reply.

Caller timeouts and wakes preserve an active reply, subject to the source’s independent clipboard idle timeout. Idle or explicit recovery flushes retained bytes and ends the reply with complete: false. An interrupting escape sequence ends it before that sequence is decoded. An input read failure flushes retained bytes and ends it before the error. Readiness errors propagate directly and can leave a reply unfinished.

Fields

§complete: bool

Whether BEL or ST terminated the reply normally.

§

KittyGraphics

Kitty graphics response (APC G ... payload).

Fields

§options: Vec<(String, String)>

Response options.

§payload: Vec<u8>

Response payload bytes.

§

Glyph(GlyphReply)

Glyph Protocol reply (APC 25a1; payload).

See crate::ansi::glyph for the requests.

§

DragDrop

One Kitty OSC 72 drag and drop message.

Metadata and payload are wire values. Callers retain the first chunk’s metadata, decode base64 when applicable, and manage transfer lifetime. An empty final data response ends a transfer; m=0 alone ends a message.

Fields

§options: Vec<(String, String)>

Colon-separated metadata pairs, including extension and routing keys.

§payload: Vec<u8>

Unchanged payload bytes, including base64 for binary data.

§

Unknown

A sequence that the decoder frames but does not recognize.

For SequenceKind::Csi and SequenceKind::Ss3, bytes holds the parameters, intermediates, and final byte. For the string kinds, bytes holds the string body. The introducer and the terminator are not included, in either the 7-bit or the 8-bit form.

A string body of more than 4096 bytes arrives as StringStart, StringChunk, and StringEnd events instead.

SequenceKind::Raw holds the exact input bytes, including any introducer. The decoder uses it for a stray byte, and for a CSI sequence or a short control string that another Escape sequence interrupts.

Fields

§kind: SequenceKind

The sequence family.

§bytes: Vec<u8>

The sequence bytes, as described above.

§

StringStart

Start of a control string body of more than 4096 bytes that has no typed event.

StringChunk events follow with the body, then one StringEnd. A recognized reply of up to 4096 bytes keeps its own event. Drag and drop, XTGETTCAP, Kitty graphics, and Glyph Protocol replies keep their events up to the source buffer size.

Fields

§kind: SequenceKind

The string family. This is never SequenceKind::Csi, SequenceKind::Ss3, or SequenceKind::Raw.

§

StringChunk(Vec<u8>)

Raw body bytes of a streamed control string, without the introducer or the terminator.

Chunk boundaries follow input availability, not text boundaries.

§

StringEnd

End of a streamed control string.

An interrupting Escape sequence ends the string before that sequence is decoded. An input read failure flushes retained bytes and ends the string before the error.

Fields

§complete: bool

Whether ST, or BEL for OSC, terminated the string normally.

Implementations§

Source§

impl Event

Source

pub fn as_key(&self) -> Option<&Key>

Borrow the Key payload if this is any key event (Event::KeyPress or Event::KeyRelease).

Source

pub fn as_mouse(&self) -> Option<&Mouse>

Borrow the Mouse payload if this is any mouse event (Event::MouseClick, Event::MouseRelease, Event::MouseWheel, or Event::MouseMove).

Trait Implementations§

Source§

impl Clone for Event

Source§

fn clone(&self) -> Self

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 Event

Source§

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

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

impl Eq for Event

Source§

impl PartialEq for Event

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Event

Auto Trait Implementations§

§

impl Freeze for Event

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnsafeUnpin for Event

§

impl UnwindSafe for Event

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
§

impl<T> ErasedDestructor for T
where T: 'static,

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

Source§

type Output = T

Should always be Self
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.