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
-
#line ⇒ Text::Line
Creates a Text::Line (alias).
-
#span ⇒ Text::Span
Creates a Text::Span (alias).
-
#text(type) ⇒ Text::Span, Text::Line
Creates a text element by type symbol.
-
#text_line ⇒ Text::Line
Creates a Text::Line.
-
#text_span ⇒ Text::Span
Creates a Text::Span.
-
#text_width(string) ⇒ Integer
Calculates the display width of a string.
Instance Method Details
#line ⇒ Text::Line
Creates a Text::Line (alias).
35 36 37 |
# File 'lib/ratatui_ruby/tui/text_factories.rb', line 35 def line(...) Text::Line.new(...) end |
#span ⇒ Text::Span
Creates a Text::Span (alias).
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 ++
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_line ⇒ Text::Line
Creates a Text::Line.
29 30 31 |
# File 'lib/ratatui_ruby/tui/text_factories.rb', line 29 def text_line(...) Text::Line.new(...) end |
#text_span ⇒ Text::Span
Creates a Text::Span.
17 18 19 |
# File 'lib/ratatui_ruby/tui/text_factories.rb', line 17 def text_span(...) Text::Span.new(...) end |