feat: add some more functions to input

This commit is contained in:
Teesh 2025-03-27 16:45:52 +02:00
parent 197248260b
commit 979a6c5979
2 changed files with 8 additions and 2 deletions

View file

@ -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();

View file

@ -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<dyn Read>, buffer: &mut String) -> bool {
file.read_to_string(buffer).unwrap_or(0) > 0
}