From 30c5bc58c4236e9f7f0146fc37e5e7050acab0a2 Mon Sep 17 00:00:00 2001 From: shadowwa Date: Fri, 11 Oct 2024 13:57:49 +0200 Subject: [PATCH] support of [K escape code from ag result --- src/devicon_lookup/parsers/color.rs | 2 +- tests/strip_ansi.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/devicon_lookup/parsers/color.rs b/src/devicon_lookup/parsers/color.rs index 6cf125f9..bfb4a74d 100644 --- a/src/devicon_lookup/parsers/color.rs +++ b/src/devicon_lookup/parsers/color.rs @@ -2,7 +2,7 @@ use crate::ParserResult; use regex::Regex; lazy_static! { - static ref ANSI_COLOR_REGEX: Regex = Regex::new(r"\x1b\[[0-9;]*m").unwrap(); + static ref ANSI_COLOR_REGEX: Regex = Regex::new(r"\x1b\[([0-9;]*m|K)").unwrap(); } pub fn strip_color(input: String) -> ParserResult { diff --git a/tests/strip_ansi.rs b/tests/strip_ansi.rs index bbbf07fb..ef4d4e3d 100644 --- a/tests/strip_ansi.rs +++ b/tests/strip_ansi.rs @@ -36,4 +36,15 @@ mod integration { .assert() .stdout(" \x1b[34mtest.rs\x1B[0m\n \x1b[31mtest.rb\x1b[0m\n"); } + + #[test] + fn calling_devicon_lookup_with_strip_color_ag_result() { + colored::control::set_override(true); + + let mut cmd = Command::cargo_bin("devicon-lookup").unwrap(); + cmd.arg("--color"); + cmd.write_stdin("\x1b[34mtest.rs\x1B[0m\x1b[K".to_string()) + .assert() + .stdout(" \x1b[34mtest.rs\x1B[0m\x1b[K\n"); + } }