diff options
author | Andrew Gallant <jamslam@gmail.com> | 2016-09-13 21:11:46 -0400 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2016-09-13 21:11:46 -0400 |
commit | fdca74148dbb168035f538506621e59b92766090 (patch) | |
tree | 40abfca4c8d3686a986d6551fd35a95463aa910e /src/search_buffer.rs | |
parent | f11d9fb9221a8c20452dee82af6429e88a8f2785 (diff) |
Stream results when feasible.0.0.19
For example, when only a single file (or stdin) is being searched, then we
should be able to print directly to the terminal instead of intermediate
buffers. (The buffers are only necessary for parallelism.)
Closes #4.
Diffstat (limited to 'src/search_buffer.rs')
-rw-r--r-- | src/search_buffer.rs | 31 |
1 files changed, 6 insertions, 25 deletions
diff --git a/src/search_buffer.rs b/src/search_buffer.rs index d91c1a82..fb16bf0b 100644 --- a/src/search_buffer.rs +++ b/src/search_buffer.rs @@ -151,10 +151,10 @@ impl<'a, W: Send + Terminal> BufferSearcher<'a, W> { mod tests { use std::path::Path; - use grep::{Grep, GrepBuilder}; - use term::Terminal; + use grep::GrepBuilder; + use term::{Terminal, TerminfoTerminal}; - use out::OutBuffer; + use out::ColoredTerminal; use printer::Printer; use super::BufferSearcher; @@ -168,38 +168,19 @@ but Doctor Watson has to have it taken out for him and dusted, and exhibited clearly, with a label attached.\ "; - const CODE: &'static str = "\ -extern crate snap; - -use std::io; - -fn main() { - let stdin = io::stdin(); - let stdout = io::stdout(); - - // Wrap the stdin reader in a Snappy reader. - let mut rdr = snap::Reader::new(stdin.lock()); - let mut wtr = stdout.lock(); - io::copy(&mut rdr, &mut wtr).expect(\"I/O operation failed\"); -} -"; - - fn matcher(pat: &str) -> Grep { - GrepBuilder::new(pat).build().unwrap() - } - fn test_path() -> &'static Path { &Path::new("/baz.rs") } - type TestSearcher<'a> = BufferSearcher<'a, OutBuffer>; + type TestSearcher<'a> = + BufferSearcher<'a, ColoredTerminal<TerminfoTerminal<Vec<u8>>>>; fn search<F: FnMut(TestSearcher) -> TestSearcher>( pat: &str, haystack: &str, mut map: F, ) -> (u64, String) { - let outbuf = OutBuffer::NoColor(vec![]); + let outbuf = ColoredTerminal::NoColor(vec![]); let mut pp = Printer::new(outbuf).with_filename(true); let grep = GrepBuilder::new(pat).build().unwrap(); let count = { |