| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Effects.Haskeline
Description
Provides the MonadHaskeline typeclass.
Since: 0.1
Synopsis
- class Monad m => MonadHaskeline (m :: Type -> Type) where
- haveTerminalUI :: m Bool
- getInputLine :: String -> m (Maybe String)
- getInputLineWithInitial :: String -> (String, String) -> m (Maybe String)
- getInputChar :: String -> m (Maybe Char)
- getPassword :: Maybe Char -> String -> m (Maybe String)
- waitForAnyKey :: String -> m Bool
- outputStr :: String -> m ()
- outputStrLn :: String -> m ()
- getExternalPrint :: m (String -> IO ())
- getHistory :: m History
- putHistory :: History -> m ()
- modifyHistory :: (History -> History) -> m ()
- withInterrupt :: HasCallStack => m a -> m a
- handleInterrupt :: HasCallStack => m a -> m a -> m a
- runInputTEnv :: (MonadIO m, MonadMask m) => (InputTEnv m -> m a) -> m a
- runInputTEnvWith :: (InputT m a -> m a) -> (InputTEnv m -> m a) -> m a
- data InputT (m :: Type -> Type) a
- data InputTEnv (m :: Type -> Type)
- runInputT :: (MonadIO m, MonadMask m) => Settings m -> InputT m a -> m a
- runInputTBehavior :: (MonadIO m, MonadMask m) => Behavior -> Settings m -> InputT m a -> m a
- runInputTBehaviorWithPrefs :: (MonadIO m, MonadMask m) => Behavior -> Prefs -> Settings m -> InputT m a -> m a
- defaultSettings :: forall (m :: Type -> Type). MonadIO m => Settings m
- defaultBehavior :: Behavior
- defaultPrefs :: Prefs
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
ReaderT
We provide two (overlapping) ReaderT instances:
A standard instance i.e.
instance (MonadHaskelinem) =>MonadHaskeline(ReaderTe m)
And one in terms of the concrete (abstract) haskeline environment:
instanceMonadHaskeline(ReaderT(InputTEnvm) m)
The latter is the intended way to run the application in real code:
run :: (MonadHaskelinem, ...) => m () -- UsesReaderT(InputTEnvm) instance main :: IO () main =runInputTDefaultrunReaderTrun
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
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
data InputTEnv (m :: Type -> Type) Source #
Instances
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 . It
uses terminal-style interaction if runInputTBehavior defaultBehaviorstdin 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 #
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
}
defaultPrefs :: Prefs Source #
The default preferences which may be overwritten in the
.haskeline file.