Guidedog / 文档
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¶
-
textin the stylecode(one of this module’s constants) whencolor, elsetextas it is;write_styledappends to a buffer instead.
- pub fn ansi::write_styled(out: &mut String, text: &str, code: &str, color: bool)¶
-
Appends
texttooutin the stylecodewhencolor, else as it is.
- pub fn ansi::color_for(is_terminal: bool, env: &SymbolEnv) -> bool¶
-
Whether
--color=autostyles a stream: only a terminal (is_terminal), and only whenenvhas noNO_COLORandTERMis notdumb.
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.