libvt.input¶
Mode-aware input event types, Kitty keyboard flag stacks, and paste guards.
-
class libvt.input.FocusEvent¶class libvt.input.FocusEvent¶
Bases:
objectTerminal window focus-in / focus-out event (
?1004).
-
class libvt.input.KeyAction¶class libvt.input.KeyAction¶
Bases:
IntEnumKey press lifecycle event type for Kitty
CSI u.
-
class libvt.input.KeyEvent¶class libvt.input.KeyEvent¶
Bases:
objectStructured keyboard event for outbound PTY encoding.
- Raises:
ValueError– Ifshifted_keyorbase_keyexceeds one character.
References
Examples
>>> from libvt.input import KeyEvent >>> KeyEvent("a", shifted_key="A").shifted_key 'A'
-
class libvt.input.KeyMod¶class libvt.input.KeyMod¶
Bases:
IntFlagKeyboard and mouse modifier bitmask matching Kitty
CSI ubits.
-
class libvt.input.KittyKeyboardFlags¶class libvt.input.KittyKeyboardFlags¶
Bases:
IntFlagProgressive-enhancement flags for the Kitty Keyboard Protocol (
CSI u).
-
class libvt.input.KittyKeyboardStack¶class libvt.input.KittyKeyboardStack¶
Bases:
objectBounded per-screen stack of
KittyKeyboardFlags.
-
class libvt.input.MouseButton¶class libvt.input.MouseButton¶
Bases:
IntEnumMouse buttons and scroll wheel directions.
-
class libvt.input.MouseEvent¶class libvt.input.MouseEvent¶
Bases:
objectZero-based
(row, col)mouse event for outbound SGR / X10 encoding.
-
class libvt.input.MouseTracker¶class libvt.input.MouseTracker¶
Bases:
objectSession-scoped mouse drag cell filter for DEC mode
?1002.Tracks the most recently reported button-drag
(row, col)cell on an interactive session so repeatedMOVEevents within the same character cell are suppressed while keepingencode()stateless.References
Examples
>>> from libvt.input import MouseAction, MouseButton, MouseEvent, MouseTracker >>> from libvt.modes import Mode, ModeState >>> modes = ModeState() >>> modes.set_mode(Mode.MOUSE_BUTTON_EVENT, enabled=True) >>> tracker = MouseTracker() >>> tracker.filter_event( ... MouseEvent(MouseButton.LEFT, MouseAction.PRESS, 1, 2), ... modes=modes, ... ) is not None True >>> tracker.filter_event( ... MouseEvent(MouseButton.LEFT, MouseAction.MOVE, 1, 2), ... modes=modes, ... ) is None True
-
class libvt.input.PasteEvent¶class libvt.input.PasteEvent¶
Bases:
objectClipboard paste payload encoded with
?2004bracketing and safety checks.
-
libvt.input.encode_input(event, *, modes, kitty_flags=¶
KittyKeyboardFlags.NONE, modify_other_keys=0, active_is_alt=None, cell_width_px=8, cell_height_px=16)libvt.input.encode_input(event, *, modes, kitty_flags=¶KittyKeyboardFlags.NONE, modify_other_keys=0, active_is_alt=None, cell_width_px=8, cell_height_px=16) Encode event into outbound PTY bytes respecting active terminal modes.
- Parameters:
event (
InputEvent) – Keyboard, mouse, focus, or paste event to encode.modes (
ModeState) – Active ANSI and DEC private modes.kitty_flags (
KittyKeyboardFlags) – Active KittyCSI uprogressive-enhancement flags; when non-zero, takes precedence over modify_other_keys.modify_other_keys (
int) –xtermXTMODKEYSmodifyOtherKeyslevel (0,1, or2).active_is_alt (
bool|None) – Whether the alternate screen buffer is active for?1007(ALTERNATE_SCROLL). WhenNone, inferred from?47/?1047/?1049in modes.cell_width_px (
int) – Cell width in pixels used to derive default?1016horizontal pixel coordinates (falls back to?1006/ X10 when<= 0andMouseEvent.pixel_xisNone).cell_height_px (
int) – Cell height in pixels used to derive default?1016vertical pixel coordinates (falls back to?1006/ X10 when<= 0andMouseEvent.pixel_yisNone).
- Returns:
Encoded VT input sequence (
b""when suppressed by active modes).- Return type:
-
libvt.input.encode_paste(text, *, bracketed, sanitize=False, allow_unbracketed_newlines=False)¶libvt.input.encode_paste(text, *, bracketed, sanitize=False, allow_unbracketed_newlines=False)¶
Encode text for terminal paste, wrapping with
?2004when bracketed.By default, rejects
ESC,NUL,DEL, 8-bitC1controls, andC0controls other than\t(and\n/\rwhen bracketed or allow_unbracketed_newlines isTrue) withUnsafePasteError. Passsanitize=Trueto remove disallowed characters instead.
-
libvt.input.is_safe_paste(text, *, bracketed=True)¶libvt.input.is_safe_paste(text, *, bracketed=True)¶
Return
Truewhen text contains no escape or injection control bytes.
Outbound input event union accepted by
encode_input()andencode().