From c81caa673b743bdac04db75c32957200bf549695 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Tue, 21 Nov 2023 07:40:56 -0500 Subject: [PATCH] core: fix file separator bug I introduced a regression in the migration off of the clap by having both the buffer writer and the printer be responsible for printing file separators in multi-threaded search. The buffer writer owns that responsibility in multi-threaded search. --- crates/core/flags/hiargs.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/core/flags/hiargs.rs b/crates/core/flags/hiargs.rs index 4f3b3f39..b4e0c096 100644 --- a/crates/core/flags/hiargs.rs +++ b/crates/core/flags/hiargs.rs @@ -592,7 +592,8 @@ impl HiArgs { &self, wtr: W, ) -> grep::printer::Standard { - grep::printer::StandardBuilder::new() + let mut builder = grep::printer::StandardBuilder::new(); + builder .byte_offset(self.byte_offset) .color_specs(self.colors.clone()) .column(self.column) @@ -615,10 +616,17 @@ impl HiArgs { self.field_match_separator.clone().into_bytes(), ) .separator_path(self.path_separator.clone()) - .separator_search(self.file_separator.clone()) .stats(self.stats.is_some()) - .trim_ascii(self.trim) - .build(wtr) + .trim_ascii(self.trim); + // When doing multi-threaded searching, the buffer writer is + // responsible for writing separators since it is the only thing that + // knows whether something has been printed or not. But for the single + // threaded case, we don't use a buffer writer and thus can let the + // printer own this. + if self.threads == 1 { + builder.separator_search(self.file_separator.clone()); + } + builder.build(wtr) } /// Builds a "summary" printer where search results are aggregated on a