Module Spectrum_capabilities

Terminal color capability detection.

Spectrum_capabilities detects what level of color support a terminal provides, based on environment variables (FORCE_COLOR, COLORTERM, TERM, TERM_PROGRAM), CI provider detection, and OS version information.

Quick Start

  let levels = Spectrum_capabilities.Capabilities.supported_color_levels () in
  match levels.stdout with
  | True_color -> print_endline "Full 24-bit RGB"
  | Eight_bit -> print_endline "256-color xterm palette"
  | Basic -> print_endline "16-color ANSI"
  | Unsupported -> print_endline "No color support detected"

Overriding Detection

Set the FORCE_COLOR environment variable to override auto-detection:

Standalone Usage

This package has no dependency on the rest of Spectrum. Use it independently when you only need to query terminal capabilities:

  let supports_color () =
    let levels = Spectrum_capabilities.Capabilities.supported_color_levels () in
    levels.stdout <> Unsupported

Attribution

The detection heuristics are adapted from the supports-color library used by Chalk (JavaScript).

See Also

module Capabilities : sig ... end

Terminal color capability detection.