From 979a6c597923e8f7c94f1cb361e4872ee2cc5338 Mon Sep 17 00:00:00 2001 From: teesh3rt Date: Thu, 27 Mar 2025 16:45:52 +0200 Subject: [PATCH] feat: add some more functions to input --- coreutils/src/commands/tee.rs | 2 +- utils/src/input.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/coreutils/src/commands/tee.rs b/coreutils/src/commands/tee.rs index ed8bf38..46bbe71 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 boxutils::input::get_like_repl(&mut buffer) { + while boxutils::input::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 index dfeb1da..067a71f 100644 --- a/utils/src/input.rs +++ b/utils/src/input.rs @@ -1,4 +1,10 @@ +use std::io::Read; + // this function makes it so that an EOF (commonly used in pipes) stops the repl -pub fn get_like_repl(buffer: &mut String) -> bool { +pub fn repl(buffer: &mut String) -> bool { std::io::stdin().read_line(buffer).unwrap_or(0) > 0 } + +pub fn repl_with_file(file: &mut Box, buffer: &mut String) -> bool { + file.read_to_string(buffer).unwrap_or(0) > 0 +} \ No newline at end of file