feat: add a convenience function for repls, will be useful later!
This commit is contained in:
parent
54bf70bca1
commit
a5f2f1866b
3 changed files with 7 additions and 2 deletions
|
|
@ -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();
|
||||
|
|
|
|||
4
utils/src/input.rs
Normal file
4
utils/src/input.rs
Normal file
|
|
@ -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
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
pub mod args;
|
||||
pub mod commands;
|
||||
pub mod registry;
|
||||
pub mod encoding;
|
||||
pub mod input;
|
||||
pub mod registry;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue