Skip to content

Commit 8a7158b

Browse files
unhappychoiceclaude
andcommitted
fix: redraw when UI state changes without animation progress
The run loop only redrew when the animation engine advanced, so the initial watch screen and the startup HEAD display could stay blank. Force a redraw on the first frame, after showing the startup HEAD, and after any terminal event. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9cfdddf commit 8a7158b

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

‎src/ui.rs‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub struct UI<'a> {
6666
menu_index: usize,
6767
prev_state: Option<Box<UIState>>,
6868
watcher: Option<CommitWatcher>,
69+
force_redraw: bool,
6970
}
7071

7172
impl<'a> UI<'a> {
@@ -133,6 +134,7 @@ impl<'a> UI<'a> {
133134
menu_index: 0,
134135
prev_state: None,
135136
watcher: None,
137+
force_redraw: true,
136138
}
137139
}
138140

@@ -410,6 +412,7 @@ impl<'a> UI<'a> {
410412
};
411413
self.engine.load_commit(&metadata);
412414
while self.engine.manual_step(StepMode::Change) {}
415+
self.force_redraw = true;
413416
}
414417

415418
fn poll_watcher(&mut self, now: Instant) {
@@ -569,6 +572,7 @@ impl<'a> UI<'a> {
569572
}
570573

571574
fn handle_event(&mut self, event: Event) {
575+
self.force_redraw = true;
572576
if let Event::Key(key) = event {
573577
self.handle_key_event(key);
574578
}
@@ -633,7 +637,7 @@ impl<'a> UI<'a> {
633637
self.sync_exit_state();
634638

635639
self.update_viewport(terminal.size()?.into());
636-
let needs_redraw = self.engine.tick();
640+
let needs_redraw = self.engine.tick() | std::mem::take(&mut self.force_redraw);
637641
self.draw_if_needed(terminal, needs_redraw)?;
638642
self.handle_pending_event(&mut poll, &mut read)?;
639643

@@ -1760,6 +1764,18 @@ mod tests {
17601764
while ui.engine.manual_step(StepMode::Change) {}
17611765
}
17621766

1767+
#[test]
1768+
fn run_loop_draws_first_frame_even_without_animation_progress() {
1769+
let mut ui = test_ui();
1770+
ui.state = UIState::Watching;
1771+
let mut terminal = Terminal::new(TestBackend::new(100, 30)).unwrap();
1772+
1773+
ui.run_loop_with(&mut terminal, |_| Ok(true), quit_event, Instant::now)
1774+
.unwrap();
1775+
1776+
assert!(buffer_text(terminal.backend().buffer()).contains("Watching for new commits..."));
1777+
}
1778+
17631779
#[test]
17641780
fn watch_mode_shows_head_in_final_state_without_playing_it() {
17651781
let test_repo = TestRepo::new();
@@ -1774,6 +1790,7 @@ mod tests {
17741790
assert!(ui.history.is_empty());
17751791
assert!(ui.engine.is_finished());
17761792
assert_eq!(ui.engine.current_metadata().unwrap().hash, head);
1793+
assert!(ui.force_redraw);
17771794
}
17781795

17791796
#[test]

0 commit comments

Comments
 (0)