class RatatuiRuby::Text::Line
A sequence of styled spans.
Words form sentences. Spans form lines.
This class composes multiple {Span} objects into a single horizontal row of text. It handles the layout of rich text fragments within the flow of a paragraph.
Use it to build multi-colored headers, status messages, or log entries.
Examples
Text::Line.new( spans: [ Text::Span.styled("User: ", Style.new(modifiers: [:bold])), Text::Span.styled("kerrick", Style.new(fg: :blue)) ] )
Attributes
Alignment within the container.
:left, :center, or :right.
Public Class Methods
Source
# File lib/ratatui_ruby/schema/text.rb, line 128 def self.from_string(content, alignment: nil) new(spans: [Span.new(content:, style: nil)], alignment:) end
Creates a simple line from a string.
Text::Line.from_string("Hello")
Source
# File lib/ratatui_ruby/schema/text.rb, line 121 def initialize(spans: [], alignment: nil, style: nil) super end
Public Instance Methods
Source
# File lib/ratatui_ruby/schema/text.rb, line 146 def width RatatuiRuby::Text.width(spans.map { |s| s.content.to_s }.join) end
Calculates the display width of this line in terminal cells.
Sums the widths of all span contents using the same unicode-aware algorithm as Text.width. Useful for layout calculations.
Examples
line = Text::Line.new(spans: [ Text::Span.new(content: "Hello "), Text::Span.new(content: "世界") ]) line.width # => 10 (6 ASCII + 4 CJK)
Returns: Integer (number of terminal cells)