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)


121
122
123
124
125
126
# File 'lib/tuile/styled_string.rb', line 121

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:



118
119
120
121
122
123
124
125
126
127
# File 'lib/tuile/styled_string.rb', line 118

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.



118
119
120
121
122
123
124
125
126
127
# File 'lib/tuile/styled_string.rb', line 118

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