Moved stdin_input to stdin::input module, pulling it out of main
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
use std::io::BufRead;
|
|
||||||
|
|
||||||
use bft_json_crdt::json_crdt::{BaseCrdt, SignedOp};
|
use bft_json_crdt::json_crdt::{BaseCrdt, SignedOp};
|
||||||
use cli::{parse_args, Commands};
|
use cli::{parse_args, Commands};
|
||||||
use crdt::TransactionList;
|
use crdt::TransactionList;
|
||||||
@@ -12,6 +10,7 @@ pub(crate) mod crdt;
|
|||||||
pub(crate) mod init;
|
pub(crate) mod init;
|
||||||
pub(crate) mod keys;
|
pub(crate) mod keys;
|
||||||
pub(crate) mod node;
|
pub(crate) mod node;
|
||||||
|
pub(crate) mod stdin;
|
||||||
pub(crate) mod utils;
|
pub(crate) mod utils;
|
||||||
pub(crate) mod websocket;
|
pub(crate) mod websocket;
|
||||||
|
|
||||||
@@ -46,7 +45,7 @@ async fn setup(name: &String) -> SideNode {
|
|||||||
let (incoming_sender, incoming_receiver) = mpsc::channel::<SignedOp>(32);
|
let (incoming_sender, incoming_receiver) = mpsc::channel::<SignedOp>(32);
|
||||||
let (stdin_sender, stdin_receiver) = std::sync::mpsc::channel();
|
let (stdin_sender, stdin_receiver) = std::sync::mpsc::channel();
|
||||||
task::spawn(async move {
|
task::spawn(async move {
|
||||||
stdin_input(stdin_sender);
|
stdin::input(stdin_sender);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Finally, create the node and return it
|
// Finally, create the node and return it
|
||||||
@@ -55,14 +54,3 @@ async fn setup(name: &String) -> SideNode {
|
|||||||
println!("Node setup complete.");
|
println!("Node setup complete.");
|
||||||
node
|
node
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wait for stdin terminal input and send it to the node if any arrives
|
|
||||||
fn stdin_input(stdin_sender: std::sync::mpsc::Sender<String>) {
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
12
side-node/src/stdin.rs
Normal file
12
side-node/src/stdin.rs
Normal file
@@ -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<String>) {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user