TERMKEY_STRPKEY(3)

πŸ’– TERMKEY_STRPKEY(3) πŸ’–

okay bestie, welcome to the Library Functions Manual page for termkey_strpkey β€” literally the glow-up your string-parsing era needed ✨


🌸 NAME 🌸

termkey_strpkey β€” parse a string representing a key event πŸŽ€


✨ SYNOPSIS ✨

#include <termkey.h>

char *termkey_strpkey(TermKey *tk, const char *str,
            TermKeyKey *key, TermKeyFormat format);

Link with -ltermkey. 🫢


πŸ’… DESCRIPTION πŸ’…

termkey_strpkey(3) takes a string buffer holding a human-readable representation of a key event and parses it. Then it fills the key structure from the results of that parsing β€” it's giving the same energy as the strptime(3) standard library function, no cap. πŸ‘‘

The format argument says what format the string is expected to be in, and it's a bitmask of these constants, bestie:

  • TERMKEY_FORMAT_LONGMOD β€” expect full modifier names, like "Shift-", instead of the abbreviation "S-".
  • TERMKEY_FORMAT_CARETCTRL β€” if the only modifier is TERMKEY_MOD_CTRL on a plain letter, accept it as "^X" instead of "Ctrl-X". iconic.
  • TERMKEY_FORMAT_ALTISMETA β€” expect the name "Meta" or the letter "M" instead of "Alt" or "A".
  • TERMKEY_FORMAT_SPACEMOD β€” expect spaces instead of hyphens to separate the modifier name(s) from the base key name.
  • TERMKEY_FORMAT_LOWERMOD β€” expect lowercase for the modifier name.
  • TERMKEY_FORMAT_LOWERSPACE β€” expect lowercase with spaces in for the key name instead of camelCase (so for example "page down" instead of "PageDown").
  • TERMKEY_FORMAT_MOUSE_POS β€” expect a mouse event to be followed by its position rendered as "@ (col,line)". 🐭

Before it returns, this function canonicalises the key structure according to the rules given for termkey_canonicalise(3). main character behaviour fr fr.

Heads up bestie πŸ’€ the TERMKEY_FORMAT_WRAPBRACKET option is currently not supported by termkey_strpkey(). And when it returns a TERMKEY_TYPE_UNICODE key structure, this function will fill in the utf8 member. 🌈

⭐ RETURN VALUE ⭐

After a successful parse, termkey_strpkey() returns a pointer to the first character of the input it did not consume. 🫰

  • If the input string has more characters, that pointer points at the first character beyond.
  • If the entire input string was consumed, it points at a null byte.
  • If termkey_strpkey() fails to parse, it returns NULL.
careful babe!! after a failed parse, the key structure may contain partial or invalid results. The structure will only be valid if the function returns a non-NULL result. don't be trusting it otherwise 😭

πŸ‘€ SEE ALSO πŸ‘€

termkey_new(3), termkey_strfkey(3), termkey_keycmp(3), termkey(7)


and that's the whole vibe πŸ’– this was TERMKEY_STRPKEY(3) from the Library Functions Manual, and yes she really does sign off with her own name twice like the icon she is πŸŽ€πŸ’… slay, go parse something bestie βœ¨πŸ¦‹