Class: PaintbrushSupport::ColorizedString

Inherits:
Object
  • Object
show all
Defined in:
lib/paintbrush_support/colorized_string.rb

Overview

Core string colorization, provides various methods for colorizing a string, uses escape sequences to store references to start and end of each coloring method to allow nested colorizing with string interpolation within each individual call to ‘paintbrush`.

Instance Method Summary collapse

Constructor Details

#initialize(colorize:, &block) ⇒ ColorizedString

Returns a new instance of ColorizedString.



8
9
10
11
12
# File 'lib/paintbrush_support/colorized_string.rb', line 8

def initialize(colorize:, &block)
  @colorize = colorize
  @block = block
  @stack = []
end

Instance Method Details

#colorizedObject

Returns a colorized string by injecting escape codes into the various calls to each color method in the provided block, rebuilds the string and returns the value with regular ANSI color codes ready to be output to a console.



17
18
19
20
21
# File 'lib/paintbrush_support/colorized_string.rb', line 17

def colorized
  Configuration.with_configuration(colorize: @colorize) do
    colorized_string
  end
end