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.
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, andset_color_depth_mode(...)selects a depth. Environment variables such asNO_COLOR,FORCE_COLOR,CLICOLOR_FORCE,COLORTERM, andTERMcan still affect the result. Tests and applications that need fixed output must clear or replace each relevant variable.I hit this while testing
lspluson 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. ImplicitDisplayandto_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:A scoped guard may provide a safer interface:
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::NeverandColorDepthMode::NoColorshould retain clear precedence.The implementation needs an explicit decision for
NO_COLOR. My preference is for the exact override to bypass process environment variables, includingNO_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
Displayandto_string()rendering use the override.RenderTarget::Capabilities,ColorMode,ColorDepthMode, andNO_COLOR.