30 lines
766 B
Rust
30 lines
766 B
Rust
use std::error::Error;
|
|
|
|
use async_std::io::stdin;
|
|
use futures::future::BoxFuture;
|
|
|
|
use super::Selector;
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
pub struct ConsoleSelector;
|
|
|
|
impl Selector for ConsoleSelector {
|
|
type Error = Box<dyn Error>;
|
|
type Response = BoxFuture<'static, Result<bool, Self::Error>>;
|
|
|
|
fn review(&self, message: String) -> Self::Response {
|
|
println!("{} (y/N) ", message);
|
|
let stdin = stdin();
|
|
Box::pin(async move {
|
|
let mut buffer = String::new();
|
|
stdin.read_line(&mut buffer).await?;
|
|
Ok(
|
|
match buffer.chars().next().unwrap_or('n').to_ascii_lowercase() {
|
|
'y' => true,
|
|
_ => false,
|
|
},
|
|
)
|
|
})
|
|
}
|
|
}
|