Skip to content

Commit d31f487

Browse files
committed
Use grep-cli for faster output
Rust io::Stdout support only line buffering, no block buffering, so we use a third party library to get it. See rust-lang/rust#60673
1 parent e716b3c commit d31f487

File tree

3 files changed

+113
-1
lines changed

3 files changed

+113
-1
lines changed

Cargo.lock

Lines changed: 108 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ categories = ["command-line-utilities"]
1717
structopt = "0.3.14"
1818
anyhow = "1.0.31"
1919
regex = "1.3.7"
20+
grep-cli = "0.1.5"
21+
termcolor = "1.1.2"
2022

2123
[dev-dependencies]
2224
assert_cmd = "1.0.1"

src/bin/tuc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use anyhow::{bail, Result};
2+
use grep_cli;
23
use regex::{escape, NoExpand, Regex};
34
use std::fmt;
45
use std::io::{BufRead, Write};
56
use std::str::FromStr;
67
use structopt::StructOpt;
8+
use termcolor;
79

810
#[derive(Debug, StructOpt)]
911
#[structopt(name = "tuc", about = "When cut doesn't cut it.")]
@@ -217,7 +219,7 @@ fn main() -> Result<()> {
217219
let re: Regex = Regex::new(format!("({})+", escape(&opt.delimiter)).as_ref()).unwrap();
218220

219221
let stdin = std::io::stdin();
220-
let mut stdout = std::io::stdout();
222+
let mut stdout = grep_cli::stdout(termcolor::ColorChoice::Never);
221223

222224
stdin
223225
.lock()

0 commit comments

Comments
 (0)