class RatatuiRuby::Session
Manages the terminal lifecycle and provides a concise API for the render loop.
Writing a TUI loop involves repetitive boilerplate. You constantly instantiate widgets (RatatuiRuby::Paragraph.new) and call global methods (RatatuiRuby.draw). This is verbose and hard to read.
The Session object simplifies this. It acts as a factory and a facade. It provides short helper methods for every widget and delegates core commands to the main module.
Use it within RatatuiRuby.run to build your interface cleanly.
Thread/Ractor Safety
Session is an *I/O handle*, not a data object. It has side effects (draw, poll_event) and is intentionally not Ractor-shareable. Caching it in instance variables (@tui = tui) during your application’s run loop is fine. However, do not include it in immutable TEA Models/Messages or pass it to other Ractors.
Available Methods
The session dynamically defines factory methods for all RatatuiRuby constants.
-
draw(node)-> Delegates toRatatuiRuby.draw -
poll_event-> Delegates toRatatuiRuby.poll_event
Widget Factories
The session acts as a dynamic factory. It creates a helper method for every class defined in the ‘RatatuiRuby` module.
**The Rule:** To instantiate a class like ‘RatatuiRuby::SomeWidget`, call `tui.some_widget(…)`.
**Common Examples:**
-
paragraph(...)->RatatuiRuby::Paragraph.new(...) -
block(...)->RatatuiRuby::Block.new(...) -
layout(...)->RatatuiRuby::Layout.new(...) -
list(...)->RatatuiRuby::List.new(...) -
table(...)->RatatuiRuby::Table.new(...) -
style(...)->RatatuiRuby::Style.new(...)
If a new class is added to the library, it is automatically available here.
Nested Helpers
-
text_span(...)->RatatuiRuby::Text::Span.new(...) -
text_line(...)->RatatuiRuby::Text::Line.new(...) -
text_width(string)->RatatuiRuby::Text.width(string)
Examples
Basic Usage (Recommended)
RatatuiRuby.run do |tui| loop do tui.draw \ tui.paragraph \ text: "Hello, Ratatui! Press 'q' to quit.", alignment: :center, block: tui.block( title: "My Ruby TUI App", borders: [:all], border_color: "cyan" ) event = tui.poll_event break if event == "q" || event == :ctrl_c end end
Raw API (Verbose)
RatatuiRuby.run do loop do RatatuiRuby.draw \ RatatuiRuby::Paragraph.new( text: "Hello, Ratatui! Press 'q' to quit.", alignment: :center, block: RatatuiRuby::Block.new( title: "My Ruby TUI App", borders: [:all], border_color: "cyan" ) ) event = RatatuiRuby.poll_event break if event == "q" || event == :ctrl_c end end
Mixed Usage (Flexible)
RatatuiRuby.run do |tui| loop do RatatuiRuby.draw \ tui.paragraph \ text: "Hello, Ratatui! Press 'q' to quit.", alignment: :center, block: tui.block( title: "My Ruby TUI App", borders: [:all], border_color: "cyan" ) event = RatatuiRuby.poll_event break if event == "q" || event == :ctrl_c end end
Public Instance Methods
Source
# File lib/ratatui_ruby/session/autodoc.rb, line 14
RatatuiRuby Delegates
Delegates to RatatuiRuby._paragraph_line_count.
:method: _paragraph_line_width :call-seq: _paragraph_line_width(*args, **kwargs, &block)
Delegates to RatatuiRuby._paragraph_line_width.
:method: _tabs_width :call-seq: _tabs_width(*args, **kwargs, &block)
Delegates to RatatuiRuby._tabs_width.
:method: _text_width :call-seq: _text_width(*args, **kwargs, &block)
Delegates to RatatuiRuby._text_width.
:method: clear_events :call-seq: clear_events(*args, **kwargs, &block)
Delegates to RatatuiRuby.clear_events.
:method: draw :call-seq: draw(*args, **kwargs, &block)
Delegates to RatatuiRuby.draw.
:method: experimental_warnings :call-seq: experimental_warnings(*args, **kwargs, &block)
Delegates to RatatuiRuby.experimental_warnings.
:method: experimental_warnings= :call-seq: experimental_warnings=(*args, **kwargs, &block)
Delegates to RatatuiRuby.experimental_warnings=.
:method: get_buffer_content :call-seq: get_buffer_content(*args, **kwargs, &block)
Delegates to RatatuiRuby.get_buffer_content.
:method: get_cell_at :call-seq: get_cell_at(*args, **kwargs, &block)
Delegates to RatatuiRuby.get_cell_at.
:method: get_cursor_position :call-seq: get_cursor_position(*args, **kwargs, &block)
Delegates to RatatuiRuby.get_cursor_position.
:method: init_terminal :call-seq: init_terminal(*args, **kwargs, &block)
Delegates to RatatuiRuby.init_terminal.
:method: init_test_terminal :call-seq: init_test_terminal(*args, **kwargs, &block)
Delegates to RatatuiRuby.init_test_terminal.
:method: inject_test_event :call-seq: inject_test_event(*args, **kwargs, &block)
Delegates to RatatuiRuby.inject_test_event.
:method: poll_event :call-seq: poll_event(*args, **kwargs, &block)
Delegates to RatatuiRuby.poll_event.
:method: resize_terminal :call-seq: resize_terminal(*args, **kwargs, &block)
Delegates to RatatuiRuby.resize_terminal.
:method: restore_terminal :call-seq: restore_terminal(*args, **kwargs, &block)
Delegates to RatatuiRuby.restore_terminal.
:method: run :call-seq: run(*args, **kwargs, &block)
Delegates to RatatuiRuby.run.
:method: warn_experimental_feature :call-seq: warn_experimental_feature(*args, **kwargs, &block)
Delegates to RatatuiRuby.warn_experimental_feature.
Widget Factories
:method: axis :call-seq: axis(*args, **kwargs, &block)
Factory for RatatuiRuby::Axis.new.
:method: bar_chart :call-seq: bar_chart(*args, **kwargs, &block)
Factory for RatatuiRuby::BarChart.new.
:method: bar_chart_bar :call-seq: bar_chart_bar(*args, **kwargs, &block)
Factory for RatatuiRuby::BarChart::Bar.new.
:method: bar_chart_bar_group :call-seq: bar_chart_bar_group(*args, **kwargs, &block)
Factory for RatatuiRuby::BarChart::BarGroup.new.
:method: block :call-seq: block(*args, **kwargs, &block)
Factory for RatatuiRuby::Block.new.
:method: calendar :call-seq: calendar(*args, **kwargs, &block)
Factory for RatatuiRuby::Calendar.new.
:method: canvas :call-seq: canvas(*args, **kwargs, &block)
Factory for RatatuiRuby::Canvas.new.
:method: cell :call-seq: cell(*args, **kwargs, &block)
Factory for RatatuiRuby::Cell.new.
:method: cell_char :call-seq: cell_char(*args, **kwargs, &block)
Helper for RatatuiRuby::Cell.char.
:method: cell_default :call-seq: cell_default(*args, **kwargs, &block)
Helper for RatatuiRuby::Cell.default.
:method: cell_empty :call-seq: cell_empty(*args, **kwargs, &block)
Helper for RatatuiRuby::Cell.empty.
:method: cell_symbol :call-seq: cell_symbol(*args, **kwargs, &block)
Helper for RatatuiRuby::Cell.symbol.
:method: center :call-seq: center(*args, **kwargs, &block)
Factory for RatatuiRuby::Center.new.
:method: chart :call-seq: chart(*args, **kwargs, &block)
Factory for RatatuiRuby::Chart.new.
:method: clear :call-seq: clear(*args, **kwargs, &block)
Factory for RatatuiRuby::Clear.new.
:method: constraint :call-seq: constraint(*args, **kwargs, &block)
Factory for RatatuiRuby::Constraint.new.
:method: constraint_fill :call-seq: constraint_fill(*args, **kwargs, &block)
Helper for RatatuiRuby::Constraint.fill.
:method: constraint_length :call-seq: constraint_length(*args, **kwargs, &block)
Helper for RatatuiRuby::Constraint.length.
:method: constraint_max :call-seq: constraint_max(*args, **kwargs, &block)
Helper for RatatuiRuby::Constraint.max.
:method: constraint_min :call-seq: constraint_min(*args, **kwargs, &block)
Helper for RatatuiRuby::Constraint.min.
:method: constraint_percentage :call-seq: constraint_percentage(*args, **kwargs, &block)
Helper for RatatuiRuby::Constraint.percentage.
:method: constraint_ratio :call-seq: constraint_ratio(*args, **kwargs, &block)
Helper for RatatuiRuby::Constraint.ratio.
:method: cursor :call-seq: cursor(*args, **kwargs, &block)
Factory for RatatuiRuby::Cursor.new.
:method: dataset :call-seq: dataset(*args, **kwargs, &block)
Factory for RatatuiRuby::Dataset.new.
:method: draw_cell :call-seq: draw_cell(*args, **kwargs, &block)
Helper for RatatuiRuby::Draw.cell.
:method: draw_string :call-seq: draw_string(*args, **kwargs, &block)
Helper for RatatuiRuby::Draw.string.
:method: draw_cell_cmd :call-seq: draw_cell_cmd(*args, **kwargs, &block)
Factory for RatatuiRuby::Draw::CellCmd.new.
:method: draw_string_cmd :call-seq: draw_string_cmd(*args, **kwargs, &block)
Factory for RatatuiRuby::Draw::StringCmd.new.
:method: error :call-seq: error(*args, **kwargs, &block)
Factory for RatatuiRuby::Error.new.
:method: error_safety :call-seq: error_safety(*args, **kwargs, &block)
Factory for RatatuiRuby::Error::Safety.new.
:method: error_terminal :call-seq: error_terminal(*args, **kwargs, &block)
Factory for RatatuiRuby::Error::Terminal.new.
:method: event :call-seq: event(*args, **kwargs, &block)
Factory for RatatuiRuby::Event.new.
:method: event_focus_gained :call-seq: event_focus_gained(*args, **kwargs, &block)
Factory for RatatuiRuby::Event::FocusGained.new.
:method: event_focus_lost :call-seq: event_focus_lost(*args, **kwargs, &block)
Factory for RatatuiRuby::Event::FocusLost.new.
:method: event_key :call-seq: event_key(*args, **kwargs, &block)
Factory for RatatuiRuby::Event::Key.new.
:method: event_mouse :call-seq: event_mouse(*args, **kwargs, &block)
Factory for RatatuiRuby::Event::Mouse.new.
:method: event_none :call-seq: event_none(*args, **kwargs, &block)
Factory for RatatuiRuby::Event::None.new.
:method: event_paste :call-seq: event_paste(*args, **kwargs, &block)
Factory for RatatuiRuby::Event::Paste.new.
:method: event_resize :call-seq: event_resize(*args, **kwargs, &block)
Factory for RatatuiRuby::Event::Resize.new.
:method: frame :call-seq: frame(*args, **kwargs, &block)
Factory for RatatuiRuby::Frame.new.
:method: gauge :call-seq: gauge(*args, **kwargs, &block)
Factory for RatatuiRuby::Gauge.new.
:method: layout :call-seq: layout(*args, **kwargs, &block)
Factory for RatatuiRuby::Layout.new.
:method: layout_split :call-seq: layout_split(*args, **kwargs, &block)
Helper for RatatuiRuby::Layout.split.
:method: line_chart :call-seq: line_chart(*args, **kwargs, &block)
Factory for RatatuiRuby::LineChart.new.
:method: line_gauge :call-seq: line_gauge(*args, **kwargs, &block)
Factory for RatatuiRuby::LineGauge.new.
:method: list :call-seq: list(*args, **kwargs, &block)
Factory for RatatuiRuby::List.new.
:method: list_item :call-seq: list_item(*args, **kwargs, &block)
Factory for RatatuiRuby::ListItem.new.
:method: list_state :call-seq: list_state(*args, **kwargs, &block)
Factory for RatatuiRuby::ListState.new.
:method: list_state_new :call-seq: list_state_new(*args, **kwargs, &block)
Helper for RatatuiRuby::ListState.new.
:method: overlay :call-seq: overlay(*args, **kwargs, &block)
Factory for RatatuiRuby::Overlay.new.
:method: paragraph :call-seq: paragraph(*args, **kwargs, &block)
Factory for RatatuiRuby::Paragraph.new.
:method: paragraph_new :call-seq: paragraph_new(*args, **kwargs, &block)
Helper for RatatuiRuby::Paragraph.new.
:method: ratatui_logo :call-seq: ratatui_logo(*args, **kwargs, &block)
Factory for RatatuiRuby::RatatuiLogo.new.
:method: ratatui_mascot :call-seq: ratatui_mascot(*args, **kwargs, &block)
Factory for RatatuiRuby::RatatuiMascot.new.
:method: rect :call-seq: rect(*args, **kwargs, &block)
Factory for RatatuiRuby::Rect.new.
:method: scrollbar :call-seq: scrollbar(*args, **kwargs, &block)
Factory for RatatuiRuby::Scrollbar.new.
:method: scrollbar_state :call-seq: scrollbar_state(*args, **kwargs, &block)
Factory for RatatuiRuby::ScrollbarState.new.
:method: scrollbar_state_new :call-seq: scrollbar_state_new(*args, **kwargs, &block)
Helper for RatatuiRuby::ScrollbarState.new.
:method: shape_circle :call-seq: shape_circle(*args, **kwargs, &block)
Factory for RatatuiRuby::Shape::Circle.new.
:method: shape_label :call-seq: shape_label(*args, **kwargs, &block)
Factory for RatatuiRuby::Shape::Label.new.
:method: shape_line :call-seq: shape_line(*args, **kwargs, &block)
Factory for RatatuiRuby::Shape::Line.new.
:method: shape_map :call-seq: shape_map(*args, **kwargs, &block)
Factory for RatatuiRuby::Shape::Map.new.
:method: shape_point :call-seq: shape_point(*args, **kwargs, &block)
Factory for RatatuiRuby::Shape::Point.new.
:method: shape_rectangle :call-seq: shape_rectangle(*args, **kwargs, &block)
Factory for RatatuiRuby::Shape::Rectangle.new.
:method: sparkline :call-seq: sparkline(*args, **kwargs, &block)
Factory for RatatuiRuby::Sparkline.new.
:method: style :call-seq: style(*args, **kwargs, &block)
Factory for RatatuiRuby::Style.new.
:method: style_default :call-seq: style_default(*args, **kwargs, &block)
Helper for RatatuiRuby::Style.default.
:method: table :call-seq: table(*args, **kwargs, &block)
Factory for RatatuiRuby::Table.new.
:method: table_state :call-seq: table_state(*args, **kwargs, &block)
Factory for RatatuiRuby::TableState.new.
:method: table_state_new :call-seq: table_state_new(*args, **kwargs, &block)
Helper for RatatuiRuby::TableState.new.
:method: tabs :call-seq: tabs(*args, **kwargs, &block)
Factory for RatatuiRuby::Tabs.new.
:method: text_width :call-seq: text_width(*args, **kwargs, &block)
Helper for RatatuiRuby::Text.width.
:method: text_line :call-seq: text_line(*args, **kwargs, &block)
Factory for RatatuiRuby::Text::Line.new.
:method: text_span :call-seq: text_span(*args, **kwargs, &block)
Factory for RatatuiRuby::Text::Span.new.