Skip to content
Myr

convert objects to string in style/secho

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

authored by Segev Finer · committed by David Lord · parent 66172ef · Browse files · 3 files+23 added−5 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+23 added−5 removed

  • tests:+7 added−0 removed
  • other:+16 added−5 removed

3 files+23 added−5 removed

modified:src/click/termui.py+14 added-5 removed
480 unmodified lines
481 * ``bright_cyan``482 * ``bright_white``483 * ``reset`` (reset the color code only)484485 .. versionadded:: 2.0486487 .. versionadded:: 7.0488 Added support for bright colors.489485 :param text: the string to style with ansi codes.486 :param fg: if provided this will become the foreground color.487 :param bg: if provided this will become the background color.488 :param bold: if provided this will enable or disable bold mode.
6 unmodified lines
495 other way round).496 :param reset: by default a reset-all code is added at the end of the497 string which means that styles do not carry over. This498 can be disabled to compose styles.499500 .. versionchanged:: 8.0501 A non-string ``message`` is converted to a string.502503 .. versionchanged:: 7.0504 Added support for bright colors.505506 .. versionadded:: 2.0507 """508 if not isinstance(text, str):509 text = str(text)510511 bits = []512 if fg:513 try:514 bits.append(f"\033[{_ansi_colors[fg]}m")
41 unmodified lines
556557 All keyword arguments are forwarded to the underlying functions558 depending on which one they go with.559560 .. versionchanged:: 8.0561 A non-string ``message`` is converted to a string.562563 .. versionadded:: 2.0564 """565 if message is not None:566 message = style(message, **styles)
134 unmodified lines
modified:tests/test_termui.py+7 added
255 unmodified lines
256 bytes = outstreams[0].getvalue()257 assert bytes == b""258259260def test_secho_non_text(runner):261 with runner.isolation() as outstreams:262 click.secho(Exception("spam"), nl=False)263 bytes = outstreams[0].getvalue()264 assert bytes == b"spam"265266267def test_progressbar_yields_all_items(runner):268 with click.progressbar(range(3)) as progress:269 assert len(list(progress)) == 3270
106 unmodified lines
modified:CHANGES.rst+2 added
37 unmodified lines
38- Include required parent arguments in help synopsis of subcommands.39 :issue:`1475`40- Help for boolean flags with ``show_default=True`` shows the flag41 name instead of ``True`` or ``False``. :issue:`1538`42- Non-string objects passed to ``style()`` and ``secho()`` will be43 converted to string. :pr:`1146`444546Version 7.1.247-------------
635 unmodified lines