Load tasks from file
This commit is contained in:
parent
8f1b2856dc
commit
5621746f37
5 changed files with 72 additions and 19 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue