Skip to content

Commit 0004e75

Browse files
committed
docs(input): Show Kitty associated text
why: Applications must request associated text along with key events. what: - Show the flag combination and resulting press and release bytes. Fixes #130
1 parent 2fc6ca1 commit 0004e75

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎docs/topics/protocols-and-input.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,28 @@ b'\x1b[27;5;59~'
117117
b'\x1b[49:33;6u'
118118
```
119119

120+
Combine `REPORT_ALL_KEYS` with `REPORT_ASSOCIATED_TEXT` to receive an encoded
121+
key press and its generated text together. Add `REPORT_EVENT_TYPES` to
122+
receive releases. Release packets carry the key and action.
123+
[Kitty keyboard flags](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#progressive-enhancement)
124+
125+
```python
126+
>>> from libvt import Terminal
127+
>>> from libvt.input import KeyAction, KeyEvent, KittyKeyboardFlags
128+
>>> term = Terminal()
129+
>>> flags = (
130+
... KittyKeyboardFlags.REPORT_ALL_KEYS
131+
... | KittyKeyboardFlags.REPORT_ASSOCIATED_TEXT
132+
... )
133+
>>> term.feed(f"\x1b[>{int(flags)}u".encode("ascii"))
134+
>>> term.encode(KeyEvent("a", text="a"))
135+
b'\x1b[97;;97u'
136+
>>> flags |= KittyKeyboardFlags.REPORT_EVENT_TYPES
137+
>>> term.feed(f"\x1b[>{int(flags)}u".encode("ascii"))
138+
>>> term.encode(KeyEvent("a", action=KeyAction.RELEASE, text="a"))
139+
b'\x1b[97;1:3u'
140+
```
141+
120142
## Paste encoding
121143

122144
By default, {func}`~libvt.input.encode_paste` (and

0 commit comments

Comments
 (0)