refactor file io and task to_string

This commit is contained in:
2023-06-26 09:40:56 -04:00
parent e90ec3e647
commit 85d81c02cc
2 changed files with 56 additions and 53 deletions

View File

@@ -76,23 +76,17 @@ impl ToString for Task {
};
let subtasks = if let Some(subtasks) = &self.subtasks {
let mut text = subtasks
let text = subtasks
.iter()
.map(|task| task.to_string())
.collect::<Vec<_>>()
.join("\n");
text.insert(0, '\n');
text.trim_end().to_string()
format!("\n{}", text).trim_end().replace("\n", "\n ")
} else {
"".into()
};
format!(
"- [{}] {}{}\n",
ch,
self.text.trim(),
subtasks.replace("\n", "\n ")
)
format!("- [{}] {}{}\n", ch, self.text.trim(), subtasks)
}
}