Raxol.Core.KeyboardShortcuts (Raxol v2.0.1)
View SourceRefactored KeyboardShortcuts that delegates to GenServer implementation.
This module provides the same API as the original KeyboardShortcuts but uses a supervised GenServer instead of the Process dictionary for state management.
Migration Notice
This module is a drop-in replacement for Raxol.Core.KeyboardShortcuts.
All functions maintain backward compatibility while providing improved
fault tolerance and functional programming patterns.
Benefits over Process Dictionary
- Supervised state management with fault tolerance
- Pure functional shortcut resolution
- Priority-based conflict resolution
- Context-aware shortcut activation
- Better debugging and testing capabilities
- No global state pollution
Summary
Functions
Clean up the keyboard shortcuts manager.
Clear all shortcuts.
Clear shortcuts for a specific context.
Check if shortcuts are enabled.
Ensures the Keyboard Shortcuts server is started.
Get the currently active context.
Get all available shortcuts (global + active context).
Get all shortcuts for a specific context.
Get formatted help text for shortcuts.
Handle keyboard events.
Initialize the keyboard shortcuts manager.
Register a batch of shortcuts at once.
Register a keyboard shortcut with a callback function.
Set the active context for shortcuts.
Set conflict resolution strategy.
Enable or disable shortcut processing.
Check if a shortcut is registered.
Show help text for available shortcuts.
Unregister a keyboard shortcut.
Functions
Clean up the keyboard shortcuts manager.
This function cleans up any resources used by the keyboard shortcuts manager and unregisters event handlers.
Clear all shortcuts.
Clear shortcuts for a specific context.
Check if shortcuts are enabled.
Ensures the Keyboard Shortcuts server is started.
Get the currently active context.
Get all available shortcuts (global + active context).
Get all shortcuts for a specific context.
Returns a map of shortcut definitions for the given context.
Get formatted help text for shortcuts.
Handle keyboard events.
This function is called by the EventManager when keyboard events occur.
Initialize the keyboard shortcuts manager.
This function sets up the necessary state for managing keyboard shortcuts and registers event handlers for keyboard events.
Register a batch of shortcuts at once.
Example
register_batch([
{"Ctrl+S", :save, &save_file/0, description: "Save file"},
{"Ctrl+O", :open, &open_file/0, description: "Open file"},
{"Ctrl+Q", :quit, &quit_app/0, description: "Quit application"}
])
Register a keyboard shortcut with a callback function.
Parameters
shortcut- The keyboard shortcut string (e.g., "Ctrl+S", "Alt+F4")name- A unique identifier for the shortcut (atom or string)callback- A function to be called when the shortcut is triggeredopts- Options for the shortcut
Options
:context- The context in which this shortcut is active (default::global):description- A description of what the shortcut does:priority- Priority level (1-10, lower = higher priority):override- Whether to override existing shortcut (default: false)
Set the active context for shortcuts.
Context-specific shortcuts will only be active when their context is set.
Set conflict resolution strategy.
Strategies
:first- Keep the first registered shortcut:last- Keep the last registered shortcut:priority- Use priority to resolve conflicts
Enable or disable shortcut processing.
Check if a shortcut is registered.
Show help text for available shortcuts.
Displays formatted help text for all available shortcuts in the current context.
Unregister a keyboard shortcut.
Parameters
shortcut- The keyboard shortcut string to unregistercontext- The context from which to unregister (default::global)