Skip to content

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.

type Stream =
| Output
| Errors

Standard output or standard error.

type Paint = { on: Bool }

Styles text with ANSI escape codes when on.

fn bold(self, text: String) -> String
fn dim(self, text: String) -> String
fn italic(self, text: String) -> String
fn underline(self, text: String) -> String
fn red(self, text: String) -> String
fn green(self, text: String) -> String
fn yellow(self, text: String) -> String
fn blue(self, text: String) -> String
fn magenta(self, text: String) -> String
fn cyan(self, text: String) -> String
fn gray(self, text: String) -> String
fn paint(on: Bool) -> Paint

A paint: on (escape codes) or off (text as it is).

fn colors_for(
terminal: Bool,
no_color: Option[String],
force_color: Option[String],
term: Option[String],
) -> Bool

Whether to color a stream. On when FORCE_COLOR is set. Otherwise on for a terminal with NO_COLOR unset and TERM not dumb.

fn styled(p: Paint, code: String, text: String) -> String

text wrapped in the escape code code (1 bold, 31 red, …) and a reset. Unchanged when the paint is off.

fn plain(text: String) -> String

text 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.