Repository navigation
feat(animation): implement typing animation engine - #16
Conversation
Add core animation system with the following features: - EditorBuffer for tracking file state - AnimationEngine with step-by-step playback - Character-by-character typing animation - Line insertion and deletion animations - Blinking cursor effect (500ms interval) - Configurable typing speed via --speed argument - Pause between hunks (1-3s) Integrate animation with UI: - EditorPane renders buffer content with cursor - StatusBarPane displays commit metadata - FileTreePane shows changed files with status icons - ~60fps event polling for smooth animation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
WalkthroughAdds a Rust-based typing animation system and integrates it into the UI: new animation module implements an editor buffer, granular animation steps, and an engine that generates and plays per-hunk edit sequences; main/UI and all panes updated to load commits, drive and render the animation, and surface commit metadata. Changes
Sequence Diagram(s)sequenceDiagram
participant Main as main.rs
participant UI as UI
participant Engine as AnimationEngine
participant Buffer as EditorBuffer
participant Panes as Render Panes
Main->>UI: new(speed_ms, is_commit_specified, repo)
Main->>UI: load_commit(metadata)
UI->>Engine: Engine::new(speed_ms)
UI->>Engine: load_commit(metadata)
Engine->>Engine: generate_steps_for_file()/hunk()
UI->>Engine: set_viewport_height(h)
loop UI loop (poll/tick)
UI->>Engine: tick()
alt step available
Engine->>Engine: execute_step(step)
Engine->>Buffer: mutate buffer (insert/delete/line)
Engine->>Engine: update_scroll()
Engine-->>UI: redraw_needed (true)
else no step
Engine-->>UI: redraw_needed (false)
end
UI->>Panes: render(engine, metadata)
Panes->>Buffer: read visible lines
Note over Panes,UI: cursor blink and terminal output handled from Engine state
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (7)
🧰 Additional context used🧬 Code graph analysis (7)src/panes/file_tree.rs (5)
src/panes/terminal.rs (3)
src/git.rs (1)
src/panes/editor.rs (3)
src/main.rs (2)
src/animation.rs (1)
src/ui.rs (1)
🔇 Additional comments (14)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Implement viewport-aware scrolling: - Calculate viewport height from terminal size - Update scroll_offset to center cursor line - Keep cursor in middle of screen during animation - Handle edge cases: - Top of file: scroll_offset stays at 0 - Bottom of file: show maximum visible content - Auto-update scroll after each animation step 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Support animating changes across multiple files: - Add SwitchFile animation step to switch between files - Track current_file_index in AnimationEngine - Process all files in commit sequentially - Add 1s pause before each file - Add 2s pause between files - Highlight current file in FileTreePane with dark gray background Animation flow: 1. Switch to file -> pause 1s 2. Animate hunks with 1.5s pause between hunks 3. Pause 2s before next file 4. Final pause 3s at end 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Move cursor to hunk start position before animating: - Add MoveCursor step at beginning of each hunk - Add 500ms pause after cursor movement - Makes hunk transitions more visible to user 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Replace instant cursor movement with smooth line-by-line animation: - Track cursor position through hunk processing - Generate MoveCursor steps for each line when moving between hunks - Move cursor line by line with 50ms pause per line - Move cursor during context lines within hunks - Add 300ms pause after cursor movement completes This makes cursor movement visible instead of teleporting, improving the visual flow of the animation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Implement Terminal pane animations showing git workflow: Before animation: - git checkout <parent_hash>^ (simulated parent commit) - Display checkout confirmation message After file editing: - git add . (stage changes) - git commit -m "message" (commit with actual commit message) - Show commit hash and file count - git push origin main (push simulation) - Enumerating objects - Counting objects - Writing objects - Show push confirmation Terminal display: - Command lines in green with bold ($-prefixed) - Output lines in normal style - Auto-scroll to show latest lines - Keep last N lines visible based on terminal height Animation flow: 1. Checkout parent -> 1s pause 2. (File editing animations) 3. git add -> 500ms pause 4. git commit -> show output -> 1s pause 5. git push -> progressive output -> 2s final pause 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Fix panic when inserting/deleting characters: - Convert char index to byte index before string operations - Handle multi-byte UTF-8 characters properly - Use char_indices() to find correct byte positions - Fix cursor rendering to use char indices not byte indices This prevents panic on line 42 when col exceeds byte length or when dealing with multi-byte characters like Japanese. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main.rs (1)
91-183: Remove the unusedprint_commit_infofunction (lines 91-183).The function is defined but never called anywhere in the codebase. This is dead code and should be removed to keep the codebase clean.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
src/animation.rs(1 hunks)src/main.rs(2 hunks)src/panes/editor.rs(1 hunks)src/panes/file_tree.rs(1 hunks)src/panes/status_bar.rs(2 hunks)src/panes/terminal.rs(1 hunks)src/ui.rs(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (7)
src/panes/status_bar.rs (2)
src/ui.rs (1)
render(106-143)src/panes/file_tree.rs (1)
render(13-65)
src/panes/editor.rs (2)
src/ui.rs (2)
render(106-143)new(29-39)src/animation.rs (2)
new(14-21)new(112-127)
src/main.rs (3)
src/git.rs (1)
open(94-98)src/animation.rs (2)
new(14-21)new(112-127)src/ui.rs (1)
new(29-39)
src/panes/file_tree.rs (5)
src/panes/terminal.rs (1)
render(13-48)src/ui.rs (2)
render(106-143)new(29-39)src/panes/editor.rs (1)
render(13-70)src/panes/status_bar.rs (1)
render(13-34)src/animation.rs (2)
new(14-21)new(112-127)
src/panes/terminal.rs (4)
src/ui.rs (2)
render(106-143)new(29-39)src/panes/file_tree.rs (1)
render(13-65)src/panes/editor.rs (1)
render(13-70)src/animation.rs (2)
new(14-21)new(112-127)
src/ui.rs (1)
src/animation.rs (3)
new(14-21)new(112-127)load_commit(134-233)
src/animation.rs (1)
src/ui.rs (2)
new(29-39)load_commit(41-44)
🔇 Additional comments (10)
src/main.rs (1)
71-89: LGTM! Clean integration flow.The main function correctly orchestrates repository loading, commit selection, and UI initialization. Error handling is appropriate with Result propagation throughout.
src/panes/status_bar.rs (1)
12-35: LGTM! Safe string handling.The metadata rendering logic correctly handles optional metadata with safe string slicing and fallback values. The hash truncation using
7.min(meta.hash.len())prevents panics on short hashes, and theunwrap_oron message extraction provides a sensible fallback.src/panes/file_tree.rs (1)
12-66: LGTM! Well-structured file tree rendering.The file tree rendering correctly maps file change statuses to colored indicators with appropriate fallback handling. The current file highlighting using index comparison is clean and efficient.
src/panes/terminal.rs (1)
12-49: LGTM! Robust terminal rendering.The terminal pane correctly handles dynamic content with safe arithmetic using
saturating_sub. The conditional styling for command lines (prefixed with "$ ") provides good visual distinction.src/ui.rs (3)
28-44: LGTM! Clean API integration.The constructor and
load_commitmethod provide a clean interface for initializing the UI with animation support. The delegation to the engine is appropriate.
68-77: Verify behavior on very small terminals.The viewport height calculation uses multiple
saturating_suboperations, which could result in a viewport height of 0 on very small terminals. For example, a terminal with 5 lines would result inviewport_height = 0after the calculations.Ensure the animation engine's
update_scrollmethod (line 427-449 in src/animation.rs) handlesviewport_height = 0gracefully, which it appears to do with the early return on line 428-430.
79-100: LGTM! Efficient render loop.The render loop correctly uses conditional redrawing based on the animation engine's tick result, avoiding unnecessary renders. The 16ms polling interval (~60fps) provides smooth animation while remaining responsive to user input.
src/animation.rs (3)
235-275: LGTM! Clear cursor movement logic.The cursor movement generation correctly handles both upward and downward movement with appropriate range constructions. The line-by-line animation with pauses provides good visual feedback.
337-425: LGTM! Well-structured animation loop.The tick/execute loop correctly handles cursor blinking, pauses, and step execution. The cursor continues blinking during pauses (line 348), which maintains visual continuity. All animation step variants are properly handled with appropriate cursor and buffer updates.
427-449: LGTM! Robust scroll management.The scroll update logic correctly handles three cases (top, middle, bottom) to keep the cursor visible and centered when possible. The early return for zero viewport height prevents division issues.
| pub fn load_commit(&mut self, metadata: &CommitMetadata) { | ||
| self.steps.clear(); | ||
| self.current_step = 0; | ||
| self.state = AnimationState::Playing; | ||
| self.current_file_index = 0; | ||
| self.terminal_lines.clear(); | ||
|
|
||
| // Git checkout to parent commit (simulation) | ||
| let parent_hash = format!("{}^", &metadata.hash[..7]); | ||
| self.steps | ||
| .push(AnimationStep::TerminalCommand { | ||
| command: format!("git checkout {}", parent_hash), | ||
| }); | ||
| self.steps.push(AnimationStep::Pause { duration_ms: 500 }); | ||
| self.steps.push(AnimationStep::TerminalOutput { | ||
| text: format!("HEAD is now at {} Previous commit", parent_hash), | ||
| }); | ||
| self.steps.push(AnimationStep::Pause { duration_ms: 1000 }); | ||
|
|
||
| // Process all file changes | ||
| for (index, change) in metadata.changes.iter().enumerate() { | ||
| // Add file switch step | ||
| let content = change.old_content.clone().unwrap_or_default(); | ||
| self.steps.push(AnimationStep::SwitchFile { | ||
| file_index: index, | ||
| content: content.clone(), | ||
| }); | ||
|
|
||
| // Add pause before starting file animation | ||
| self.steps.push(AnimationStep::Pause { duration_ms: 1000 }); | ||
|
|
||
| // Generate animation steps for this file | ||
| self.generate_steps_for_file(change); | ||
|
|
||
| // Add pause between files | ||
| if index < metadata.changes.len() - 1 { | ||
| self.steps.push(AnimationStep::Pause { duration_ms: 2000 }); | ||
| } | ||
| } | ||
|
|
||
| // Git add | ||
| self.steps.push(AnimationStep::Pause { duration_ms: 2000 }); | ||
| self.steps.push(AnimationStep::TerminalCommand { | ||
| command: "git add .".to_string(), | ||
| }); | ||
| self.steps.push(AnimationStep::Pause { duration_ms: 500 }); | ||
|
|
||
| // Git commit | ||
| let commit_message = metadata.message.lines().next().unwrap_or("Update"); | ||
| self.steps | ||
| .push(AnimationStep::TerminalCommand { | ||
| command: format!("git commit -m \"{}\"", commit_message), | ||
| }); | ||
| self.steps.push(AnimationStep::Pause { duration_ms: 800 }); | ||
| self.steps.push(AnimationStep::TerminalOutput { | ||
| text: format!("[main {}] {}", &metadata.hash[..7], commit_message), | ||
| }); | ||
| self.steps.push(AnimationStep::TerminalOutput { | ||
| text: format!( | ||
| " {} file{} changed", | ||
| metadata.changes.len(), | ||
| if metadata.changes.len() == 1 { "" } else { "s" } | ||
| ), | ||
| }); | ||
| self.steps.push(AnimationStep::Pause { duration_ms: 1000 }); | ||
|
|
||
| // Git push | ||
| self.steps.push(AnimationStep::TerminalCommand { | ||
| command: "git push origin main".to_string(), | ||
| }); | ||
| self.steps.push(AnimationStep::Pause { duration_ms: 500 }); | ||
| self.steps.push(AnimationStep::TerminalOutput { | ||
| text: "Enumerating objects: 5, done.".to_string(), | ||
| }); | ||
| self.steps.push(AnimationStep::Pause { duration_ms: 300 }); | ||
| self.steps.push(AnimationStep::TerminalOutput { | ||
| text: "Counting objects: 100% (5/5), done.".to_string(), | ||
| }); | ||
| self.steps.push(AnimationStep::Pause { duration_ms: 300 }); | ||
| self.steps.push(AnimationStep::TerminalOutput { | ||
| text: "Writing objects: 100% (3/3), done.".to_string(), | ||
| }); | ||
| self.steps.push(AnimationStep::Pause { duration_ms: 500 }); | ||
| self.steps.push(AnimationStep::TerminalOutput { | ||
| text: format!("To https://github.com/user/repo.git"), | ||
| }); | ||
| self.steps.push(AnimationStep::TerminalOutput { | ||
| text: format!(" {}..{} main -> main", &parent_hash[..7], &metadata.hash[..7]), | ||
| }); | ||
| self.steps.push(AnimationStep::Pause { duration_ms: 2000 }); | ||
|
|
||
| // Start with the first file's content | ||
| if let Some(change) = metadata.changes.first() { | ||
| if let Some(old_content) = &change.old_content { | ||
| self.buffer = EditorBuffer::from_content(old_content); | ||
| } else { | ||
| self.buffer = EditorBuffer::new(); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Potential panic on short commit hashes.
The load_commit method slices commit hashes without length checks on lines 142, 189, and 221:
&metadata.hash[..7]assumes the hash is at least 7 characters&parent_hash[..7]similarly assumes sufficient length
While Git commit hashes are typically 40 characters, defensive programming suggests using 7.min(hash.len()) as done in status_bar.rs line 19.
Apply this diff to add safe slicing:
- let parent_hash = format!("{}^", &metadata.hash[..7]);
+ let hash_short = &metadata.hash[..7.min(metadata.hash.len())];
+ let parent_hash = format!("{}^", hash_short);And update other occurrences similarly (lines 189, 221).
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In src/animation.rs around lines 134-233, the code unsafely slices commit hashes
at lines ~142, ~189 and ~221 using &metadata.hash[..7] and &parent_hash[..7];
compute a safe short_hash = &metadata.hash[..metadata.hash.len().min(7)] and use
that everywhere instead of direct slicing; set parent_ref = format!("{}^",
short_hash) (don’t slice parent_ref), and when you need the parent short id use
short_hash (or a separately computed parent_short if you prefer) for formatting
the terminal outputs; replace all direct &...[..7] slices with these safe
values.
Replace instant command display with typing animation: - Add TerminalPrompt step to start command line with "$ " - Add TerminalTypeChar step to type one character at a time - Create add_terminal_command helper to generate typing steps - Each character typed uses the same speed as editor typing Terminal command flow: 1. TerminalPrompt - add "$ " line 2. TerminalTypeChar (repeated) - add each character to last line 3. Pause - wait before showing output 4. TerminalOutput - show command result Commands now type out like: $ g $ gi $ git $ git $ git a $ git ad $ git add $ git add . 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Add terminal commands for file operations:
- open {fileName} - before switching to each file
- git add {fileName} - after editing each file
- Remove global git add . command
Animation flow per file:
1. Pause 1.5s (except first file)
2. Type "open {fileName}"
3. Switch file display
4. Pause 800ms
5. Animate file changes
6. Pause 1s
7. Type "git add {fileName}"
8. Pause 500ms
This makes the workflow clearer by showing:
- Which file is being opened
- Individual git add for each modified file
- Better visibility of file-by-file editing process
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Start with empty editor buffer instead of pre-loading first file:
- Editor shows empty state initially
- First file loads only after "open {fileName}" command
- Add 1s pause before first open command (after git checkout)
- Keep 1.5s pause before subsequent file opens
Animation flow:
1. git checkout - show parent commit
2. Empty editor visible
3. Pause 1s
4. Type "open src/main.rs"
5. Load and display file
6. Start editing animation
This makes it clearer that no file is open initially.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Fix line number misalignment during editing: - Track actual buffer line position instead of diff line numbers - Deletion: keep buffer_line same (next line moves up) - Addition: increment buffer_line (inserted new line) - Context: increment buffer_line (move to next line) Previous bug: - Used separate old_line and new_line counters - Incorrectly incremented old_line on Addition - Didn't track actual buffer state after edits This fixes the issue where edits appeared at wrong line positions after insertions/deletions shifted the buffer content. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Add line number display to editor pane: - Show line numbers on the left side (right-aligned) - Dynamic width based on total line count (min 3 digits) - Current line: yellow + bold - Other lines: dark gray - Separator: "│" between line numbers and content Display format: 1 │ first line 2 │ second line 3 │ code here <- current line (yellow + bold) 4 │ more code Line numbers start from 1 (human-readable, not 0-indexed). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Track which pane is currently active and show cursor there: - Add ActivePane enum (Editor, Terminal) - Track active_pane in AnimationEngine - Update active_pane on each animation step: - Editor operations: Editor pane - Terminal operations: Terminal pane - Show cursor only in active pane Editor cursor: - Shown during file editing (InsertChar, DeleteChar, etc.) - At specific line and column position Terminal cursor: - Shown during command typing (TerminalPrompt, TerminalTypeChar) - At end of last line (command prompt) - Blinking white block after command text This makes it clear which pane is being operated at any time. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Add animation finish detection - Auto-reload with new random commit when not using --commit flag - Exit normally when using --commit flag - Implement continuous playback mode for screensaver use case
- Add 70-130% random variation to character typing speed - Make typing more realistic and natural - Only apply variation to InsertChar and TerminalTypeChar steps - Other animation steps maintain consistent speed
- Track cumulative line offset from additions/deletions - Adjust each hunk's target position by accumulated offset - Fix line misalignment when processing multiple hunks - Pass buffer_line position between hunk processing steps
- Reduce cursor movement pause from 50ms to 15ms - Cursor now moves faster than typing (30ms default) - Apply to both hunk navigation and context line movements
… indices - Git diff line numbers start at 1 (1-indexed) - Array indices start at 0 (0-indexed) - Convert hunk.old_start by subtracting 1 before use - Fix off-by-one error causing edits to appear one line below
- Define duration multipliers as constants at module level - All pauses now scale proportionally with --speed flag - Cursor movement: 0.5x speed - Line operations: 6.7-10x speed - Hunk transitions: 50x speed - Git commands: 16.7-66.7x speed - Faster speed setting now makes entire animation faster
…code - Keep single UI instance in raw mode to prevent screen flicker - Load next commits internally within same UI session - Fix infinite loop issue by properly managing should_quit flag - Remove unused code: delete_char, get_content, print_commit_info - Remove unused constants and enum variants - Simplify git2 usage in random_commit 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Fix integer underflow when hunk.old_start is 0 (new files) - Add explicit UIState enum for robust state management - Cache commits in GitRepository to avoid repeated scans - Make inter-commit wait time proportional to typing speed - Reset animation timing state on commit load 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Group files by directory in tree structure - Add change statistics (+N -N) for each file - Remove emoji icons for cleaner display - Indent files under their parent directories 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Summary
Implements the core typing animation engine (#7) that replays Git commits character by character.
Key Features
--speedargument (default 30ms/char)UI Integration
+Green for additions-Red for deletions~Yellow for modifications>Blue for renamesImplementation Details
Testing
Build successful. Animation logic implemented and integrated with UI components.
Related
Closes #7
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes / Reliability