class RatatuiRuby::List
Displays a selectable list of items.
Users need to choose from options. Menus, file explorers, and selectors are everywhere. Implementing navigation, highlighting, and scrolling state from scratch is tedious.
This widget manages the list. It renders the items. It highlights the selection. It handles the scrolling window.
Use it to build main menus, navigation sidebars, or logs.
Examples
# Basic List List.new(items: ["Item 1", "Item 2"]) # Navigation Menu List.new( items: ["New Game", "Load Game", "Options", "Quit"], selected_index: 0, highlight_style: Style.new(bg: :blue), highlight_symbol: ">> " )
Attributes
Optional wrapping block.
Render direction.
:top_to_bottom or :bottom_to_top.
When to show the highlight symbol column.
:always, :when_selected, or :never.
Style for the selected item.
Symbol drawn before the selected item.
The items to display (Array of Strings).
Whether to repeat the highlight symbol for each line of the selected item.
Number of items to keep visible above/below the selected item when scrolling (Integer or nil).
Index of the active selection (Integer or nil).
Base style for unselected items.
Public Class Methods
Source
# File lib/ratatui_ruby/schema/list.rb, line 87 def initialize(items: [], selected_index: nil, style: nil, highlight_style: nil, highlight_symbol: "> ", repeat_highlight_symbol: false, highlight_spacing: :when_selected, direction: :top_to_bottom, scroll_padding: nil, block: nil) super( items: items, selected_index: selected_index.nil? ? nil : Integer(selected_index), style: style, highlight_style: highlight_style, highlight_symbol: highlight_symbol, repeat_highlight_symbol: repeat_highlight_symbol, highlight_spacing: highlight_spacing, direction: direction, scroll_padding: scroll_padding.nil? ? nil : Integer(scroll_padding), block: block ) end
Creates a new List.
Integer parameters accept any object responding to to_int or to_i (duck-typed).
- items
-
Array of Strings.
selected_index-
Numeric (nullable, coerced to Integer).
- style
-
Styleobject. highlight_style-
Styleobject. highlight_symbol-
String (default:
"> "). repeat_highlight_symbol-
Boolean (default:
false). highlight_spacing-
Symbol (default:
:when_selected). - direction
-
Symbol (default:
:top_to_bottom). scroll_padding-
Numeric (nullable, coerced to Integer, default:
nil). - block
-
Block(optional).