Import std.term.style
std.term.style
std.term's styles: a TermColor for text, one for what's behind it, and TextAttributes, in a Style, which a terminal shows through the escape codes Apply writes, in as many colors as it shows, the nearest of them where it shows fewer. Paint styles text for the console, which gets the text alone where it isn't a terminal or NO_COLOR is set. StripStyles and VisibleWidth read text that has codes in it.
std/term/style.fb
Types
ColorLevel
enum
Public Enum ColorLevel
How many colors a terminal shows.
-
None, as a pipe or a file, or a terminal where NO_COLOR is set, which gets no styles at all.
-
The 16 basic ones.
-
-
24-bit color.
ColorKind
enum
Public Enum ColorKind
What a TermColor is.
-
The terminal's own color.
-
One of the 16 basic ones.
-
One of 256 indexed ones.
-
Red, green, and blue, 24-bit.
TermColor
struct
Public Struct TermColor Implements Hashable, Printable
A color for text, or for what's behind it: the terminal's NORMAL one, its zero; one of the 16 BASIC ones or 256 INDEXED ones, by its Index; or RGB's R, G, and B. A terminal that shows fewer colors gets the nearest it has, as Nearest gives it.
-
Whether it's the terminal's own, a basic one, an indexed one, or RGB.
-
A BASIC or INDEXED color's index.
-
An RGB color's red.
-
An RGB color's green.
-
An RGB color's blue.
-
The terminal's own color, for text or what's behind it.
-
Black, a basic color.
-
Red, a basic color.
-
Green, a basic color.
-
Yellow, a basic color.
-
Blue, a basic color.
-
Magenta, a basic color.
-
Cyan, a basic color.
-
White, a basic color.
-
Bright black, which most terminals show as gray.
-
Bright red, a basic color.
-
Bright green, a basic color.
-
Bright yellow, a basic color.
-
Bright blue, a basic color.
-
Bright magenta, a basic color.
-
Bright cyan, a basic color.
-
Bright white, a basic color.
-
One of the 16 basic colors by its number: black, red, green, yellow, blue, magenta, cyan, and white from 0 to 7, and their bright ones from 8 to 15. Panics past 15.
-
One of 256 colors by its number: the 16 basic ones, then a cube of 6 reds by 6 greens by 6 blues from 16 to 231, and 24 grays, darkest first, from 232 to 255.
-
Red, green, and blue, from 0 to 255 each.
-
The color hex
textgives, as CSS writes one: "#rgb" or "#rrggbb", with or without the "#", in either case. Any other text panics; TryHex takestextfrom outside the program. -
The color hex
textgives, as Hex takes it, or Null fortextthat isn't one. -
Its red, green, and blue: an RGB color's own, and for another, what xterm shows it as. The terminal's NORMAL color has none of its own, so it's black's.
-
The color as a terminal that shows
level's colors shows it: itself, where it has it, or the nearest one it has, by red, green, and blue. NONE has none, so it's NORMAL there. -
"normal", "red", "bright red", "color 208", or "#ff8800".
TextAttributes
enum
@Flags Public Enum TextAttributes
How text looks, beside its colors, in any mix. Not every terminal shows every one.
-
None.
-
Bold.
-
Dim.
-
Italic.
-
Underlined.
-
Blinking.
-
The colors swapped.
-
Hidden.
-
Struck through.
Style
struct
Public Struct Style Implements Hashable, Printable
How text looks: its Foreground color, the Background color behind it, and its Attributes. Its
zero is plain text, as the terminal shows it, and Style(TermColor.Red).Bold() is bold red.
-
Its text's color.
-
The color behind its text.
-
Its attributes, like BOLD, which combine.
-
Whether it's plain text, as the terminal shows it.
-
A copy with
backgroundbehind the text. -
A copy with
attributestoo. -
A copy that's bold too.
-
A copy that's dim too.
-
A copy that's italic too.
-
A copy that's underlined too.
-
A copy that blinks too.
-
A copy with its colors swapped too.
-
A copy that's hidden too.
-
A copy that's struck through too.
-
This style over
under: its own colors, andunder's where it has the terminal's NORMAL ones, and both's attributes, as a list's selected line is drawn over its own style. -
The escape code that starts it, from plain text, as a terminal of
level's colors shows it, like "\e[0;1;31m", or "" wherelevelis NONE. A plain style is "\e[0m". -
textas this style shows it on a terminal oflevel's colors: between the codes that start it and the one that ends it, or alone wherelevelis NONE or the style is plain. -
Like "bold red on blue", or "plain".
Functions
ConsoleColors
function
Public Function ConsoleColors(stream: StandardStream = StandardStream.OUTPUT): ColorLevel
How many colors stream shows, which Paint goes by: NONE where it isn't a terminal, or
NO_COLOR is set and isn't empty, or TERM is "dumb"; TRUE_COLOR where COLORTERM is "truecolor" or
"24bit", or on Windows' console; INDEXED where TERM has "256color" in it; and BASIC otherwise.
Paint
function
Public Function Paint(text: String, style: Style): String
text in style, for stdout: with the codes that show it where stdout is a terminal that shows
colors, and alone where it isn't, or NO_COLOR is set, as Print(Paint("done",
Style(TermColor.Green))).
Paint
function
Public Function Paint(text: String, style: Style, stream: StandardStream): String
text in style, for stream, as stream shows colors.
StripStyles
function
Public Function StripStyles(text: String): String
text without the escape codes in it: a CSI's, like a style's "\e[1;31m" or a cursor move; an
OSC's, like a link's, or a DCS's, an APC's, a PM's, or an SOS's, like a sixel image's or kitty's
graphics', up to its BEL or ST; and any other escape and the characters it takes, as "\e(B" or
"\e7". A code cut short at the end goes, as far as it goes.
VisibleWidth
function
Public Function VisibleWidth(text: String): Int
The columns text takes in a terminal, as DisplayWidth counts them, without its escape codes.
Each line's are counted alike, so for text of several lines it's the widest one's.
Report an issue with this page or with FutureBlitz on GitHub.