ask before deleting task
This commit is contained in:
parent
d85639ef57
commit
bd0ea82f8e
1 changed files with 18 additions and 1 deletions
19
src/main.rs
19
src/main.rs
|
@ -1,6 +1,6 @@
|
|||
use clap::Parser;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::io::Write;
|
||||
use std::io::{BufRead, Write};
|
||||
use xdg::BaseDirectories;
|
||||
|
||||
mod cli;
|
||||
|
@ -47,6 +47,23 @@ fn main() {
|
|||
println!("invalid index");
|
||||
}
|
||||
|
||||
println!("You are deleting task:");
|
||||
println!(" {}", tasks[idx - 1].name);
|
||||
println!();
|
||||
println!("In most cases you need to `finish` command");
|
||||
loop {
|
||||
print!("Do you still want to delete the task? (y/N): ");
|
||||
std::io::stdout().flush().unwrap();
|
||||
let mut stdin = std::io::stdin().lock();
|
||||
let mut buf = String::new();
|
||||
stdin.read_line(&mut buf).unwrap();
|
||||
match buf.chars().next().unwrap_or_default() {
|
||||
'\r' | '\n' | 'n' | 'N' => return,
|
||||
'y' | 'Y' => break,
|
||||
_ => println!("Unrecognised answer. Please try again."),
|
||||
}
|
||||
}
|
||||
|
||||
tasks.remove(idx - 1);
|
||||
|
||||
let mut file = std::fs::File::create(&tasks_file_path).unwrap();
|
||||
|
|
Loading…
Reference in a new issue