summaryrefslogtreecommitdiffstats
path: root/src/choice.rs
diff options
context:
space:
mode:
authorRyan Geary <rtgnj42@gmail.com>2020-06-24 21:08:15 -0400
committerRyan Geary <rtgnj42@gmail.com>2020-06-24 22:15:08 -0400
commit67ddbec6b59f8b79ca958bca2ce7cdf0507c3fdb (patch)
tree195e963fa1e6496f09525a316d444481fe6879b0 /src/choice.rs
parent2ee77aa848be60acdf75b02cf2a8c0ff97196ad1 (diff)
Use LineWriter when input is stdin (#10)feature/print-lines-when-stdin-is-pipe
Diffstat (limited to 'src/choice.rs')
-rw-r--r--src/choice.rs41
1 files changed, 13 insertions, 28 deletions
diff --git a/src/choice.rs b/src/choice.rs
index d7447fe..9df4580 100644
--- a/src/choice.rs
+++ b/src/choice.rs
@@ -1,5 +1,4 @@
use std::convert::TryInto;
-use std::io::{BufWriter, Write};
use std::iter::FromIterator;
use crate::config::Config;
@@ -36,12 +35,7 @@ impl Choice {
}
}
- pub fn print_choice<W: Write>(
- &self,
- line: &String,
- config: &Config,
- handle: &mut BufWriter<W>,
- ) {
+ pub fn print_choice<W: WriteReceiver>(&self, line: &String, config: &Config, handle: &mut W) {
if config.opt.character_wise {
let line_chars = line[0..line.len() - 1].chars();
self.print_choice_generic(line_chars, config, handle);
@@ -62,10 +56,10 @@ impl Choice {
self.negative_index
}
- fn print_choice_generic<W, T, I>(&self, mut iter: I, config: &Config, handle: &mut BufWriter<W>)
+ fn print_choice_generic<W, T, I>(&self, mut iter: I, config: &Config, handle: &mut W)
where
- W: Write,
- T: Writeable + Copy,
+ W: WriteReceiver,
+ T: Writeable,
I: Iterator<Item = T>,
{
if self.is_reverse_range() && !self.has_negative_index() {
@@ -81,23 +75,14 @@ impl Choice {
}
}
- fn print_choice_loop<W, T, I>(iter: I, config: &Config, handle: &mut BufWriter<W>)
- where
- W: Write,
- T: Writeable + Copy,
- I: Iterator<Item = T>,
- {
- Choice::print_choice_loop_max_items(iter, config, handle, isize::max_value());
- }
-
fn print_choice_loop_max_items<W, T, I>(
iter: I,
config: &Config,
- handle: &mut BufWriter<W>,
+ handle: &mut W,
max_items: isize,
) where
- W: Write,
- T: Writeable + Copy,
+ W: WriteReceiver,
+ T: Writeable,
I: Iterator<Item = T>,
{
let mut peek_iter = iter.peekable();
@@ -111,10 +96,10 @@ impl Choice {
}
}
- fn print_choice_negative<W, T, I>(&self, iter: I, config: &Config, handle: &mut BufWriter<W>)
+ fn print_choice_negative<W, T, I>(&self, iter: I, config: &Config, handle: &mut W)
where
- W: Write,
- T: Writeable + Copy,
+ W: WriteReceiver,
+ T: Writeable,
I: Iterator<Item = T>,
{
let vec = Vec::from_iter(iter);
@@ -136,10 +121,10 @@ impl Choice {
}
}
- fn print_choice_reverse<W, T, I>(&self, mut iter: I, config: &Config, handle: &mut BufWriter<W>)
+ fn print_choice_reverse<W, T, I>(&self, mut iter: I, config: &Config, handle: &mut W)
where
- W: Write,
- T: Writeable + Copy,
+ W: WriteReceiver,
+ T: Writeable,
I: Iterator<Item = T>,
{
if self.end > 0 {