#grep #pattern #print #printer #sink


An implementation of the grep crate’s Sink trait that provides standard printing of search results, similar to grep itself

3 unstable releases

0.1.1 Sep 7, 2018
0.1.0 Aug 20, 2018
0.0.1 Aug 8, 2018

#4 in #print

Download history 552/week @ 2018-11-27 554/week @ 2018-12-04 741/week @ 2018-12-11 526/week @ 2018-12-18 486/week @ 2018-12-25 496/week @ 2019-01-01 588/week @ 2019-01-08 608/week @ 2019-01-15 466/week @ 2019-01-22 616/week @ 2019-01-29 617/week @ 2019-02-05 513/week @ 2019-02-12 406/week @ 2019-02-19 488/week @ 2019-02-26 508/week @ 2019-03-05

35 downloads per month
Used in 2 crates (1 directly)


10K SLoC


Print results from line oriented searching in a human readable, aggregate or JSON Lines format.

Linux build status Windows build status

Dual-licensed under MIT or the UNLICENSE.



NOTE: You probably don't want to use this crate directly. Instead, you should prefer the facade defined in the grep crate.


Add this to your Cargo.toml:

grep-printer = "0.1"

and this to your crate root:

extern crate grep_printer;


This crate provides featureful and fast printers that interoperate with the grep-searcher crate.

Brief overview

The Standard printer shows results in a human readable format, and is modeled after the formats used by standard grep-like tools. Features include, but are not limited to, cross platform terminal coloring, search & replace, multi-line result handling and reporting summary statistics.

The JSON printer shows results in a machine readable format. To facilitate a stream of search results, the format uses JSON Lines by emitting a series of messages as search results are found.

The Summary printer shows aggregate results for a single search in a human readable format, and is modeled after similar formats found in standard grep-like tools. This printer is useful for showing the total number of matches and/or printing file paths that either contain or don't contain matches.


This example shows how to create a "standard" printer and execute a search.

extern crate grep_regex;
extern crate grep_printer;
extern crate grep_searcher;

use std::error::Error;

use grep_regex::RegexMatcher;
use grep_printer::Standard;
use grep_searcher::Searcher;

const SHERLOCK: &'static [u8] = b"\
For the Doctor Watsons of this world, as opposed to the Sherlock
Holmeses, success in the province of detective work must always
be, to a very large extent, the result of luck. Sherlock Holmes
can extract a clew from a wisp of straw or a flake of cigar ash;
but Doctor Watson has to have it taken out for him and dusted,
and exhibited clearly, with a label attached.

# fn main() { example().unwrap(); }
fn example() -> Result<(), Box<Error>> {
let matcher = RegexMatcher::new(r"Sherlock")?;
let mut printer = Standard::new_no_color(vec![]);
Searcher::new().search_slice(&matcher, SHERLOCK, printer.sink(&matcher))?;

// into_inner gives us back the underlying writer we provided to
// new_no_color, which is wrapped in a termcolor::NoColor. Thus, a second
// into_inner gives us back the actual buffer.
let output = String::from_utf8(printer.into_inner().into_inner())?;
let expected = "\
1:For the Doctor Watsons of this world, as opposed to the Sherlock
3:be, to a very large extent, the result of luck. Sherlock Holmes
assert_eq!(output, expected);


~144K SLoC