This commit is contained in:
MeexReay 2025-02-09 01:30:59 +03:00
parent 4646c6b274
commit 3ba2b30008

42
main.rs
View File

@ -53,28 +53,30 @@ fn recv_loop(host: &str) -> Result<(), Box<dyn Error>> {
Ok(()) Ok(())
} }
fn read_host() -> Option<String> { fn get_input(prompt: &str, default: &str) -> String {
let mut out = stdout().lock(); let input = || -> Option<String> {
out.write_all("Host (default: meex.lol:11234) > ".as_bytes()).ok()?; let mut out = stdout().lock();
out.flush().ok()?; out.write_all(prompt.as_bytes()).ok()?;
stdin().lock().lines().next() out.flush().ok()?;
.map(|o| o.ok()) stdin().lock().lines().next()
.flatten() .map(|o| o.ok())
.map(|o| o.trim().to_string()) .flatten()
}();
if let Some(input) = &input {
if input.is_empty() {
default
} else {
input
}
} else {
default
}.to_string()
} }
fn main() { fn main() {
let host = read_host(); let host = get_input("Host (default: meex.lol:11234) > ", DEFAULT_HOST);
let prefix = get_input("Prefix (default: none) > ", "");
let host = if let Some(host) = &host {
if host.is_empty() {
DEFAULT_HOST
} else {
host
}
} else {
DEFAULT_HOST
}.to_string();
thread::spawn({ thread::spawn({
let host = host.clone(); let host = host.clone();
@ -87,6 +89,6 @@ fn main() {
let mut lines = stdin().lock().lines(); let mut lines = stdin().lock().lines();
while let Some(Ok(message)) = lines.next() { while let Some(Ok(message)) = lines.next() {
send_message(&host, &message).expect("Error sending message"); send_message(&host, &format!("{}{}", &prefix, &message)).expect("Error sending message");
} }
} }