tada/action/
zen.rs

1//! Automatically reschedule overdue tasks
2
3use crate::action::*;
4use crate::list::Line;
5use clap::{ArgMatches, Command};
6use rand::seq::SliceRandom;
7
8/// Options for the `zen` subcommand.
9pub fn get_action() -> Action {
10	let name = String::from("zen");
11	let mut command = Command::new("zen").about("Automatically reschedule overdue tasks")
12		.after_help(
13			"Zen will reschedule any overdue tasks on your todo list. It does not consult you \
14			to ask for a new due date, but guesses when a sensible due date might be."
15		);
16	command = FileType::TodoTxt.add_args(command);
17	command = Outputter::add_args_minimal(command);
18	Action { name, command }
19}
20
21/// Execute the `zen` subcommand.
22pub fn execute(args: &ArgMatches) {
23	let mut outputter = Outputter::from_argmatches_minimal(args);
24	let todo_filename = FileType::TodoTxt.filename(args);
25	let list = List::from_url(todo_filename.clone())
26		.expect("Could not read todo list");
27	let mut new_list = List::new();
28
29	for line in list.lines {
30		match line.kind {
31			LineKind::Item => {
32				let new_line = Line::from_item(line.item.unwrap().zen());
33				new_list.lines.push(new_line);
34			}
35			_ => new_list.lines.push(line),
36		}
37	}
38
39	new_list.to_url(todo_filename);
40
41	outputter.write_status(String::from(zen_quote()));
42}
43
44pub fn zen_quote() -> &'static str {
45	let quotes = Vec::from([
46		// Marcus Aurelius
47		"The nearer a man comes to a calm mind, the closer he is to strength.",
48		"It is in your power to withdraw yourself whenever you desire. Perfect tranquility\n\
49		within consists in the good ordering of the mind, the realm of your own.",
50		// Bhagavad Gita
51		"All sorrows are destroyed upon attainment of tranquility. The intellect of such\n\
52		a tranquil person soon becomes completely steady.",
53		// Chris Bradford
54		"A samurai must remain calm at all times even in the face of danger.",
55		// Buddhism
56		"Those who are free of resentful thoughts surely find peace.",
57		"Passaddhi, calm or tranquillity, is the fifth factor of enlightenment.",
58		// Pema Chodron
59		"You are the sky. Everything else... it's just the weather.",
60		// Cicero
61		"The pursuit, even of the best things, ought to be calm and tranquil.",
62		"We think a happy life consists in tranquility of mind.",
63		// Khaled Hosseini
64		"Quiet is peace. Tranquility. Quiet is turning down the volume knob on life. Silence\n\
65		is pushing the off button. Shutting it down. All of it.",
66		// Mehmet Murat ildan
67		"Tranquillity is a fertile soil where you can plant and reap the solutions!",
68		// Nelson Mandela
69		"I never lose; either win or learn.",
70		// Alfred Tennyson
71		"The noonday quiet holds the hill.",
72		// Zen
73		"No snowflake ever falls in the wrong place.",
74		"When you reach the top of the mountain, keep climbing.",
75	]);
76
77	quotes.choose(&mut rand::thread_rng()).unwrap()
78}
79
80#[cfg(test)]
81mod tests {
82	use super::*;
83
84	#[test]
85	fn test_get_action() {
86		assert_eq!(String::from("zen"), get_action().name);
87	}
88}