Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions crates/bashkit/src/builtins/rg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1777,6 +1777,9 @@ fn parse_ansi_fg(value: &str) -> Result<String> {
if let Some(rgb) = parse_rgb_color(value) {
return Ok(format!("38;2;{};{};{}", rgb.0, rgb.1, rgb.2));
}
if let Some(number) = parse_ansi_color_number(value) {
return Ok(format!("38;5;{number}"));
}
match value {
"black" => Ok("30".to_string()),
"red" => Ok("31".to_string()),
Expand All @@ -1796,6 +1799,9 @@ fn parse_ansi_bg(value: &str) -> Result<String> {
if let Some(rgb) = parse_rgb_color(value) {
return Ok(format!("48;2;{};{};{}", rgb.0, rgb.1, rgb.2));
}
if let Some(number) = parse_ansi_color_number(value) {
return Ok(format!("48;5;{number}"));
}
match value {
"black" => Ok("40".to_string()),
"red" => Ok("41".to_string()),
Expand All @@ -1822,6 +1828,14 @@ fn parse_rgb_color(value: &str) -> Option<(u8, u8, u8)> {
Some((r, g, b))
}

fn parse_ansi_color_number(value: &str) -> Option<u8> {
if value.chars().all(|ch| ch.is_ascii_digit()) {
value.parse().ok()
} else {
None
}
}

fn parse_rg_separator(value: &str) -> String {
let mut output = Vec::new();
let mut chars = value.chars().peekable();
Expand Down Expand Up @@ -5248,6 +5262,34 @@ mod tests {
cwd: "/",
output: RgDiffOutput::Exact,
},
RgDiffCase {
name: "colors ansi foreground number",
args: &[
"--color=always",
"--colors",
"match:fg:5",
"needle",
"proj/a.txt",
],
stdin: None,
files: DIFF_BASIC_FILES,
cwd: "/",
output: RgDiffOutput::Exact,
},
RgDiffCase {
name: "colors ansi background number",
args: &[
"--color=always",
"--colors",
"match:bg:5",
"needle",
"proj/a.txt",
],
stdin: None,
files: DIFF_BASIC_FILES,
cwd: "/",
output: RgDiffOutput::Exact,
},
RgDiffCase {
name: "quiet",
args: &["-q", "needle", "proj"],
Expand Down
Loading