{-# 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 (forall a b. a -> PrimF b -> PrimF a
forall a b. (a -> b) -> PrimF a -> PrimF b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> PrimF b -> PrimF a
$c<$ :: forall a b. a -> PrimF b -> PrimF a
fmap :: forall a b. (a -> b) -> PrimF a -> PrimF b
$cfmap :: forall a b. (a -> b) -> PrimF a -> PrimF b
Functor)
say :: MonadFree PrimF m => Stylized Text -> m ()
say :: forall (m :: * -> *). MonadFree PrimF m => Stylized Text -> m ()
say = forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
Free.liftF forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall f. Stylized Text -> f -> PrimF f
`Say` ())
sayLn :: MonadFree PrimF m => Stylized Text -> m ()
sayLn :: forall (m :: * -> *). MonadFree PrimF m => Stylized Text -> m ()
sayLn Stylized Text
message = forall (m :: * -> *). MonadFree PrimF m => Stylized Text -> m ()
say (Stylized Text
message forall a. Semigroup a => a -> a -> a
<> Text -> Stylized Text
text Text
"\n")
askLn :: MonadFree PrimF m => Stylized Text -> Maybe Text -> m Text
askLn :: forall (m :: * -> *).
MonadFree PrimF m =>
Stylized Text -> Maybe Text -> m Text
askLn Stylized Text
prompt Maybe Text
def = forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
Free.liftF (forall f. Stylized Text -> Maybe Text -> (Text -> f) -> PrimF f
AskLn Stylized Text
prompt Maybe Text
def forall a. a -> a
id)
askChar :: MonadFree PrimF m => Stylized Text -> m Char
askChar :: forall (m :: * -> *). MonadFree PrimF m => Stylized Text -> m Char
askChar = forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
Free.liftF forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall f. Stylized Text -> (Char -> f) -> PrimF f
`AskChar` forall a. a -> a
id)
askPassword :: MonadFree PrimF m => Stylized Text -> Maybe Char -> m Text
askPassword :: forall (m :: * -> *).
MonadFree PrimF m =>
Stylized Text -> Maybe Char -> m Text
askPassword Stylized Text
prompt Maybe Char
mask = forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
Free.liftF (forall f. Stylized Text -> Maybe Char -> (Text -> f) -> PrimF f
AskPassword Stylized Text
prompt Maybe Char
mask forall a. a -> a
id)
pushCompFunc :: MonadFree PrimF m => CompletionFunc IO -> m ()
pushCompFunc :: forall (m :: * -> *).
MonadFree PrimF m =>
CompletionFunc IO -> m ()
pushCompFunc = forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
Free.liftF forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall f. CompletionFunc IO -> f -> PrimF f
`PushCompFunc` ())
popCompFunc :: MonadFree PrimF m => m ()
popCompFunc :: forall (m :: * -> *). MonadFree PrimF m => m ()
popCompFunc = forall (f :: * -> *) (m :: * -> *) a.
(Functor f, MonadFree f m) =>
f a -> m a
Free.liftF (forall f. f -> PrimF f
PopCompFunc ())