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