Module: Dry::CLI::Help::Colors
- Defined in:
- lib/dry/cli/help/colors.rb,
sig/dry/cli/help.rbs
Overview
Every pastel style as a method. Include it, or extend a module with it:
include Dry::CLI::Help::Colors
red("text") # => decorated text
red.bold("text") # => chained styles
Whether the methods decorate is one process-wide switch, Colors.enabled=.
Help screens do not read it: they follow the color setting instead.
Constant Summary collapse
- HUES =
%i[black red green yellow blue magenta cyan white].freeze
- FOREGROUNDS =
(HUES + HUES.map { :"bright_#{it}" }).freeze
- BACKGROUNDS =
FOREGROUNDS.map { :"on_#{it}" }.freeze
- MODIFIERS =
%i[clear bold dim italic underline inverse hidden strikethrough].freeze
- STYLES =
(FOREGROUNDS + BACKGROUNDS + MODIFIERS).freeze
- SETTINGS =
Values the color switch and the
colorsetting accept. [true, false, :auto].freeze
Class Attribute Summary collapse
-
.enabled ⇒ Boolean, Symbol
True, false or :auto.
Class Method Summary collapse
-
.enabled_for?(setting, io) ⇒ Boolean
:autocolors a terminal unless NO_COLOR is set to anything but the empty string. -
.pastel ⇒ Pastel
Shared by every includer, rebuilt when the switch changes.
Instance Method Summary collapse
Class Attribute Details
.enabled ⇒ Boolean, Symbol
Returns true, false or :auto.
29 30 31 |
# File 'lib/dry/cli/help/colors.rb', line 29 def enabled @enabled end |
Class Method Details
.enabled_for?(setting, io) ⇒ Boolean
:auto colors a terminal unless NO_COLOR is set to anything but
the empty string. https://no-color.org
51 52 53 54 55 |
# File 'lib/dry/cli/help/colors.rb', line 51 def enabled_for?(setting, io) return setting unless setting == :auto io.respond_to?(:tty?) && io.tty? && ENV.fetch("NO_COLOR", "").empty? end |
.pastel ⇒ Pastel
Returns shared by every includer, rebuilt when the switch changes.
41 42 43 |
# File 'lib/dry/cli/help/colors.rb', line 41 def pastel @pastel ||= ::Pastel.new(enabled: enabled_for?(enabled, $stdout)) end |