module Tput::Keyboard

Overview

Enhanced keyboard protocol negotiation and enabling.

Tput#probe! detects which protocols the terminal supports; this module picks the best one (honoring user exclusions) and turns it on/off. Mirrors the image-backend resolve pattern: a ranked candidate list, minus user-excluded protocols, picking the first the terminal actually supports, falling back to the always-available Legacy baseline.

Parsing lives in Tput::Input#parse_key_event / Tput::KeyEvent: a terminal that doesn't support (or that the user excluded) an enhanced protocol simply never emits the richer sequences.

Direct including types

Defined in:

tput/keyboard.cr

Instance Method Summary

Instance Method Detail

def best_keyboard_protocol : KeyboardProtocol #

The keyboard protocol to use: an explicit keyboard.protocol config override if set, otherwise the first ranked candidate that is neither user-excluded nor unsupported — falling back to Legacy, which always works.


[View source]
def disable_keyboard_protocol : Nil #

Disables whatever enhanced protocol #enable_keyboard_protocol turned on, restoring the terminal's default keyboard reporting.


[View source]
def disable_kitty_keyboard : Nil #

Pops one entry off the terminal's kitty keyboard protocol stack (CSI < u), undoing one #enable_kitty_keyboard.


[View source]
def disable_modify_other_keys : Nil #

Disables xterm modifyOtherKeys (CSI > 4 n).


[View source]
def enable_keyboard_protocol(events : Bool = false) : KeyboardProtocol #

Enables the best available enhanced keyboard protocol (#best_keyboard_protocol) and returns the protocol actually enabled (Legacy means nothing extra was turned on).

Pass events true to also request modifier-aware and press/repeat/release reporting — needed to observe lone modifier keys and key releases (e.g. a "tap Alt" gesture). With events false only escape-code disambiguation is requested, which never relocates ordinary typing. Ignored by ModifyOtherKeys, which cannot report lone modifiers or releases regardless.


[View source]
def enable_kitty_keyboard(flags : KittyKeyboard = KittyKeyboard::DisambiguateEscapeCodes) : Nil #

Pushes a kitty keyboard flags set onto the terminal's protocol stack (CSI > flags u); undo with #disable_kitty_keyboard.


[View source]
def enable_modify_other_keys(level : Int32 = 2) : Nil #

Enables xterm modifyOtherKeys at level (1 or 2), via CSI > 4 ; Ps m.


[View source]
def excluded_keyboard_protocols : Array(KeyboardProtocol) #

Protocols the user has excluded via the keyboard.exclude config option (comma/space-separated names, e.g. "kitty modify_other_keys"). Unknown names are ignored. Mirrors crysterm's media.exclude.


[View source]
def keyboard_candidates : Array(KeyboardProtocol) #

Ranked candidate protocols, best → worst, always ending in Legacy.


[View source]
def keyboard_protocol_supported?(protocol : KeyboardProtocol) : Bool #

Whether protocol is usable on this terminal. Legacy always is; the enhanced ones require the corresponding Tput#probe! reply.


[View source]