Skip to main content

TerminalCapabilities class

Namespace: Arlecchino.Rendering.Terminals · Assembly: Arlecchino.Core

What the terminal can actually show. Detected once at startup and consulted by every style when it builds its escape sequence; assign TerminalCapabilities.Color to override the guess.

public static class TerminalCapabilities

Properties

MemberSummary
BackgroundThe color behind the text, as the terminal reported it, or null when it did not say. Undrawing a sixel means painting over it, so a picture stays where it is until this is known.
CellSizeKnownWhether Glyphs.CellWidth and Glyphs.CellHeight came from the terminal rather than from the standing guess. Sixel sizing rests on them.
ColorHow much color styles may emit, detected on first use. It is process-wide, like Theme.Palette, since the framework assumes one terminal per process.
KittyWhether the terminal answered the kitty graphics query. Set by TerminalProbe.Ask; assign it to answer for a terminal that will not.
SixelWhether the terminal said it speaks sixel, as set by TerminalProbe.Ask. Assign it to answer for a terminal that will not.

Methods

MemberSummary
DetectColor()Reads the environment and decides what the terminal can show.
DetectColor(string, string, string, string)The same decision made from explicit values, which is what makes it testable. NO_COLOR or TERM=dumb mean no color at all; truecolor, 24bit or a Windows Terminal session mean 24-bit; everything else falls back to the palette.
NearestPaletteColor(Rgb)Picks the palette color closest to an exact one. This is the conversion RgbTermColor uses when the terminal cannot do 24-bit, available for your own rendering.
Resolve(ImageProtocol)Turns ImageProtocol.Auto into the best of what the terminal admitted to, kitty first, and hands anything else back unchanged. With nothing detected it answers ImageProtocol.Blocks.

Properties in detail

Background

public static Nullable<Rgb> Background { get; set; }

The color behind the text, as the terminal reported it, or null when it did not say. Undrawing a sixel means painting over it, so a picture stays where it is until this is known.

Type Nullable<T><Rgb>

CellSizeKnown

public static bool CellSizeKnown { get; set; }

Whether Glyphs.CellWidth and Glyphs.CellHeight came from the terminal rather than from the standing guess. Sixel sizing rests on them.

Type bool

Color

public static ColorSupport Color { get; set; }

How much color styles may emit, detected on first use. It is process-wide, like Theme.Palette, since the framework assumes one terminal per process.

Type ColorSupport

Kitty

public static bool Kitty { get; set; }

Whether the terminal answered the kitty graphics query. Set by TerminalProbe.Ask; assign it to answer for a terminal that will not.

Type bool

Sixel

public static bool Sixel { get; set; }

Whether the terminal said it speaks sixel, as set by TerminalProbe.Ask. Assign it to answer for a terminal that will not.

Type bool

Methods in detail

DetectColor()

public static ColorSupport DetectColor();

Reads the environment and decides what the terminal can show.

Returns ColorSupport — The detected level of color support.

DetectColor(string, string, string, string)

public static ColorSupport DetectColor(
string? noColor,
string? term,
string? colorTerm,
string? windowsTerminalSession);

The same decision made from explicit values, which is what makes it testable. NO_COLOR or TERM=dumb mean no color at all; truecolor, 24bit or a Windows Terminal session mean 24-bit; everything else falls back to the palette.

Parameters

NameTypeDescription
noColorstringValue of NO_COLOR.
termstringValue of TERM.
colorTermstringValue of COLORTERM.
windowsTerminalSessionstringValue of WT_SESSION.

Returns ColorSupport — How much color those values imply the terminal supports.

NearestPaletteColor(Rgb)

public static TerminalColor NearestPaletteColor(Rgb color);

Picks the palette color closest to an exact one. This is the conversion RgbTermColor uses when the terminal cannot do 24-bit, available for your own rendering.

Parameters

NameTypeDescription
colorRgbThe color to approximate.

Returns TerminalColor — The nearest of the sixteen ANSI colors.

Resolve(ImageProtocol)

public static ImageProtocol Resolve(ImageProtocol protocol);

Turns ImageProtocol.Auto into the best of what the terminal admitted to, kitty first, and hands anything else back unchanged. With nothing detected it answers ImageProtocol.Blocks.

Parameters

NameTypeDescription
protocolImageProtocolWhat was asked for.

Returns ImageProtocol — What to actually draw with.