-
Notifications
You must be signed in to change notification settings - Fork 3.3k
{Style} Refine style framework #16258
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 |
| # dependencies for specific OSes | ||
| if not sys.platform.startswith('cygwin'): | ||
| DEPENDENCIES.append('psutil~=5.7') | ||
|
|
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.
Move the dependency of psutil to core as it is used by core, not command modules. @houk-ms
|
LGTM from the design side as per our latest discussion! |
|
@zhoxing-ms,
Let me add some comments to make it clearer. |
# Conflicts: # src/azure-cli-core/azure/cli/core/__init__.py
| # Convert str to the theme dict | ||
| if isinstance(theme, str): | ||
| if theme.lower() == 'none': | ||
| theme = THEME_NONE | ||
| elif theme.lower() == 'dark': | ||
| theme = THEME_DARK | ||
| elif theme.lower() == 'light': | ||
| theme = THEME_LIGHT | ||
| else: | ||
| from azure.cli.core.azclierror import CLIInternalError | ||
| raise CLIInternalError("Invalid theme. Supported themes: none, dark, light") |
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 do we need to support the case that theme is string?
By the way, could we consider setting a theme configuration as a enum for this mapping relationship instead of if-else logic? Such as:
class THEME(Enum):
none = THEME_NONE,
dark = THEME_DARK,
light = THEME_LIGHT
If this enum is used as parameter, I personally think it is more readable and easier maintained~
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 do we need to support the case that
themeis string?
Because everything passed to CLI via the shell will be treated as str.
Moreover, the values of an Enum are usually basic types like str or int. Using dict as the value, like
class Theme(Enum):
DARK = THEME_DARK
LIGHT = THEME_LIGHT
NONE = THEME_NONEwill result in:
> az demo style -h
Arguments
--theme : The theme to format styled text. Allowed values: {<Style.PRIMARY:
'primary'>: '\x1b[39m', <Style.SECONDARY: 'secondary'>: '\x1b[90m',
<Style.IMPORTANT: 'important'>: '\x1b[35m', <Style.ACTION: 'action'>:
'\x1b[34m', <Style.HYPERLINK: 'hyperlink'>: '\x1b[36m', <Style.ERROR:
'error'>: '\x1b[31m', <Style.SUCCESS: 'success'>: '\x1b[32m',
<Style.WARNING: 'warning'>: '\x1b[33m'}, {<Style.PRIMARY: 'primary'>:
'\x1b[39m', <Style.SECONDARY: 'secondary'>: '\x1b[90m', <Style.IMPORTANT:
'important'>: '\x1b[95m', <Style.ACTION: 'action'>: '\x1b[94m',
<Style.HYPERLINK: 'hyperlink'>: '\x1b[96m', <Style.ERROR: 'error'>:
'\x1b[91m', <Style.SUCCESS: 'success'>: '\x1b[92m', <Style.WARNING:
'warning'>: '\x1b[93m'}, {}. Default: dark.
But the idea of using Enum for Theme is good. Added as requested:
azure-cli/src/azure-cli-core/azure/cli/core/style.py
Lines 67 to 77 in 6240eaf
| class Theme(str, Enum): | |
| DARK = 'dark' | |
| LIGHT = 'light' | |
| NONE = 'none' | |
| THEME_DEFINITIONS = { | |
| Theme.NONE: THEME_NONE, | |
| Theme.DARK: THEME_DARK, | |
| Theme.LIGHT: THEME_LIGHT | |
| } |
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
| # Linux | ||
| process.name.return_value = "python" | ||
| parent1.name.return_value = "bash" | ||
| parent2.name.return_value = "init" | ||
| parent3.name.return_value = "init" | ||
| self.assertEqual(_get_parent_proc_name(), "bash") |
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.
Out of curiosity, I just want to confirm that Mac and Linux are exactly the same, 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.
Yes. Mac is also using bash, but it doesn't really mater as long as no ancestor process is called powershell.exe, pwsh.exe.
However, I think pwsh running on Linux can be a more complex scenario. I need to do more testing on that.
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
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.
@jiasli When do you plan to get this PR merged? Is it possible to catch S181?

Description
Refine the style framework.
Since
BLUEandLIGHTBLUE_EXare not very visible/accessible underpowershell.exe(see the demo at https://github.com/jiasli/color-demo), they are replaced withLIGHTWHITE_EX.ℹ This doesn't apply to PowerShell sessions inside modern terminals, see item 5.
get_parent_proc_nameremoved by {Packaging} Get rid of psutil dependency #11665. {Core} Add SessionId for telemetry #15076 has made sure that psutil is not installed under cygwin.Honor
cli_ctx.enable_colorso that when color is disabled, it can remove color when formatting styled text. This can eliminate the necessity to make 2 versions of the same string, one with color, one without, likeazure-cli/src/azure-cli-core/azure/cli/core/commands/constants.py
Lines 35 to 37 in 026016e
In the demo, you may easily turn off color with
Change the color of primary and secondary text:
BRIGHT WHITEso that at least primary text is visible under both dark/light themesBRIGHT BLACKAdd light theme support which uses dark versions of colors. To try it, in light/dark-themed terminals, run
Add function
is_modern_terminalto detect if the terminal is a modern terminal like VS Code, Windows Terminal.print_styled_textwrapsprintand can passkwargs.format_styled_textsupports more formats.Testing Guide
powershell.exe:pwsh.exe: