diff --git a/CHANGES b/CHANGES index d76faf9c9..0b444fd06 100644 --- a/CHANGES +++ b/CHANGES @@ -25,6 +25,7 @@ Version 7.0 a Unix shell command. See #664. - Fix bug that caused bashcompletion to give improper completions on chained commands. See #774. +- Add support for bright colors. - 't' and 'f' are now converted to True and False. - Fix bug that caused bashcompletion to give improper completions on chained commands when a required option/argument was being completed. diff --git a/click/termui.py b/click/termui.py index 6683b8931..3f8dbb99e 100644 --- a/click/termui.py +++ b/click/termui.py @@ -16,8 +16,25 @@ # functions to customize how they work. visible_prompt_func = raw_input -_ansi_colors = ('black', 'red', 'green', 'yellow', 'blue', 'magenta', - 'cyan', 'white', 'reset') +_ansi_colors = { + 'black': 30, + 'red': 31, + 'green': 32, + 'yellow': 33, + 'blue': 34, + 'magenta': 35, + 'cyan': 36, + 'white': 37, + 'reset': 39, + 'bright_black': 90, + 'bright_red': 91, + 'bright_green': 92, + 'bright_yellow': 93, + 'bright_blue': 94, + 'bright_magenta': 95, + 'bright_cyan': 96, + 'bright_white': 97, +} _ansi_reset_all = '\033[0m' @@ -368,10 +385,21 @@ def style(text, fg=None, bg=None, bold=None, dim=None, underline=None, * ``magenta`` * ``cyan`` * ``white`` (might be light gray) + * ``bright_black`` + * ``bright_red`` + * ``bright_green`` + * ``bright_yellow`` + * ``bright_blue`` + * ``bright_magenta`` + * ``bright_cyan`` + * ``bright_white`` * ``reset`` (reset the color code only) .. versionadded:: 2.0 + .. versionadded:: 7.0 + Added support for bright colors. + :param text: the string to style with ansi codes. :param fg: if provided this will become the foreground color. :param bg: if provided this will become the background color. @@ -390,13 +418,13 @@ def style(text, fg=None, bg=None, bold=None, dim=None, underline=None, bits = [] if fg: try: - bits.append('\033[%dm' % (_ansi_colors.index(fg) + 30)) - except ValueError: + bits.append('\033[%dm' % (_ansi_colors[fg])) + except KeyError: raise TypeError('Unknown color %r' % fg) if bg: try: - bits.append('\033[%dm' % (_ansi_colors.index(bg) + 40)) - except ValueError: + bits.append('\033[%dm' % (_ansi_colors[bg] + 10)) + except KeyError: raise TypeError('Unknown color %r' % bg) if bold is not None: bits.append('\033[%dm' % (1 if bold else 22)) diff --git a/examples/colors/colors.py b/examples/colors/colors.py index 1e365bd22..193b92712 100644 --- a/examples/colors/colors.py +++ b/examples/colors/colors.py @@ -2,7 +2,9 @@ all_colors = 'black', 'red', 'green', 'yellow', 'blue', 'magenta', \ - 'cyan', 'white' + 'cyan', 'white', 'bright_black', 'bright_red', \ + 'bright_green', 'bright_yellow', 'bright_blue', \ + 'bright_magenta', 'bright_cyan', 'bright_white' @click.command()