lunar-lib 0.10.0

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 Prompter: OkayPrompter + AskPrompter {}

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