Expand description
Injectable environment detection.
This module centralizes process-global detection of terminal properties — width, TTY status, and ANSI color capability — behind overridable function pointers so tests can force specific values without touching real environment state.
It follows the same pattern used by
set_theme_detector and
set_icon_detector.
§Usage
In application code, call the detect_* functions. They resolve to real
terminal queries by default:
use standout_render::{detect_terminal_width, detect_is_tty, detect_color_capability};
let _width = detect_terminal_width();
let _tty = detect_is_tty();
let _color = detect_color_capability();In tests, override any of them with a function pointer or a non-capturing
closure (both coerce to fn(...) -> T):
use standout_render::{set_terminal_width_detector, detect_terminal_width};
set_terminal_width_detector(|| Some(80));
assert_eq!(detect_terminal_width(), Some(80));Capturing closures are not supported — if you need per-test state, route it through a thread-local or a static the detector reads from.
Overrides are process-global, so tests that set them should be annotated
with #[serial] (via the serial_test crate) and should use
DetectorGuard to guarantee cleanup even when the test panics.
Structs§
- Detector
Guard - RAII guard that calls
reset_detectorswhen dropped.
Functions§
- detect_
color_ capability - Returns
truewhen ANSI color output is supported on stdout. - detect_
is_ tty - Returns
truewhen stdout is attached to a terminal. - detect_
terminal_ width - Returns the current terminal width in columns, or
Nonewhen unavailable. - reset_
detectors - Resets every environment detector in this module to its default (real-terminal) implementation.
- set_
color_ capability_ detector - Overrides the detector used to check whether ANSI color is supported on stdout.
- set_
terminal_ width_ detector - Overrides the detector used to query terminal width.
- set_
tty_ detector - Overrides the detector used to check whether stdout is a TTY.