Minga.Keymap.KeyParser (Minga v0.1.0)

Copy Markdown View Source

Parses human-readable key sequence strings into trie key tuples.

Converts strings like "SPC g s" or "C-x C-s" into the [{codepoint, modifiers}] format used by Minga.Keymap.Bindings.

Supported tokens

TokenMeaning
SPCSpace (codepoint 32)
TABTab (codepoint 9)
RETReturn/Enter (codepoint 13)
ESCEscape (codepoint 27)
DELDelete (codepoint 127)
C-xCtrl + x
M-xAlt/Meta + x
aSingle character

Examples

iex> Minga.Keymap.KeyParser.parse("SPC g s")
{:ok, [{32, 0}, {103, 0}, {115, 0}]}

iex> Minga.Keymap.KeyParser.parse("C-s")
{:ok, [{115, 2}]}

iex> Minga.Keymap.KeyParser.parse("")
{:error, "empty key sequence"}

Summary

Functions

Parses a key sequence string into a list of {codepoint, modifiers} tuples.

Like parse/1 but raises on error.

Functions

parse(str)

@spec parse(String.t()) :: {:ok, [Minga.Keymap.Bindings.key()]} | {:error, String.t()}

Parses a key sequence string into a list of {codepoint, modifiers} tuples.

Returns {:ok, keys} on success or {:error, reason} on failure.

parse!(str)

@spec parse!(String.t()) :: [Minga.Keymap.Bindings.key()]

Like parse/1 but raises on error.