mirror of
https://github.com/herdrdev/herdr.git
synced 2026-09-22 16:01:07 +00:00
fix: skip unchanged status command renders
This commit is contained in:
+6
-1
@@ -64,6 +64,11 @@ impl App {
|
||||
results,
|
||||
cache_updates,
|
||||
} => self.handle_git_status_refreshed(results, cache_updates),
|
||||
AppEvent::TabBarCommandFinished {
|
||||
generation,
|
||||
segment_index,
|
||||
result,
|
||||
} => self.handle_tab_bar_command_finished(generation, segment_index, result),
|
||||
ev @ AppEvent::TerminalBell { .. } => {
|
||||
self.handle_internal_event(ev);
|
||||
false
|
||||
@@ -150,7 +155,7 @@ impl App {
|
||||
result,
|
||||
} = ev
|
||||
{
|
||||
self.handle_tab_bar_command_finished(generation, segment_index, result);
|
||||
let _ = self.handle_tab_bar_command_finished(generation, segment_index, result);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -2351,6 +2351,37 @@ mod tests {
|
||||
assert!(!app.git_refresh_in_flight);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tab_bar_command_events_render_only_when_visible_output_changes() {
|
||||
if !crate::platform::status_commands_supported() {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut app = test_app();
|
||||
app.configure_tab_bar_status(
|
||||
&[crate::config::TabBarRightEntryConfig::Command {
|
||||
command: "status".into(),
|
||||
interval_seconds: 5,
|
||||
timeout_seconds: 2,
|
||||
}],
|
||||
" ",
|
||||
);
|
||||
let generation = app.tab_bar_status_generation;
|
||||
let event = |generation, output: Option<&str>| AppEvent::TabBarCommandFinished {
|
||||
generation,
|
||||
segment_index: 0,
|
||||
result: Ok(output.map(str::to_string)),
|
||||
};
|
||||
|
||||
assert!(!app.handle_internal_event_with_prefix_sync(event(generation, None)));
|
||||
assert!(app.handle_internal_event_with_prefix_sync(event(generation, Some("ready"))));
|
||||
assert!(!app.handle_internal_event_with_prefix_sync(event(generation, Some("ready"))));
|
||||
assert!(!app.handle_internal_event_with_prefix_sync(event(
|
||||
generation.wrapping_add(1),
|
||||
Some("stale"),
|
||||
)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn git_status_event_clears_in_flight_refresh() {
|
||||
let mut app = test_app();
|
||||
|
||||
@@ -174,16 +174,16 @@ impl App {
|
||||
generation: u64,
|
||||
segment_index: usize,
|
||||
result: Result<Option<String>, String>,
|
||||
) {
|
||||
) -> bool {
|
||||
if generation != self.tab_bar_status_generation {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
let Some(runtime) = self
|
||||
.tab_bar_commands
|
||||
.iter_mut()
|
||||
.find(|runtime| runtime.segment_index == segment_index)
|
||||
else {
|
||||
return;
|
||||
return false;
|
||||
};
|
||||
runtime.task = None;
|
||||
|
||||
@@ -194,11 +194,14 @@ impl App {
|
||||
None
|
||||
}
|
||||
};
|
||||
if let Some(TabBarStatusSegment::Text(current)) =
|
||||
let Some(TabBarStatusSegment::Text(current)) =
|
||||
self.state.tab_bar_right.get_mut(segment_index)
|
||||
{
|
||||
*current = output;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
let changed = *current != output;
|
||||
*current = output;
|
||||
changed
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user