Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: colorized output #121

Open
cllns opened this issue Jun 27, 2022 · 3 comments
Open

Feature request: colorized output #121

cllns opened this issue Jun 27, 2022 · 3 comments

Comments

@cllns
Copy link
Member

cllns commented Jun 27, 2022

This is a feature I started working on long ago for Hanami: hanami/hanami#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
Copy link
Member Author

cllns commented Jul 25, 2022

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
Copy link
Member Author

cllns commented Sep 18, 2022

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)

@RomanTurner
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants