Class: Tuile::StyledString::Span
- Inherits:
-
Object
- Object
- Tuile::StyledString::Span
- Defined in:
- lib/tuile/styled_string.rb
Overview
A maximal run of text sharing a single Style. ‘text` is plain — it never contains ANSI escape sequences. Spans inside a Tuile::StyledString are normalized: no empty text, no two adjacent spans share a style.
Instance Attribute Summary collapse
- #style ⇒ Style readonly
-
#text ⇒ String
readonly
Frozen plain text.
Instance Method Summary collapse
-
#initialize(text:, style:) ⇒ Span
constructor
A new instance of Span.
Constructor Details
#initialize(text:, style:) ⇒ Span
Returns a new instance of Span.
137 138 139 140 141 142 |
# File 'lib/tuile/styled_string.rb', line 137 def initialize(text:, style:) raise ArgumentError, "text must be a String" unless text.is_a?(String) raise ArgumentError, "style must be a #{Style}" unless style.is_a?(Style) super(text: -text, style: style) end |
Instance Attribute Details
#style ⇒ Style (readonly)
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/tuile/styled_string.rb', line 134 class Span < Data.define(:text, :style) # @param text [String] # @param style [Style] def initialize(text:, style:) raise ArgumentError, "text must be a String" unless text.is_a?(String) raise ArgumentError, "style must be a #{Style}" unless style.is_a?(Style) super(text: -text, style: style) end end |
#text ⇒ String (readonly)
Returns frozen plain text.
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/tuile/styled_string.rb', line 134 class Span < Data.define(:text, :style) # @param text [String] # @param style [Style] def initialize(text:, style:) raise ArgumentError, "text must be a String" unless text.is_a?(String) raise ArgumentError, "style must be a #{Style}" unless style.is_a?(Style) super(text: -text, style: style) end end |