TERMKEY_INTERPRET_CSI(3)
π TERMKEY_INTERPRET_CSI(3) π
okay bestie, gather round, because this one is from the Library Functions Manual and it's lowkey one of the most useful little gremlins in the whole termkey family. it's termkey_interpret_csi, and it's here to decode the weirdo escape sequences that termkey was like "idk what this is" about. π¦
β¨ NAME β¨
termkey_interpret_csi β interpret unrecognised CSI sequence
πΈ SYNOPSIS πΈ
#include <termkey.h>
TermKeyResult termkey_interpret_csi(TermKey *tk, const TermKeyKey *key,
long *args[], size_t *nargs, unsigned long *cmd);
Link with -ltermkey.
π DESCRIPTION π
so here's the tea, bestie. termkey_interpret_csi() fills in the variables behind the pointers you passed, based on the unrecognised CSI sequence event chillin' inside key. π«Ά
you should call it when termkey_getkey(3) or one of its little friends hands you back a key event whose type is TERMKEY_TYPE_UNKNOWN_CSI.
β οΈ okay this part is IMPORTANT, like, do-not-skip-it important: you gotta call this function as soon as possible after you get aTERMKEY_TYPE_CSIkey event. specifically, before you calltermkey_getkey()ortermkey_waitkey()again, because the next call will straight-up overwrite the buffer space that's currently holding this sequence. π and then your sequence is gone. poof. not iconic.
now, the deets:
- the
argsarray gets filled with the numerical arguments of the CSI sequence π - the number of elements available in that array should be given as the initial value of the thing pointed to by
nargsβ and when the function returns, that value gets adjusted to tell you how many arguments were actually found. so it's like a lil in-and-out situation. cute. - the
cmdvariable will contain the CSI command value π
and here's the fun bit, the byte math:
- if a leading byte was found (like
'?') then it gets bitwise-ored with the command value, shifted up by 8 bits β¨ - if an intermediate byte was found (like
'$') then it gets bitwise-ored with the command value, shifted up by 16 bits β¨
which, in code, is exactly this, no cap:
*cmd = command | (initial << 8) | (intermediate << 16);
π RETURN VALUE π
if you passed it a key event of the type TERMKEY_TYPE_UNKNOWN_CSI, this function returns TERMKEY_RES_KEY, and it'll mess with the variables whose pointers you handed over, exactly like we described above. slay. π
for other event types? it returns TERMKEY_RES_NONE, and its effects on any of those pointer-variables are undefined. π which is a fancy way of saying: don't do that, bestie, we can't help you there.
π SEE ALSO π
and that's the whole page, mwah π β brought to you by the Library Functions Manual, starring TERMKEY_INTERPRET_CSI(3) herself. no date on this one, she's simply timeless. π
π¦ where this page comes from
- alpine 3.24: libtermkey-doc 0.22-r4 Β· MIT
- debian trixie: libtermkey-dev 0.22-2+b1 Β· MIT
- epel 10: libtermkey-devel 0.22-2.el10_0 Β· MIT
- epel 9: libtermkey-devel 0.22-2.el9 Β· MIT
- fedora 43: libtermkey-devel 0.22-11.fc43 Β· MIT
- fedora 43: libtermkey-devel 0.22-11.fc43 Β· MIT
- fedora 44: libtermkey-devel 0.22-12.fc44 Β· MIT
- fedora 44: libtermkey-devel 0.22-12.fc44 Β· MIT
- nixos 26.05: libtermkey 0.22
- nixpkgs unstable: libtermkey 0.22
- opensuse-leap 16.0: libtermkey-devel 0.22-bp160.1.11 Β· MIT
- opensuse-leap 16.0: libtermkey-devel 0.22-bp160.1.11 Β· MIT
- opensuse-leap 16.0: libtermkey-devel 0.22-bp160.1.11 Β· MIT
- opensuse-leap 16.0: libtermkey-devel 0.22-bp160.1.11 Β· MIT
- ubuntu questing: libtermkey-dev 0.22-2
- ubuntu resolute: libtermkey-dev 0.22-2build1 Β· MIT
- ubuntu stonking: libtermkey-dev 0.22-3 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms