mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-03-03 14:32:22 +02:00
printer: always use \n in the summary printer
Previously, the \x00 byte would be printed when --null-data was being used.
This commit is contained in:
parent
bb6f0f5519
commit
4b692bb7b0
@ -561,13 +561,13 @@ impl<'p, 's, M: Matcher, W: WriteColor> SummarySink<'p, 's, M, W> {
|
|||||||
/// write that path to the underlying writer followed by a line terminator.
|
/// write that path to the underlying writer followed by a line terminator.
|
||||||
/// (If a path terminator is set, then that is used instead of the line
|
/// (If a path terminator is set, then that is used instead of the line
|
||||||
/// terminator.)
|
/// terminator.)
|
||||||
fn write_path_line(&mut self, searcher: &Searcher) -> io::Result<()> {
|
fn write_path_line(&mut self) -> io::Result<()> {
|
||||||
if self.path.is_some() {
|
if self.path.is_some() {
|
||||||
self.write_path()?;
|
self.write_path()?;
|
||||||
if let Some(term) = self.summary.config.path_terminator {
|
if let Some(term) = self.summary.config.path_terminator {
|
||||||
self.write(&[term])?;
|
self.write(&[term])?;
|
||||||
} else {
|
} else {
|
||||||
self.write_line_term(searcher)?;
|
self.write_line_term()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -624,9 +624,9 @@ impl<'p, 's, M: Matcher, W: WriteColor> SummarySink<'p, 's, M, W> {
|
|||||||
self.interpolator.finish(status, &mut *self.summary.wtr.borrow_mut())
|
self.interpolator.finish(status, &mut *self.summary.wtr.borrow_mut())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write the line terminator configured on the given searcher.
|
/// Write the `\n` line terminator.
|
||||||
fn write_line_term(&self, searcher: &Searcher) -> io::Result<()> {
|
fn write_line_term(&self) -> io::Result<()> {
|
||||||
self.write(searcher.line_terminator().as_bytes())
|
self.write(b"\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write the given bytes using the give style.
|
/// Write the given bytes using the give style.
|
||||||
@ -774,7 +774,7 @@ impl<'p, 's, M: Matcher, W: WriteColor> Sink for SummarySink<'p, 's, M, W> {
|
|||||||
if show_count {
|
if show_count {
|
||||||
self.write_path_field()?;
|
self.write_path_field()?;
|
||||||
self.write(self.match_count.to_string().as_bytes())?;
|
self.write(self.match_count.to_string().as_bytes())?;
|
||||||
self.write_line_term(searcher)?;
|
self.write_line_term()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SummaryKind::CountMatches => {
|
SummaryKind::CountMatches => {
|
||||||
@ -785,17 +785,17 @@ impl<'p, 's, M: Matcher, W: WriteColor> Sink for SummarySink<'p, 's, M, W> {
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.expect("CountMatches should enable stats tracking");
|
.expect("CountMatches should enable stats tracking");
|
||||||
self.write(stats.matches().to_string().as_bytes())?;
|
self.write(stats.matches().to_string().as_bytes())?;
|
||||||
self.write_line_term(searcher)?;
|
self.write_line_term()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SummaryKind::PathWithMatch => {
|
SummaryKind::PathWithMatch => {
|
||||||
if self.match_count > 0 {
|
if self.match_count > 0 {
|
||||||
self.write_path_line(searcher)?;
|
self.write_path_line()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SummaryKind::PathWithoutMatch => {
|
SummaryKind::PathWithoutMatch => {
|
||||||
if self.match_count == 0 {
|
if self.match_count == 0 {
|
||||||
self.write_path_line(searcher)?;
|
self.write_path_line()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SummaryKind::Quiet => {}
|
SummaryKind::Quiet => {}
|
||||||
@ -806,6 +806,7 @@ impl<'p, 's, M: Matcher, W: WriteColor> Sink for SummarySink<'p, 's, M, W> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use grep_matcher::LineTerminator;
|
||||||
use grep_regex::RegexMatcher;
|
use grep_regex::RegexMatcher;
|
||||||
use grep_searcher::SearcherBuilder;
|
use grep_searcher::SearcherBuilder;
|
||||||
use termcolor::NoColor;
|
use termcolor::NoColor;
|
||||||
@ -1163,4 +1164,24 @@ and exhibited clearly, with a label attached.
|
|||||||
// mush on to find all matches.
|
// mush on to find all matches.
|
||||||
assert_eq!(3, match_count);
|
assert_eq!(3, match_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn use_standard_line_terminator() {
|
||||||
|
let matcher = RegexMatcher::new(r"Watson|Sherlock").unwrap();
|
||||||
|
let mut printer = SummaryBuilder::new()
|
||||||
|
.kind(SummaryKind::CountMatches)
|
||||||
|
.build_no_color(vec![]);
|
||||||
|
SearcherBuilder::new()
|
||||||
|
.line_terminator(LineTerminator::byte(0))
|
||||||
|
.build()
|
||||||
|
.search_reader(
|
||||||
|
&matcher,
|
||||||
|
SHERLOCK,
|
||||||
|
printer.sink_with_path(&matcher, "sherlock"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let got = printer_contents(&mut printer);
|
||||||
|
assert_eq_printed!("sherlock:4\n", got);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user