diff --git a/app/Main.hs b/app/Main.hs index 2f4e709..1c3dee1 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -2,7 +2,7 @@ module Main where import Control.Monad -import qualified Brick as B +import qualified Brick as B import TaskMachine.Options import TaskMachine.UI diff --git a/src/TaskMachine/Task.hs b/src/TaskMachine/Task.hs index a8a726c..ae82c10 100644 --- a/src/TaskMachine/Task.hs +++ b/src/TaskMachine/Task.hs @@ -20,6 +20,8 @@ module TaskMachine.Task , charToPriority , Description , Snippet(..) + -- * Misc stuff + , compareTasks -- * Formatting , formatTask , formatTasks @@ -49,6 +51,7 @@ module TaskMachine.Task ) where import Control.Monad +import Data.Function import qualified Data.List.NonEmpty as NE import Data.Void @@ -119,7 +122,7 @@ formatCreated d = 'c' : formatDate d data Completion = Incomplete | Complete (Maybe Day) - deriving (Show) + deriving (Eq, Ord, Show) -- | Convert a 'Completion' to its string representation, which can be parsed by 'pCompletion'. -- @@ -137,7 +140,7 @@ data Priority | PrioH | PrioI | PrioJ | PrioK | PrioL | PrioM | PrioN | PrioO | PrioP | PrioQ | PrioR | PrioS | PrioT | PrioU | PrioV | PrioW | PrioX | PrioY | PrioZ - deriving (Bounded, Enum, Eq, Show, Ord) + deriving (Bounded, Enum, Eq, Ord, Show) -- | Convert a 'Priority' to its string representation, which can be parsed by 'pPriority'. -- @@ -178,7 +181,7 @@ data Snippet -- ^ A word of the form @key:value@. -- The key and value cannot contain any spaces. -- The key cannot contain any @":"@ characters, but the value can. - deriving (Eq, Show) + deriving (Show) -- | Convert a 'Description' into its string representation, which can be parsed by 'pDescription'. -- @@ -226,7 +229,7 @@ pCreated = label "creation date" $ char 'c' *> pDate -- | Parse a 'Completion' (see 'formatCompletion'). pCompletion :: Parser Completion pCompletion = Incomplete <$ char '-' - <|> char 'x' *> (label "completion date" $ Complete <$> maybeParse pDate) + <|> char 'x' *> label "completion date" (Complete <$> maybeParse pDate) -- Priority @@ -307,3 +310,22 @@ pTask -- | Parse a list of 'Task's (see 'formatTasks'). pTasks :: Parser [Task] pTasks = many pTask <* eof + + {- Misc stuff -} + +compareTasks :: Task -> Task -> Ordering +compareTasks a b = mconcat + [ compare (taskCompletion a) (taskCompletion b) + , compareMaybe (taskPriority a) (taskPriority b) + , compareMaybe (taskDue a) (taskDue b) + , compareDescription (taskDescription a) (taskDescription b) + ] + where + -- Inverted compare for Maybes: Nothing comes after Just + compareMaybe :: Ord a => Maybe a -> Maybe a -> Ordering + compareMaybe Nothing Nothing = EQ + compareMaybe (Just _) Nothing = LT + compareMaybe Nothing (Just _) = GT + compareMaybe (Just x) (Just y) = compare x y + compareDescription :: Description -> Description -> Ordering + compareDescription = compare `on` formatDescription diff --git a/src/TaskMachine/UI.hs b/src/TaskMachine/UI.hs index b53c74e..c792342 100644 --- a/src/TaskMachine/UI.hs +++ b/src/TaskMachine/UI.hs @@ -11,9 +11,9 @@ import qualified Graphics.Vty.Input.Events as VTY import TaskMachine.Options import TaskMachine.UI.NewTask +import TaskMachine.UI.Popup import TaskMachine.UI.TaskList import TaskMachine.UI.TopBar -import TaskMachine.UI.Popup import TaskMachine.UI.Types drawBaseLayer :: UIState -> B.Widget RName diff --git a/src/TaskMachine/UI/Task.hs b/src/TaskMachine/UI/Task.hs index aa1a808..5a2c311 100644 --- a/src/TaskMachine/UI/Task.hs +++ b/src/TaskMachine/UI/Task.hs @@ -55,9 +55,9 @@ renderSnippet s = B.str $ format renderTask :: Task -> B.Widget n renderTask t = B.hBox $ catMaybes [ Just $ withSpace $ renderCompletion $ taskCompletion t - , (withSpace . renderPriority) <$> taskPriority t - , (withSpace . renderDue) <$> taskDue t - , (withSpace . renderCreated) <$> taskCreated t + , withSpace . renderPriority <$> taskPriority t + , withSpace . renderDue <$> taskDue t + , withSpace . renderCreated <$> taskCreated t , Just $ renderDescription $ taskDescription t ] diff --git a/todo.txt b/todo.txt index a7ae29b..f37e717 100644 --- a/todo.txt +++ b/todo.txt @@ -1,7 +1,7 @@ -- c2018-09-18 Sort tasks by completion, priority, due date, description -- c2018-09-18 Quit using Esc or q -- c2018-09-18 Offer "retry" or "quit" +dialogue - syntax error in todo file - c2018-09-18 Offer "retry" or "quit" +dialogue - couldn't load from todo file - c2018-09-18 Offer "retry" or "quit" +dialogue - couldn't save to todo file +- c2018-09-18 Offer "retry" or "quit" +dialogue - syntax error in todo file - c2018-09-18 Offer to clean up file when loading (adding creation/completion dates) - c2018-09-18 Purge - move completed tasks to a separate file +- c2018-09-18 Quit using Esc or q +- c2018-09-18 Sort tasks by completion, priority, due date, description