Class: Dry::Logger::Formatters::Colors Private
- Inherits:
-
Object
- Object
- Dry::Logger::Formatters::Colors
- Defined in:
- lib/dry/logger/formatters/colors.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.
Shell colorizer
This was ported from hanami-utils
Defined Under Namespace
Classes: UnknownColorCodeError
Constant Summary collapse
- COLORS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Escapes codes for terminals to output strings in colors
{black: 30, red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, cyan: 36, gray: 37}.freeze
Class Method Summary collapse
-
.[](code) ⇒ Object
private
Helper method to translate between color names and terminal escape codes.
-
.call(color, input) ⇒ String
private
Colorizes output 8 colors available: black, red, green, yellow, blue, magenta, cyan, and gray.
- .evaluate(input) ⇒ Object private
- .start(color) ⇒ Object private
- .stop ⇒ Object private
Class Method Details
.[](code) ⇒ 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.
Helper method to translate between color names and terminal escape codes
78 79 80 |
# File 'lib/dry/logger/formatters/colors.rb', line 78 def self.[](code) COLORS.fetch(code) { raise UnknownColorCodeError, code } end |
.call(color, input) ⇒ String
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.
Colorizes output 8 colors available: black, red, green, yellow, blue, magenta, cyan, and gray
56 57 58 |
# File 'lib/dry/logger/formatters/colors.rb', line 56 def self.call(color, input) "#{start(color)}#{input}#{stop}" end |
.evaluate(input) ⇒ 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.
36 37 38 39 40 41 42 |
# File 'lib/dry/logger/formatters/colors.rb', line 36 def self.evaluate(input) COLORS.keys.reduce(input.dup) { |output, color| output.gsub!("<#{color}>", start(color)) output.gsub!("</#{color}>", stop) output } end |
.start(color) ⇒ 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.
62 63 64 |
# File 'lib/dry/logger/formatters/colors.rb', line 62 def self.start(color) "\e[#{self[color]}m" end |
.stop ⇒ 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.
68 69 70 |
# File 'lib/dry/logger/formatters/colors.rb', line 68 def self.stop "\e[0m" end |