diff --git a/coreutils/src/commands/tee.rs b/coreutils/src/commands/tee.rs index e149097..ed8bf38 100644 --- a/coreutils/src/commands/tee.rs +++ b/coreutils/src/commands/tee.rs @@ -39,7 +39,7 @@ impl Command for Tee { } let mut buffer = String::new(); - while std::io::stdin().read_line(&mut buffer).unwrap_or(0) > 0 { + while boxutils::input::get_like_repl(&mut buffer) { for output in &mut writes { let _ = output.write_all(buffer.as_bytes()); let _ = output.flush(); diff --git a/utils/src/input.rs b/utils/src/input.rs new file mode 100644 index 0000000..dfeb1da --- /dev/null +++ b/utils/src/input.rs @@ -0,0 +1,4 @@ +// this function makes it so that an EOF (commonly used in pipes) stops the repl +pub fn get_like_repl(buffer: &mut String) -> bool { + std::io::stdin().read_line(buffer).unwrap_or(0) > 0 +} diff --git a/utils/src/lib.rs b/utils/src/lib.rs index 55df7ff..2cfa076 100644 --- a/utils/src/lib.rs +++ b/utils/src/lib.rs @@ -1,4 +1,5 @@ pub mod args; pub mod commands; +pub mod encoding; +pub mod input; pub mod registry; -pub mod encoding; \ No newline at end of file