diff --git a/Cargo.lock b/Cargo.lock index 8fdde1f..396e572 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "0.6.20" @@ -52,6 +67,48 @@ dependencies = [ "windows-sys 0.60.2", ] +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "bumpalo" +version = "3.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" + +[[package]] +name = "cc" +version = "1.2.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "590f9024a68a8c40351881787f1934dc11afd69090f5edb6831464694d836ea3" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" + +[[package]] +name = "chrono" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + [[package]] name = "clap" version = "4.5.46" @@ -108,12 +165,48 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "find-msvc-tools" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e178e4fba8a2726903f6ba98a6d221e76f9c12c650d5dc0e6afdc50677b49650" + [[package]] name = "heck" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "iana-time-zone" +version = "0.1.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.1" @@ -126,18 +219,55 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" +[[package]] +name = "js-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +[[package]] +name = "libc" +version = "0.2.175" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" + +[[package]] +name = "log" +version = "0.4.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" + [[package]] name = "memchr" version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + [[package]] name = "once_cell_polyfill" version = "1.70.1" @@ -162,6 +292,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "ryu" version = "1.0.20" @@ -200,6 +336,12 @@ dependencies = [ "serde", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "strsim" version = "0.11.1" @@ -221,6 +363,7 @@ dependencies = [ name = "tasky-cli" version = "0.3.1" dependencies = [ + "chrono", "clap", "colored", "serde", @@ -239,12 +382,123 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "wasm-bindgen" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "windows-core" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "windows-link" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" +[[package]] +name = "windows-result" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-sys" version = "0.59.0" diff --git a/Cargo.toml b/Cargo.toml index f2e23bc..80620d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,4 @@ clap = { version = "4.0", features = ["derive"] } # CLI argument parsing serde = { version = "1.0", features = ["derive"] } # JSON serialization serde_json = "1.0" # JSON handling colored = "2.0" +chrono = "0.4.41" diff --git a/src/commands.rs b/src/commands.rs index 18ca6ba..c77ed7b 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,21 +1,34 @@ use crate::storage::save_tasks; use crate::task::Task; +use chrono::DateTime; +use chrono::offset::Utc; use colored::*; -pub fn add_task(tasks: &mut Vec, text: String) { - let new_task = Task::new(text.clone()); - tasks.push(new_task); +pub fn add_task(tasks: &mut Vec, text: String, date_string: String) { + let new_task = Task::new(text.clone(), date_string.clone()); + println!("Adding task: {}", new_task.date_string); + tasks.push(new_task.clone()); save_tasks(tasks); - println!("Added: {}", text.green()); + println!("Added: {} --due {}", text.green(), date_string.blue()); } pub fn list_tasks(tasks: &[Task]) { if tasks.is_empty() { println!("No tasks yet!"); } else { + let now: DateTime = Utc::now(); + let current_date = now.format("%Y-%m-%d").to_string(); + for (i, task) in tasks.iter().enumerate() { let status = if task.done { "[X]" } else { "[ ]" }; - println!("{}: {} {}", i, status.yellow(), task.text.blue()); + let (task_text, date_text) = if current_date > task.date_string { + // Overdue + (task.text.blue(), task.date_string.red()) + } else { + // Due today or in the future + (task.text.blue(), task.date_string.yellow()) + }; + println!("{}: {} {} due {}", i, status, task_text, date_text); } } } @@ -39,3 +52,18 @@ pub fn done_task(tasks: &mut Vec, index: usize) { println!("Error: Invalid index {}", index); } } +pub fn edit_task(tasks: &mut Vec, index: usize, new_text: String) { + if index < tasks.len() { + let old_text = tasks[index].text.clone(); + tasks[index].text = new_text.clone(); + save_tasks(tasks); + println!( + "Edited task {}: '{}' -> '{}'", + index, + old_text.yellow(), + new_text.green() + ); + } else { + println!("Error: Invalid index {index}"); + } +} diff --git a/src/lib.rs b/src/lib.rs index 1922918..a8c1fa5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,6 @@ pub mod storage; pub mod task; // Add commands module // Re-export for convenience -pub use commands::{add_task, done_task, list_tasks, remove_task}; +pub use commands::{add_task, done_task, edit_task, list_tasks, remove_task}; pub use storage::{load_tasks, save_tasks}; pub use task::Task; diff --git a/src/main.rs b/src/main.rs index 7f03389..6fe9f51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use clap::{Parser, Subcommand}; use colored::control; -use tasky_cli::commands::{add_task, done_task, list_tasks, remove_task}; +use tasky_cli::commands::{add_task, done_task, edit_task, list_tasks, remove_task}; use tasky_cli::storage::load_tasks; // Import from tasky_cli #[derive(Parser)] @@ -16,8 +16,9 @@ struct Args { #[derive(Subcommand)] enum Commands { - Add { text: String }, + Add { text: String, date_string: String }, List, + Edit { index: usize, new_text: String }, Remove { index: usize }, Done { index: usize }, } @@ -29,8 +30,8 @@ fn main() { let mut tasks = load_tasks(); match args.command { - Commands::Add { text } => { - add_task(&mut tasks, text); + Commands::Add { text, date_string } => { + add_task(&mut tasks, text, date_string); } Commands::List => { list_tasks(&tasks); @@ -41,5 +42,8 @@ fn main() { Commands::Done { index } => { done_task(&mut tasks, index); } + Commands::Edit { index, new_text } => { + edit_task(&mut tasks, index, new_text); + } } } diff --git a/src/storage.rs b/src/storage.rs index f1129c7..42cf509 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -12,6 +12,7 @@ pub fn load_tasks() -> Vec { } pub fn save_tasks(tasks: &[Task]) { + println!("{}", tasks.len()); let json = serde_json::to_string_pretty(tasks).expect("Failed to serialize tasks"); fs::write(TASKS_FILE, json).expect("Failed to write tasks file"); } diff --git a/src/task.rs b/src/task.rs index 7b43270..f60c96d 100644 --- a/src/task.rs +++ b/src/task.rs @@ -4,11 +4,16 @@ use serde::{Deserialize, Serialize}; pub struct Task { pub text: String, pub done: bool, + pub date_string: String, } impl Task { - pub fn new(text: String) -> Self { - Self { text, done: false } + pub fn new(text: String, date_string: String) -> Self { + Self { + text, + done: false, + date_string, + } } pub fn mark_done(&mut self) {