@@ -39,6 +39,7 @@ use console::{Key, Term};
39
39
/// ```
40
40
pub struct Input < ' a , T > {
41
41
prompt : String ,
42
+ report : bool ,
42
43
default : Option < T > ,
43
44
show_default : bool ,
44
45
initial_text : Option < String > ,
@@ -69,6 +70,14 @@ impl<T> Input<'_, T> {
69
70
self
70
71
}
71
72
73
+ /// Indicates whether to report the input value after interaction.
74
+ ///
75
+ /// The default is to report the input value.
76
+ pub fn report ( & mut self , val : bool ) -> & mut Self {
77
+ self . report = val;
78
+ self
79
+ }
80
+
72
81
/// Sets initial text that user can accept or erase.
73
82
pub fn with_initial_text < S : Into < String > > ( & mut self , val : S ) -> & mut Self {
74
83
self . initial_text = Some ( val. into ( ) ) ;
@@ -110,6 +119,7 @@ impl<'a, T> Input<'a, T> {
110
119
pub fn with_theme ( theme : & ' a dyn Theme ) -> Self {
111
120
Self {
112
121
prompt : "" . into ( ) ,
122
+ report : true ,
113
123
default : None ,
114
124
show_default : true ,
115
125
initial_text : None ,
@@ -403,7 +413,9 @@ where
403
413
}
404
414
}
405
415
406
- render. input_prompt_selection ( & self . prompt , & default. to_string ( ) ) ?;
416
+ if self . report {
417
+ render. input_prompt_selection ( & self . prompt , & default. to_string ( ) ) ?;
418
+ }
407
419
term. flush ( ) ?;
408
420
return Ok ( default. clone ( ) ) ;
409
421
} else if !self . permit_empty {
@@ -425,7 +437,9 @@ where
425
437
history. write ( & value) ;
426
438
}
427
439
428
- render. input_prompt_selection ( & self . prompt , & input) ?;
440
+ if self . report {
441
+ render. input_prompt_selection ( & self . prompt , & input) ?;
442
+ }
429
443
term. flush ( ) ?;
430
444
431
445
return Ok ( value) ;
@@ -492,7 +506,9 @@ where
492
506
}
493
507
}
494
508
495
- render. input_prompt_selection ( & self . prompt , & default. to_string ( ) ) ?;
509
+ if self . report {
510
+ render. input_prompt_selection ( & self . prompt , & default. to_string ( ) ) ?;
511
+ }
496
512
term. flush ( ) ?;
497
513
return Ok ( default. clone ( ) ) ;
498
514
} else if !self . permit_empty {
@@ -509,7 +525,9 @@ where
509
525
}
510
526
}
511
527
512
- render. input_prompt_selection ( & self . prompt , & input) ?;
528
+ if self . report {
529
+ render. input_prompt_selection ( & self . prompt , & input) ?;
530
+ }
513
531
term. flush ( ) ?;
514
532
515
533
return Ok ( value) ;
0 commit comments