diff --git a/src/cmd_add.rs b/src/cmd_add.rs index ca5608a..973e282 100644 --- a/src/cmd_add.rs +++ b/src/cmd_add.rs @@ -1,3 +1,4 @@ +use crate::cmd_list; use crate::model::Task; use crate::services::{ContentGetter, ContentSetter, StringOutputer, UserCmdRunner}; use crate::tasks::{add_line_in_contents, get_all_tasks}; @@ -40,15 +41,14 @@ pub fn cmd_add( let new_line = format!("- [ ] {}", task_name); let result = add_line_in_contents(content_getter, line_num, new_line.clone())?; - outputer.info(format!("{}", result)); - let set_result = content_setter.set_contents(result); + content_setter.set_contents(result)?; let new_task = Task { name: task_name.clone(), line: new_line, line_num: line_num, - is_completed: false, + is_checked: false, is_focused: false, num: task_num, }; @@ -65,5 +65,5 @@ pub fn cmd_add( Err(e) => return Err(e), }; - set_result + cmd_list(outputer, content_getter) } diff --git a/src/cmd_check.rs b/src/cmd_check.rs index 93592b9..8673bd4 100644 --- a/src/cmd_check.rs +++ b/src/cmd_check.rs @@ -9,7 +9,7 @@ pub fn cmd_check( content_setter: &dyn ContentSetter, user_cmd_runner: &dyn UserCmdRunner, args: Vec, - completed: bool, + checked: bool, ) -> Result<(), String> { let rank_one_based = match get_cmd_rank_arg(args)? { None => return cmd_list(outputer, content_getter), @@ -23,16 +23,16 @@ pub fn cmd_check( let task = &tasks[rank_one_based - 1]; - if completed && task.is_completed { + if checked && task.is_checked { outputer.info(format!("Already checked: [{}] {}", task.num, task.name)); return Ok(()); - } else if !completed && !task.is_completed { + } else if !checked && !task.is_checked { outputer.info(format!("Already unckecked: [{}] {}", task.num, task.name)); return Ok(()); } - let checked_line = toggle_line_completion(task.line.clone(), completed); - let action = if completed { "Checked" } else { "Unchecked" }; + let checked_line = toggle_line_completion(task.line.clone(), checked); + let action = if checked { "Checked" } else { "Unchecked" }; outputer.info(format!("{}: [{}] {}", action, task.num, task.name)); let replaced_content = @@ -41,16 +41,16 @@ pub fn cmd_check( let result = content_setter.set_contents(replaced_content); let mut updated_task = task.clone(); - updated_task.is_completed = completed; + updated_task.is_checked = checked; updated_task.line = checked_line; match user_cmd_runner.build( String::from("check"), - String::from(if completed { "CHECK" } else { "UNCHECK" }), + String::from(if checked { "CHECK" } else { "UNCHECK" }), format!( "Marked \"{}\" as {}", task.name, - if completed { "done" } else { "not done" } + if checked { "done" } else { "not done" } ), ) { Ok(Some(mut cmd)) => { diff --git a/src/cmd_focus.rs b/src/cmd_focus.rs index 1e1976d..254b9da 100644 --- a/src/cmd_focus.rs +++ b/src/cmd_focus.rs @@ -23,9 +23,9 @@ pub fn cmd_focus( let task = &tasks[rank_one_based - 1]; - if task.is_completed { + if task.is_checked { outputer.info(format!( - "Completed, cannot proceed: [{}] {}", + "Task is completed, cannot proceed: [{}] {}", task.num, task.name )); return Ok(()); diff --git a/src/model.rs b/src/model.rs index 211d64b..efe0127 100644 --- a/src/model.rs +++ b/src/model.rs @@ -2,7 +2,7 @@ pub struct Task { pub num: usize, pub name: String, - pub is_completed: bool, + pub is_checked: bool, pub line_num: usize, pub line: String, pub is_focused: bool, diff --git a/src/services.rs b/src/services.rs index b53bce0..c3c4538 100644 --- a/src/services.rs +++ b/src/services.rs @@ -123,10 +123,7 @@ impl UserCmdRunner for UserCmdRunnerReal { .env("TAX_TASK_NAME", &task.name) .env("TAX_TASK_LINE", &task.line) .env("TAX_TASK_LINE_NUM", format!("{}", task.line_num)) - .env( - "TAX_TASK_COMPLETED", - if task.is_completed { "1" } else { "0" }, - ) + .env("TAX_TASK_CHECKED", if task.is_checked { "1" } else { "0" }) .env("TAX_TASK_FOCUSED", if task.is_focused { "1" } else { "0" }) } diff --git a/src/tasks.rs b/src/tasks.rs index a1481d0..b9bbdf5 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -55,7 +55,7 @@ pub fn get_all_tasks(content_getter: &dyn ContentGetter) -> Result, St tasks.push(Task { name: name, num: task_num, - is_completed: is_check_symbol(check_symbol), + is_checked: is_check_symbol(check_symbol), line_num: line_num, line: String::from(&cap[0]), is_focused: is_focused, @@ -74,14 +74,14 @@ pub fn get_all_tasks(content_getter: &dyn ContentGetter) -> Result, St pub fn get_open_tasks(content_getter: &dyn ContentGetter) -> Result, String> { Ok(get_all_tasks(content_getter)? .into_iter() - .filter(|task| !task.is_completed) + .filter(|task| !task.is_checked) .collect()) } pub fn get_closed_tasks(content_getter: &dyn ContentGetter) -> Result, String> { Ok(get_all_tasks(content_getter)? .into_iter() - .filter(|task| task.is_completed) + .filter(|task| task.is_checked) .collect()) } @@ -100,8 +100,8 @@ pub fn format_numbered_task(task: &Task) -> String { format!("[{}] {}", task.num, task.name) } -pub fn toggle_line_completion(line: String, completed: bool) -> String { - let (re, replacement) = if completed { +pub fn toggle_line_completion(line: String, checked: bool) -> String { + let (re, replacement) = if checked { ( Regex::new( r"(?x) diff --git a/src/test_helpers.rs b/src/test_helpers.rs index 16fdad1..e0bc3e2 100644 --- a/src/test_helpers.rs +++ b/src/test_helpers.rs @@ -63,7 +63,7 @@ pub fn get_std_test_contents() -> (Vec, Vec) { line_num: 2, line: String::from("- [ ] Standard unchecked"), name: String::from("Standard unchecked"), - is_completed: false, + is_checked: false, is_focused: false, }, crate::model::Task { @@ -71,7 +71,7 @@ pub fn get_std_test_contents() -> (Vec, Vec) { line_num: 3, line: String::from("- [] Collapsed unchecked"), name: String::from("Collapsed unchecked"), - is_completed: false, + is_checked: false, is_focused: false, }, crate::model::Task { @@ -79,7 +79,7 @@ pub fn get_std_test_contents() -> (Vec, Vec) { line_num: 4, line: String::from("- [ ] **Standard unchecked focused**"), name: String::from("**Standard unchecked focused**"), - is_completed: false, + is_checked: false, is_focused: true, }, crate::model::Task { @@ -87,7 +87,7 @@ pub fn get_std_test_contents() -> (Vec, Vec) { line_num: 5, line: String::from("* [ ] Star unchecked"), name: String::from("Star unchecked"), - is_completed: false, + is_checked: false, is_focused: false, }, crate::model::Task { @@ -95,7 +95,7 @@ pub fn get_std_test_contents() -> (Vec, Vec) { line_num: 7, line: String::from("- [x] Checked"), name: String::from("Checked"), - is_completed: true, + is_checked: true, is_focused: false, }, crate::model::Task { @@ -103,7 +103,7 @@ pub fn get_std_test_contents() -> (Vec, Vec) { line_num: 8, line: String::from("- [x] **Focused checked**"), name: String::from("**Focused checked**"), - is_completed: true, + is_checked: true, is_focused: true, }, ],