Skip to content
Myr

click.style: add support for bright colors

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

Also fix the 'reset' option for parameters fg and bg Fix #703

authored by Panagiotis Ktistakis · committed by Panagiotis Ktistakis · parent e634d7f · Browse files · 2 files+35 added−6 removed
This commit

State

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

Diff stats

2 files+35 added−6 removed

  • other:+35 added−6 removed

2 files+35 added−6 removed

modified:click/termui.py+34 added-6 removed
12 unmodified lines
13# The prompt functions to use. The doc tools currently override these14# functions to customize how they work.15visible_prompt_func = raw_input1617_ansi_colors = ('black', 'red', 'green', 'yellow', 'blue', 'magenta',18 'cyan', 'white', 'reset')17_ansi_colors = {18 'black': 30,19 'red': 31,20 'green': 32,21 'yellow': 33,22 'blue': 34,23 'magenta': 35,24 'cyan': 36,25 'white': 37,26 'reset': 39,27 'bright_black': 90,28 'bright_red': 91,29 'bright_green': 92,30 'bright_yellow': 93,31 'bright_blue': 94,32 'bright_magenta': 95,33 'bright_cyan': 96,34 'bright_white': 97,35}36_ansi_reset_all = '\033[0m'373839def hidden_prompt_func(prompt):
331 unmodified lines
371 * ``blue``372 * ``magenta``373 * ``cyan``374 * ``white`` (might be light gray)375 * ``bright_black``376 * ``bright_red``377 * ``bright_green``378 * ``bright_yellow``379 * ``bright_blue``380 * ``bright_magenta``381 * ``bright_cyan``382 * ``bright_white``383 * ``reset`` (reset the color code only)384385 .. versionadded:: 2.0386387 .. versionadded:: 7.0388 Added support for bright colors.389390 :param text: the string to style with ansi codes.391 :param fg: if provided this will become the foreground color.392 :param bg: if provided this will become the background color.393 :param bold: if provided this will enable or disable bold mode.
10 unmodified lines
404 """405 bits = []406 if fg:407 try:380 bits.append('\033[%dm' % (_ansi_colors.index(fg) + 30))381 except ValueError:408 bits.append('\033[%dm' % (_ansi_colors[fg]))409 except KeyError:410 raise TypeError('Unknown color %r' % fg)411 if bg:412 try:385 bits.append('\033[%dm' % (_ansi_colors.index(bg) + 40))386 except ValueError:413 bits.append('\033[%dm' % (_ansi_colors[bg] + 10))414 except KeyError:415 raise TypeError('Unknown color %r' % bg)416 if bold is not None:417 bits.append('\033[%dm' % (1 if bold else 22))418 if dim is not None:
159 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 inproper completions on 27 chained commands. See #774.28- Add support for bright colors.2930Version 6.831-----------32
354 unmodified lines