class ChalkBox::Supports

Overview

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.

Defined in:

chalk_box/supports.cr

Constructors

Instance Method Summary

Constructor Detail

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

[View source]

Instance Method Detail

def has16m #

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


[View source]
def has256 #

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


[View source]
def hasBasic #

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


[View source]
def 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

[View source]