Skip to content
Myr

Merge pull request #809 from forkbong/bright-colors

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Add support for bright colors

authored by Dan Sully · committed by GitHub · parents 789ba88, c0ccf30 · Browse files · 3 files+38 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+38 added−7 removed

  • other:+38 added−7 removed

3 files+38 added−7 removed

modified:click/termui.py+34 added-6 removed
14 unmodified lines
15# The prompt functions to use. The doc tools currently override these16# functions to customize how they work.17visible_prompt_func = raw_input1819_ansi_colors = ('black', 'red', 'green', 'yellow', 'blue', 'magenta',20 'cyan', 'white', 'reset')19_ansi_colors = {20 'black': 30,21 'red': 31,22 'green': 32,23 'yellow': 33,24 'blue': 34,25 'magenta': 35,26 'cyan': 36,27 'white': 37,28 'reset': 39,29 'bright_black': 90,30 'bright_red': 91,31 'bright_green': 92,32 'bright_yellow': 93,33 'bright_blue': 94,34 'bright_magenta': 95,35 'bright_cyan': 96,36 'bright_white': 97,37}38_ansi_reset_all = '\033[0m'394041def hidden_prompt_func(prompt):
342 unmodified lines
384 * ``blue``385 * ``magenta``386 * ``cyan``387 * ``white`` (might be light gray)388 * ``bright_black``389 * ``bright_red``390 * ``bright_green``391 * ``bright_yellow``392 * ``bright_blue``393 * ``bright_magenta``394 * ``bright_cyan``395 * ``bright_white``396 * ``reset`` (reset the color code only)397398 .. versionadded:: 2.0399400 .. versionadded:: 7.0401 Added support for bright colors.402403 :param text: the string to style with ansi codes.404 :param fg: if provided this will become the foreground color.405 :param bg: if provided this will become the background color.406 :param bold: if provided this will enable or disable bold mode.
10 unmodified lines
417 """418 bits = []419 if fg:420 try:393 bits.append('\033[%dm' % (_ansi_colors.index(fg) + 30))394 except ValueError:421 bits.append('\033[%dm' % (_ansi_colors[fg]))422 except KeyError:423 raise TypeError('Unknown color %r' % fg)424 if bg:425 try:398 bits.append('\033[%dm' % (_ansi_colors.index(bg) + 40))399 except ValueError:426 bits.append('\033[%dm' % (_ansi_colors[bg] + 10))427 except KeyError:428 raise TypeError('Unknown color %r' % bg)429 if bold is not None:430 bits.append('\033[%dm' % (1 if bold else 22))431 if dim is not None:
159 unmodified lines
modified:examples/colors/colors.py+3 added-1 removed
1import click234all_colors = 'black', 'red', 'green', 'yellow', 'blue', 'magenta', \5 'cyan', 'white'5 'cyan', 'white', 'bright_black', 'bright_red', \6 'bright_green', 'bright_yellow', 'bright_blue', \7 'bright_magenta', 'bright_cyan', 'bright_white'8910@click.command()11def cli():
17 unmodified lines
modified:CHANGES+1 added
23 unmodified lines
24- `CliRunner.invoke` now may receive `args` as a string representing25 a Unix shell command. See #664.26- Fix bug that caused bashcompletion to give improper completions on 27 chained commands. See #774.28- Add support for bright colors.29- 't' and 'f' are now converted to True and False. 30- Fix bug that caused bashcompletion to give improper completions on31 chained commands when a required option/argument was being completed.32 See #790.
371 unmodified lines