summaryrefslogtreecommitdiffstats
path: root/src/ansi/mod.rs
diff options
context:
space:
mode:
authorThomas Otto <th1000s@posteo.net>2021-12-07 22:42:34 +0100
committerDan Davison <dandavison7@gmail.com>2021-12-07 19:18:23 -0500
commit47b073d224757217de468063904d1c8342e290d1 (patch)
treecfa604633e69f06ca672b8f5404a49bfc397ab94 /src/ansi/mod.rs
parent7eb56b0997bc0250494b872c134b1947a7886c7f (diff)
Move explain_ansi() part out of parse_ansi()
Diffstat (limited to 'src/ansi/mod.rs')
-rw-r--r--src/ansi/mod.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/ansi/mod.rs b/src/ansi/mod.rs
index f45c13e7..fe27bbe6 100644
--- a/src/ansi/mod.rs
+++ b/src/ansi/mod.rs
@@ -155,6 +155,25 @@ fn strip_ansi_codes_from_strings_iterator<'a>(
.join("")
}
+pub fn explain_ansi(line: &str, colorful: bool) -> String {
+ use crate::style::Style;
+
+ parse_style_sections(line)
+ .into_iter()
+ .map(|(ansi_term_style, s)| {
+ let style = Style {
+ ansi_term_style,
+ ..Style::default()
+ };
+ if colorful {
+ format!("({}){}", style.to_painted_string(), style.paint(s))
+ } else {
+ format!("({}){}", style.to_string(), s)
+ }
+ })
+ .collect()
+}
+
#[cfg(test)]
mod tests {
use crate::ansi::ansi_preserving_index;