-
Notifications
You must be signed in to change notification settings - Fork 3.3k
{Style} Support style with color #16220
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
Conversation
|
Style |
|
Azure Pipelines successfully started running 2 pipeline(s). |
houk-ms
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job ~
Can we also provide a simple developer doc later (may in another pr)?
| # https://python-prompt-toolkit.readthedocs.io/en/stable/pages/printing_text.html#style-text-tuples | ||
| formatted_parts = [] | ||
| for text in styled_text: | ||
| formatted_parts.append(THEME[text[0]] + text[1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key checking for THEME? Or add some error handling logics here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch. Added checks and tests as requested.
| short-summary: Upgrade Azure CLI and extensions | ||
| """ | ||
|
|
||
| helps['demo'] = """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious is this a convention to add a demo command here? The command is convenient for developers but also visible to users right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious is this a convention to add a demo command here?
No. We don't have such convention. The only existing usage of this pattern is az self-test:
| g.command('self-test', 'check_cli', deprecate_info=g.deprecate(hide=True)) |
The command is convenient for developers but also visible to users right?
It is not visible to the user, as the parent command group has been marked as hide=True:
azure-cli/src/azure-cli/azure/cli/command_modules/util/commands.py
Lines 18 to 19 in bc2d0d4
| with self.command_group('demo', deprecate_info=g.deprecate(hide=True)) as g: | |
| g.custom_command('style', 'demo_style') |
| } | ||
|
|
||
|
|
||
| def print_styled_text(styled, file=sys.stderr): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I ask why the default value of the file parameter is sys.stderr instead of sys.stdout?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only the JSON output should go to stdout and the user may pipe it to downstream commands. Per the description of stderr:
https://en.wikipedia.org/wiki/Standard_streams#sys.stderr
This is similar to sys.stdout because it also prints directly to the Console. But the difference is that can be used to print Exceptions and Error messages and also info/debugging comments. (Which is why it is called Standard Error). This can be very useful when the stdout is used to write data instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, got it~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for az next, it is only used interactively, so the stream doesn't really matter as everything is printed to the screen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
Of course. I will add the doc once this feature is stabilized. |
zhoxing-ms
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Maybe we can also encapsulate a util to reuse some common pattern prompts in the future, such as: TASK DONE: Style.SUCCESS + '(✓) Done:' + Style.PRIMARY + ...
Nice suggestion. Let's do this until there is some real usage so that the design/quality can be verified. |
| PRIMARY = "primary" | ||
| SECONDARY = "secondary" | ||
| IMPORTANT = "important" | ||
| ACTION = "action" # name TBD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chenlomis, what style name should we use for light blue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi there
Am slightly confused
Did you mean finding an internal short name for the the bright blue?
https://devdivdesignguide.azurewebsites.net/command-line-interface/color-guidelines-for-command-line-interface/#action-colors
zhoxing-ms
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
Support style with color.
For a complete demo, see
src/azure-cli/azure/cli/command_modules/util/custom.pyand runaz demo style.