Skip to content

runnable: set FORCE_COLOR for a Python run with runnable.outputLang=ansi - #47

Merged
ewels merged 1 commit into
mainfrom
runnable-force-color
Nov 18, 2026
Merged

ewels merged 1 commit into
mainfrom
runnable-force-color

Conversation

@ewels

@ewels ewels commented Nov 18, 2026

Copy link
Copy Markdown
Owner

A Python run with runnable.outputLang=ansi now has FORCE_COLOR=1 in its environment. Rich, rich-click and Typer print colours with no change to the code. Before, authors had to set FORCE_COLOR in a hidden line, which was the last workaround left in a runnable rich-click --help block after #43.

A Rich example after Run code

  • The change
    • The client passes color: true to run() when the block has runnable.outputLang=ansi, from the data-scb-runnable-ansi attribute that the client already reads for the output.
    • The Pyodide runtime sets FORCE_COLOR=1 before such a run, and removes it before any other run, as it does for COLUMNS. It already resets Rich's cached console before each run, so the new value takes effect.
    • Custom runtimes get color in the options of run(). The Runtime type and the runtime guide describe it. The JavaScript runtime ignores it, since JavaScript code prints colour codes itself.
  • Docs
    • "Output in a language" says that the runtime sets FORCE_COLOR, in place of telling authors to set it.
    • "A command line tool" no longer asks for a hidden FORCE_COLOR line for rich-click or Typer.
    • "Coloured output from a run" has a new Python example that prints with Rich.
    • The skill, DECISIONS.md and the changelog have entries too. The changelog entry is under Unreleased, for 1.5.0.
  • For the release
    • This goes in 1.5.0. release-1.5.0 needs this commit, and its changelog entry moved into the 1.5.0 section.

Tests

  • New Playwright test: the Rich example prints ✔ Built in bold, in a colour that differs from the plain output. It runs in one project, as the other Pyodide tests do. The example indexes after it in runnable.test.ts move up by one.
  • pnpm lint, pnpm lint:docs and pnpm test (606 unit tests and 8 script tests) pass. The runnable and compat Playwright specs pass: 43 passed, 17 skipped.
  • I ran the rich-click demo's hello.py with runnable.args="--help" runnable.outputLang=ansi and no hidden lines, and its help printed in colour.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ewels
ewels merged commit 9073fd6 into main Nov 18, 2026
7 checks passed
@ewels
ewels deleted the runnable-force-color branch November 18, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant