Skip to content

feat: add termlog_colors option to force/disable color output - #8280

Open
gaurav0107 wants to merge 1 commit into
mitmproxy:mainfrom
gaurav0107:fix/7824-add-color-always
Open

gaurav0107 wants to merge 1 commit into
mitmproxy:mainfrom
gaurav0107:fix/7824-add-color-always

Conversation

@gaurav0107

Copy link
Copy Markdown
Contributor

Description

Adds a termlog_colors option (auto/always/never) so users can override mitmproxy's automatic isatty()-based color detection. The primary motivation is to keep colored output when piping mitmdump through a pager:

mitmdump --set termlog_colors=always | less -R

This mirrors the well-known --color={auto,always,never} flag from coreutils (ls, grep).

The override threads through vt_codes.ensure_supported(f, override=...), which is called from:

  • termlog (logging output)
  • dumper (mitmdump flow output)
  • errorcheck (startup-error stderr printing)

Default behavior is unchanged: "auto" preserves the existing isatty() / Windows console-mode detection. The new option is keyword-only on ensure_supported, so any third-party callers continue to work without modification.

Checklist

  • I have updated tests where applicable.
  • I have added an entry to the CHANGELOG (or this change does not need one).

Summary

Closes #7824.

Tests added:

  • test/mitmproxy/utils/test_vt_codes.py — test_override_always, test_override_never, test_override_auto_default
  • test/mitmproxy/addons/test_termlog.py — test_force_color, test_disable_color
  • test/mitmproxy/addons/test_dumper.py — test_force_color, test_disable_color

Local verification:

  • uv run pytest test/mitmproxy/utils/test_vt_codes.py test/mitmproxy/addons/test_termlog.py test/mitmproxy/addons/test_dumper.py test/mitmproxy/addons/test_errorcheck.py — 31 passed
  • uv run pytest test/mitmproxy/addons/ — 533 passed, 1 skipped
  • uv run mypy — 288 source files, no issues
  • uv run ruff check . && uv run ruff format --check . — clean

@gaurav0107
gaurav0107 marked this pull request as ready for review June 10, 2026 04:12
Add a termlog_colors option (auto/always/never) that lets users force-enable
or force-disable ANSI color output for log and mitmdump flow output,
independent of TTY auto-detection. This is useful when piping mitmdump
output to a pager while keeping colors (e.g. mitmdump | less -R), or when
disabling colors in environments that are incorrectly detected as a TTY.

The option is honored by termlog, dumper, and the vt_codes TTY detection
helper, with errorcheck validating the allowed values.
@gaurav0107
gaurav0107 force-pushed the fix/7824-add-color-always branch from 853c142 to 353e361 Compare July 2, 2026 15:11

This branch has not been deployed

No deployments
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.

add --color=always

1 participant