1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//! History management for undo operations.
//!
//! This module handles saving and loading rename history to enable
//! undo functionality. History is stored in `.fren_history.json` in
//! the current working directory. All operations are async and non-blocking.
use ;
use fs;
use PathBuf;
use ;
/// Represents a single rename action in the history.
/// History of rename operations for undo support.
const HISTORY_FILE: &str = ".fren_history.json";
/// Saves rename history to disk asynchronously.
///
/// If the actions list is empty, no file is created.
///
/// # Arguments
///
/// * `actions` - List of rename actions to save
///
/// # Returns
///
/// * `Ok(())` - History saved successfully
/// * `Err(Box<dyn Error>)` - If file I/O fails
///
/// # Examples
///
/// ```
/// # tokio_test::block_on(async {
/// use freneng::history::{save_history, RenameAction};
/// use std::path::PathBuf;
///
/// let actions = vec![RenameAction {
/// old_path: PathBuf::from("old.txt"),
/// new_path: PathBuf::from("new.txt"),
/// }];
/// save_history(actions).await.unwrap();
/// # })
/// ```
pub async
/// Loads rename history from disk asynchronously.
///
/// # Returns
///
/// * `Ok(Some(History))` - History loaded successfully
/// * `Ok(None)` - No history file exists
/// * `Err(Box<dyn Error>)` - If file I/O or parsing fails
///
/// # Examples
///
/// ```
/// # tokio_test::block_on(async {
/// use freneng::history::load_history;
///
/// match load_history().await.unwrap() {
/// Some(history) => println!("Loaded {} actions", history.actions.len()),
/// None => println!("No history found"),
/// }
/// # })
/// ```
pub async
/// Clears the rename history by deleting the history file asynchronously.
///
/// # Returns
///
/// * `Ok(())` - History cleared (or didn't exist)
/// * `Err(Box<dyn Error>)` - If file deletion fails
///
/// # Examples
///
/// ```
/// # tokio_test::block_on(async {
/// use freneng::history::clear_history;
///
/// clear_history().await.unwrap();
/// # })
/// ```
pub async