Closed erichutchins closed 3 years ago
That seems sensible. Could you send a PR?
An alternative implementation would be to take the stdout lock outside of the loop once and for all. Can you also test whether it has an impact on performance (with LZ4 and the index in page cache)?
If it does not, let's stick to not taking the lock explicitly.
I made a small PR for this issue following the examples from here: https://rust-cli.github.io/book/tutorial/output.html#a-note-on-printing-performance
The best practice according to BurntSushi is that you would want line buffering when printing to a tty but block buffering when the output is a file. I don’t know if you want to add any dependencies, but ripgrep has an underlying grep-cli
crate with a stdout function that addresses this: https://docs.rs/grep-cli/0.1.5/grep_cli/fn.stdout.html
I commonly use
head
to preview search results but this causes a panic. I resorted to some silly bash tricks to filter out this error.Would you be amenable to swapping
println
forwriteln
and ignoring broken pipes? Something like: