Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Termynal mode now keeps its colors when `NO_COLOR` is set in the build environment (e.g. ReadTheDocs). The capture `Console` passes `no_color=False`, so the help is no longer silently rendered monochrome — the output is a build artifact converted to HTML, not interactive terminal output ([#38](https://github.com/syn54x/mkdocs-typer2/issues/38)).

## [0.4.0] - 2026-06-16

### Added
Expand Down
6 changes: 5 additions & 1 deletion src/mkdocs_typer2/termynal_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ def _colored_help(command: click.core.Command, info_name: str, width: int = 80)
``rich_format_help()`` hardcodes ``console = _get_rich_console()`` with no
console/file parameter to inject (``CliRunner`` drops rich color, and the
env-var knobs are import-time + process-global). So we swap that private
factory for a buffer-backed ``Console``.
factory for a buffer-backed ``Console``. That console sets
``no_color=False`` so the captured help keeps its color even when
``NO_COLOR`` is set in the environment (e.g. ReadTheDocs): this is a build
artifact converted to HTML, not interactive terminal output.

If that private hook ever disappears (a future typer rename), we degrade
safely: ``format_help`` runs with stdout redirected into the same buffer, so
Expand All @@ -184,6 +187,7 @@ def _colored_help(command: click.core.Command, info_name: str, width: int = 80)
lambda stderr=False: Console( # noqa: ARG005
force_terminal=True,
color_system="standard",
no_color=False,
width=width,
file=buf,
highlight=False,
Expand Down
13 changes: 13 additions & 0 deletions tests/test_termynal_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ def test_render_termynal_html_typer_colored_and_balanced():
assert html.count("<span") == html.count("</span>")


def test_render_termynal_html_keeps_color_when_no_color_set(monkeypatch):
# NO_COLOR in the build env (e.g. ReadTheDocs) must not strip color from the
# captured help: it is a build artifact converted to HTML, not interactive
# terminal output. rich's no_color defaults to ("NO_COLOR" in os.environ).
monkeypatch.setenv("NO_COLOR", "1")

html = render_termynal_html(
"mkdocs_typer2.cli.cli", "mkdocs-typer2", TermynalOptions(subcommands=1)
)

assert 'style="color:' in html


def test_render_termynal_html_root_only_by_default():
html = render_termynal_html("mkdocs_typer2.cli.cli", "mkdocs-typer2")

Expand Down
Loading