From 53d1c84f5cb26d5e289db5a0e6ef31e5226e289d Mon Sep 17 00:00:00 2001 From: aaron-jack-manning Date: Sun, 21 Aug 2022 12:34:34 +1000 Subject: [PATCH] default list ordering --- src/tasks.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/tasks.rs b/src/tasks.rs index 4fc5214..b82d93f 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -19,7 +19,7 @@ pub struct Task { pub data : InternalTask, } -#[derive(Default, Debug, Clone, clap::ValueEnum, serde::Serialize, serde::Deserialize)] +#[derive(Default, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum, serde::Serialize, serde::Deserialize)] pub enum Priority { #[default] Low, @@ -266,9 +266,15 @@ pub fn list(vault_folder : &path::Path) -> Result<(), error::Error> { table.set_header(vec!["Id", "Name", "Tags", "Priority"]); - for id in ids { - let task = Task::load(id, vault_folder.to_path_buf(), true)?; + let mut tasks = Vec::with_capacity(ids.len()); + for id in ids { + tasks.push(Task::load(id, vault_folder.to_path_buf(), true)?); + } + + tasks.sort_by(|t1, t2| t2.data.priority.cmp(&t1.data.priority)); + + for task in tasks { if !task.data.discarded && !task.data.complete { table.add_row( vec![