class RatatuiRuby::Widgets::Paragraph
Displays a block of text.
Raw strings are insufficient for UIs. They overflow constraints. They don’t respect alignment (left, center, right).
This widget creates a smart text container. It wraps content to fit the area. It aligns text as requested. It supports scrolling.
Use it for everything from simple labels to complex, multi-paragraph documents.
See also: examples/widget_scroll_text/app.rb for scrollable paragraphs.
Examples
# Basic Text Paragraph.new(text: "Hello, World!") # Styled container with wrapping Paragraph.new( text: "This is a long line that will wrap automatically.", style: Style.new(fg: :green), wrap: true, block: Block.new(title: "Output", borders: [:all]) ) # Scrolling mechanism Paragraph.new(text: large_text, scroll: [scroll_y, 0])
Attributes
Text alignment.
:left, :center, or :right.
Optional wrapping block.
Scroll offset [y, x].
Base style for the text.
The content to display.
Whether to wrap text at the edge of the container (Boolean).
Public Class Methods
Source
# File lib/ratatui_ruby/widgets/paragraph.rb, line 80 def initialize(text:, style: RatatuiRuby::Style::Style.default, block: nil, wrap: false, alignment: :left, scroll: [0, 0]) super( text:, style:, block:, wrap:, alignment:, scroll: [Integer(scroll[0]), Integer(scroll[1])] ) end
Creates a new Paragraph.
- text
-
String or
Text::Linearray. - style
-
Styleobject. - block
-
Blockobject. - wrap
-
Boolean (default: false).
- alignment
-
Symbol (default:
:left). - scroll
-
Array of [y, x] integers (duck-typed via
to_int).
Source
# File lib/ratatui_ruby/widgets/paragraph.rb, line 92 def self.new(text:, style: nil, fg: nil, bg: nil, block: nil, wrap: false, alignment: :left, scroll: [0, 0]) style ||= RatatuiRuby::Style::Style.new(fg:, bg:) coerced_scroll = [Integer(scroll[0]), Integer(scroll[1])] super(text:, style:, block:, wrap:, alignment:, scroll: coerced_scroll) end
Legacy constructor support.
Public Instance Methods
Source
# File lib/ratatui_ruby/widgets/paragraph.rb, line 101 def line_count(width) RatatuiRuby.warn_experimental_feature("Paragraph#line_count") RatatuiRuby._paragraph_line_count(self, Integer(width)) end
Returns the number of lines the paragraph would take up if rendered with the given width.
- width
-
Integer (max width).
Source
# File lib/ratatui_ruby/widgets/paragraph.rb, line 107 def line_width RatatuiRuby.warn_experimental_feature("Paragraph#line_width") RatatuiRuby._paragraph_line_width(self) end
Returns the minimum width needed to not wrap any text.