From 17b3334aeaab0167a48087d3abe3bda9e7e3c56b Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Wed, 21 Aug 2024 11:05:43 +0300 Subject: [PATCH] fix: prompt via readline --- src/helpers.rs | 9 --------- src/main.rs | 4 ++-- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/helpers.rs b/src/helpers.rs index 7cafdf7..99792e6 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -10,15 +10,6 @@ pub fn some_non_empty(str: &str) -> Option { if str.is_empty() { None } else { Some(str.to_string()) } } -pub fn prompt(prompt: &str) -> Option { - print!("{} ", prompt); - stdout().flush().unwrap(); - match stdin().lines().next() { - Some(Ok(line)) => Some(line), - _ => None, - } -} - /// Parses the hour from a plain number in the String, /// with max of max_future hours into the future. pub fn parse_hour(str: &str, max_future: i64) -> Option> { diff --git a/src/main.rs b/src/main.rs index f8d1eaa..9b45530 100644 --- a/src/main.rs +++ b/src/main.rs @@ -168,7 +168,7 @@ async fn main() { Ok(Ok(key)) => key, _ => { warn!("Could not read keys from {}", keysfile.to_string_lossy()); - let keys = prompt("Secret key?") + let keys = or_warn!(rl.readline("Secret key? ")) .and_then(|s| or_warn!(Keys::from_str(&s))) .unwrap_or_else(|| { info!("Generating and persisting new key"); @@ -195,7 +195,7 @@ async fn main() { } Err(e) => { warn!("Could not read relays file: {}", e); - if let Some(line) = prompt("Relay?") { + if let Ok(line) = rl.readline("Relay? ") { let url = if line.contains("://") { line } else {