Class: Sai::ANSI::SequenceProcessor Private

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

Overview

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

Extract ANSI sequence information from a string

Author:

Since:

  • 0.3.0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ SequenceProcessor

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 SequenceProcessor

Parameters:

  • string (String) —

    the string to parse

Author:

Since:

  • 0.3.0



54
55
56
57
58
59
60
61
62
# File 'lib/sai/ansi/sequence_processor.rb', line 54

def initialize(string)
  @scanner = StringScanner.new(string)
  @segments = []
  @current_segment = { text: +'', foreground: nil, background: nil, styles: [] }
  @encoded_pos = 0
  @stripped_pos = 0
  @color_parser = ColorParser.new(@current_segment)
  @style_parser = StyleParser.new(@current_segment)
end

Class Method Details

.process(string) ⇒ Array<Hash{Symbol => Object}>

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 SequenceProcessor and parse the provided string

Parameters:

  • string (String) —

    the string to parse

Returns:

  • (Array<Hash{Symbol => Object}>) —

    the segments

Author:

Since:

  • 0.3.0



39
40
41
# File 'lib/sai/ansi/sequence_processor.rb', line 39

def self.process(string)
  new(string).process
end

Instance Method Details

#process ⇒ Array<Hash{Symbol => Object}>

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.

Parse a string and return a hash of segments

Returns:

  • (Array<Hash{Symbol => Object}>) —

    the segments

Author:

Since:

  • 0.3.0



73
74
75
76
77
78
# File 'lib/sai/ansi/sequence_processor.rb', line 73

def process
  consume_tokens
  finalize_segment_if_text!

  @segments
end