Open cllns opened 2 years ago
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.
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 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
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:
dry-cli
, like each command'shelp
and the list of subcommandssay
that users of the library can use to print in color (instead of usingprint
).e.g.
This should probably be like
print
rather thanputs
(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?