Load tasks from file

This commit is contained in:
Joscha 2018-09-11 20:03:17 +00:00
parent 8f1b2856dc
commit 5621746f37
5 changed files with 72 additions and 19 deletions

View file

@ -2,13 +2,28 @@
module TaskMachine.TaskList
( LTask(..)
, fromTasks
, loadLTasks
) where
import qualified Data.Vector as V
import Text.Megaparsec
import TaskMachine.Todotxt
data LTask = LTask
{ ltaskNumber :: Integer
-- ^ Sort by this number to get the original order of the tasks
, ltaskTast :: Task
, ltaskTask :: Task
-- ^ The 'Task' itself
}
} deriving (Show)
fromTasks :: [Task] -> [LTask]
fromTasks = zipWith LTask [1..]
loadLTasks :: FilePath -> IO (Either String (V.Vector LTask))
loadLTasks file = do
content <- readFile file
case parseTasks file content of
Right tasks -> pure $ Right $ V.fromList $ fromTasks tasks
Left parseError -> pure $ Left $ show parseError