gd_report::ansi =============== .. rust:module:: gd_report::ansi :synopsis: 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. 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. .. code-block:: rust 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"); .. rubric:: Functions .. rust:function:: pub fn 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; :rust:fn:`write_styled ` appends to a buffer instead. .. rust:function:: pub fn 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. .. rust:function:: pub fn 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``. .. rust:function:: pub fn terminal_color(is_terminal: bool) -> bool :rust:fn:`color_for ` with this process's environment. .. rubric:: Constants .. rust:const:: pub const BOLD_RED: &str = "1;31" Bold red, for errors. .. rust:const:: pub const BOLD_YELLOW: &str = "1;33" Bold yellow, for warnings. .. rust:const:: pub const BOLD_CYAN: &str = "1;36" Bold cyan, for notes and names. .. rust:const:: pub const CYAN: &str = "36" Cyan, for places. .. rust:const:: pub const RED: &str = "31" Red, for carets and failures. .. rust:const:: pub const GREEN: &str = "32" Green, for hints and success. .. rust:const:: pub const FAINT: &str = "2" Faint, for codes and labels.