Class: Sai::ANSI::SequencedString::Segment

Inherits:
Object
  • Object
show all
Defined in:
lib/sai/ansi/sequenced_string.rb

Overview

A segment of an ANSI encoded string

Author:

Since:

  • 0.3.0

Defined Under Namespace

Classes: Location

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Segment

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a new instance of Segment

Parameters:

  • options (Hash{Symbol => Object}) —

    the options to initialize the Segment with

Options Hash (**options):

Author:

Since:

  • 0.3.0



408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/sai/ansi/sequenced_string.rb', line 408

def initialize(**options)
  @background = options.fetch(:background, nil)
  @foreground = options.fetch(:foreground, nil)
  @encoded_location = Location.new(
    end_position: options.fetch(:encoded_end), #: Integer
    start_position: options.fetch(:encoded_start) #: Integer
  )
  @stripped_location = Location.new(
    end_position: options.fetch(:stripped_end), #: Integer
    start_position: options.fetch(:stripped_start) #: Integer
  )
  @styles = options.fetch(:styles, [])
  @text = options.fetch(:text)

  freeze
end

Instance Attribute Details

#background ⇒ String? (readonly)

The background color sequences for the Segment

Returns:

  • (String, nil) —

    the background color sequences

Author:

Since:

  • 0.3.0



322
323
324
# File 'lib/sai/ansi/sequenced_string.rb', line 322

def background
  @background
end

#encoded_location ⇒ Location (readonly) Also known as: encoded_loc

The Location of the encoded string within the Sai::ANSI::SequencedString

Returns:

Author:

Since:

  • 0.3.0



342
343
344
# File 'lib/sai/ansi/sequenced_string.rb', line 342

def encoded_location
  @encoded_location
end

#foreground ⇒ String? (readonly)

The foreground color sequences for the Segment

Returns:

  • (String, nil) —

    the foreground color sequences

Author:

Since:

  • 0.3.0



332
333
334
# File 'lib/sai/ansi/sequenced_string.rb', line 332

def foreground
  @foreground
end

#stripped_location ⇒ Location (readonly) Also known as: stripped_loc

The Location of the encoded string without it's encoding within the Sai::ANSI::SequencedString

Returns:

Author:

Since:

  • 0.3.0



353
354
355
# File 'lib/sai/ansi/sequenced_string.rb', line 353

def stripped_location
  @stripped_location
end

#styles ⇒ Array<String> (readonly)

The style sequences (bold, underline, etc...) for the segment

Returns:

  • (Array<String>) —

    the style sequences

Author:

Since:

  • 0.3.0



364
365
366
# File 'lib/sai/ansi/sequenced_string.rb', line 364

def styles
  @styles
end

#text ⇒ String (readonly)

The raw text of the Segment without any of its ANSI sequences

Returns:

  • (String)

Author:

Since:

  • 0.3.0



374
375
376
# File 'lib/sai/ansi/sequenced_string.rb', line 374

def text
  @text
end