haskeline-effectful
Safe HaskellNone
LanguageGHC2021

Effectful.Haskeline.Dynamic

Description

Provides a dynamic effect for haskeline.

Since: 0.1

Synopsis

Effect

data Haskeline (a :: Type -> Type) b where Source #

Dynamic haskeline effect.

Since: 0.1

Constructors

HaveTerminalUI :: forall (a :: Type -> Type). Haskeline a Bool 
GetInputLine :: forall (a :: Type -> Type). String -> Haskeline a (Maybe String) 
GetInputLineWithInitial :: forall (a :: Type -> Type). String -> (String, String) -> Haskeline a (Maybe String) 
GetInputChar :: forall (a :: Type -> Type). String -> Haskeline a (Maybe Char) 
GetPassword :: forall (a :: Type -> Type). Maybe Char -> String -> Haskeline a (Maybe String) 
WaitForAnyKey :: forall (a :: Type -> Type). String -> Haskeline a Bool 
OutputStr :: forall (a :: Type -> Type). String -> Haskeline a () 
OutputStrLn :: forall (a :: Type -> Type). String -> Haskeline a () 
GetHistory :: forall (a :: Type -> Type). Haskeline a History 
PutHistory :: forall (a :: Type -> Type). History -> Haskeline a () 
ModifyHistory :: forall (a :: Type -> Type). (History -> History) -> Haskeline a () 
WithInterrupt :: forall (a :: Type -> Type) b. a b -> Haskeline a b 
HandleInterrupt :: forall (a :: Type -> Type) b. a b -> a b -> Haskeline a b 

Instances

Instances details
ShowEffect Haskeline Source #

Since: 0.1

Instance details

Defined in Effectful.Haskeline.Dynamic

Methods

showEffectCons :: forall (m :: Type -> Type) a. Haskeline m a -> String Source #

type DispatchOf Haskeline Source #

Since: 0.1

Instance details

Defined in Effectful.Haskeline.Dynamic

haveTerminalUI :: forall (es :: [Effect]). (HasCallStack, Haskeline :> es) => Eff es Bool Source #

Lifted haveTerminalUI.

Since: 0.1

getInputLine :: forall (es :: [Effect]). (HasCallStack, Haskeline :> es) => String -> Eff es (Maybe String) Source #

Lifted getInputLine.

Since: 0.1

getInputChar :: forall (es :: [Effect]). (HasCallStack, Haskeline :> es) => String -> Eff es (Maybe Char) Source #

Lifted havegetInputCharTerminalUI.

Since: 0.1

getPassword :: forall (es :: [Effect]). (HasCallStack, Haskeline :> es) => Maybe Char -> String -> Eff es (Maybe String) Source #

Lifted getPassword.

Since: 0.1

waitForAnyKey :: forall (es :: [Effect]). (HasCallStack, Haskeline :> es) => String -> Eff es Bool Source #

Lifted waitForAnyKey.

Since: 0.1

outputStr :: forall (es :: [Effect]). (HasCallStack, Haskeline :> es) => String -> Eff es () Source #

Lifted outputStr.

Since: 0.1

outputStrLn :: forall (es :: [Effect]). (HasCallStack, Haskeline :> es) => String -> Eff es () Source #

Lifted outputStrLn.

Since: 0.1

getHistory :: forall (es :: [Effect]). (HasCallStack, Haskeline :> es) => Eff es History Source #

Lifted getHistory.

Since: 0.1

putHistory :: forall (es :: [Effect]). (HasCallStack, Haskeline :> es) => History -> Eff es () Source #

Lifted putHistory.

Since: 0.1

modifyHistory :: forall (es :: [Effect]). (HasCallStack, Haskeline :> es) => (History -> History) -> Eff es () Source #

Lifted modifyHistory.

Since: 0.1

withInterrupt :: forall (es :: [Effect]) a. (HasCallStack, Haskeline :> es) => Eff es a -> Eff es a Source #

Lifted withInterrupt.

Since: 0.1

handleInterrupt :: forall (es :: [Effect]) a. (HasCallStack, Haskeline :> es) => Eff es a -> Eff es a -> Eff es a Source #

Lifted handleInterrupt.

Since: 0.1

Handlers

runHaskeline :: forall (es :: [Effect]) a. (HasCallStack, IOE :> es, Reader (InputTEnv IO) :> es) => Eff (Haskeline ': es) a -> Eff es a Source #

Runs Haskeline in IO.

Since: 0.1

Reader

These functions allow eliminating the Haskeline effect in terms of ReaderT.

Examples:

 app :: (Haskeline :> es) => Eff es String
 app = do
   mLine <- getInputLine "Enter your name: "
   let name = fromMaybe "<blank>" mLine
   outputStrLn $ "Hello: " ++ name
   pure name

 appIO :: IO String
 appIO = do
   runInputTEnv
     $ env -> runEffInputTEnv env
     $ runHaskeline app

runHaskelinePure :: Eff (Haskeline : es) a -> Eff es a
runHaskelinePure = interpret_ $ \case
  GetInputLine _ -> pure $ Just "some name"
  OutputStrLn _ -> pure ()
  _ -> error "todo"

appPure :: String
appPure = runPureEff $ runHaskelinePure app

runEffInputTEnv Source #

Arguments

:: forall (m :: Type -> Type) a. HasCallStack 
=> InputTEnv m

The InputT environment.

-> Eff '[Reader (InputTEnv m), IOE] a

Eff action that requires the InputTEnv environment.

-> IO a

IO result.

Runner for Eff with InputTEnv. Intended for usage with runInputTEnv or runInputTEnvWith.

Since: 0.1

runInputTEnv Source #

Arguments

:: (HasCallStack, MonadIO m, MonadMask m) 
=> (InputTEnv m -> m a)

Action.

-> m a

IO result.

runInputTEnvWith with default haskeline settings.

Examples:

-- eff :: Eff [Reader (InputTEnv m), IOE] a
runInputTEnv $ env -> runEffInputTEnv env eff

Since: 0.1

runInputTEnvWith Source #

Arguments

:: HasCallStack 
=> (InputT m a -> m a)

InputT runner.

-> (InputTEnv m -> m a)

Action.

-> m a

IO result.

Runs ReaderT InputTEnv in IO with InputT runner.

Examples:

-- eff :: Eff [Reader (InputTEnv m), IOE] a
runInputTEnvWith runInput $ env -> runEffInputTEnv env eff

Since: 0.1

Haskeline Re-exports

Types

data InputT (m :: Type -> Type) a Source #

A monad transformer which carries all of the state and settings relevant to a line-reading application.

Instances

Instances details
MonadTrans InputT Source # 
Instance details

Defined in System.Console.Haskeline.InputT

Methods

lift :: Monad m => m a -> InputT m a #

MonadCatch m => MonadCatch (InputT m) Source # 
Instance details

Defined in System.Console.Haskeline.InputT

Methods

catch :: (HasCallStack, Exception e) => InputT m a -> (e -> InputT m a) -> InputT m a #

MonadMask m => MonadMask (InputT m) Source # 
Instance details

Defined in System.Console.Haskeline.InputT

Methods

mask :: HasCallStack => ((forall a. InputT m a -> InputT m a) -> InputT m b) -> InputT m b #

uninterruptibleMask :: HasCallStack => ((forall a. InputT m a -> InputT m a) -> InputT m b) -> InputT m b #

generalBracket :: HasCallStack => InputT m a -> (a -> ExitCase b -> InputT m c) -> (a -> InputT m b) -> InputT m (b, c) #

MonadThrow m => MonadThrow (InputT m) Source # 
Instance details

Defined in System.Console.Haskeline.InputT

Methods

throwM :: (HasCallStack, Exception e) => e -> InputT m a #

Applicative m => Applicative (InputT m) Source # 
Instance details

Defined in System.Console.Haskeline.InputT

Methods

pure :: a -> InputT m a #

(<*>) :: InputT m (a -> b) -> InputT m a -> InputT m b #

liftA2 :: (a -> b -> c) -> InputT m a -> InputT m b -> InputT m c #

(*>) :: InputT m a -> InputT m b -> InputT m b #

(<*) :: InputT m a -> InputT m b -> InputT m a #

Functor m => Functor (InputT m) Source # 
Instance details

Defined in System.Console.Haskeline.InputT

Methods

fmap :: (a -> b) -> InputT m a -> InputT m b #

(<$) :: a -> InputT m b -> InputT m a #

Monad m => Monad (InputT m) Source # 
Instance details

Defined in System.Console.Haskeline.InputT

Methods

(>>=) :: InputT m a -> (a -> InputT m b) -> InputT m b #

(>>) :: InputT m a -> InputT m b -> InputT m b #

return :: a -> InputT m a #

MonadFail m => MonadFail (InputT m) Source # 
Instance details

Defined in System.Console.Haskeline.InputT

Methods

fail :: String -> InputT m a #

MonadFix m => MonadFix (InputT m) Source # 
Instance details

Defined in System.Console.Haskeline.InputT

Methods

mfix :: (a -> InputT m a) -> InputT m a #

MonadIO m => MonadIO (InputT m) Source # 
Instance details

Defined in System.Console.Haskeline.InputT

Methods

liftIO :: IO a -> InputT m a #

data InputTEnv (m :: Type -> Type) Source #

The abstract environment used by InputT, for ReaderT usage.

Since: haskeline-0.8.4.0

IO Runners

runInputT :: (MonadIO m, MonadMask m) => Settings m -> InputT m a -> m a Source #

Run a line-reading application. This function should suffice for most applications.

This function is equivalent to runInputTBehavior defaultBehavior. It uses terminal-style interaction if stdin is connected to a terminal and has echoing enabled. Otherwise (e.g., if stdin is a pipe), it uses file-style interaction.

If it uses terminal-style interaction, Prefs will be read from the user's ~/.haskeline file (if present). If it uses file-style interaction, Prefs are not relevant and will not be read.

runInputTBehavior :: (MonadIO m, MonadMask m) => Behavior -> Settings m -> InputT m a -> m a Source #

Run a line-reading application according to the given behavior.

If it uses terminal-style interaction, Prefs will be read from the user's ~/.haskeline file (if present). If it uses file-style interaction, Prefs are not relevant and will not be read.

runInputTBehaviorWithPrefs :: (MonadIO m, MonadMask m) => Behavior -> Prefs -> Settings m -> InputT m a -> m a Source #

Run a line-reading application.

Config

defaultSettings :: forall (m :: Type -> Type). MonadIO m => Settings m Source #

A useful default. In particular:

defaultSettings = Settings {
          complete = completeFilename,
          historyFile = Nothing,
          autoAddHistory = True
          }

defaultBehavior :: Behavior Source #

Read input from stdin. Use terminal-style interaction if stdin is connected to a terminal and has echoing enabled. Otherwise (e.g., if stdin is a pipe), use file-style interaction.

This behavior should suffice for most applications.

defaultPrefs :: Prefs Source #

The default preferences which may be overwritten in the .haskeline file.