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

Colorize text formatter #134

Merged
merged 1 commit into from
Apr 5, 2016

Conversation

nbekirov
Copy link
Contributor

This PR colorizes the text formatter to improve terminal readability when used locally.

Before
before

After
after

Configuration

The new feature is controlled via text_formatter:colors property in .pronto.yml. This is also reflected in the README.md. By default it's disabled.

This feature is always disabled (configuration is ignored) when not in TTY to enable file I/O redirection, grep, etc.

N.B. I've had some hard time trying to enable it by default as there seems to be some issues with overriding truthy ConfigFile::EMPTY values via .pronto.yml/ENV settings. I'll investigate further and report back.

P.S. I've left the proposed --colored option out as it would require a bit of a bigger refactoring to centralize the configuration and its modification. Currently TEXT_FORMATTER_COLORS=true pronto run will be available as an alternative.

New dependencies

I've used Rainbow as suggested in #129.

Colorizable mixin

This is a reusable module intended to be used by any formatter that may need colorization. Its implementation is inspired by the one seen in Rubocop.

Colors and styles

The colors I've used are inspired by Rubocop as I find them to be quite nice and recognizable.

Resolves #129


def rainbow
@rainbow ||= Rainbow.new.tap do |rainbow|
rainbow.enabled = config.text_formatter_colors && $stdout.tty?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much more terse, with improved clarity, than the equivalent rubocop cop code. Nice job!

@nbekirov
Copy link
Contributor Author

@tscheffe Thank you for your thorough code review! Please check my replies and fixup commit. I hope you will like the end result better. :)

@tscheffert
Copy link

Everything is looking good to me! Works great!

Waiting on review from @mmozuras then right?

@nbekirov
Copy link
Contributor Author

nbekirov commented Apr 1, 2016

Thanks, Trent!

@mmozuras
I'm available to make any further changes needed. Also I can rebase(+squash) my commits upon your request.

@mmozuras
Copy link
Member

mmozuras commented Apr 3, 2016

@nbekirov looks good 👍
There's only thing I'm not sure about: it there a need for it to be configurable? In what kind of scenario, would I like to disable it manually?

@nbekirov
Copy link
Contributor Author

nbekirov commented Apr 4, 2016

@mmozuras Indeed, the config toggle is not needed per se - I'll remove it.

@nbekirov nbekirov force-pushed the colorize-text-formatter branch from 3409ff8 to e6bd124 Compare April 4, 2016 19:02
- Add Rainbow dependency
- Add Colorizable mixin
- Apply Colorizable to TextFormatter
    - location
    - level
- Add/Update specs
@nbekirov nbekirov force-pushed the colorize-text-formatter branch from e6bd124 to 1a4548b Compare April 4, 2016 19:22
@nbekirov
Copy link
Contributor Author

nbekirov commented Apr 4, 2016

@mmozuras I've removed the configuration, rebased, and squashed! Please let me know what do you think. 😃

@mmozuras mmozuras merged commit 6e037a3 into prontolabs:master Apr 5, 2016
@mmozuras
Copy link
Member

mmozuras commented Apr 5, 2016

@nbekirov amazing, thanks 👏 😄

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

Successfully merging this pull request may close these issues.

3 participants