class

ChalkBox::Supports

Inherits Reference / Object

Detect whether a terminal supports color

This module is based in chalk/supports-color

API

The returned object specifies a level of support for color through a .level property and a corresponding flag:

.level = 1 and .hasBasic = true: Basic color support (16 colors)
.level = 2 and .has256 = true: 256 color support
.level = 3 and .has16m = true: 16 million (truecolor) support

Info

It obeys the --color and --no-color CLI flags.

For situations where using --color is not possible, add an environment variable FORCE_COLOR with any value to force color. Trumps --no-color.

Explicit 256/truecolor mode can be enabled using the --color=256 and --color=16m flags, respectively.

Constructors

new(env : ::ENV.class | Hash(String, String) = ENV, argv : Array(String) = ARGV, stdout : IO::FileDescriptor = STDOUT)
Source

Instance methods

has16m

Checks (if not already) and returns if have supports for 16m colors

Source
has256

Checks (if not already) and returns if have supports for 256 colors

Source
hasBasic

Checks (if not already) and returns if have supports for basic ANSI colors

Source
level

Checks (if not already) and returns colors support level

Code levels:

1 - for basic supports
2 - for 256 colors supports
3 - for 16m colors supports
Source