File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ use crate :: i18n:: t;
2+ use std:: io:: { self , Read , Write } ;
3+ use std:: process;
4+
5+ /// Waits for user to press any key
6+ ///
7+ /// # Arguments
8+ ///
9+ /// * `prompt` - Optional message to display. If None, a default message will be shown
10+ /// * `is_en` - Whether to display messages in English
11+ pub fn wait_for_key ( prompt : Option < & str > ) {
12+ if let Some ( msg) = prompt {
13+ print ! ( "{} " , msg) ;
14+ } else {
15+ print ! ( "{}" , t( "wait_for_key" ) ) ;
16+ }
17+ io:: stdout ( ) . flush ( ) . unwrap ( ) ;
18+ let mut buffer = [ 0u8 ; 1 ] ;
19+ io:: stdin ( ) . read_exact ( & mut buffer) . unwrap ( ) ;
20+ }
21+
22+ /// Waits for user input and then exits the program
23+ ///
24+ /// # Arguments
25+ ///
26+ /// * `msg` - Optional message to display before exiting. If None, a default message will be shown
27+ pub fn exit_on_keypress ( msg : Option < & str > ) {
28+ wait_for_key ( msg) ;
29+ process:: exit ( 0 ) ;
30+ }
Original file line number Diff line number Diff line change 1+ pub mod keypress;
You can’t perform that action at this time.
0 commit comments