2024-01-11 04:32:26 +00:00
|
|
|
use std::borrow::Borrow;
|
2023-12-21 17:04:35 +00:00
|
|
|
|
2023-12-22 19:39:25 +00:00
|
|
|
#[cfg(feature = "mnemonic")]
|
|
|
|
use keyfork_mnemonic_util::Wordlist;
|
|
|
|
|
2024-01-11 04:32:26 +00:00
|
|
|
pub mod terminal;
|
2024-01-09 07:21:46 +00:00
|
|
|
pub mod validators;
|
2024-01-11 04:32:26 +00:00
|
|
|
pub use terminal::{Terminal, DefaultTerminal, default_terminal};
|
2024-01-09 07:21:46 +00:00
|
|
|
|
2023-12-21 17:04:35 +00:00
|
|
|
#[derive(thiserror::Error, Debug)]
|
|
|
|
pub enum Error {
|
|
|
|
#[error("The given handler is not a TTY")]
|
|
|
|
NotATTY,
|
|
|
|
|
2024-01-09 07:21:46 +00:00
|
|
|
#[error("Validation of the input failed after {0} retries (last error: {1})")]
|
|
|
|
Validation(u8, String),
|
|
|
|
|
2023-12-21 17:04:35 +00:00
|
|
|
#[error("IO Error: {0}")]
|
|
|
|
IO(#[from] std::io::Error),
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type Result<T, E = Error> = std::result::Result<T, E>;
|
|
|
|
|
2023-12-28 22:54:38 +00:00
|
|
|
pub enum Message {
|
|
|
|
Text(String),
|
|
|
|
Data(String),
|
|
|
|
}
|
|
|
|
|
2024-01-11 04:28:56 +00:00
|
|
|
pub trait PromptHandler {
|
|
|
|
fn prompt_input(&mut self, prompt: &str) -> Result<String>;
|
|
|
|
|
|
|
|
fn prompt_wordlist(&mut self, prompt: &str, wordlist: &Wordlist) -> Result<String>;
|
|
|
|
|
|
|
|
#[cfg(feature = "mnemonic")]
|
|
|
|
fn prompt_validated_wordlist<V, F, E>(
|
|
|
|
&mut self,
|
|
|
|
prompt: &str,
|
|
|
|
wordlist: &Wordlist,
|
|
|
|
retries: u8,
|
|
|
|
validator_fn: F,
|
|
|
|
) -> Result<V, Error>
|
|
|
|
where
|
|
|
|
F: Fn(String) -> Result<V, E>,
|
|
|
|
E: std::error::Error;
|
|
|
|
|
|
|
|
fn prompt_passphrase(&mut self, prompt: &str) -> Result<String>;
|
|
|
|
|
|
|
|
fn prompt_validated_passphrase<V, F, E>(
|
|
|
|
&mut self,
|
|
|
|
prompt: &str,
|
|
|
|
retries: u8,
|
|
|
|
validator_fn: F,
|
|
|
|
) -> Result<V, Error>
|
|
|
|
where
|
|
|
|
F: Fn(String) -> Result<V, E>,
|
|
|
|
E: std::error::Error;
|
|
|
|
|
|
|
|
fn prompt_message(&mut self, prompt: impl Borrow<Message>) -> Result<()>;
|
|
|
|
}
|