@@ -23,6 +23,7 @@ pub struct Confirm<'a> {
2323 prompt : String ,
2424 default : bool ,
2525 show_default : bool ,
26+ disable_default : bool ,
2627 wait_for_newline : bool ,
2728 theme : & ' a dyn Theme ,
2829}
@@ -60,6 +61,7 @@ impl<'a> Confirm<'a> {
6061 prompt : "" . into ( ) ,
6162 default : true ,
6263 show_default : true ,
64+ disable_default : false ,
6365 wait_for_newline : false ,
6466 theme,
6567 }
@@ -109,6 +111,16 @@ impl<'a> Confirm<'a> {
109111 self
110112 }
111113
114+ /// Select whether the user must explicitly confirm their selection.
115+ ///
116+ /// When `false` (default), the user can input a newline to select the default.
117+ ///
118+ /// When `true`, the user must input a letter - a newline will do nothing.
119+ pub fn disable_default ( & mut self , val : bool ) -> & mut Confirm < ' a > {
120+ self . disable_default = val;
121+ self
122+ }
123+
112124 /// Enables user interaction and returns the result.
113125 ///
114126 /// If the user confirms the result is `true`, `false` if declines or default (configured in [default](#method.default)) if pushes enter.
@@ -156,7 +168,7 @@ impl<'a> Confirm<'a> {
156168 let rv = match & * input_buf. trim_end ( ) . to_lowercase ( ) {
157169 "y" | "yes" => true ,
158170 "n" | "no" => false ,
159- "" => self . default ,
171+ "" if ! self . disable_default => self . default ,
160172 _ => {
161173 // On invalid input re-render the user prompt.
162174 render. confirm_prompt ( & self . prompt , default) ?;
@@ -178,7 +190,7 @@ impl<'a> Confirm<'a> {
178190 let rv = match input {
179191 'y' | 'Y' => true ,
180192 'n' | 'N' => false ,
181- '\n' | '\r' => self . default ,
193+ '\n' | '\r' if ! self . disable_default => self . default ,
182194 _ => {
183195 continue ;
184196 }
0 commit comments