Class: Archaeo::ColorOutput
- Inherits:
-
Object
- Object
- Archaeo::ColorOutput
- Defined in:
- lib/archaeo/color_output.rb
Overview
Minimal ANSI color helper for CLI output.
Detects whether the output stream supports color and wraps strings with escape codes accordingly. Respects –no-color and TERM=dumb.
Constant Summary collapse
- COLORS =
{ red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, cyan: 36, white: 37, }.freeze
- STYLES =
{ bold: 1, dim: 2, }.freeze
Instance Method Summary collapse
- #error(text) ⇒ Object
- #info(text) ⇒ Object
-
#initialize(enabled: nil, stream: $stderr) ⇒ ColorOutput
constructor
A new instance of ColorOutput.
- #success(text) ⇒ Object
- #warning(text) ⇒ Object
Constructor Details
#initialize(enabled: nil, stream: $stderr) ⇒ ColorOutput
Returns a new instance of ColorOutput.
25 26 27 |
# File 'lib/archaeo/color_output.rb', line 25 def initialize(enabled: nil, stream: $stderr) @enabled = enabled.nil? ? detect_color_support(stream) : enabled end |
Instance Method Details
#error(text) ⇒ Object
49 50 51 |
# File 'lib/archaeo/color_output.rb', line 49 def error(text) red(bold(text)) end |
#info(text) ⇒ Object
53 54 55 |
# File 'lib/archaeo/color_output.rb', line 53 def info(text) cyan(text) end |
#success(text) ⇒ Object
41 42 43 |
# File 'lib/archaeo/color_output.rb', line 41 def success(text) green(bold(text)) end |
#warning(text) ⇒ Object
45 46 47 |
# File 'lib/archaeo/color_output.rb', line 45 def warning(text) yellow(bold(text)) end |