-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathApp.hs
More file actions
32 lines (27 loc) · 947 Bytes
/
Copy pathApp.hs
File metadata and controls
32 lines (27 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module App (App, PromptResult (..), Env (..), printText) where
import Config.AppConfig (AppConfig)
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Reader (ReaderT, asks)
import Data.Map (Map)
import Data.Text (Text)
import Prelude hiding (putStrLn)
type App a = ReaderT Env IO a
{- | The environment defines the Apps dependencies.
This is useful for testing, as these dependencies
can be mocked easily. Apart from the AppConfig,
it contains all the IO functions, like printing to
the terminal or reading a file.
-}
data Env = Env
{ config :: AppConfig
, putStrLn :: Text -> IO ()
, readFile :: FilePath -> IO Text
, appendFile :: FilePath -> Text -> IO ()
, promptForEntry :: Map Text Text -> Text -> App (PromptResult Text)
, sleep :: IO ()
}
data PromptResult a = Result a | Skip deriving (Show)
printText :: Text -> App ()
printText text = do
putStrLn <- asks (.putStrLn)
liftIO $ putStrLn text