module Byline
(
MonadByline,
BylineT,
runBylineT,
say,
sayLn,
askLn,
askChar,
askPassword,
askUntil,
Stylized,
ToStylizedText (..),
text,
fg,
bg,
bold,
underline,
swapFgBg,
Color,
black,
red,
green,
yellow,
blue,
magenta,
cyan,
white,
rgb,
)
where
import Byline.Internal.Color
import Byline.Internal.Eval (BylineT, MonadByline (..), runBylineT)
import qualified Byline.Internal.Prim as Prim
import Byline.Internal.Stylized
say ::
(MonadByline m, ToStylizedText a) =>
a ->
m ()
say :: a -> m ()
say =
a -> Stylized Text
forall a. ToStylizedText a => a -> Stylized Text
toStylizedText
(a -> Stylized Text) -> (Stylized Text -> m ()) -> a -> m ()
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Stylized Text -> FT PrimF Identity ()
forall (m :: * -> *). MonadFree PrimF m => Stylized Text -> m ()
Prim.say
(Stylized Text -> FT PrimF Identity ())
-> (FT PrimF Identity () -> m ()) -> Stylized Text -> m ()
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> FT PrimF Identity () -> m ()
forall (m :: * -> *) a. MonadByline m => F PrimF a -> m a
liftByline
sayLn ::
(MonadByline m, ToStylizedText a) =>
a ->
m ()
sayLn :: a -> m ()
sayLn =
a -> Stylized Text
forall a. ToStylizedText a => a -> Stylized Text
toStylizedText
(a -> Stylized Text) -> (Stylized Text -> m ()) -> a -> m ()
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Stylized Text -> FT PrimF Identity ()
forall (m :: * -> *). MonadFree PrimF m => Stylized Text -> m ()
Prim.sayLn
(Stylized Text -> FT PrimF Identity ())
-> (FT PrimF Identity () -> m ()) -> Stylized Text -> m ()
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> FT PrimF Identity () -> m ()
forall (m :: * -> *) a. MonadByline m => F PrimF a -> m a
liftByline
askLn ::
(MonadByline m, ToStylizedText a) =>
a ->
Maybe Text ->
m Text
askLn :: a -> Maybe Text -> m Text
askLn a
prompt Maybe Text
def = F PrimF Text -> m Text
forall (m :: * -> *) a. MonadByline m => F PrimF a -> m a
liftByline (Stylized Text -> Maybe Text -> F PrimF Text
forall (m :: * -> *).
MonadFree PrimF m =>
Stylized Text -> Maybe Text -> m Text
Prim.askLn (a -> Stylized Text
forall a. ToStylizedText a => a -> Stylized Text
toStylizedText a
prompt) Maybe Text
def)
askChar ::
(MonadByline m, ToStylizedText a) =>
a ->
m Char
askChar :: a -> m Char
askChar =
a -> Stylized Text
forall a. ToStylizedText a => a -> Stylized Text
toStylizedText
(a -> Stylized Text) -> (Stylized Text -> m Char) -> a -> m Char
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Stylized Text -> FT PrimF Identity Char
forall (m :: * -> *). MonadFree PrimF m => Stylized Text -> m Char
Prim.askChar
(Stylized Text -> FT PrimF Identity Char)
-> (FT PrimF Identity Char -> m Char) -> Stylized Text -> m Char
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> FT PrimF Identity Char -> m Char
forall (m :: * -> *) a. MonadByline m => F PrimF a -> m a
liftByline
askPassword ::
(MonadByline m, ToStylizedText a) =>
a ->
Maybe Char ->
m Text
askPassword :: a -> Maybe Char -> m Text
askPassword a
prompt =
Stylized Text -> Maybe Char -> F PrimF Text
forall (m :: * -> *).
MonadFree PrimF m =>
Stylized Text -> Maybe Char -> m Text
Prim.askPassword (a -> Stylized Text
forall a. ToStylizedText a => a -> Stylized Text
toStylizedText a
prompt)
(Maybe Char -> F PrimF Text)
-> (F PrimF Text -> m Text) -> Maybe Char -> m Text
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> F PrimF Text -> m Text
forall (m :: * -> *) a. MonadByline m => F PrimF a -> m a
liftByline
askUntil ::
(MonadByline m, ToStylizedText a, ToStylizedText e) =>
a ->
Maybe Text ->
(Text -> m (Either e b)) ->
m b
askUntil :: a -> Maybe Text -> (Text -> m (Either e b)) -> m b
askUntil a
prompt Maybe Text
def Text -> m (Either e b)
confirm = m b
go
where
go :: m b
go = do
Text
answer <- a -> Maybe Text -> m Text
forall (m :: * -> *) a.
(MonadByline m, ToStylizedText a) =>
a -> Maybe Text -> m Text
askLn a
prompt Maybe Text
def
Text -> m (Either e b)
confirm Text
answer m (Either e b) -> (Either e b -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Left e
msg -> e -> m ()
forall (m :: * -> *) a.
(MonadByline m, ToStylizedText a) =>
a -> m ()
sayLn e
msg m () -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> m b
go
Right b
res -> b -> m b
forall (f :: * -> *) a. Applicative f => a -> f a
pure b
res