pub fn ask(&self, substitute: Option<&'a str>) -> crate::Result<bool> {
        let message = match (self.placeholder, substitute) {
            (None, _) => Cow::Borrowed(self.prompt),
            (Some(_), None) => unreachable!("dev error, should be reported, we checked this won't happen"),
            (Some(placeholder), Some(subs)) => Cow::Owned(self.prompt.replace(placeholder, subs)),
        };

        // Ask the same question to end while no valid answers are given
        loop {
            print!("{} [{}Y{}/{}n{}] ", message, *colors::GREEN, *colors::RESET, *colors::RED, *colors::RESET);
            io::stdout().flush()?;

            let mut answer = String::new();
            io::stdin().read_line(&mut answer)?;

            answer.make_ascii_lowercase();
            match answer.trim() {
                "" | "y" | "yes" => return Ok(true),
                "n" | "no" => return Ok(false),
                _ => continue, // Try again
            }
        }
    }
/// Creates user message and receives a boolean input to be used on the program
Creates user message and receives a boolean input to be used on the program
Creates user message and receives a boolean input to be used on the program
pub fn ask(&self, substitute: Option<&'a str>) -> crate::Result<bool> {
        let message = match (self.placeholder, substitute) {
            (None, _) => Cow::Borrowed(self.prompt),
            (Some(_), None) => unreachable!("dev error, should be reported, we checked this won't happen"),
            (Some(placeholder), Some(subs)) => Cow::Owned(self.prompt.replace(placeholder, subs)),
        };
        // Ask the same question to end while no valid answers are given
        loop {
            print!("{} [{}Y{}/{}n{}] ", message, *colors::GREEN, *colors::RESET, *colors::RED, *colors::RESET);
            io::stdout().flush()?;
            let mut answer = String::new();
            io::stdin().read_line(&mut answer)?;
            answer.make_ascii_lowercase();
            match answer.trim() {
                "" | "y" | "yes" => return Ok(true),
                "n" | "no" => return Ok(false),
                _ => continue, // Try again
            }
        }
    }
pub fn ask ( & self , substitute : Option < & ' a str > ) -> crate :: Result < bool > { let message = match ( self . placeholder , substitute ) { ( None , _ ) => Cow :: Borrowed ( self . prompt ) , ( Some ( _ ) , None ) => unreachable ! ( " " ) , ( Some ( placeholder ) , Some ( subs ) ) => Cow :: Owned ( self . prompt . replace ( placeholder , subs ) ) , } ; // Ask the same question to end while no valid answers are given loop { print ! ( " " message colors GREEN colors RESET colors RED colors RESET ) ; io :: stdout ( ) . flush ( ) ? ; let mut answer = String :: new ( ) ; io :: stdin ( ) . read_line ( & mut answer ) ? ; answer . make_ascii_lowercase ( ) ; match answer . trim ( ) { " " | " " | " " => return Ok ( true ) , " " | " " => return Ok ( false ) , _ => continue , // Try again } } }
Creates user message and receives a boolean input to be used on the program
Creates user message and receives a boolean input to be used on the program
&self
substitute
Option<&'a str>
&self
substitute
Option<&'a str>