effects-haskeline
Safe HaskellNone
LanguageGHC2021

Effects.Haskeline

Description

Provides the MonadHaskeline typeclass.

Since: 0.1

Synopsis

Class

class Monad m => MonadHaskeline (m :: Type -> Type) where Source #

Allows haskeline effects.

Since: 0.1

Methods

haveTerminalUI :: m Bool Source #

Lifted haveTerminalUI.

Since: 0.1

getInputLine :: String -> m (Maybe String) Source #

Lifted getInputLine.

Since: 0.1

getInputLineWithInitial :: String -> (String, String) -> m (Maybe String) Source #

Lifted getInputLineWithInitial.

Since: 0.1

getInputChar :: String -> m (Maybe Char) Source #

Lifted getInputChar.

Since: 0.1

getPassword :: Maybe Char -> String -> m (Maybe String) Source #

Lifted getPassword.

Since: 0.1

waitForAnyKey :: String -> m Bool Source #

Lifted waitForAnyKey.

Since: 0.1

outputStr :: String -> m () Source #

Lifted outputStr.

Since: 0.1

outputStrLn :: String -> m () Source #

Lifted outputStrLn.

Since: 0.1

getExternalPrint :: m (String -> IO ()) Source #

Lifted getExternalPrint.

Since: 0.1

getHistory :: m History Source #

Lifted getHistory.

Since: 0.1

putHistory :: History -> m () Source #

Lifted putHistory.

Since: 0.1

modifyHistory :: (History -> History) -> m () Source #

Lifted modifyHistory.

Since: 0.1

withInterrupt :: HasCallStack => m a -> m a Source #

Lifted withInterrupt.

Since: 0.1

handleInterrupt :: HasCallStack => m a -> m a -> m a Source #

Lifted handleInterrupt.

Since: 0.1

Instances

Instances details
(MonadIO m, MonadMask m) => MonadHaskeline (InputT m) Source #

Since: 0.1

Instance details

Defined in Effects.Haskeline

(MonadIO m, MonadMask m) => MonadHaskeline (ReaderT (InputTEnv m) m) Source #

Since: 0.1

Instance details

Defined in Effects.Haskeline

MonadHaskeline m => MonadHaskeline (ReaderT e m) Source #

Since: 0.1

Instance details

Defined in Effects.Haskeline

ReaderT

We provide two (overlapping) ReaderT instances: A standard instance i.e.

  instance (MonadHaskeline m) => MonadHaskeline (ReaderT e m)

And one in terms of the concrete (abstract) haskeline environment:

  instance MonadHaskeline (ReaderT (InputTEnv m) m)

The latter is the intended way to run the application in real code:

  run :: (MonadHaskeline m, ...) => m ()

  -- Uses ReaderT (InputTEnv m) instance
  main :: IO ()
  main = runInputTDefault runReaderT run

On the other hand, the former is useful for deriving e.g.

  newtype AppT e m a = MkAppT {unAppT :: ReaderT e m a }
    deriving (Applicative, Functor, Monad) via (ReaderT e m)

  deriving instance (MonadHaskeline m) => MonadHaskeline (AppT env m)

This allows typical usage with some custom type that picks up the instances automatically.

Runners

runInputTEnv :: (MonadIO m, MonadMask m) => (InputTEnv m -> m a) -> m a Source #

runInputTWith with default haskeline settings.

Since: 0.1

runInputTEnvWith Source #

Arguments

:: (InputT m a -> m a)

InputT Runner.

-> (InputTEnv m -> m a)

Action.

-> m a

IO Result.

Runs ReaderT InputTEnv in IO with InputT runner.

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 #

(MonadIO m, MonadMask m) => MonadHaskeline (InputT m) Source #

Since: 0.1

Instance details

Defined in Effects.Haskeline

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 #

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.