Module: RatatuiRuby::TUI::StateFactories

Included in:
RatatuiRuby::TUI
Defined in:
lib/ratatui_ruby/tui/state_factories.rb

Overview

State object factory methods for Session.

Provides convenient access to stateful widget state objects (ListState, TableState, ScrollbarState) without fully qualifying the class names.

Instance Method Summary collapse

Instance Method Details

#list_stateListState

Creates a ListState.

Returns:



18
19
20
# File 'lib/ratatui_ruby/tui/state_factories.rb', line 18

def list_state(...)
  ListState.new(...)
end

#scrollbar_stateScrollbarState

Creates a ScrollbarState.

Returns:



30
31
32
# File 'lib/ratatui_ruby/tui/state_factories.rb', line 30

def scrollbar_state(...)
  ScrollbarState.new(...)
end

#state(type, arg = nil) ⇒ ListState, ...

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

– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++

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

– SPDX-SnippetEnd ++

Parameters:

  • type (Symbol)

    State type: :list, :table, :scrollbar

Returns:



66
67
68
69
70
71
72
73
74
# 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

#table_stateTableState

Creates a TableState.

Returns:



24
25
26
# File 'lib/ratatui_ruby/tui/state_factories.rb', line 24

def table_state(...)
  TableState.new(...)
end