Skip to content

Commit 06bd6b3

Browse files
committed
use colors instead of icons
1 parent eb0bf60 commit 06bd6b3

2 files changed

Lines changed: 227 additions & 155 deletions

File tree

examples/git_diff_example.rs

Lines changed: 60 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use prollytree::storage::InMemoryNodeStorage;
2525
use prollytree::tree::{ProllyTree, Tree};
2626

2727
fn main() {
28-
println!("🔀 Git-like Tree Diffing Example 🔀\n");
28+
println!("\x1b[1;36mGit-like Tree Diffing Example\x1b[0m\n");
2929

3030
// Create a shared configuration for consistency
3131
let config = TreeConfig {
@@ -43,7 +43,7 @@ fn main() {
4343
// ============================================================================
4444
// Step 1: Create a common "main" branch with initial data
4545
// ============================================================================
46-
println!("📦 Creating main branch with initial data...");
46+
println!("\x1b[1;32mCreating main branch with initial data...\x1b[0m");
4747
let storage_main = InMemoryNodeStorage::<32>::default();
4848
let mut main_tree = ProllyTree::new(storage_main, config.clone());
4949

@@ -60,13 +60,19 @@ fn main() {
6060
main_tree.insert(key.as_bytes().to_vec(), value.as_bytes().to_vec());
6161
}
6262

63-
println!(" ✅ Main branch created with {} files", initial_data.len());
64-
println!(" 🌳 Main tree hash: {:?}", main_tree.get_root_hash());
63+
println!(
64+
" \x1b[32mMain branch created with {} files\x1b[0m",
65+
initial_data.len()
66+
);
67+
println!(
68+
" \x1b[33mMain tree hash: {:?}\x1b[0m",
69+
main_tree.get_root_hash()
70+
);
6571

6672
// ============================================================================
6773
// Step 2: Create "feature" branch - simulating git checkout -b feature
6874
// ============================================================================
69-
println!("\n🌿 Creating feature branch from main...");
75+
println!("\n\x1b[1;32mCreating feature branch from main...\x1b[0m");
7076
let storage_feature = InMemoryNodeStorage::<32>::default();
7177
let mut feature_tree = ProllyTree::new(storage_feature, config.clone());
7278

@@ -79,11 +85,19 @@ fn main() {
7985
let feature_changes = vec![
8086
// Modified files
8187
("file1.txt", "Hello World - Feature Edition!"),
82-
("config.json", r#"{"version": "1.1", "debug": true, "feature_flag": true}"#),
83-
88+
(
89+
"config.json",
90+
r#"{"version": "1.1", "debug": true, "feature_flag": true}"#,
91+
),
8492
// New files
85-
("feature.rs", "pub fn new_feature() { /* implementation */ }"),
86-
("tests/test_feature.rs", "#[test] fn test_new_feature() { assert!(true); }"),
93+
(
94+
"feature.rs",
95+
"pub fn new_feature() { /* implementation */ }",
96+
),
97+
(
98+
"tests/test_feature.rs",
99+
"#[test] fn test_new_feature() { assert!(true); }",
100+
),
87101
];
88102

89103
for (key, value) in &feature_changes {
@@ -93,13 +107,16 @@ fn main() {
93107
// Delete a file in feature branch
94108
feature_tree.delete(b"readme.md");
95109

96-
println!(" ✅ Feature branch created with modifications");
97-
println!(" 🌳 Feature tree hash: {:?}", feature_tree.get_root_hash());
110+
println!(" \x1b[32mFeature branch created with modifications\x1b[0m");
111+
println!(
112+
" \x1b[33mFeature tree hash: {:?}\x1b[0m",
113+
feature_tree.get_root_hash()
114+
);
98115

99116
// ============================================================================
100117
// Step 3: Create "hotfix" branch - another parallel development
101118
// ============================================================================
102-
println!("\n🚀 Creating hotfix branch from main...");
119+
println!("\n\x1b[1;32mCreating hotfix branch from main...\x1b[0m");
103120
let storage_hotfix = InMemoryNodeStorage::<32>::default();
104121
let mut hotfix_tree = ProllyTree::new(storage_hotfix, config);
105122

@@ -119,37 +136,42 @@ fn main() {
119136
hotfix_tree.insert(key.as_bytes().to_vec(), value.as_bytes().to_vec());
120137
}
121138

122-
println!(" ✅ Hotfix branch created with urgent fixes");
123-
println!(" 🌳 Hotfix tree hash: {:?}", hotfix_tree.get_root_hash());
139+
println!(" \x1b[32mHotfix branch created with urgent fixes\x1b[0m");
140+
println!(
141+
" \x1b[33mHotfix tree hash: {:?}\x1b[0m",
142+
hotfix_tree.get_root_hash()
143+
);
124144

125145
// ============================================================================
126146
// Step 4: Perform Git-like diffs between branches
127147
// ============================================================================
128-
println!("\n🔍 Performing Git-like diffs...\n");
148+
println!("\n\x1b[1;34mPerforming Git-like diffs...\x1b[0m\n");
129149

130150
// Diff 1: main vs feature (like git diff main..feature)
131-
println!("📊 Diff: main -> feature (shows what feature adds/changes)");
132-
println!(" Similar to: git diff main..feature");
151+
println!("\x1b[1;35mDiff: main -> feature (shows what feature adds/changes)\x1b[0m");
152+
println!(" \x1b[90mSimilar to: git diff main..feature\x1b[0m");
133153
let main_to_feature_diff = main_tree.diff(&feature_tree);
134154
print_diff_summary(&main_to_feature_diff, "main", "feature");
135155

136156
// Diff 2: main vs hotfix (like git diff main..hotfix)
137-
println!("\n📊 Diff: main -> hotfix (shows what hotfix adds/changes)");
138-
println!(" Similar to: git diff main..hotfix");
157+
println!("\n\x1b[1;35mDiff: main -> hotfix (shows what hotfix adds/changes)\x1b[0m");
158+
println!(" \x1b[90mSimilar to: git diff main..hotfix\x1b[0m");
139159
let main_to_hotfix_diff = main_tree.diff(&hotfix_tree);
140160
print_diff_summary(&main_to_hotfix_diff, "main", "hotfix");
141161

142162
// Diff 3: feature vs hotfix (like git diff feature..hotfix)
143-
println!("\n📊 Diff: feature -> hotfix (shows differences between parallel branches)");
144-
println!(" Similar to: git diff feature..hotfix");
163+
println!(
164+
"\n\x1b[1;35mDiff: feature -> hotfix (shows differences between parallel branches)\x1b[0m"
165+
);
166+
println!(" \x1b[90mSimilar to: git diff feature..hotfix\x1b[0m");
145167
let feature_to_hotfix_diff = feature_tree.diff(&hotfix_tree);
146168
print_diff_summary(&feature_to_hotfix_diff, "feature", "hotfix");
147169

148170
// ============================================================================
149171
// Step 5: Show detailed analysis
150172
// ============================================================================
151-
println!("\n📈 Detailed Diff Analysis:");
152-
println!("═══════════════════════════════════════");
173+
println!("\n\x1b[1;34mDetailed Diff Analysis:\x1b[0m");
174+
println!("\x1b[90m═══════════════════════════════════════\x1b[0m");
153175

154176
analyze_diff(&main_to_feature_diff, "Main → Feature");
155177
analyze_diff(&main_to_hotfix_diff, "Main → Hotfix");
@@ -158,21 +180,21 @@ fn main() {
158180
// ============================================================================
159181
// Summary
160182
// ============================================================================
161-
println!("\n🎯 Summary:");
162-
println!(" • Prolly Trees enable efficient git-like diffing");
163-
println!(" • Each branch maintains its own merkle tree structure");
164-
println!(" • Diffs show exact changes: additions, deletions, modifications");
165-
println!(" • Perfect for version control, distributed systems, and data synchronization");
166-
println!(" • Hash-based verification ensures data integrity across branches");
183+
println!("\n\x1b[1;36mSummary:\x1b[0m");
184+
println!(" \x1b[32m• Prolly Trees enable efficient git-like diffing\x1b[0m");
185+
println!(" \x1b[32m• Each branch maintains its own merkle tree structure\x1b[0m");
186+
println!(" \x1b[32m• Diffs show exact changes: additions, deletions, modifications\x1b[0m");
187+
println!(" \x1b[32m• Perfect for version control, distributed systems, and data synchronization\x1b[0m");
188+
println!(" \x1b[32m• Hash-based verification ensures data integrity across branches\x1b[0m");
167189
}
168190

169191
fn print_diff_summary(diffs: &[DiffResult], _from_branch: &str, _to_branch: &str) {
170192
let (added, removed, modified) = count_diff_types(diffs);
171-
172-
println!(" 📈 Changes: +{} files, -{} files, ~{} files modified", added, removed, modified);
173-
193+
194+
println!(" \x1b[33mChanges: \x1b[32m+{}\x1b[0m files, \x1b[31m-{}\x1b[0m files, \x1b[34m~{}\x1b[0m files modified", added, removed, modified);
195+
174196
if diffs.is_empty() {
175-
println!(" ✨ No differences found - branches are identical");
197+
println!(" \x1b[32mNo differences found - branches are identical\x1b[0m");
176198
}
177199
}
178200

@@ -193,8 +215,8 @@ fn count_diff_types(diffs: &[DiffResult]) -> (usize, usize, usize) {
193215
}
194216

195217
fn analyze_diff(diffs: &[DiffResult], comparison: &str) {
196-
println!("\n🔍 {}", comparison);
197-
println!("───────────────────────────────");
218+
println!("\n\x1b[1;34m{}\x1b[0m", comparison);
219+
println!("\x1b[90m───────────────────────────────\x1b[0m");
198220

199221
if diffs.is_empty() {
200222
println!(" No changes detected");
@@ -205,15 +227,15 @@ fn analyze_diff(diffs: &[DiffResult], comparison: &str) {
205227
match diff {
206228
DiffResult::Added(key, _value) => {
207229
let filename = String::from_utf8_lossy(key);
208-
println!(" Added: {}", filename);
230+
println!(" \x1b[32m+ Added: {}\x1b[0m", filename);
209231
}
210232
DiffResult::Removed(key, _value) => {
211233
let filename = String::from_utf8_lossy(key);
212-
println!(" Removed: {}", filename);
234+
println!(" \x1b[31m- Removed: {}\x1b[0m", filename);
213235
}
214236
DiffResult::Modified(key, _old_value, _new_value) => {
215237
let filename = String::from_utf8_lossy(key);
216-
println!(" 🔄 Modified: {}", filename);
238+
println!(" \x1b[34m~ Modified: {}\x1b[0m", filename);
217239
}
218240
}
219241
}

0 commit comments

Comments
 (0)