From d217007549f58466fd161131e77c47bec3cebaab Mon Sep 17 00:00:00 2001 From: Mykhailo Chalyi Date: Fri, 22 May 2026 21:13:28 -0500 Subject: [PATCH] feat(rg): support hex ansi color numbers --- crates/bashkit/src/builtins/rg/mod.rs | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/crates/bashkit/src/builtins/rg/mod.rs b/crates/bashkit/src/builtins/rg/mod.rs index ca575cd98..81ea9c5e9 100644 --- a/crates/bashkit/src/builtins/rg/mod.rs +++ b/crates/bashkit/src/builtins/rg/mod.rs @@ -1829,6 +1829,12 @@ fn parse_rgb_color(value: &str) -> Option<(u8, u8, u8)> { } fn parse_ansi_color_number(value: &str) -> Option { + if let Some(hex) = value + .strip_prefix("0x") + .or_else(|| value.strip_prefix("0X")) + { + return u8::from_str_radix(hex, 16).ok(); + } if value.chars().all(|ch| ch.is_ascii_digit()) { value.parse().ok() } else { @@ -5290,6 +5296,34 @@ mod tests { cwd: "/", output: RgDiffOutput::Exact, }, + RgDiffCase { + name: "colors ansi foreground hex number", + args: &[ + "--color=always", + "--colors", + "match:fg:0xff", + "needle", + "proj/a.txt", + ], + stdin: None, + files: DIFF_BASIC_FILES, + cwd: "/", + output: RgDiffOutput::Exact, + }, + RgDiffCase { + name: "colors ansi background hex number", + args: &[ + "--color=always", + "--colors", + "match:bg:0x05", + "needle", + "proj/a.txt", + ], + stdin: None, + files: DIFF_BASIC_FILES, + cwd: "/", + output: RgDiffOutput::Exact, + }, RgDiffCase { name: "quiet", args: &["-q", "needle", "proj"],