dry-cli icon indicating copy to clipboard operation
dry-cli copied to clipboard

Feature request: colorized output

Open cllns opened this issue 3 years ago • 3 comments

This is a feature I started working on long ago for Hanami: https://github.com/hanami/hanami/pull/906

There could be two parts to this:

  • Colorizing the output of dry-cli, like each command's help and the list of subcommands
  • Adding something like say that users of the library can use to print in color (instead of using print).

e.g.

say "create", color: :red

This should probably be like print rather than puts (no trailing newline), since people should be able to print in several colors on one line.

The concrete use-case for this could be like hanami/hanami#906, being able to colorize the output of file generation for Hanami.

Is this something we'd be interested in adding to dry-cli? Any thoughts on the API?

cllns avatar Jun 27 '22 23:06 cllns

Another idea for an API could be something like:

class MyGenerator
  include Dry::CLI::Colors

  def call
    puts Red["create"], " ", Green["lib/foo.rb"], " ", RGB["Main file", 55, 66, 77]
  end
end

This avoids the issue of needing to have two different method (one with a trailing newline and another without), or needing a special output method at all.

May want to add TextColors and BackgroundColors if that's desired, but I feel like that could be deferred.

cllns avatar Jul 25 '22 22:07 cllns

We may also want to add bold, underline, etc: https://stackoverflow.com/a/42449998

Those could be extracted as Dry::CLI::Styles (either separately from Colors, or Styles could have them all together)

cllns avatar Sep 18 '22 15:09 cllns

@cllns Any updates with this? I think this would be a great feature. I know they have something like this in Thor if there is needed inspiration Thor:Color

RomanTurner avatar Feb 02 '23 02:02 RomanTurner