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

Updated poutput to use new style_output definition. #1269

Merged
merged 6 commits into from
Jul 28, 2023
Merged

Conversation

anselor
Copy link
Contributor

@anselor anselor commented Apr 26, 2023

Closes #1268

@codecov
Copy link

codecov bot commented Apr 26, 2023

Codecov Report

Patch coverage: 84.84% and project coverage change: -0.04% ⚠️

Comparison is base (adc5a71) 97.96% compared to head (7785320) 97.93%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1269      +/-   ##
==========================================
- Coverage   97.96%   97.93%   -0.04%     
==========================================
  Files          22       22              
  Lines        5700     5705       +5     
==========================================
+ Hits         5584     5587       +3     
- Misses        116      118       +2     
Files Changed Coverage Δ
cmd2/cmd2.py 97.55% <81.48%> (-0.09%) ⬇️
cmd2/ansi.py 100.00% <100.00%> (ø)
cmd2/argparse_custom.py 95.33% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kmvanbrunt
Copy link
Member

I like the idea of adding a psuccess() method. However, I have reservations about applying style in poutput() for the following reasons.

  1. The docstring for ansi.style_output says it "colors text for normal output." That implies all output will have this style. However, async alerts, tab completions, prompts, and argparse help text aren't printed with poutput(). A developer would need to edit other functions to acheive a matching style.

  2. Adding apply_style to ppaged() and pfeedback() is confusing since style is only applied when the msg text is sent by these functions to poutput().

  3. Adding the apply_style argument to poutput() breaks any existing code which prints already styled text since it defaults to True. In practice developers won't notice a visible change since style_output defaults to nothing. However, their code is still wrong since they aren't setting apply_style to False when they call poutput.

@tleonhardt What are your thoughts?

@anselor anselor force-pushed the poutput-psuccess branch 4 times, most recently from 7ce6ed2 to d5508e9 Compare June 28, 2023 18:11
@anselor
Copy link
Contributor Author

anselor commented Jun 29, 2023

I feel part of the issue is our current print methods conflate where to send output with how to send output. I've made some adjustments that move in the direction of keeping things separate.

@anselor
Copy link
Contributor Author

anselor commented Jul 2, 2023

@tleonhardt @kmvanbrunt ?


def pwarning(self, msg: Any = '', *, end: str = '\n', apply_style: bool = True) -> None:
def pwarning(
Copy link
Member

Choose a reason for hiding this comment

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

Should the signature for pwarning() match that of pfailure() (i.e. remove apply_style).
This seems appropriate since we now have two wrappers for perror(). They should work the same way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was reluctant to make an API breaking change to pwarning(). I don't know if it's possible to mark a single argument deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a deprecation to the parameter documentation. We can remove it in the major version revision.

@anselor anselor merged commit a55bb1e into master Jul 28, 2023
30 of 42 checks passed
@tleonhardt tleonhardt deleted the poutput-psuccess branch August 17, 2023 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

poutput() and ansi styles.
2 participants