TermUI.Widgets.ContextMenu (TermUI v0.2.0)
View SourceContext menu widget for displaying floating menus at cursor position.
Context menu appears at a specific position (usually on right-click) and displays a list of actions. It automatically closes on selection, escape, or clicking outside.
Usage
ContextMenu.new(
items: [
ContextMenu.action(:cut, "Cut", shortcut: "Ctrl+X"),
ContextMenu.action(:copy, "Copy", shortcut: "Ctrl+C"),
ContextMenu.action(:paste, "Paste", shortcut: "Ctrl+V"),
ContextMenu.separator(),
ContextMenu.action(:select_all, "Select All", shortcut: "Ctrl+A")
],
position: {x, y},
on_select: fn id -> handle_action(id) end,
on_close: fn -> handle_close() end
)Features
- Floating overlay at specified position
- Keyboard navigation (Up/Down/Enter/Escape)
- Closes on selection or escape
- Closes on click outside menu bounds
- Z-order above other content
Summary
Functions
Creates an action menu item.
Gets the currently focused item ID.
Hides the context menu.
Creates new ContextMenu widget props.
Creates a separator.
Updates the position of the context menu.
Shows the context menu.
Gets whether the context menu is visible.
Functions
Creates an action menu item.
Gets the currently focused item ID.
Hides the context menu.
Creates new ContextMenu widget props.
Options
:items- List of menu items (required):position- {x, y} tuple for menu position (required):on_select- Callback when item is selected:on_close- Callback when menu is closed:item_style- Style for normal items:selected_style- Style for focused item:disabled_style- Style for disabled items
@spec separator() :: map()
Creates a separator.
@spec set_position( map(), {non_neg_integer(), non_neg_integer()} ) :: map()
Updates the position of the context menu.
Shows the context menu.
Gets whether the context menu is visible.