tangled
alpha
login
or
join now
ngp.computer
/
tsk
A file-based task manager
0
fork
atom
overview
issues
pulls
pipelines
ADD: rot/tor
ngp.computer
1 year ago
9ebd6cd6
06348fdc
+56
-14
2 changed files
expand all
collapse all
unified
split
src
main.rs
workspace.rs
+20
-14
src/main.rs
···
87
87
88
88
/// Drops the task on the top of the stack and archives it.
89
89
Drop,
90
90
+
91
91
+
Rot,
92
92
+
Tor,
90
93
}
91
94
92
95
#[derive(Args)]
···
113
116
114
117
fn main() {
115
118
let cli = Cli::parse();
119
119
+
let dir = cli.dir.unwrap_or(default_dir());
116
120
match cli.command {
117
117
-
Commands::Init => command_init(cli.dir.unwrap_or(default_dir())),
118
118
-
Commands::Push { edit, body, title } => {
119
119
-
command_push(cli.dir.unwrap_or(default_dir()), edit, body, title)
120
120
-
}
121
121
-
Commands::List { all, count } => command_list(cli.dir.unwrap_or(default_dir()), all, count),
122
122
-
Commands::Swap => command_swap(cli.dir.unwrap_or(default_dir())),
123
123
-
Commands::Edit { task_id } => command_edit(cli.dir.unwrap_or(default_dir()), task_id),
121
121
+
Commands::Init => command_init(dir),
122
122
+
Commands::Push { edit, body, title } => command_push(dir, edit, body, title),
123
123
+
Commands::List { all, count } => command_list(dir, all, count),
124
124
+
Commands::Swap => command_swap(dir),
125
125
+
Commands::Edit { task_id } => command_edit(dir, task_id),
124
126
Commands::Completion { shell } => command_completion(shell),
125
125
-
Commands::Drop => command_drop(cli.dir.unwrap_or(default_dir())),
126
126
-
Commands::Find {
127
127
-
search_body,
128
128
-
search_archived,
129
129
-
} => command_search(cli.dir.unwrap_or(default_dir())),
127
127
+
Commands::Drop => command_drop(dir),
128
128
+
Commands::Find { .. } => command_search(dir),
129
129
+
Commands::Rot => Workspace::from_path(dir).unwrap().rot().unwrap(),
130
130
+
Commands::Tor => Workspace::from_path(dir).unwrap().tor().unwrap(),
130
131
}
131
132
}
132
133
···
222
223
if let Some(id) = Workspace::from_path(dir)
223
224
.expect("Unable to find .tsk dir")
224
225
.drop()
225
225
-
.expect("Unable to drop task.") {
226
226
-
println!("Dropped {id}")
226
226
+
.expect("Unable to drop task.")
227
227
+
{
228
228
+
println!("Dropped {id}")
227
229
}
228
230
}
229
231
···
236
238
eprintln!("No task to drop.")
237
239
}
238
240
}
241
241
+
242
242
+
fn command_rot(dir: PathBuf) {
243
243
+
Workspace::from_path(dir).unwrap().rot().unwrap();
244
244
+
}
+36
src/workspace.rs
···
147
147
Ok(())
148
148
}
149
149
150
150
+
pub fn rot(&self) -> Result<()> {
151
151
+
let mut stack = TaskStack::from_tskdir(&self.path)?;
152
152
+
let top = stack.pop();
153
153
+
let second = stack.pop();
154
154
+
let third = stack.pop();
155
155
+
156
156
+
if top.is_none() || second.is_none() || third.is_none() {
157
157
+
return Ok(())
158
158
+
}
159
159
+
160
160
+
stack.push(second.unwrap());
161
161
+
stack.push(top.unwrap());
162
162
+
stack.push(third.unwrap());
163
163
+
stack.save()?;
164
164
+
Ok(())
165
165
+
}
166
166
+
167
167
+
/// The inverse of tor. Pushes the top item behind the second item, shifting #2 and #3 to #1
168
168
+
/// and #2 respectively.
169
169
+
pub fn tor(&self) -> Result<()> {
170
170
+
let mut stack = TaskStack::from_tskdir(&self.path)?;
171
171
+
let top = stack.pop();
172
172
+
let second = stack.pop();
173
173
+
let third = stack.pop();
174
174
+
175
175
+
if top.is_none() || second.is_none() || third.is_none() {
176
176
+
return Ok(())
177
177
+
}
178
178
+
179
179
+
stack.push(top.unwrap());
180
180
+
stack.push(third.unwrap());
181
181
+
stack.push(second.unwrap());
182
182
+
stack.save()?;
183
183
+
Ok(())
184
184
+
}
185
185
+
150
186
pub fn drop(&self) -> Result<Option<Id>> {
151
187
let mut stack = self.read_stack()?;
152
188
if let Some(stack_item) = stack.pop() {