Module binds
Keybindings Module This module provides functionality to define, manage, and persist keybindings.
Users can set keybindings with specific modifiers, keys, actions, and options.
Functions
set (modifiers, key, action, arguments, options) | Sets a new keybinding. |
write (file) | Writes the current keybindings to a given file. |
reset () | Resets the keybindings list by clearing all defined keybindings. |
Tables
list | List of all defined keybindings. |
default_keys | Default keys used in the keybinding system. |
default_options | Default options for keybindings. |
Functions
- set (modifiers, key, action, arguments, options)
-
Sets a new keybinding.
Validates input parameters and inserts the new bind into the internal list.
Parameters:
- modifiers string The modifier keys (e.g., "Ctrl", "Alt").
- key string The key to bind (e.g., "Return", "Backspace").
- action string The action to perform when the keybinding is triggered.
- arguments string|nil Optional arguments for the action. Default is `""`.
- options table|nil Optional table containing `flags` and `description`.
Raises:
error If any input parameter is invalid or contains invalid flags.Usage:
binds.set("Ctrl", "C", "copy", nil, { flags = "c", description = "Copy selected text" })
- write (file)
-
Writes the current keybindings to a given file.
Formats each keybinding and writes it along with its description as comments.
Parameters:
- file userdata The file handle to write the keybindings to.
Usage:
local file = io.open("keybindings.lua", "w") binds.write(file) file:close()
- reset ()
-
Resets the keybindings list by clearing all defined keybindings.
Usage:
binds.reset()
Tables
- list
- List of all defined keybindings. Each keybinding is a table containing modifiers, key, action, arguments, flags, and description.
- default_keys
-
Default keys used in the keybinding system.
Fields:
- Return
- Backspace
- default_options
-
Default options for keybindings.
These defaults are used when specific options are not provided during keybinding setup.
Fields:
- flags string Flags for the bind (e.g., "MODIFIER"). Default is `""`.
- description string Description of the bind action. Default is `""`.