Table of Contents

Namespace Terminal.Gui.Drawing

Colors, attributes, text styling, and drawing primitives.

The Drawing namespace provides visual styling, color management, and drawing primitives for Terminal.Gui.

Key Types

  • Attribute - Foreground/background color and text style combination
  • Color - Terminal colors including TrueColor (24-bit) support
  • Scheme - Maps semantic visual roles to attributes
  • LineCanvas - Line drawing with automatic glyph joining
  • Thickness - Border and spacing dimensions
  • Glyphs - Standard drawing characters for UI elements

Color Support

// Named colors
Color red = Color.Red;

// TrueColor (24-bit RGB)
Color custom = new (128, 64, 255);

// Create an attribute
Attribute attr = new (Color.White, Color.Blue);

Scheme System

Schemes map semantic roles to visual attributes:

Role Purpose
Normal Default appearance
Focus Focused view
HotNormal Hotkey indicator
Disabled Disabled state

See Also

Classes

AnsiColorCodeExtensions

Extension methods for the AnsiColorCode enum type.

ColorModelExtensions

Extension methods for the ColorModel enum type.

ColorName16Extensions

Extension methods for the ColorName16 enum type.

ColorParseException

An exception thrown when something goes wrong when trying to parse a Color.

ColorQuantizer

Translates colors in an image into a Palette of up to MaxColors colors (typically 256).

ColorStrings

Provides a mapping between Color and the W3C standard color name strings.

EuclideanColorDistance

Calculates the distance between two colors using Euclidean distance in 3D RGB space. This measures the straight-line distance between the two points representing the colors.

Euclidean distance in RGB space is calculated as:

√((R2 - R1)² + (G2 - G1)² + (B2 - B1)²)
Values vary from 0 to ~441.67 linearly This distance metric is commonly used for comparing colors in RGB space, though it doesn't account for perceptual differences in color.
FillPair

Describes a pair of IFill which cooperate in creating Attribute. One gives foreground color while other gives background.

Glyphs

Defines the standard set of glyphs used to draw checkboxes, lines, borders, etc...

Gradient

Describes a Spectrum of colors that can be combined to make a color gradient. Use BuildCoordinateColorMapping(int, int, GradientDirection) to create into gradient fill area maps.

GradientDirectionExtensions

Extension methods for the GradientDirection enum type.

GradientFill

Implementation of IFill that uses a color gradient (including radial, diagonal etc.).

GraphemeHelper

Provides utility methods for enumerating Unicode grapheme clusters (user-perceived characters) in a string. A grapheme cluster may consist of one or more Rune values, including combining marks or zero-width joiner (ZWJ) sequences such as emoji family groups.

LineCanvas

A canvas for composing box-drawing and line-art characters with automatic intersection resolution. See Drawing Deep Dive for an in-depth look at the design and usage of this class.

LineDirectionsExtensions

Extension methods for the LineDirections enum type.

LineStyleExtensions

Extension methods for the LineStyle enum type.

MarkdownStyleRoleExtensions

Extension methods for the MarkdownStyleRole enum type.

PopularityPaletteWithThreshold

Simple fast palette building algorithm which uses the frequency that a color is seen to determine whether it will appear in the final palette. Includes a threshold whereby colors will be considered 'the same'. This reduces the chance of underrepresented colors being missed completely.

Region

Represents a region composed of one or more rectangles, providing methods for geometric set operations such as union, intersection, exclusion, and complement. This class is designed for use in graphical or terminal-based user interfaces where regions need to be manipulated to manage screen areas, clipping, or drawing boundaries.

RegionOpExtensions

Extension methods for the RegionOp enum type.

Scheme

Represents a theme definition that maps each VisualRole (such as Focus, Disabled, etc.) to an Attribute describing its foreground color, background color, and text style.

See https://gui-cs.github.io/Terminal.Gui/docs/drawing.html for more information.

SchemesExtensions

Extension methods for the Schemes enum type.

SixelEncoder

Encodes a images into the sixel console image output format.

SixelSupportDetector

Uses Ansi escape sequences to detect whether sixel is supported by the terminal.

SixelSupportResult

Describes the discovered state of sixel support and ancillary information e.g. Resolution. You can use any SixelSupportDetector to discover this information.

SixelToRender

Describes a request to render a given SixelData at a given ScreenPosition. Requires that the terminal and IDriver both support sixel.

SolidFill

IFill implementation that uses a solid color for all points

StandardColorExtensions

Extension methods for the StandardColor enum type.

StandardColorsNameResolver

Standard (W3C+) color name resolver.

StraightLine

A line between two points on a horizontal or vertical Orientation and a given style/color.

StraightLineExtensions

Extension methods for StraightLine (including collections).

StyledSegment

A segment of styled text produced by Markdown during layout.

TextMateSyntaxHighlighter

An ISyntaxHighlighter implementation powered by TextMateSharp. Provides syntax highlighting for 50+ languages using VS Code's TextMate grammar engine.

VisualRoleEventArgs

Provides data for cancellable workflow events that resolve an Attribute for a specific VisualRole in the Cancellable Work Pattern (CWP).

VisualRoleExtensions

Extension methods for the VisualRole enum type.

Structs

Attribute

Represents the visual styling for a UI element, including foreground and background color and text style.

Cell

Represents a single row/column in a Terminal.Gui rendering surface (e.g. LineCanvas and IDriver).

CellEventArgs

Args for events that relate to a specific Cell.

Color

Represents a 24-bit color encoded in ARGB32 format.

The RGB components define the color identity (what color it is), while the alpha channel defines rendering intent (how transparent it should be when drawn).

Thickness

Describes the thickness of a frame around a rectangle. Four int values describe the Left, Top, Right, and Bottom sides of the rectangle, respectively.

Interfaces

IColorDistance

Interface for algorithms that compute the relative distance between pairs of colors. This is used for color matching to a limited palette, such as in Sixel rendering.

IColorNameResolver

When implemented by a class, allows mapping Color to human understandable name (e.g. w3c color names) and vice versa.

ICustomColorFormatter

An interface to support custom formatting and parsing of Color values.

IFill

Describes an area fill (e.g. solid color or gradient).

IPaletteBuilder

Builds a palette of a given size for a given set of input colors.

ISyntaxHighlighter

Provides syntax highlighting for fenced code blocks in Markdown.

Enums

AnsiColorCode

The 16 foreground color codes used by ANSI Esc sequences for 256 color terminals. Add 10 to these values for background color.

ColorModel

Describes a way of modelling color e.g. Hue, Saturation, and Lightness.

ColorName16

Defines the 16 legacy color names and values that can be used to set the foreground and background colors in Terminal.Gui apps. Used with Color.

GradientDirection

Describes the pattern that a Gradient results in e.g. Vertical, Horizontal etc

LineDirections

Direction flags for box-drawing character analysis during overlapped compositing.

LineStyle

Defines the style of lines for a LineCanvas.

MarkdownStyleRole

Identifies the semantic role of a styled text segment within a Markdown.

RegionOp

Specifies the operation to perform when combining two regions or a Region with a Rectangle>, defining how their rectangular areas are merged, intersected, or subtracted.

Schemes

The built-in scheme names used by SchemeManager. GetSchemeNames() returns a collection valid scheme names, based on this enum.

StandardColor

Represents standard color names with their RGB values. Derived from the W3C color names, but includes other common names.

TextStyle

Defines non-color style flags for an Attribute.

VisualRole

Represents the semantic visual role of a visual element rendered by a View. Each VisualRole maps to a property of Scheme (e.g., Normal).