Add ByteString
This commit is contained in:
parent
c2a0a64a20
commit
c6745f5b35
18
app/Main.hs
18
app/Main.hs
@ -1,11 +1,13 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
module Main(main,parseTask, serializeTask, getPriority, comparePriority, TaskMap) where
|
module Main(main, parseTask, serializeTask, getPriority, comparePriority, TaskMap) where
|
||||||
|
|
||||||
import System.IO
|
import System.IO
|
||||||
import System.Directory
|
import System.Directory
|
||||||
import Data.Text (Text, pack, unpack, isInfixOf, lines, unlines, strip, splitOn)
|
import Data.Text (Text, pack, unpack, isInfixOf, lines, unlines, strip)
|
||||||
import qualified Data.Text.IO as TIO
|
import qualified Data.Text.IO as TIO
|
||||||
|
import qualified Data.ByteString as BS
|
||||||
|
import qualified Data.ByteString.Char8 as BSC
|
||||||
import Control.Monad (when)
|
import Control.Monad (when)
|
||||||
import Data.List (sortBy)
|
import Data.List (sortBy)
|
||||||
import Data.Ord (comparing)
|
import Data.Ord (comparing)
|
||||||
@ -42,8 +44,8 @@ displayTasks = do
|
|||||||
exists <- doesFileExist todoFile
|
exists <- doesFileExist todoFile
|
||||||
if exists
|
if exists
|
||||||
then do
|
then do
|
||||||
contents <- TIO.readFile todoFile
|
contents <- BSC.readFile todoFile
|
||||||
let taskMap = parseTask contents
|
let taskMap = parseTask (pack (BSC.unpack contents))
|
||||||
putStrLn "Tasks:"
|
putStrLn "Tasks:"
|
||||||
mapM_ (putStrLn . showTask) (Map.toList taskMap)
|
mapM_ (putStrLn . showTask) (Map.toList taskMap)
|
||||||
else putStrLn "No tasks found."
|
else putStrLn "No tasks found."
|
||||||
@ -57,12 +59,12 @@ addTask = do
|
|||||||
exists <- doesFileExist todoFile
|
exists <- doesFileExist todoFile
|
||||||
if exists
|
if exists
|
||||||
then do
|
then do
|
||||||
contents <- TIO.readFile todoFile
|
contents <- BSC.readFile todoFile
|
||||||
let taskMap = parseTask contents
|
let taskMap = parseTask (pack (BSC.unpack contents))
|
||||||
newId = if Map.null taskMap then 1 else fst (Map.findMax taskMap) + 1
|
newId = if Map.null taskMap then 1 else fst (Map.findMax taskMap) + 1
|
||||||
newTaskMap = Map.insert newId (pack task) taskMap
|
newTaskMap = Map.insert newId (pack task) taskMap
|
||||||
TIO.writeFile todoFile (serializeTask newTaskMap)
|
BSC.writeFile todoFile (BSC.pack (unpack (serializeTask newTaskMap)))
|
||||||
else TIO.writeFile todoFile (pack task <> "\n")
|
else BSC.writeFile todoFile (BSC.pack (task <> "\n"))
|
||||||
putStrLn "Task added."
|
putStrLn "Task added."
|
||||||
main
|
main
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@ dependencies:
|
|||||||
- text
|
- text
|
||||||
- directory
|
- directory
|
||||||
- containers
|
- containers
|
||||||
|
- bytestring
|
||||||
|
|
||||||
|
|
||||||
ghc-options:
|
ghc-options:
|
||||||
- -Wall
|
- -Wall
|
||||||
|
@ -35,6 +35,7 @@ library
|
|||||||
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints
|
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints
|
||||||
build-depends:
|
build-depends:
|
||||||
base >=4.7 && <5
|
base >=4.7 && <5
|
||||||
|
, bytestring
|
||||||
, containers
|
, containers
|
||||||
, directory
|
, directory
|
||||||
, text
|
, text
|
||||||
@ -51,6 +52,7 @@ executable todo-app
|
|||||||
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
|
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
|
||||||
build-depends:
|
build-depends:
|
||||||
base >=4.7 && <5
|
base >=4.7 && <5
|
||||||
|
, bytestring
|
||||||
, containers
|
, containers
|
||||||
, directory
|
, directory
|
||||||
, text
|
, text
|
||||||
@ -69,6 +71,7 @@ test-suite todo-app-test
|
|||||||
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
|
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
|
||||||
build-depends:
|
build-depends:
|
||||||
base >=4.7 && <5
|
base >=4.7 && <5
|
||||||
|
, bytestring
|
||||||
, containers
|
, containers
|
||||||
, directory
|
, directory
|
||||||
, hspec
|
, hspec
|
||||||
|
Loading…
Reference in New Issue
Block a user