Skip to content

#698 - Revisiting Color Support #704

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

Merged
merged 39 commits into from
Jun 29, 2019
Merged

Conversation

xNinjaKittyx
Copy link

@xNinjaKittyx xNinjaKittyx commented Jun 25, 2019

Addresses #698

Changes:

  • poutput and perror no longer use color kwarg, which has been split into fg and bg.
  • fg and bg use human names of color like blue or red.
  • perror is split into 2 functions perror and pexcept. pexcept will behave identical to the previous perror, but perror will only print to stderr with no stacktraces or Exception messages.

@codecov
Copy link

codecov bot commented Jun 25, 2019

Codecov Report

Merging #704 into master will increase coverage by 0.4%.
The diff coverage is 96.13%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #704     +/-   ##
=========================================
+ Coverage   95.23%   95.63%   +0.4%     
=========================================
  Files          11       12      +1     
  Lines        3274     3345     +71     
=========================================
+ Hits         3118     3199     +81     
+ Misses        156      146     -10
Impacted Files Coverage Δ
cmd2/parsing.py 100% <ø> (ø) ⬆️
cmd2/utils.py 97.81% <ø> (-0.04%) ⬇️
cmd2/constants.py 100% <ø> (ø) ⬆️
cmd2/transcript.py 93.69% <100%> (ø) ⬆️
cmd2/ansi.py 100% <100%> (ø)
cmd2/history.py 100% <100%> (ø) ⬆️
cmd2/argparse_completer.py 90.16% <87.5%> (-0.1%) ⬇️
cmd2/cmd2.py 95.78% <94.33%> (+0.62%) ⬆️
cmd2/plugin.py 100% <0%> (ø) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bef0774...83e4188. Read the comment docs.

@tleonhardt
Copy link
Member

tleonhardt commented Jun 25, 2019

Recommend updating test_utils.py to add new unit tests for style_message() so that new utility function has 100% code coverage.

3 or 4 unit tests should do the trick. The currently uncovered cases are:

  • bg happy day
  • fg exception
  • bg exception

@tleonhardt
Copy link
Member

Thanks for the PR! I'll take a look at it tonight.

@tleonhardt
Copy link
Member

@xNinjaKittyx By the way, your PR is excellent, so please don't take any offense at other developers collaborating to make it even better. We might have a moderately peculiar culture here on this project, where it is extremely common for developers to collaborate and work to improve each other's PRs.

@tleonhardt
Copy link
Member

tleonhardt commented Jun 26, 2019

I like this PR as-is, but I also like the direction @kmvanbrunt is moving in to address the suggestion by @kotfu to decouple the functions for outputting text from the one for styling it and think that is probably a more flexible and maintainable improvement albeit at the cost of a small amount of convenience.

Some things I think we will need to address once the changes stabilize and before merging into master include:

TODO

  • Update the CHANGELOG
  • Make sure Sphinx docs are still accurate, particularly for section on output functions
  • Update examples/colors.py example
  • Move styling function and associated color dictionaries to a new file called something like color.py or ansi.py and add two-stage functions for retrieving the color text which first look in the dictionaries, but then attempt to fallback to getting the color directly from colorama using the getattr "hack" suggested by @xNinjaKittyx

@xNinjaKittyx xNinjaKittyx requested a review from anselor as a code owner June 26, 2019 06:33
@kmvanbrunt kmvanbrunt self-assigned this Jun 27, 2019
@kmvanbrunt
Copy link
Member

@xNinjaKittyx
Sorry for basically stealing this PR. Issue #698 was based on a conversation I had with @tleonhardt, so I already had some thoughts on the direction we wanted to go.

Then I looked at the style() function you posted from click and I got very inspired. Since a lot of code needed to be changed, I just went ahead and did it to have it done quickly. Time was an important factor because @tleonhardt and I are doing a cmd2 talk at PyOhio in a month. I wanted to stabilize the code and give us enough time to make the presentation.

Thanks for your help and don't be discouraged from contributing in the future. I don't usually steal :)

@xNinjaKittyx
Copy link
Author

@kmvanbrunt It's all good. I'm glad that inspired you :D.
I've never heard about PyOhio, but if they post the content online, I'll make sure to give it a watch.

I use this library quite a bit at work, so I thought I'd contribute when I see something I can do. I'll be on the lookout.

@tleonhardt tleonhardt added this to the 0.9.14 milestone Jun 27, 2019
Also:
- Updated examples that use color to use cmd2.ansi instead of colorama
- Updated tests that use color to use cmd2.ansi instead of colorama
- plumbum_colorspy example shows how to override color lookup functions to use a different color library
@tleonhardt
Copy link
Member

@kotfu If you get a chance to look at this, your feedback would be appreciated.

@xNinjaKittyx Can you please review that changes that @kmvanbrunt and I have made to your PR to make sure they all seem reasonable to you?

@xNinjaKittyx
Copy link
Author

I think there's a few more breaking changes that might need to be documented.

  • the signature of self.poutput() and self.perror() is now declaring that end is a mandatory kwarg now.
  • self.perror() and the new pexcept() no longer have traceback_war, err_color, war_color (I know color is mentioned, but might be helpful to also mention the specific variable names?)

@tleonhardt tleonhardt merged commit d9ec6f7 into master Jun 29, 2019
@tleonhardt tleonhardt deleted the feature/revisit-color-support branch June 29, 2019 18:14
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