Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ clap = { version = "4.6.0", features = ["derive"] }
ratatui = "0.30.0"
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
tokio = { version = "1.48.0", features = ["rt", "sync", "time"] }
uuid = { version = "1.22.0", features = ["v4", "serde"] }

[dev-dependencies]
Expand Down
70 changes: 70 additions & 0 deletions src/cli/clean/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ impl CleanAnimation {
render_sections(&self.sections, true)
}

pub fn tick(&mut self) -> bool {
let mut changed = false;

for section in &mut self.sections {
changed |= tick_in_flight(&mut section.root);
}

changed
}

pub fn prime_resume(
&mut self,
restacked_branches: &[RestackPreview],
Expand Down Expand Up @@ -146,6 +156,16 @@ fn clear_in_flight(node: &mut VisualNode) {
}
}

fn tick_in_flight(node: &mut VisualNode) -> bool {
let mut changed = node.status.tick();

for child in &mut node.children {
changed |= tick_in_flight(child);
}

changed
}

#[cfg(test)]
mod tests {
use super::CleanAnimation;
Expand Down Expand Up @@ -306,4 +326,54 @@ mod tests {
)
);
}

#[test]
fn tick_advances_in_flight_throbber_without_changing_progress() {
let mut animation = CleanAnimation::new(&CleanPlan {
trunk_branch: "main".into(),
current_branch: "feat/auth".into(),
requested_branch_name: Some("feat/auth".into()),
candidates: vec![CleanCandidate {
node_id: Uuid::new_v4(),
branch_name: "feat/auth".into(),
parent_branch_name: "main".into(),
reason: CleanReason::IntegratedIntoParent {
parent_base: RestackBaseTarget::local("main"),
},
tree: CleanTreeNode {
branch_name: "feat/auth".into(),
children: vec![CleanTreeNode {
branch_name: "feat/auth-api".into(),
children: vec![],
}],
},
restack_plan: vec![],
depth: 0,
}],
blocked: vec![],
});

animation.apply_event(&CleanEvent::RebaseStarted {
branch_name: "feat/auth-api".into(),
onto_branch: "main".into(),
});
animation.apply_event(&CleanEvent::RebaseProgress {
branch_name: "feat/auth-api".into(),
onto_branch: "main".into(),
current_commit: 2,
total_commits: 5,
});

let before = animation.render_active();

assert!(animation.tick());

let after = animation.render_active();

assert!(before.contains("\u{1b}[34m/\u{1b}[0m"));
assert!(after.contains("\u{1b}[34m-\u{1b}[0m"));
assert!(before.contains("[2/5]"));
assert!(after.contains("[2/5]"));
assert!(after.contains("feat/auth-api"));
}
}
9 changes: 9 additions & 0 deletions src/cli/operation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ impl BranchStatus {
total_commits: Some(total_commits),
}
}

pub fn tick(&mut self) -> bool {
let Self::InFlight { frame_index, .. } = self else {
return false;
};

*frame_index = (*frame_index + 1) % markers::THROBBER_FRAMES.len();
true
}
}

pub fn render_sections(sections: &[OperationSection], final_view: bool) -> String {
Expand Down
Loading