mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-20 19:50:55 +03:00
49 lines
1.5 KiB
Rust
49 lines
1.5 KiB
Rust
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)
|
|
}
|