{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
module Control.Effect.Readline
( -- * Readline effect
  Readline(..)
, prompt
, print
  -- * Re-exports
, Algebra
, Has
, run
) where

import Control.Algebra
import Data.Kind (Type)
import Data.Text.Prettyprint.Doc (Doc)
import Data.Text.Prettyprint.Doc.Render.Terminal (AnsiStyle)
import Prelude hiding (print)

prompt :: Has Readline sig m => String -> m (Int, Maybe String)
prompt :: String -> m (Int, Maybe String)
prompt String
p = Readline m (Int, Maybe String) -> m (Int, Maybe String)
forall (eff :: (* -> *) -> * -> *) (sig :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Member eff sig, Algebra sig m) =>
eff m a -> m a
send (String -> Readline m (Int, Maybe String)
forall (m :: * -> *). String -> Readline m (Int, Maybe String)
Prompt String
p)

print :: Has Readline sig m => Doc AnsiStyle -> m ()
print :: Doc AnsiStyle -> m ()
print Doc AnsiStyle
s = Readline m () -> m ()
forall (eff :: (* -> *) -> * -> *) (sig :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Member eff sig, Algebra sig m) =>
eff m a -> m a
send (Doc AnsiStyle -> Readline m ()
forall (m :: * -> *). Doc AnsiStyle -> Readline m ()
Print Doc AnsiStyle
s)


data Readline (m :: Type -> Type) (k :: Type) where
  Prompt :: String -> Readline m (Int, Maybe String)
  Print :: Doc AnsiStyle -> Readline m ()