Skip to content

Commit 7805317

Browse files
feat: add diff subcommand to visualize working tree changes (#123)
* Add support for diff * Add tests * Run lint * Update docs
1 parent 7545577 commit 7805317

8 files changed

Lines changed: 906 additions & 113 deletions

File tree

‎README.md‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ See the [Installation Guide](docs/installation.md) for more options and troubles
6262

6363
## Features
6464

65-
🎬 **Commit Replay as Animation** — Realistic typing, cursor movement, deletions, and file operations
66-
🎨 **Tree-sitter Syntax Highlighting** — 29 languages supported
67-
🌳 **Project File Tree** — Directory structure with change statistics
68-
🖥️ **Screensaver Mode** — Endless random commit playback
69-
🎭 **Themes** — 9 built-in themes + full customization support
70-
⚡ **Fast & Lightweight** — Built with Rust for performance
65+
🎬 **Commit Replay as Animation** — Realistic typing, cursor movement, deletions, and file operations
66+
🔍 **Working Tree Diff View** — Visualize staged/unstaged changes before committing
67+
🎨 **Tree-sitter Syntax Highlighting** — 29 languages supported
68+
🌳 **Project File Tree** — Directory structure with change statistics
69+
🖥️ **Screensaver Mode** — Endless random commit playback
70+
🎭 **Themes** — 9 built-in themes + full customization support
71+
⚡ **Fast & Lightweight** — Built with Rust for performance
7172

7273
## Usage
7374

@@ -106,6 +107,12 @@ gitlogue --commit abc123 --loop
106107
# Loop through a commit range
107108
gitlogue --commit HEAD~10..HEAD --loop
108109

110+
# View staged changes (default)
111+
gitlogue diff
112+
113+
# View unstaged changes instead
114+
gitlogue diff --unstaged
115+
109116
# Filter commits by author or email (case-insensitive partial match)
110117
gitlogue --author "john"
111118

‎docs/usage.md‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ This guide covers all the features and options available in gitlogue.
77
- [Basic Usage](#basic-usage)
88
- [Command-Line Options](#command-line-options)
99
- [Subcommands](#subcommands)
10+
- [theme list](#theme-list)
11+
- [diff](#diff)
1012
- [Configuration File](#configuration-file)
1113
- [Keyboard Controls](#keyboard-controls)
1214
- [Use Cases](#use-cases)
@@ -308,6 +310,53 @@ This displays:
308310
- Brief description
309311
- Preview of the color scheme (coming soon)
310312

313+
### `diff`
314+
315+
View staged working tree changes with animations. This is useful for visualizing your changes before committing.
316+
317+
```bash
318+
# View staged changes (default)
319+
gitlogue diff
320+
321+
# View unstaged changes instead
322+
gitlogue diff --unstaged
323+
```
324+
325+
#### Options
326+
327+
| Option | Description |
328+
|--------|-------------|
329+
| `--unstaged` | Show unstaged changes instead of staged |
330+
| `-s, --speed <MS>` | Typing speed in milliseconds per character |
331+
| `-t, --theme <NAME>` | Theme to use |
332+
| `--background[=BOOL]` | Show background colors (use `--background=false` for transparent) |
333+
| `--loop[=BOOL]` | Loop the animation continuously |
334+
| `-i, --ignore <PATTERN>` | Ignore files matching pattern (can be specified multiple times) |
335+
| `--speed-rule <PATTERN:MS>` | Set typing speed for files matching pattern |
336+
337+
#### Examples
338+
339+
```bash
340+
# Review staged changes before committing
341+
gitlogue diff
342+
343+
# View unstaged work in progress
344+
gitlogue diff --unstaged --theme dracula
345+
346+
# Loop through staged changes for a presentation
347+
gitlogue diff --loop --speed 20
348+
349+
# Focus on source files, ignore generated content
350+
gitlogue diff -i "*.lock" -i "dist/**"
351+
```
352+
353+
#### Use Cases
354+
355+
- **Pre-commit review**: Visualize exactly what you're about to commit
356+
- **Code presentation**: Show staged changes to teammates
357+
- **Learning**: See your changes animated with syntax highlighting
358+
- **Debugging**: Trace through modifications to understand what changed
359+
311360
## Keyboard Controls
312361

313362
While gitlogue is running:

‎src/animation.rs‎

Lines changed: 125 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -354,40 +354,63 @@ impl AnimationEngine {
354354
self.last_update = Instant::now();
355355
self.pause_until = None;
356356

357-
// Time travel to commit date
358-
let parent_hash = format!("{}^", &metadata.hash[..7]);
359-
let datetime_str = metadata.date.format("%Y-%m-%d %H:%M:%S").to_string();
360-
self.add_terminal_command(&format!("time-travel {}", datetime_str));
361-
self.steps.push(AnimationStep::Pause {
362-
multiplier: CHECKOUT_PAUSE,
363-
});
364-
self.steps.push(AnimationStep::TerminalOutput {
365-
text: "⚡ Initializing temporal displacement field...".to_string(),
366-
});
367-
self.steps.push(AnimationStep::Pause {
368-
multiplier: CHECKOUT_OUTPUT_PAUSE * 0.5,
369-
});
370-
self.steps.push(AnimationStep::TerminalOutput {
371-
text: "✨ Warping through spacetime...".to_string(),
372-
});
373-
self.steps.push(AnimationStep::Pause {
374-
multiplier: CHECKOUT_OUTPUT_PAUSE * 0.5,
375-
});
376-
self.steps.push(AnimationStep::TerminalOutput {
377-
text: format!("🕰️ Arrived at {}", datetime_str),
378-
});
379-
self.steps.push(AnimationStep::TerminalOutput {
380-
text: format!(
381-
"📍 Location: commit {} by {}",
382-
&metadata.hash[..7],
383-
metadata.author
384-
),
385-
});
386-
self.steps.push(AnimationStep::Pause {
387-
multiplier: CHECKOUT_OUTPUT_PAUSE,
388-
});
389-
390-
// Apply new metadata after time-travel animation
357+
// Check if this is a working tree diff (not a real commit)
358+
let is_working_tree = metadata.hash == "working-tree";
359+
360+
if is_working_tree {
361+
// Simplified intro for working tree diffs
362+
self.add_terminal_command("git diff --stat");
363+
self.steps.push(AnimationStep::Pause {
364+
multiplier: CHECKOUT_PAUSE,
365+
});
366+
self.steps.push(AnimationStep::TerminalOutput {
367+
text: format!("📝 {}", metadata.message),
368+
});
369+
self.steps.push(AnimationStep::TerminalOutput {
370+
text: format!(
371+
"📁 {} file{} changed",
372+
metadata.changes.len(),
373+
if metadata.changes.len() == 1 { "" } else { "s" }
374+
),
375+
});
376+
self.steps.push(AnimationStep::Pause {
377+
multiplier: CHECKOUT_OUTPUT_PAUSE,
378+
});
379+
} else {
380+
// Time travel to commit date
381+
let datetime_str = metadata.date.format("%Y-%m-%d %H:%M:%S").to_string();
382+
self.add_terminal_command(&format!("time-travel {}", datetime_str));
383+
self.steps.push(AnimationStep::Pause {
384+
multiplier: CHECKOUT_PAUSE,
385+
});
386+
self.steps.push(AnimationStep::TerminalOutput {
387+
text: "⚡ Initializing temporal displacement field...".to_string(),
388+
});
389+
self.steps.push(AnimationStep::Pause {
390+
multiplier: CHECKOUT_OUTPUT_PAUSE * 0.5,
391+
});
392+
self.steps.push(AnimationStep::TerminalOutput {
393+
text: "✨ Warping through spacetime...".to_string(),
394+
});
395+
self.steps.push(AnimationStep::Pause {
396+
multiplier: CHECKOUT_OUTPUT_PAUSE * 0.5,
397+
});
398+
self.steps.push(AnimationStep::TerminalOutput {
399+
text: format!("🕰️ Arrived at {}", datetime_str),
400+
});
401+
self.steps.push(AnimationStep::TerminalOutput {
402+
text: format!(
403+
"📍 Location: commit {} by {}",
404+
&metadata.hash[..7],
405+
metadata.author
406+
),
407+
});
408+
self.steps.push(AnimationStep::Pause {
409+
multiplier: CHECKOUT_OUTPUT_PAUSE,
410+
});
411+
}
412+
413+
// Apply new metadata after intro animation
391414
self.steps.push(AnimationStep::ResetState);
392415

393416
// Sort file changes to match FileTree display order (directory -> filename)
@@ -527,65 +550,74 @@ impl AnimationEngine {
527550
}
528551
}
529552

530-
// Git commit
531-
let commit_message = metadata.message.lines().next().unwrap_or("Update");
532-
self.add_terminal_command(&format!("git commit -m \"{}\"", commit_message));
533-
self.steps.push(AnimationStep::Pause {
534-
multiplier: GIT_COMMIT_PAUSE,
535-
});
536-
self.steps.push(AnimationStep::TerminalOutput {
537-
text: format!("💾 [main {}] {}", &metadata.hash[..7], commit_message),
538-
});
539-
self.steps.push(AnimationStep::TerminalOutput {
540-
text: format!(
541-
"📝 {} file{} changed - immortalized forever!",
542-
metadata.changes.len(),
543-
if metadata.changes.len() == 1 { "" } else { "s" }
544-
),
545-
});
546-
self.steps.push(AnimationStep::Pause {
547-
multiplier: COMMIT_OUTPUT_PAUSE,
548-
});
549-
550-
// Git push
551-
self.add_terminal_command("git push origin main");
552-
self.steps.push(AnimationStep::Pause {
553-
multiplier: GIT_PUSH_PAUSE,
554-
});
555-
self.steps.push(AnimationStep::TerminalOutput {
556-
text: "🚀 Launching code into the cloud...".to_string(),
557-
});
558-
self.steps.push(AnimationStep::Pause {
559-
multiplier: PUSH_OUTPUT_PAUSE,
560-
});
561-
self.steps.push(AnimationStep::TerminalOutput {
562-
text: "📦 Compressing digital dreams: 100% (5/5)".to_string(),
563-
});
564-
self.steps.push(AnimationStep::Pause {
565-
multiplier: PUSH_OUTPUT_PAUSE,
566-
});
567-
self.steps.push(AnimationStep::TerminalOutput {
568-
text: "✍️ Signing with invisible ink: done.".to_string(),
569-
});
570-
self.steps.push(AnimationStep::Pause {
571-
multiplier: GIT_PUSH_PAUSE,
572-
});
573-
self.steps.push(AnimationStep::TerminalOutput {
574-
text: "📡 Beaming to origin/main via satellite...".to_string(),
575-
});
576-
self.steps.push(AnimationStep::Pause {
577-
multiplier: PUSH_OUTPUT_PAUSE,
578-
});
579-
self.steps.push(AnimationStep::TerminalOutput {
580-
text: format!(
581-
" {}..{} ✨ SUCCESS",
582-
&parent_hash[..7],
583-
&metadata.hash[..7]
584-
),
585-
});
586-
self.steps.push(AnimationStep::Pause {
587-
multiplier: PUSH_FINAL_PAUSE,
588-
});
553+
// Skip git commit/push animation for working tree diffs
554+
if is_working_tree {
555+
// Just add a final pause for working tree mode
556+
self.steps.push(AnimationStep::Pause {
557+
multiplier: PUSH_FINAL_PAUSE,
558+
});
559+
} else {
560+
// Git commit
561+
let parent_hash = format!("{}^", &metadata.hash[..7]);
562+
let commit_message = metadata.message.lines().next().unwrap_or("Update");
563+
self.add_terminal_command(&format!("git commit -m \"{}\"", commit_message));
564+
self.steps.push(AnimationStep::Pause {
565+
multiplier: GIT_COMMIT_PAUSE,
566+
});
567+
self.steps.push(AnimationStep::TerminalOutput {
568+
text: format!("💾 [main {}] {}", &metadata.hash[..7], commit_message),
569+
});
570+
self.steps.push(AnimationStep::TerminalOutput {
571+
text: format!(
572+
"📝 {} file{} changed - immortalized forever!",
573+
metadata.changes.len(),
574+
if metadata.changes.len() == 1 { "" } else { "s" }
575+
),
576+
});
577+
self.steps.push(AnimationStep::Pause {
578+
multiplier: COMMIT_OUTPUT_PAUSE,
579+
});
580+
581+
// Git push
582+
self.add_terminal_command("git push origin main");
583+
self.steps.push(AnimationStep::Pause {
584+
multiplier: GIT_PUSH_PAUSE,
585+
});
586+
self.steps.push(AnimationStep::TerminalOutput {
587+
text: "🚀 Launching code into the cloud...".to_string(),
588+
});
589+
self.steps.push(AnimationStep::Pause {
590+
multiplier: PUSH_OUTPUT_PAUSE,
591+
});
592+
self.steps.push(AnimationStep::TerminalOutput {
593+
text: "📦 Compressing digital dreams: 100% (5/5)".to_string(),
594+
});
595+
self.steps.push(AnimationStep::Pause {
596+
multiplier: PUSH_OUTPUT_PAUSE,
597+
});
598+
self.steps.push(AnimationStep::TerminalOutput {
599+
text: "✍️ Signing with invisible ink: done.".to_string(),
600+
});
601+
self.steps.push(AnimationStep::Pause {
602+
multiplier: GIT_PUSH_PAUSE,
603+
});
604+
self.steps.push(AnimationStep::TerminalOutput {
605+
text: "📡 Beaming to origin/main via satellite...".to_string(),
606+
});
607+
self.steps.push(AnimationStep::Pause {
608+
multiplier: PUSH_OUTPUT_PAUSE,
609+
});
610+
self.steps.push(AnimationStep::TerminalOutput {
611+
text: format!(
612+
" {}..{} ✨ SUCCESS",
613+
&parent_hash[..7],
614+
&metadata.hash[..7]
615+
),
616+
});
617+
self.steps.push(AnimationStep::Pause {
618+
multiplier: PUSH_FINAL_PAUSE,
619+
});
620+
}
589621

590622
// Start with empty editor (no file opened yet)
591623
self.buffer = EditorBuffer::new();

0 commit comments

Comments
 (0)