{-# OPTIONS_HADDOCK hide #-}
module Byline.Internal.Prim
( PrimF (..),
say,
sayLn,
askLn,
askChar,
askPassword,
pushCompFunc,
popCompFunc,
)
where
import Byline.Internal.Completion (CompletionFunc)
import Byline.Internal.Stylized (Stylized, text)
import Control.Monad.Trans.Free.Church (MonadFree)
import qualified Control.Monad.Trans.Free.Church as Free
data PrimF f
= Say (Stylized Text) f
| AskLn (Stylized Text) (Maybe Text) (Text -> f)
| AskChar (Stylized Text) (Char -> f)
| AskPassword (Stylized Text) (Maybe Char) (Text -> f)
| PushCompFunc (CompletionFunc IO) f
| PopCompFunc f
deriving (Functor)
say :: MonadFree PrimF m => Stylized Text -> m ()
say = Free.liftF . (`Say` ())
sayLn :: MonadFree PrimF m => Stylized Text -> m ()
sayLn message = say (message <> text "\n")
askLn :: MonadFree PrimF m => Stylized Text -> Maybe Text -> m Text
askLn prompt def = Free.liftF (AskLn prompt def id)
askChar :: MonadFree PrimF m => Stylized Text -> m Char
askChar = Free.liftF . (`AskChar` id)
askPassword :: MonadFree PrimF m => Stylized Text -> Maybe Char -> m Text
askPassword prompt mask = Free.liftF (AskPassword prompt mask id)
pushCompFunc :: MonadFree PrimF m => CompletionFunc IO -> m ()
pushCompFunc = Free.liftF . (`PushCompFunc` ())
popCompFunc :: MonadFree PrimF m => m ()
popCompFunc = Free.liftF (PopCompFunc ())