mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-31 09:00:54 +03:00
Initial Hotplug support (#8)
This allows to dynamically add clients when an event is received from an unknown IP address. The user is asked to confirm any unknown connection from new clients. Currently the back-ends for event producing and consuming are not yet notified, so events will not be received and sent to the newly created clients.
This commit is contained in:
committed by
GitHub
parent
0feb1350a9
commit
225ef818a2
49
src/ioutils.rs
Normal file
49
src/ioutils.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use std::io::{self, Write};
|
||||
|
||||
use crate::client::Position;
|
||||
|
||||
|
||||
pub fn ask_confirmation(default: bool) -> Result<bool, io::Error> {
|
||||
eprint!("{}", if default {" [Y,n] "} else { " [y,N] "});
|
||||
io::stderr().flush()?;
|
||||
let answer = loop {
|
||||
let mut buffer = String::new();
|
||||
io::stdin().read_line(&mut buffer)?;
|
||||
let answer = buffer.to_lowercase();
|
||||
let answer = answer.trim();
|
||||
match answer {
|
||||
"" => break default,
|
||||
"y" => break true,
|
||||
"n" => break false,
|
||||
_ => {
|
||||
eprint!("Enter y for Yes or n for No: ");
|
||||
io::stderr().flush()?;
|
||||
continue
|
||||
}
|
||||
}
|
||||
};
|
||||
Ok(answer)
|
||||
}
|
||||
|
||||
pub fn ask_position() -> Result<Position, io::Error> {
|
||||
eprint!("Enter position - top (t) | bottom (b) | left(l) | right(r): ");
|
||||
io::stderr().flush()?;
|
||||
let pos = loop {
|
||||
let mut buffer = String::new();
|
||||
io::stdin().read_line(&mut buffer)?;
|
||||
let answer = buffer.to_lowercase();
|
||||
let answer = answer.trim();
|
||||
match answer {
|
||||
"t" | "top" => break Position::Top,
|
||||
"b" | "bottom" => break Position::Bottom,
|
||||
"l" | "left" => break Position::Right,
|
||||
"r" | "right" => break Position::Left,
|
||||
_ => {
|
||||
eprint!("Invalid position: {answer} - enter top (t) | bottom (b) | left(l) | right(r): ");
|
||||
io::stderr().flush()?;
|
||||
continue
|
||||
}
|
||||
};
|
||||
};
|
||||
Ok(pos)
|
||||
}
|
||||
Reference in New Issue
Block a user