std.term
Text styled for a terminal with ANSI escape codes.
A paint from console.paint(stream) is on only for a terminal. Off, it returns text unchanged.
Stream
Section titled “Stream”type Stream = | Output | ErrorsStandard output or standard error.
type Paint = { on: Bool }Styles text with ANSI escape codes when on.
Methods
Section titled “Methods”Paint.bold
Section titled “Paint.bold”fn bold(self, text: String) -> StringPaint.dim
Section titled “Paint.dim”fn dim(self, text: String) -> StringPaint.italic
Section titled “Paint.italic”fn italic(self, text: String) -> StringPaint.underline
Section titled “Paint.underline”fn underline(self, text: String) -> StringPaint.red
Section titled “Paint.red”fn red(self, text: String) -> StringPaint.green
Section titled “Paint.green”fn green(self, text: String) -> StringPaint.yellow
Section titled “Paint.yellow”fn yellow(self, text: String) -> StringPaint.blue
Section titled “Paint.blue”fn blue(self, text: String) -> StringPaint.magenta
Section titled “Paint.magenta”fn magenta(self, text: String) -> StringPaint.cyan
Section titled “Paint.cyan”fn cyan(self, text: String) -> StringPaint.gray
Section titled “Paint.gray”fn gray(self, text: String) -> StringFunctions
Section titled “Functions”fn paint(on: Bool) -> PaintA paint: on (escape codes) or off (text as it is).
colors_for
Section titled “colors_for”fn colors_for( terminal: Bool, no_color: Option[String], force_color: Option[String], term: Option[String],) -> BoolWhether to color a stream. On when FORCE_COLOR is set.
Otherwise on for a terminal with NO_COLOR unset and TERM not dumb.
styled
Section titled “styled”fn styled(p: Paint, code: String, text: String) -> Stringtext wrapped in the escape code code (1 bold, 31 red, …) and a
reset. Unchanged when the paint is off.
fn plain(text: String) -> Stringtext without its escape codes, as a terminal shows it: ESC [ up to a
final character from @ to ~ (a colour), ESC ] up to a BEL or ESC \
(a hyperlink, a title), and ESC with the characters from space to /
after it and the one after those.