Guidedog Handbuch 1.0.0-beta.16
Sprache
Auf dieser Seite
Guidedog / Dokumentation 1.0.0-beta.16

gd_report::ansi

ANSI styling for terminals: the style codes reports and command lines use, text in a style, and whether a stream should be styled at all. Words never depend on styling, so a caller passes color: false and gets plain text.

use gd_report::ansi;
assert_eq!(ansi::styled("ok", ansi::GREEN, true), "\x1b[32mok\x1b[0m");
assert_eq!(ansi::styled("ok", ansi::GREEN, false), "ok");

Functions

pub fn ansi::styled(text: &str, code: &str, color: bool) -> String

text in the style code (one of this module’s constants) when color, else text as it is; write_styled appends to a buffer instead.

pub fn ansi::write_styled(out: &mut String, text: &str, code: &str, color: bool)

Appends text to out in the style code when color, else as it is.

pub fn ansi::color_for(is_terminal: bool, env: &SymbolEnv) -> bool

Whether --color=auto styles a stream: only a terminal (is_terminal), and only when env has no NO_COLOR and TERM is not dumb.

pub fn ansi::terminal_color(is_terminal: bool) -> bool

color_for with this process’s environment.

Constants

pub const ansi::BOLD_RED: &str = "1;31"

Bold red, for errors.

pub const ansi::BOLD_YELLOW: &str = "1;33"

Bold yellow, for warnings.

pub const ansi::BOLD_CYAN: &str = "1;36"

Bold cyan, for notes and names.

pub const ansi::CYAN: &str = "36"

Cyan, for places.

pub const ansi::RED: &str = "31"

Red, for carets and failures.

pub const ansi::GREEN: &str = "32"

Green, for hints and success.

pub const ansi::FAINT: &str = "2"

Faint, for codes and labels.