@@ -31,7 +31,6 @@ pub enum EventLoopResult {
3131 Select ,
3232}
3333
34- // TODO: add performance using output buffer
3534pub fn enter_event_loop < W : Write , S : CalculateResizeHint > (
3635 state : & mut S ,
3736 function_component : & mut impl FunctionComponent < W , S > ,
@@ -41,15 +40,15 @@ pub fn enter_event_loop<W: Write, S: CalculateResizeHint>(
4140 enable_raw_mode ( ) ?;
4241
4342 // Use to handle clean up.
44- #[ allow( unused_assignments) ]
45- let mut maybe_return_this: Option < EventLoopResult > = None ;
43+ let return_this: EventLoopResult ;
4644
4745 // First render before blocking the main thread for user input.
4846 function_component. render ( state) ?;
4947
5048 loop {
5149 let key_event = read_key_press ( ) ;
52- match on_keypress ( state, key_event) {
50+ let it = on_keypress ( state, key_event) ;
51+ match it {
5352 EventLoopResult :: ContinueAndRerenderAndClear => {
5453 // Clear the viewport.
5554 function_component. clear_viewport_for_resize ( state) ?;
@@ -65,31 +64,26 @@ pub fn enter_event_loop<W: Write, S: CalculateResizeHint>(
6564 }
6665 EventLoopResult :: ExitWithResult ( it) => {
6766 // Break the loop and return the result.
68- maybe_return_this = Some ( EventLoopResult :: ExitWithResult ( it) ) ;
67+ return_this = EventLoopResult :: ExitWithResult ( it) ;
6968 function_component. clear_viewport ( state) ?;
7069 break ;
7170 }
7271 EventLoopResult :: ExitWithoutResult => {
7372 // Break the loop and return the result.
74- maybe_return_this = Some ( EventLoopResult :: ExitWithoutResult ) ;
73+ return_this = EventLoopResult :: ExitWithoutResult ;
7574 function_component. clear_viewport ( state) ?;
7675 break ;
7776 }
7877 EventLoopResult :: ExitWithError => {
79- maybe_return_this = Some ( EventLoopResult :: ExitWithError ) ;
78+ return_this = EventLoopResult :: ExitWithError ;
8079 function_component. clear_viewport ( state) ?;
8180 break ;
8281 }
8382 }
8483 }
8584
8685 // 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)
9589}
0 commit comments