From c83d8a2f55d10d5167cac5fa6649ab0d8ddb3129 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Sun, 11 Aug 2024 12:05:29 +0300 Subject: [PATCH] feat(tasks): option to fully set sorting --- README.md | 2 +- src/main.rs | 11 ++++++++--- src/tasks.rs | 6 ++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c9c7a03..cb9ac90 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ To stop time-tracking completely, simply move to the root of all tasks. Dots and slashes can be repeated to move to parent tasks. - `:[IND][PROP]` - add property column PROP at IND or end, if it already exists remove property column PROP or IND (1-indexed) -- `::[PROP]` - Sort by property PROP +- `::[PROP]` - Sort by property PROP (multiple space-separated values allowed) - `([TIME]` - insert timetracking with the specified offset in minutes (empty: list tracked times) - `)[TIME]` - stop timetracking with the specified offset in minutes - convenience helper to move to root (empty: stop now) - `>[TEXT]` - complete active task and move to parent, with optional state description diff --git a/src/main.rs b/src/main.rs index ba91132..6f67252 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use std::cell::RefCell; -use std::collections::HashMap; +use std::collections::{HashMap, VecDeque}; use std::env::{args, var}; use std::fs; use std::fs::File; @@ -280,8 +280,13 @@ async fn main() { Some(':') => { let next = iter.next(); if let Some(':') = next { - // TODO reverse order if present - tasks.add_sorting_property(iter.collect()) + let str: String = iter.collect(); + let result = str.split_whitespace().map(|s| s.to_string()).collect::>(); + if result.len() == 1 { + tasks.add_sorting_property(str.trim().to_string()) + } else { + tasks.set_sorting(result) + } } else if let Some(digit) = next.and_then(|s| s.to_digit(10)) { let index = (digit as usize).saturating_sub(1); let remaining = iter.collect::().trim().to_string(); diff --git a/src/tasks.rs b/src/tasks.rs index 5251fb2..ed3ef5d 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -792,7 +792,13 @@ impl Tasks { &mut self.properties } + pub(crate) fn set_sorting(&mut self, vec: VecDeque) { + self.sorting = vec; + info!("Now sorting by {:?}", self.sorting); + } + pub(crate) fn add_sorting_property(&mut self, property: String) { + // TODO reverse order if already present self.sorting.push_front(property); self.sorting.truncate(4); info!("Now sorting by {:?}", self.sorting);