ask before deleting task

This commit is contained in:
Dmitriy Pleshevskiy 2022-08-05 00:31:01 +03:00
parent d85639ef57
commit bd0ea82f8e
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215

View file

@ -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();