brain: Preserve footer context while loading
273ad484485a91256381d5371e27bda5e1177714
Keep the application and mode badges visible during repository work, and use smoother spinner frames for clearer activity feedback. Assisted-by: Codex:gpt-5.6-sol
1 parent
7fc72fc9
crates/brain/src/session/status.rs
+42 -16
| 67 | 67 | /// Separator shown between footer status segments: ·. |
|
| 68 | 68 | const FOOTER_SEPARATOR: &str = " · "; |
|
| 69 | 69 | /// Marker used when footer text truncates: …. |
|
| 70 | 70 | const FOOTER_ELLIPSIS: &str = "…"; |
|
| 71 | 71 | /// Frames used by the repository-operation status spinner. |
|
| 72 | - | const SPINNER_FRAMES: &[char] = &['|', '/', '-', '\\']; |
|
| 72 | + | const SPINNER_FRAMES: &[char] = &['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; |
|
| 73 | 73 | /// Separator shown between plain action hints. |
|
| 74 | 74 | const ACTION_SEPARATOR: &str = " · "; |
|
| 75 | 75 | /// Key label shown for Tab: ⭾. |
|
| 76 | 76 | const TAB_KEY: &str = "⭾"; |
|
| 77 | 77 | /// Key label shown for Return: ⮐. |
| 189 | 189 | fn bar(&self, cols: usize) -> HStack<'_> { |
|
| 190 | 190 | if let Some(error) = &self.error { |
|
| 191 | 191 | return HStack::default() |
|
| 192 | 192 | .child(recoverable_error(error, FOOTER_VALUE_FG, FOOTER_BG).truncated(cols, "")); |
|
| 193 | 193 | } |
|
| 194 | - | if let Some((operation, frame)) = self.loading { |
|
| 195 | - | let spinner = SPINNER_FRAMES[frame % SPINNER_FRAMES.len()]; |
|
| 196 | - | return HStack::default().child( |
|
| 197 | - | Line::blank() |
|
| 198 | - | .item(Label::from_char(spinner).fg(FOOTER_VALUE_FG)) |
|
| 199 | - | .item(Label::space()) |
|
| 200 | - | .item(Label::new(operation).fg(FOOTER_VALUE_FG)) |
|
| 201 | - | .style(Style::default().bg(FOOTER_BG)) |
|
| 202 | - | .truncated(cols, FOOTER_ELLIPSIS), |
|
| 203 | - | ); |
|
| 194 | + | if self.loading.is_some() { |
|
| 195 | + | return HStack::default().child(self.left_status().truncated(cols, FOOTER_ELLIPSIS)); |
|
| 204 | 196 | } |
|
| 205 | 197 | let right = self.right_status(); |
|
| 206 | 198 | let left_width = cols |
|
| 207 | 199 | .saturating_sub(right.width()) |
|
| 208 | 200 | .saturating_sub(STATUS_RIGHT_PADDING) |
| 215 | 207 | .child(Line::new(Label::space().bg(FOOTER_BG)).padded(STATUS_RIGHT_PADDING)) |
|
| 216 | 208 | } |
|
| 217 | 209 | ||
| 218 | 210 | /// Returns the left status section with application, mode, and review context. |
|
| 219 | 211 | fn left_status(&self) -> Line { |
|
| 220 | - | let context = match &self.context { |
|
| 221 | - | StatusContext::Commit { short, summary } => Line::blank() |
|
| 222 | - | .item(Label::new(short).fg(FOOTER_HASH_FG)) |
|
| 212 | + | let context = if let Some((operation, frame)) = self.loading { |
|
| 213 | + | let spinner = SPINNER_FRAMES[frame % SPINNER_FRAMES.len()]; |
|
| 214 | + | Line::new(Label::from_char(spinner).fg(FOOTER_VALUE_FG)) |
|
| 223 | 215 | .item(Label::space()) |
|
| 224 | - | .item(Label::new(summary).fg(FOOTER_SUMMARY_FG)), |
|
| 225 | - | StatusContext::Range(range) => Line::new(Label::new(range).fg(FOOTER_SUMMARY_FG)), |
|
| 216 | + | .item(Label::new(operation).fg(FOOTER_VALUE_FG)) |
|
| 217 | + | } else { |
|
| 218 | + | match &self.context { |
|
| 219 | + | StatusContext::Commit { short, summary } => Line::blank() |
|
| 220 | + | .item(Label::new(short).fg(FOOTER_HASH_FG)) |
|
| 221 | + | .item(Label::space()) |
|
| 222 | + | .item(Label::new(summary).fg(FOOTER_SUMMARY_FG)), |
|
| 223 | + | StatusContext::Range(range) => Line::new(Label::new(range).fg(FOOTER_SUMMARY_FG)), |
|
| 224 | + | } |
|
| 226 | 225 | }; |
|
| 227 | 226 | Line::blank() |
|
| 228 | 227 | .item( |
|
| 229 | 228 | Label::new(" brain ") |
|
| 230 | 229 | .fg(Color::White) |
| 686 | 685 | let status = buffer.line(0); |
|
| 687 | 686 | assert!(status.contains("patch does not apply")); |
|
| 688 | 687 | assert!(!status.contains("brain")); |
|
| 689 | 688 | } |
|
| 690 | 689 | ||
| 690 | + | #[test] |
|
| 691 | + | fn loading_status_preserves_application_and_mode() { |
|
| 692 | + | let mut status = Status { |
|
| 693 | + | mode: "commit", |
|
| 694 | + | context: StatusContext::Commit { |
|
| 695 | + | short: "1234567".to_owned(), |
|
| 696 | + | summary: "summary".to_owned(), |
|
| 697 | + | }, |
|
| 698 | + | progress: ReviewProgress::default(), |
|
| 699 | + | stats: DiffStat::default(), |
|
| 700 | + | palette: DiffPalette::default(), |
|
| 701 | + | visibility: Visibility::default(), |
|
| 702 | + | error: None, |
|
| 703 | + | loading: Some(("accepting hunk", 1)), |
|
| 704 | + | }; |
|
| 705 | + | let mut buffer = Buffer::empty(Rect::new(0, 0, 80, 1)); |
|
| 706 | + | ||
| 707 | + | status.render(buffer.area(), &mut buffer); |
|
| 708 | + | let rendered = buffer.line(0); |
|
| 709 | + | ||
| 710 | + | assert!(rendered.contains(" brain ")); |
|
| 711 | + | assert!(rendered.contains(" commit ")); |
|
| 712 | + | assert!(rendered.contains("⠙ accepting hunk")); |
|
| 713 | + | assert!(!rendered.contains("1234567")); |
|
| 714 | + | assert!(!rendered.contains("summary")); |
|
| 715 | + | } |
|
| 716 | + | ||
| 691 | 717 | #[test] |
|
| 692 | 718 | fn completed_commit_status_hides_diff_summary() { |
|
| 693 | 719 | let mut status = Status { |
|
| 694 | 720 | mode: "commit", |
|
| 695 | 721 | context: StatusContext::Commit { |