Module: RatatuiRuby::TUI::TextFactories

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

Overview

Text factory methods for Session.

Provides convenient access to Text::Span and Text::Line without fully qualifying the class names.

Instance Method Summary collapse

Instance Method Details

#lineText::Line

Creates a Text::Line (alias).

Returns:



35
36
37
# File 'lib/ratatui_ruby/tui/text_factories.rb', line 35

def line(...)
  Text::Line.new(...)
end

#spanText::Span

Creates a Text::Span (alias).

Returns:



23
24
25
# File 'lib/ratatui_ruby/tui/text_factories.rb', line 23

def span(...)
  Text::Span.new(...)
end

#text(type) ⇒ Text::Span, Text::Line

Creates a text element by type symbol.

Building text programmatically requires knowing which method to call. When the text type comes from config or user input, you need a dispatcher.

This method routes text creation through a single entry point. Pass the type as a symbol and the remaining parameters as kwargs.

Use it for dynamic text generation or config-driven rendering.

Also available as: tui.span, tui.text_span

Examples

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

tui.text(:span, content: "Hello", style: Style.with(fg: :blue))
tui.text(:line, spans: [tui.span(content: "World")])

– SPDX-SnippetEnd ++

Parameters:

  • type (Symbol)

    Text type: :span, :line

Returns:



76
77
78
79
80
81
82
83
# File 'lib/ratatui_ruby/tui/text_factories.rb', line 76

def text(type, **)
  case type
  when :span then text_span(**)
  when :line then text_line(**)
  else
    raise ArgumentError, "Unknown text type: #{type.inspect}. Valid types: :span, :line"
  end
end

#text_lineText::Line

Creates a Text::Line.

Returns:



29
30
31
# File 'lib/ratatui_ruby/tui/text_factories.rb', line 29

def text_line(...)
  Text::Line.new(...)
end

#text_spanText::Span

Creates a Text::Span.

Returns:



17
18
19
# File 'lib/ratatui_ruby/tui/text_factories.rb', line 17

def text_span(...)
  Text::Span.new(...)
end

#text_width(string) ⇒ Integer

Calculates the display width of a string.

Returns:

  • (Integer)


41
42
43
# File 'lib/ratatui_ruby/tui/text_factories.rb', line 41

def text_width(string)
  Text.width(string)
end