TermUI.Widgets.ContextMenu.Inline (TermUI v1.0.0)
View SourceInline context menu variant for keyboard-only environments.
Unlike the standard ContextMenu which appears at a mouse position, the Inline variant renders in place with numbered items for direct selection. This makes it ideal for TTY mode where mouse positioning may not be available.
Usage
ContextMenu.Inline.new(
items: [
ContextMenu.action(:copy, "Copy"),
ContextMenu.action(:paste, "Paste"),
ContextMenu.action(:delete, "Delete")
],
on_select: fn id -> handle_action(id) end,
on_close: fn -> handle_close() end
)Rendering
Items are rendered with numbered prefixes:
[1] Copy [2] Paste [3] DeleteIn vertical orientation:
[1] Copy
[2] Paste
[3] DeleteKeyboard Controls
- Number keys (1-9): Directly select the numbered item
- Up/Down (vertical) or Left/Right (horizontal): Navigate between items
- Enter/Space: Select the currently focused item
- Escape: Close the menu without selecting
Notes
- Separators and disabled items are not numbered
- Maximum of 9 items can be numbered (items 10+ require arrow navigation)
- Only selectable items (non-disabled actions) get numbers
Callback Error Handling
Callbacks (on_select, on_close) are executed synchronously. Callback
exceptions are rescued and logged by the shared behaviour.
See TermUI.Widgets.ContextMenu moduledoc for callback best practices.
Summary
Functions
Gets the currently focused item ID.
Hides the menu.
Creates new ContextMenu.Inline widget props.
Shows the menu.
Gets whether the menu is visible.
Types
Functions
Gets the currently focused item ID.
Hides the menu.
Creates new ContextMenu.Inline widget props.
Options
:items- List of menu items (required). UseContextMenu.action/3andContextMenu.separator/0to create items.:on_select- Callback when item is selected:fn id -> ... endExecuted synchronously. Should not raise exceptions.:on_close- Callback when menu is closed without selection:fn -> ... endExecuted synchronously. Should not raise exceptions.:orientation-:horizontal(side by side) or:vertical(stacked). Default::horizontal:item_style- Style for normal items:selected_style- Style for focused item:disabled_style- Style for disabled items:number_style- Style for the[n]prefix
Shows the menu.
Gets whether the menu is visible.