libvt.input

Mode-aware input event types, Kitty keyboard flag stacks, and paste guards.

class libvt.input.FocusEvent
class libvt.input.FocusEvent

Bases: object

Terminal window focus-in / focus-out event (?1004).

class libvt.input.KeyAction
class libvt.input.KeyAction

Bases: IntEnum

Key press lifecycle event type for Kitty CSI u.

class libvt.input.KeyEvent
class libvt.input.KeyEvent

Bases: object

Structured keyboard event for outbound PTY encoding.

Raises:

ValueError – If shifted_key or base_key exceeds 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: IntFlag

Keyboard and mouse modifier bitmask matching Kitty CSI u bits.

class libvt.input.KittyKeyboardFlags
class libvt.input.KittyKeyboardFlags

Bases: IntFlag

Progressive-enhancement flags for the Kitty Keyboard Protocol (CSI u).

class libvt.input.KittyKeyboardStack
class libvt.input.KittyKeyboardStack

Bases: object

Bounded per-screen stack of KittyKeyboardFlags.

class libvt.input.MouseAction
class libvt.input.MouseAction

Bases: StrEnum

Mouse pointer action.

class libvt.input.MouseButton
class libvt.input.MouseButton

Bases: IntEnum

Mouse buttons and scroll wheel directions.

class libvt.input.MouseEvent
class libvt.input.MouseEvent

Bases: object

Zero-based (row, col) mouse event for outbound SGR / X10 encoding.

class libvt.input.MouseTracker
class libvt.input.MouseTracker

Bases: object

Session-scoped mouse drag cell filter for DEC mode ?1002.

Tracks the most recently reported button-drag (row, col) cell on an interactive session so repeated MOVE events within the same character cell are suppressed while keeping encode() 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: object

Clipboard paste payload encoded with ?2004 bracketing 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)
function[source]
function[source]
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 Kitty CSI u progressive-enhancement flags; when non-zero, takes precedence over modify_other_keys.

  • modify_other_keys (int) – xterm XTMODKEYS modifyOtherKeys level (0, 1, or 2).

  • active_is_alt (bool | None) – Whether the alternate screen buffer is active for ?1007 (ALTERNATE_SCROLL). When None, inferred from ?47 / ?1047 / ?1049 in modes.

  • cell_width_px (int) – Cell width in pixels used to derive default ?1016 horizontal pixel coordinates (falls back to ?1006 / X10 when <= 0 and MouseEvent.pixel_x is None).

  • cell_height_px (int) – Cell height in pixels used to derive default ?1016 vertical pixel coordinates (falls back to ?1006 / X10 when <= 0 and MouseEvent.pixel_y is None).

Returns:

Encoded VT input sequence (b"" when suppressed by active modes).

Return type:

bytes

libvt.input.encode_paste(text, *, bracketed, sanitize=False, allow_unbracketed_newlines=False)
function[source]
function[source]
libvt.input.encode_paste(text, *, bracketed, sanitize=False, allow_unbracketed_newlines=False)

Encode text for terminal paste, wrapping with ?2004 when bracketed.

By default, rejects ESC, NUL, DEL, 8-bit C1 controls, and C0 controls other than \t (and \n / \r when bracketed or allow_unbracketed_newlines is True) with UnsafePasteError. Pass sanitize=True to remove disallowed characters instead.

Parameters:
  • text (str)

  • bracketed (bool)

  • sanitize (bool)

  • allow_unbracketed_newlines (bool)

Return type:

bytes

libvt.input.is_safe_paste(text, *, bracketed=True)
function[source]
function[source]
libvt.input.is_safe_paste(text, *, bracketed=True)

Return True when text contains no escape or injection control bytes.

Parameters:
Return type:

bool

type libvt.input.InputEvent = KeyEvent | MouseEvent | FocusEvent | PasteEvent
type
type
type libvt.input.InputEvent = KeyEvent | MouseEvent | FocusEvent | PasteEvent

Outbound input event union accepted by encode_input() and encode().