fix: prompt via readline

This commit is contained in:
xeruf 2024-08-21 11:05:43 +03:00
parent 77ba311bab
commit 17b3334aea
2 changed files with 2 additions and 11 deletions

View File

@ -10,15 +10,6 @@ pub fn some_non_empty(str: &str) -> Option<String> {
if str.is_empty() { None } else { Some(str.to_string()) } if str.is_empty() { None } else { Some(str.to_string()) }
} }
pub fn prompt(prompt: &str) -> Option<String> {
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, /// Parses the hour from a plain number in the String,
/// with max of max_future hours into the future. /// with max of max_future hours into the future.
pub fn parse_hour(str: &str, max_future: i64) -> Option<DateTime<Local>> { pub fn parse_hour(str: &str, max_future: i64) -> Option<DateTime<Local>> {

View File

@ -168,7 +168,7 @@ async fn main() {
Ok(Ok(key)) => key, Ok(Ok(key)) => key,
_ => { _ => {
warn!("Could not read keys from {}", keysfile.to_string_lossy()); 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))) .and_then(|s| or_warn!(Keys::from_str(&s)))
.unwrap_or_else(|| { .unwrap_or_else(|| {
info!("Generating and persisting new key"); info!("Generating and persisting new key");
@ -195,7 +195,7 @@ async fn main() {
} }
Err(e) => { Err(e) => {
warn!("Could not read relays file: {}", 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("://") { let url = if line.contains("://") {
line line
} else { } else {