module RatatuiRuby::TUI::StateFactories
State object factory methods for Session.
Provides convenient access to stateful widget state objects (ListState, TableState, ScrollbarState) without fully qualifying the class names.
Public Instance Methods
Source
# File lib/ratatui_ruby/tui/state_factories.rb, line 18 def list_state(...) ListState.new(...) end
Creates a ListState. @return [ListState]
Source
# File lib/ratatui_ruby/tui/state_factories.rb, line 30 def scrollbar_state(...) ScrollbarState.new(...) end
Creates a ScrollbarState. @return [ScrollbarState]
Source
# File lib/ratatui_ruby/tui/state_factories.rb, line 66 def state(type, arg = nil) case type when :list then list_state(arg) when :table then table_state(arg) when :scrollbar then scrollbar_state(arg || 0) else raise ArgumentError, "Unknown state type: :#{type}. Valid types: :list, :table, :scrollbar" end end
Creates a state object by type symbol.
Stateful widgets need companion state objects. When building dynamic UIs, the state type must be determined at runtime.
This dispatcher routes state creation through a single entry point. Pass the type as a symbol and the remaining parameters.
Use it for generic list/table factories or config-driven components.
Also available as: tui.list_state, tui.table_state
Examples
tui.state(:list, nil) # => ListState with no selection tui.state(:table, 0) # => TableState with row 0 selected tui.state(:scrollbar, 100) # => ScrollbarState with 100 content length
@param type [Symbol] State type: :list, :table, :scrollbar @return [ListState, TableState, ScrollbarState]
Source
# File lib/ratatui_ruby/tui/state_factories.rb, line 24 def table_state(...) TableState.new(...) end
Creates a TableState. @return [TableState]