summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Geary <rtgnj42@gmail.com>2019-09-29 23:06:30 -0400
committerRyan Geary <rtgnj42@gmail.com>2019-09-29 23:10:33 -0400
commit09ddbb4f659076e08b2e85fb65fea97623178eb7 (patch)
treec206a005e35ee7c460800bbcf01c9038c53b96ff
parentba26c1f42d9cc0ff8e06982d9456479881da8f0a (diff)
Use BufWriter and write(ln)! instead of print(ln)!
-rw-r--r--src/choice.rs10
-rw-r--r--src/main.rs10
2 files changed, 15 insertions, 5 deletions
diff --git a/src/choice.rs b/src/choice.rs
index ab56fc0..eb20dc4 100644
--- a/src/choice.rs
+++ b/src/choice.rs
@@ -172,6 +172,7 @@ mod tests {
}
+use crate::io::{BufWriter, Write};
use regex::Regex;
use std::convert::TryInto;
use std::num::ParseIntError;
@@ -214,8 +215,13 @@ pub enum Choice {
}
impl Choice {
- pub fn print_choice(&self, line: &String, opt: &Opt) {
- print!("{}", self.get_choice_slice(line, opt).join(" "));
+ pub fn print_choice(
+ &self,
+ line: &String,
+ opt: &Opt,
+ handle: &mut BufWriter<std::io::StdoutLock>,
+ ) {
+ write!(handle, "{}", self.get_choice_slice(line, opt).join(" "));
}
fn get_choice_slice<'a>(&self, line: &'a String, opt: &Opt) -> Vec<&'a str> {
diff --git a/src/main.rs b/src/main.rs
index 063fa39..b3bdc29 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,5 +1,5 @@
use std::fs::File;
-use std::io::{self, BufRead, BufReader, Read};
+use std::io::{self, BufRead, BufReader, Read, Write};
use structopt::StructOpt;
mod choice;
@@ -14,14 +14,18 @@ fn main() {
let buf = BufReader::new(read);
+ let stdout = io::stdout();
+ let lock = stdout.lock();
+ let mut handle = io::BufWriter::new(lock);
+
let lines = buf.lines();
for line in lines {
match line {
Ok(l) => {
for choice in &opt.choice {
- choice.print_choice(&l, &opt);
+ choice.print_choice(&l, &opt, &mut handle);
}
- println!();
+ writeln!(handle, "");
}
Err(e) => println!("ERROR: {}", e),
}