@@ -31,7 +31,6 @@ pub enum EventLoopResult {
31
31
Select ,
32
32
}
33
33
34
- // TODO: add performance using output buffer
35
34
pub fn enter_event_loop < W : Write , S : CalculateResizeHint > (
36
35
state : & mut S ,
37
36
function_component : & mut impl FunctionComponent < W , S > ,
@@ -41,15 +40,15 @@ pub fn enter_event_loop<W: Write, S: CalculateResizeHint>(
41
40
enable_raw_mode ( ) ?;
42
41
43
42
// Use to handle clean up.
44
- #[ allow( unused_assignments) ]
45
- let mut maybe_return_this: Option < EventLoopResult > = None ;
43
+ let return_this: EventLoopResult ;
46
44
47
45
// First render before blocking the main thread for user input.
48
46
function_component. render ( state) ?;
49
47
50
48
loop {
51
49
let key_event = read_key_press ( ) ;
52
- match on_keypress ( state, key_event) {
50
+ let it = on_keypress ( state, key_event) ;
51
+ match it {
53
52
EventLoopResult :: ContinueAndRerenderAndClear => {
54
53
// Clear the viewport.
55
54
function_component. clear_viewport_for_resize ( state) ?;
@@ -65,31 +64,26 @@ pub fn enter_event_loop<W: Write, S: CalculateResizeHint>(
65
64
}
66
65
EventLoopResult :: ExitWithResult ( it) => {
67
66
// Break the loop and return the result.
68
- maybe_return_this = Some ( EventLoopResult :: ExitWithResult ( it) ) ;
67
+ return_this = EventLoopResult :: ExitWithResult ( it) ;
69
68
function_component. clear_viewport ( state) ?;
70
69
break ;
71
70
}
72
71
EventLoopResult :: ExitWithoutResult => {
73
72
// Break the loop and return the result.
74
- maybe_return_this = Some ( EventLoopResult :: ExitWithoutResult ) ;
73
+ return_this = EventLoopResult :: ExitWithoutResult ;
75
74
function_component. clear_viewport ( state) ?;
76
75
break ;
77
76
}
78
77
EventLoopResult :: ExitWithError => {
79
- maybe_return_this = Some ( EventLoopResult :: ExitWithError ) ;
78
+ return_this = EventLoopResult :: ExitWithError ;
80
79
function_component. clear_viewport ( state) ?;
81
80
break ;
82
81
}
83
82
}
84
83
}
85
84
86
85
// Perform cleanup of raw mode, and show cursor.
87
- match maybe_return_this {
88
- Some ( it) => {
89
- execute ! ( function_component. get_write( ) , Show ) ?;
90
- disable_raw_mode ( ) ?;
91
- Ok ( it)
92
- }
93
- None => Ok ( EventLoopResult :: ExitWithoutResult ) ,
94
- }
86
+ execute ! ( function_component. get_write( ) , Show ) ?;
87
+ disable_raw_mode ( ) ?;
88
+ Ok ( return_this)
95
89
}
0 commit comments