When using grep-printer
, only the first line has colored matches. How do I make all lines have color?
#2961
-
Please tick this box to confirm you have reviewed the above.
What version of ripgrep are you using?crate: grep = "0.3.2" How did you install ripgrep?Cargo What operating system are you using ripgrep on?NixOS 24.11.20241230.3ffbbdb (Vicuna) Describe your bug.
What are the steps to reproduce the behavior?Example code: use grep::{printer, regex, searcher};
use termcolor;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let content = "abcde abcde\nabcde abcde\nabcde abcde";
let search_terms = [
"abcde", // regular match
"^abcde", // start of the line
"abcde$", // end of the line
];
let color_specs = printer::ColorSpecs::new(&["match:fg:red".parse()?]);
for search_term in search_terms {
let matcher = regex::RegexMatcherBuilder::new().build(search_term)?;
let mut printer = printer::StandardBuilder::new()
.color_specs(color_specs.clone())
.build(termcolor::StandardStream::stdout(
termcolor::ColorChoice::Always,
));
println!();
println!("Searching for \"{search_term}\":");
searcher::Searcher::new().search_slice(
&matcher,
&content.as_bytes(),
printer.sink(&matcher),
)?;
}
Ok(())
} What is the actual behavior?Output image from example code: What is the expected behavior?My expectation would be that for the search term "^abcde" matches would be colored for all printed lines. Is it a bug in |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You need to enable |
Beta Was this translation helpful? Give feedback.
You need to enable
grep_regex::RegexMatcherBuilder::multi_line
. Then it should work.