Namespace Terminal.Gui.Drawing
The Drawing
namespace provides comprehensive text rendering, color management, and visual styling for Terminal.Gui applications.
Terminal.Gui.Drawing contains the core drawing primitives and visual styling system for Terminal.Gui. This namespace handles everything from basic color and attribute management to complex line drawing and text formatting capabilities.
The drawing system supports both simple and advanced scenarios, including Unicode text rendering, automatic line joining for complex shapes, thickness-based adornments, and comprehensive color schemes with semantic visual roles.
Key Components
- Attribute: Defines visual styling (foreground, background, text style)
- Color: Terminal color support including TrueColor and named colors
- Scheme: Maps semantic visual roles to concrete attributes
- LineCanvas: Advanced line drawing with automatic glyph joining
- Thickness: Framework for defining border and adornment widths
- Glyphs: Standard set of drawing characters for UI elements
Example Usage
// Get the attribute for a Focused view
Attribute? focusedAttribute = GetAttributeForRole(VisualRole.Focused);
// Move to 5,5 and output a string with the focused attribute
Move (5,5);
AddStr("Hello");
Classes
- AnsiColorNameResolver
Color name resolver for ColorName16.
- 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.
- GradientFill
Implementation of IFill that uses a color gradient (including radial, diagonal etc.).
- LineCanvas
Facilitates box drawing and line intersection detection and rendering. Does not support diagonal lines.
- MultiStandardColorNameResolver
Color name resolver prioritizing Standard (W3C+) colors with fallback to ANSI 4-bit (16) colors.
- 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.
- 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.
A Scheme enables consistent, semantic theming of UI elements by associating each visual state with a specific style. Each property (e.g., Normal, Focus, Disabled) is an Attribute. If a property is not explicitly set, its value is derived from other roles (typically Normal) using well-defined inheritance rules.
Scheme objects are immutable. To update a scheme, create a new instance with the desired values. Use SchemeManager to manage available schemes and apply them to views.
See https://gui-cs.github.io/Terminal.GuiV2Docs/docs/drawing.html for more information.
- 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 IConsoleDriver both support sixel.
- 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).
- VisualRoleEventArgs
Provides data for cancellable workflow events that resolve an Attribute for a specific VisualRole in the Cancellable Work Pattern (CWP).
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 IConsoleDriver).
- CellEventArgs
Args for events that relate to a specific Cell.
- Color
Represents a 24-bit color encoded in ARGB32 format.
- 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.
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 away of modelling color e.g. Hue Saturation 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
- LineStyle
Defines the style of lines for a LineCanvas.
- 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.
- 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).