Skip to content

Commit 4694e1f

Browse files
committed
[tuify] Refactor event loop code
1 parent 62c564d commit 4694e1f

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

docs/dd_editor_component.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl EditorEngine {
159159
}
160160

161161
pub struct EditorBuffer {
162-
// TODO
162+
163163
}
164164
```
165165

tuify/src/event_loop.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ pub enum EventLoopResult {
3131
Select,
3232
}
3333

34-
// TODO: add performance using output buffer
3534
pub 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
}

tuify/src/giti/branch/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
pub mod delete;
2-
pub use delete::*;
2+
pub use delete::*;

tuify/src/giti/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
pub mod branch;
2-
pub use branch::*;
2+
pub use branch::*;

0 commit comments

Comments
 (0)