Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed becomes checked #8

Merged
merged 1 commit into from
Jul 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/cmd_add.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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,
};
Expand All @@ -65,5 +65,5 @@ pub fn cmd_add(
Err(e) => return Err(e),
};

set_result
cmd_list(outputer, content_getter)
}
16 changes: 8 additions & 8 deletions src/cmd_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn cmd_check(
content_setter: &dyn ContentSetter,
user_cmd_runner: &dyn UserCmdRunner,
args: Vec<String>,
completed: bool,
checked: bool,
) -> Result<(), String> {
let rank_one_based = match get_cmd_rank_arg(args)? {
None => return cmd_list(outputer, content_getter),
Expand All @@ -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 =
Expand All @@ -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)) => {
Expand Down
4 changes: 2 additions & 2 deletions src/cmd_focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
Expand Down
2 changes: 1 addition & 1 deletion src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" })
}

Expand Down
10 changes: 5 additions & 5 deletions src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn get_all_tasks(content_getter: &dyn ContentGetter) -> Result<Vec<Task>, 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,
Expand All @@ -74,14 +74,14 @@ pub fn get_all_tasks(content_getter: &dyn ContentGetter) -> Result<Vec<Task>, St
pub fn get_open_tasks(content_getter: &dyn ContentGetter) -> Result<Vec<Task>, 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<Vec<Task>, String> {
Ok(get_all_tasks(content_getter)?
.into_iter()
.filter(|task| task.is_completed)
.filter(|task| task.is_checked)
.collect())
}

Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,47 +63,47 @@ pub fn get_std_test_contents() -> (Vec<String>, Vec<crate::model::Task>) {
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 {
num: 2,
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 {
num: 3,
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 {
num: 4,
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 {
num: 5,
line_num: 7,
line: String::from("- [x] Checked"),
name: String::from("Checked"),
is_completed: true,
is_checked: true,
is_focused: false,
},
crate::model::Task {
num: 6,
line_num: 8,
line: String::from("- [x] **Focused checked**"),
name: String::from("**Focused checked**"),
is_completed: true,
is_checked: true,
is_focused: true,
},
],
Expand Down