From 950a63c103dcc256c78ac3d94e92dd1196e2bdbd Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 11 Jun 2024 18:35:33 +0100 Subject: [PATCH] Moved stdin_input to stdin::input module, pulling it out of main --- side-node/src/main.rs | 16 ++-------------- side-node/src/stdin.rs | 12 ++++++++++++ 2 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 side-node/src/stdin.rs diff --git a/side-node/src/main.rs b/side-node/src/main.rs index 86c3c3a..29d2950 100644 --- a/side-node/src/main.rs +++ b/side-node/src/main.rs @@ -1,5 +1,3 @@ -use std::io::BufRead; - use bft_json_crdt::json_crdt::{BaseCrdt, SignedOp}; use cli::{parse_args, Commands}; use crdt::TransactionList; @@ -12,6 +10,7 @@ pub(crate) mod crdt; pub(crate) mod init; pub(crate) mod keys; pub(crate) mod node; +pub(crate) mod stdin; pub(crate) mod utils; pub(crate) mod websocket; @@ -46,7 +45,7 @@ async fn setup(name: &String) -> SideNode { let (incoming_sender, incoming_receiver) = mpsc::channel::(32); let (stdin_sender, stdin_receiver) = std::sync::mpsc::channel(); task::spawn(async move { - stdin_input(stdin_sender); + stdin::input(stdin_sender); }); // Finally, create the node and return it @@ -55,14 +54,3 @@ async fn setup(name: &String) -> SideNode { println!("Node setup complete."); node } - -/// Wait for stdin terminal input and send it to the node if any arrives -fn stdin_input(stdin_sender: std::sync::mpsc::Sender) { - let stdin = std::io::stdin(); - let lines = stdin.lock().lines(); - for line in lines { - println!("We're in stdin_input"); - let line = line.unwrap(); - stdin_sender.send(line).unwrap(); - } -} diff --git a/side-node/src/stdin.rs b/side-node/src/stdin.rs new file mode 100644 index 0000000..9d74705 --- /dev/null +++ b/side-node/src/stdin.rs @@ -0,0 +1,12 @@ +use std::io::BufRead; + +/// Wait for stdin terminal input and send it to the node if any arrives +pub(crate) fn input(stdin_sender: std::sync::mpsc::Sender) { + let stdin = std::io::stdin(); + let lines = stdin.lock().lines(); + for line in lines { + println!("We're in stdin_input"); + let line = line.unwrap(); + stdin_sender.send(line).unwrap(); + } +}