Class: Tuile::StyledString::Span

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(text:, style:) ⇒ Span

Returns a new instance of Span.

Parameters:

  • text (String)
  • style (Style)

Raises:

  • (ArgumentError)


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

#styleStyle (readonly)

Returns:



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

#textString (readonly)

Returns frozen plain text.

Returns:

  • (String)

    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