lunar-lib 0.11.1

Common utilities for lunar applications
Documentation
use std::fmt::Display;

mod multiple_choice;
pub use multiple_choice::*;

#[cfg(feature = "cli-prompter")]
mod cli_prompter;
#[cfg(feature = "cli-prompter")]
pub use cli_prompter::*;

pub trait OkayPrompter {
    /// Tells the prompter to start an "Okay" prompt
    ///
    /// This prompt just requires user input for a confirmation something happend.
    /// An example usage is "Press any key to continue..."
    fn okay<T: Display>(&self, msg: T);
}

pub trait AskPrompter {
    /// Tells the prompter to start a "Yes/No" prompt
    ///
    /// This prompt just requires user input for a confirmation if they want to do something.
    /// An example usage is "Are you sure you want to do this? \[Y/n\]"
    ///
    /// This function should return [`None`] if the result couldn't be parsed
    fn ask<T: Display>(&self, msg: T, default: bool) -> Option<bool>;
}

pub trait TextPrompter {
    /// Tells the prompter to start a text input prompt
    ///
    /// This prompt requires the user to input a string.
    /// An example usage is "Enter your name below"
    ///
    /// If `secret` is true, the prompt is meant for secretive inputs, like entering passwords, where the text should be hidden
    ///
    /// This function should return [`None`] if the result couldn't be parsed
    fn text_prompt<T: Display>(
        &self,
        msg: T,
        secret: bool,
        default: Option<String>,
    ) -> Option<String>;
}

pub trait Prompter: OkayPrompter + AskPrompter {}

impl<T: OkayPrompter + AskPrompter> Prompter for T {}