Skip to content

Commit

Permalink
Cyan->magenta, green->blue
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Feb 8, 2025
1 parent f4938c7 commit dee907f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
3 changes: 1 addition & 2 deletions Lib/_colorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@

class ANSIColors:
BACKGROUND_YELLOW = "\x1b[43m"
BOLD_CYAN = "\x1b[1;36m"
BOLD_BLUE = "\x1b[1;34m"
BOLD_GREEN = "\x1b[1;32m"
BOLD_MAGENTA = "\x1b[1;35m"
BOLD_RED = "\x1b[1;31m"
CYAN = "\x1b[36m"
BLACK = "\x1b[30m"
GREEN = "\x1b[32m"
GREY = "\x1b[90m"
Expand Down
34 changes: 18 additions & 16 deletions Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ def _format_usage(self, usage, actions, groups, prefix):
from _colorize import get_colors

ansi = get_colors()
bold_cyan = ansi.BOLD_CYAN
bold_green = ansi.BOLD_GREEN
cyan = ansi.CYAN
bold_magenta = ansi.BOLD_MAGENTA
bold_blue = ansi.BOLD_BLUE
magenta = ansi.MAGENTA
reset = ansi.RESET

if prefix is None:
Expand All @@ -308,14 +308,14 @@ def _format_usage(self, usage, actions, groups, prefix):
# if usage is specified, use that
if usage is not None:
usage = (
cyan
+ usage % dict(prog=f"{bold_cyan}{self._prog}{reset}{cyan}")
magenta
+ usage % dict(prog=f"{bold_magenta}{self._prog}{reset}{magenta}")
+ reset
)

# if no optionals or positionals are available, usage is just prog
elif usage is None and not actions:
usage = f"{bold_cyan}{self._prog}{reset}"
usage = f"{bold_magenta}{self._prog}{reset}"

# if optionals and positionals are available, calculate usage
elif usage is None:
Expand Down Expand Up @@ -391,10 +391,10 @@ def get_lines(parts, indent, prefix=None):
usage = '\n'.join(lines)

usage = usage.removeprefix(prog)
usage = f"{bold_cyan}{prog}{reset}{cyan}{usage}{reset}"
usage = f"{bold_magenta}{prog}{reset}{magenta}{usage}{reset}"

# prefix with 'usage:'
return f'{bold_green}{prefix}{reset}{usage}\n\n'
return f'{bold_blue}{prefix}{reset}{usage}\n\n'

def _format_actions_usage(self, actions, groups):
return ' '.join(self._get_actions_usage_parts(actions, groups))
Expand Down Expand Up @@ -553,14 +553,16 @@ def _format_action_invocation(self, action, *, colorize=False):
from _colorize import get_colors

ansi = get_colors()
bold_cyan, cyan, reset = ansi.BOLD_CYAN, ansi.CYAN, ansi.RESET
bold_magenta = ansi.BOLD_MAGENTA
magenta = ansi.MAGENTA
reset = ansi.RESET
else:
bold_cyan = cyan = reset = ""
bold_magenta = magenta = reset = ""

if not action.option_strings:
default = self._get_default_metavar_for_positional(action)
return (
bold_cyan
bold_magenta
+ ' '.join(self._metavar_formatter(action, default)(1))
+ reset
)
Expand All @@ -570,17 +572,17 @@ def _format_action_invocation(self, action, *, colorize=False):
# if the Optional doesn't take a value, format is:
# -s, --long
if action.nargs == 0:
return bold_cyan + ', '.join(action.option_strings) + reset
return bold_magenta + ', '.join(action.option_strings) + reset

# if the Optional takes a value, format is:
# -s, --long ARGS
else:
default = self._get_default_metavar_for_optional(action)
args_string = (
f"{cyan}{self._format_args(action, default)}{reset}"
f"{magenta}{self._format_args(action, default)}{reset}"
)
return (
bold_cyan
bold_magenta
+ ', '.join(action.option_strings)
+ reset
+ ' '
Expand Down Expand Up @@ -2652,7 +2654,7 @@ def format_help(self):
from _colorize import get_colors

ansi = get_colors()
bold_green, reset = ansi.BOLD_GREEN, ansi.RESET
bold_blue, reset = ansi.BOLD_BLUE, ansi.RESET

formatter = self._get_formatter()

Expand All @@ -2665,7 +2667,7 @@ def format_help(self):

# positionals, optionals and user-defined groups
for action_group in self._action_groups:
formatter.start_section(f"{bold_green}{action_group.title}:{reset}")
formatter.start_section(f"{bold_blue}{action_group.title}:{reset}")
formatter.add_text(action_group.description)
formatter.add_arguments(action_group._group_actions)
formatter.end_section()
Expand Down

0 comments on commit dee907f

Please sign in to comment.