Skip to content

Add an exact capability override for deterministic rendering #14

Description

@seapagan

I want to add a thread-local capability override that bypasses terminal and environment detection for implicit rendering.

ColorizeConfig::set_color_mode(ColorMode::Always) disables TTY gating, and set_color_depth_mode(...) selects a depth. Environment variables such as NO_COLOR, FORCE_COLOR, CLICOLOR_FORCE, COLORTERM, and TERM can still affect the result. Tests and applications that need fixed output must clear or replace each relevant variable.

I hit this while testing lsplus on Windows. Windows Terminal sets variables that the Codex environment does not, so identical tests can produce different escape sequences. The test guard now has to lock and restore an expanding set of process variables.

RenderTarget::Capabilities(...) already accepts caller-provided capabilities for explicit rendering. Implicit Display and to_string() rendering still resolve against stdout and the process environment.

Proposed API

Add an exact override to ColorizeConfig, stored with the existing thread-local configuration:

ColorizeConfig::set_capabilities_override(Some(
    TerminalCapabilities {
        color_level: ColorLevel::Ansi16,
        // remaining capability fields
    },
));

ColorizeConfig::set_capabilities_override(None);

A scoped guard may provide a safer interface:

let _guard = ColorizeConfig::override_capabilities(
    TerminalCapabilities::ansi16(),
);

Dropping the guard would restore the previous value.

Semantics to define

The override should control implicit rendering and skip TTY and environment capability detection. Program configuration such as ColorMode::Never and ColorDepthMode::NoColor should retain clear precedence.

The implementation needs an explicit decision for NO_COLOR. My preference is for the exact override to bypass process environment variables, including NO_COLOR, while preserving programmatic hard disables. That gives tests and embedding applications full control without mutating process state.

Normal rendering should keep the existing detection path when no override is set.

Uses

This would support stable snapshot and integration tests across shells and operating systems. It would also help applications that already know the capabilities of a remote terminal, captured destination, or embedded output surface.

Acceptance criteria

  • Callers can set and clear an exact thread-local capability override.
  • Implicit Display and to_string() rendering use the override.
  • The override does not require environment mutation.
  • Tests cover precedence, restoration, and thread isolation.
  • Existing detection behavior remains unchanged when callers set no override.
  • Public documentation explains the relationship with RenderTarget::Capabilities, ColorMode, ColorDepthMode, and NO_COLOR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions