    module System.Console.Haskeline.InputT where

    import System.Console.Haskeline.History
    import System.Console.Haskeline.Command.History
    import System.Console.Haskeline.Command.Undo
    import System.Console.Haskeline.Command.KillRing
    import System.Console.Haskeline.Monads as Monads
    import System.Console.Haskeline.Prefs
    import System.Console.Haskeline.Completion
    import System.Console.Haskeline.Backend
    import System.Console.Haskeline.Term

    import Control.Exception (IOException)
    import Control.Monad.Catch
    import Control.Monad.Fail as Fail
    import Control.Monad.Fix
    import Data.IORef
    import System.Directory(getHomeDirectory)
    import System.FilePath
    import System.IO

    -- | Application-specific customizations to the user interface.
    data Settings m = Settings {forall (m :: * -> *). Settings m -> CompletionFunc m
    complete :: CompletionFunc m, -- ^ Custom tab completion.
                                forall (m :: * -> *). Settings m -> Maybe FilePath
    historyFile :: Maybe FilePath, -- ^ Where to read/write the history at the
                                                            -- start and end of each
                                                            -- line input session.
                                forall (m :: * -> *). Settings m -> Bool
    autoAddHistory :: Bool -- ^ If 'True', each nonblank line returned by
                                    -- @getInputLine@ will be automatically added to the history.

                                }

    -- | Because 'complete' is the only field of 'Settings' depending on @m@,
    -- the expression @defaultSettings {completionFunc = f}@ leads to a type error
    -- from being too general.  This function works around that issue, and may become unnecessary if another field
    -- depending on @m@ is added.

    setComplete :: CompletionFunc m -> Settings m -> Settings m
    setComplete :: forall (m :: * -> *). CompletionFunc m -> Settings m -> Settings m
    setComplete CompletionFunc m
    f Settings m
    s = Settings m
    s {complete :: CompletionFunc m
    complete = CompletionFunc m
    f}

    -- | A monad transformer which carries all of the state and settings
    -- relevant to a line-reading application.
    newtype InputT m a = InputT {forall (m :: * -> *) a.
    InputT m a
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         a
    unInputT ::
                                    ReaderT RunTerm
                                    -- Use ReaderT (IO _) vs StateT so that exceptions (e.g., ctrl-c)
                                    -- don't cause us to lose the existing state.
                                    (ReaderT (IORef History)
                                    (ReaderT (IORef KillRing)
                                    (ReaderT Prefs
                                    (ReaderT (Settings m) m)))) a}
                                deriving (forall a b. a -> InputT m b -> InputT m a
    forall a b. (a -> b) -> InputT m a -> InputT m b
    forall (m :: * -> *) a b.
    Functor m =>
    a -> InputT m b -> InputT m a
    forall (m :: * -> *) a b.
    Functor m =>
    (a -> b) -> InputT m a -> InputT m b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    <$ :: forall a b. a -> InputT m b -> InputT m a
    $c<$ :: forall (m :: * -> *) a b.
    Functor m =>
    a -> InputT m b -> InputT m a
    fmap :: forall a b. (a -> b) -> InputT m a -> InputT m b
    $cfmap :: forall (m :: * -> *) a b.
    Functor m =>
    (a -> b) -> InputT m a -> InputT m b
    Functor, forall a. a -> InputT m a
    forall a b. InputT m a -> InputT m b -> InputT m a
    forall a b. InputT m a -> InputT m b -> InputT m b
    forall a b. InputT m (a -> b) -> InputT m a -> InputT m b
    forall a b c.
    (a -> b -> c) -> InputT m a -> InputT m b -> InputT m c
    forall (f :: * -> *).
    Functor f
    -> (forall a. a -> f a)
    -> (forall a b. f (a -> b) -> f a -> f b)
    -> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
    -> (forall a b. f a -> f b -> f b)
    -> (forall a b. f a -> f b -> f a)
    -> Applicative f
    forall {m :: * -> *}. Applicative m => Functor (InputT m)
    forall (m :: * -> *) a. Applicative m => a -> InputT m a
    forall (m :: * -> *) a b.
    Applicative m =>
    InputT m a -> InputT m b -> InputT m a
    forall (m :: * -> *) a b.
    Applicative m =>
    InputT m a -> InputT m b -> InputT m b
    forall (m :: * -> *) a b.
    Applicative m =>
    InputT m (a -> b) -> InputT m a -> InputT m b
    forall (m :: * -> *) a b c.
    Applicative m =>
    (a -> b -> c) -> InputT m a -> InputT m b -> InputT m c
    <* :: forall a b. InputT m a -> InputT m b -> InputT m a
    $c<* :: forall (m :: * -> *) a b.
    Applicative m =>
    InputT m a -> InputT m b -> InputT m a
    *> :: forall a b. InputT m a -> InputT m b -> InputT m b
    $c*> :: forall (m :: * -> *) a b.
    Applicative m =>
    InputT m a -> InputT m b -> InputT m b
    liftA2 :: forall a b c.
    (a -> b -> c) -> InputT m a -> InputT m b -> InputT m c
    $cliftA2 :: forall (m :: * -> *) a b c.
    Applicative m =>
    (a -> b -> c) -> InputT m a -> InputT m b -> InputT m c
    <*> :: forall a b. InputT m (a -> b) -> InputT m a -> InputT m b
    $c<*> :: forall (m :: * -> *) a b.
    Applicative m =>
    InputT m (a -> b) -> InputT m a -> InputT m b
    pure :: forall a. a -> InputT m a
    $cpure :: forall (m :: * -> *) a. Applicative m => a -> InputT m a
    Applicative, forall a. a -> InputT m a
    forall a b. InputT m a -> InputT m b -> InputT m b
    forall a b. InputT m a -> (a -> InputT m b) -> InputT m b
    forall {m :: * -> *}. Monad m => Applicative (InputT m)
    forall (m :: * -> *) a. Monad m => a -> InputT m a
    forall (m :: * -> *) a b.
    Monad m =>
    InputT m a -> InputT m b -> InputT m b
    forall (m :: * -> *) a b.
    Monad m =>
    InputT m a -> (a -> InputT m b) -> InputT m b
    forall (m :: * -> *).
    Applicative m
    -> (forall a b. m a -> (a -> m b) -> m b)
    -> (forall a b. m a -> m b -> m b)
    -> (forall a. a -> m a)
    -> Monad m
    return :: forall a. a -> InputT m a
    $creturn :: forall (m :: * -> *) a. Monad m => a -> InputT m a
    >> :: forall a b. InputT m a -> InputT m b -> InputT m b
    $c>> :: forall (m :: * -> *) a b.
    Monad m =>
    InputT m a -> InputT m b -> InputT m b
    >>= :: forall a b. InputT m a -> (a -> InputT m b) -> InputT m b
    $c>>= :: forall (m :: * -> *) a b.
    Monad m =>
    InputT m a -> (a -> InputT m b) -> InputT m b
    Monad, forall a. IO a -> InputT m a
    forall (m :: * -> *).
    Monad m -> (forall a. IO a -> m a) -> MonadIO m
    forall {m :: * -> *}. MonadIO m => Monad (InputT m)
    forall (m :: * -> *) a. MonadIO m => IO a -> InputT m a
    liftIO :: forall a. IO a -> InputT m a
    $cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> InputT m a
    MonadIO,
                                          forall e a. Exception e => e -> InputT m a
    forall (m :: * -> *).
    Monad m -> (forall e a. Exception e => e -> m a) -> MonadThrow m
    forall {m :: * -> *}. MonadThrow m => Monad (InputT m)
    forall (m :: * -> *) e a.
    (MonadThrow m, Exception e) =>
    e -> InputT m a
    throwM :: forall e a. Exception e => e -> InputT m a
    $cthrowM :: forall (m :: * -> *) e a.
    (MonadThrow m, Exception e) =>
    e -> InputT m a
    MonadThrow, forall e a.
    Exception e =>
    InputT m a -> (e -> InputT m a) -> InputT m a
    forall (m :: * -> *).
    MonadThrow m
    -> (forall e a. Exception e => m a -> (e -> m a) -> m a)
    -> MonadCatch m
    forall {m :: * -> *}. MonadCatch m => MonadThrow (InputT m)
    forall (m :: * -> *) e a.
    (MonadCatch m, Exception e) =>
    InputT m a -> (e -> InputT m a) -> InputT m a
    catch :: forall e a.
    Exception e =>
    InputT m a -> (e -> InputT m a) -> InputT m a
    $ccatch :: forall (m :: * -> *) e a.
    (MonadCatch m, Exception e) =>
    InputT m a -> (e -> InputT m a) -> InputT m a
    MonadCatch, forall b.
    ((forall a. InputT m a -> InputT m a) -> InputT m b) -> InputT m b
    forall a b c.
    InputT m a
    -> (a -> ExitCase b -> InputT m c)
    -> (a -> InputT m b)
    -> InputT m (b, c)
    forall {m :: * -> *}. MonadMask m => MonadCatch (InputT m)
    forall (m :: * -> *) b.
    MonadMask m =>
    ((forall a. InputT m a -> InputT m a) -> InputT m b) -> InputT m b
    forall (m :: * -> *) a b c.
    MonadMask m =>
    InputT m a
    -> (a -> ExitCase b -> InputT m c)
    -> (a -> InputT m b)
    -> InputT m (b, c)
    forall (m :: * -> *).
    MonadCatch m
    -> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
    -> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
    -> (forall a b c.
        m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c))
    -> MonadMask m
    generalBracket :: forall a b c.
    InputT m a
    -> (a -> ExitCase b -> InputT m c)
    -> (a -> InputT m b)
    -> InputT m (b, c)
    $cgeneralBracket :: forall (m :: * -> *) a b c.
    MonadMask m =>
    InputT m a
    -> (a -> ExitCase b -> InputT m c)
    -> (a -> InputT m b)
    -> InputT m (b, c)
    uninterruptibleMask :: forall b.
    ((forall a. InputT m a -> InputT m a) -> InputT m b) -> InputT m b
    $cuninterruptibleMask :: forall (m :: * -> *) b.
    MonadMask m =>
    ((forall a. InputT m a -> InputT m a) -> InputT m b) -> InputT m b
    mask :: forall b.
    ((forall a. InputT m a -> InputT m a) -> InputT m b) -> InputT m b
    $cmask :: forall (m :: * -> *) b.
    MonadMask m =>
    ((forall a. InputT m a -> InputT m a) -> InputT m b) -> InputT m b
    MonadMask)
                    -- NOTE: we're explicitly *not* making InputT an instance of our
                    -- internal MonadState/MonadReader classes.  Otherwise haddock
                    -- displays those instances to the user, and it makes it seem like
                    -- we implement the mtl versions of those classes.

    instance MonadTrans InputT where
        lift :: forall (m :: * -> *) a. Monad m => m a -> InputT m a
    lift = forall (m :: * -> *) a.
    ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    InputT forall b c a. (b -> c) -> (a -> b) -> a -> c
    . forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift forall b c a. (b -> c) -> (a -> b) -> a -> c
    . forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift forall b c a. (b -> c) -> (a -> b) -> a -> c
    . forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift forall b c a. (b -> c) -> (a -> b) -> a -> c
    . forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift forall b c a. (b -> c) -> (a -> b) -> a -> c
    . forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift

    instance ( Fail.MonadFail m ) => Fail.MonadFail (InputT m) where
        fail :: forall a. FilePath -> InputT m a
    fail = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift forall b c a. (b -> c) -> (a -> b) -> a -> c
    . forall (m :: * -> *) a. MonadFail m => FilePath -> m a
    Fail.fail

    instance ( MonadFix m ) => MonadFix (InputT m) where
        mfix :: forall a. (a -> InputT m a) -> InputT m a
    mfix a -> InputT m a
    f = forall (m :: * -> *) a.
    ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    InputT (forall (m :: * -> *) a. MonadFix m => (a -> m a) -> m a
    mfix (forall (m :: * -> *) a.
    InputT m a
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         a
    unInputT forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> InputT m a
    f))

    -- | Run an action in the underlying monad, as per 'lift', passing it a runner
    -- function which restores the current 'InputT' context. This can be used in
    -- the event that we have some function that takes an action in the underlying
    -- monad as an argument (such as 'lift', 'hoist', 'forkIO', etc) and we want
    -- to compose it with actions in 'InputT'.
    withRunInBase :: Monad m =>
        ((forall a . InputT m a -> m a) -> m b) -> InputT m b
    withRunInBase :: forall (m :: * -> *) b.
    Monad m =>
    ((forall a. InputT m a -> m a) -> m b) -> InputT m b
    withRunInBase (forall a. InputT m a -> m a) -> m b
    inner = forall (m :: * -> *) a.
    ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    InputT forall a b. (a -> b) -> a -> b
    $ do
        RunTerm
    runTerm <- forall r (m :: * -> *). MonadReader r m => m r
    ask
        IORef History
    history <- forall r (m :: * -> *). MonadReader r m => m r
    ask
        IORef KillRing
    killRing <- forall r (m :: * -> *). MonadReader r m => m r
    ask
        Prefs
    prefs <- forall r (m :: * -> *). MonadReader r m => m r
    ask
        Settings m
    settings <- forall r (m :: * -> *). MonadReader r m => m r
    ask
        forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift forall a b. (a -> b) -> a -> b
    $ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift forall a b. (a -> b) -> a -> b
    $ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift forall a b. (a -> b) -> a -> b
    $ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift forall a b. (a -> b) -> a -> b
    $ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift forall a b. (a -> b) -> a -> b
    $ (forall a. InputT m a -> m a) -> m b
    inner forall a b. (a -> b) -> a -> b
    $
            forall a b c. (a -> b -> c) -> b -> a -> c
    flip forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
    runReaderT Settings m
    settings forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
            forall a b c. (a -> b -> c) -> b -> a -> c
    flip forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
    runReaderT Prefs
    prefs forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
            forall a b c. (a -> b -> c) -> b -> a -> c
    flip forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
    runReaderT IORef KillRing
    killRing forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
            forall a b c. (a -> b -> c) -> b -> a -> c
    flip forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
    runReaderT IORef History
    history forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
            forall a b c. (a -> b -> c) -> b -> a -> c
    flip forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
    runReaderT RunTerm
    runTerm forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
            forall (m :: * -> *) a.
    InputT m a
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         a
    unInputT

    -- | Get the current line input history.
    getHistory :: MonadIO m => InputT m History
    getHistory :: forall (m :: * -> *). MonadIO m => InputT m History
    getHistory = forall (m :: * -> *) a.
    ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    InputT forall s (m :: * -> *). MonadState s m => m s
    get

    -- | Set the line input history.
    putHistory :: MonadIO m => History -> InputT m ()
    putHistory :: forall (m :: * -> *). MonadIO m => History -> InputT m ()
    putHistory = forall (m :: * -> *) a.
    ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    InputT forall b c a. (b -> c) -> (a -> b) -> a -> c
    . forall s (m :: * -> *). MonadState s m => s -> m ()
    put

    -- | Change the current line input history.
    modifyHistory :: MonadIO m => (History -> History) -> InputT m ()
    modifyHistory :: forall (m :: * -> *).
    MonadIO m =>
    (History -> History) -> InputT m ()
    modifyHistory = forall (m :: * -> *) a.
    ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    InputT forall b c a. (b -> c) -> (a -> b) -> a -> c
    . forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
    modify

    -- for internal use only
    type InputCmdT m = StateT Layout (UndoT (StateT HistLog (ReaderT (IORef KillRing)
                            -- HistLog can be just StateT, since its final state
                            -- isn't used outside of InputCmdT.
                    (ReaderT Prefs (ReaderT (Settings m) m)))))

    runInputCmdT :: MonadIO m => TermOps -> InputCmdT m a -> InputT m a
    runInputCmdT :: forall (m :: * -> *) a.
    MonadIO m =>
    TermOps -> InputCmdT m a -> InputT m a
    runInputCmdT TermOps
    tops InputCmdT m a
    f = forall (m :: * -> *) a.
    ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    InputT forall a b. (a -> b) -> a -> b
    $ do
        Layout
    layout <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO forall a b. (a -> b) -> a -> b
    $ TermOps -> IO Layout
    getLayout TermOps
    tops
        History
    history <- forall s (m :: * -> *). MonadState s m => m s
    get
        forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift forall a b. (a -> b) -> a -> b
    $ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift forall a b. (a -> b) -> a -> b
    $ forall (m :: * -> *) s a. Monad m => s -> StateT s m a -> m a
    evalStateT' (History -> HistLog
    histLog History
    history) forall a b. (a -> b) -> a -> b
    $ forall (m :: * -> *) a. Monad m => UndoT m a -> m a
    runUndoT forall a b. (a -> b) -> a -> b
    $ forall (m :: * -> *) s a. Monad m => s -> StateT s m a -> m a
    evalStateT' Layout
    layout InputCmdT m a
    f

    instance (MonadIO m, MonadMask m) => CommandMonad (InputCmdT m) where
        runCompletion :: (FilePath, FilePath) -> InputCmdT m (FilePath, [Completion])
    runCompletion (FilePath, FilePath)
    lcs = do
            Settings m
    settings <- forall r (m :: * -> *). MonadReader r m => m r
    ask
            forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift forall a b. (a -> b) -> a -> b
    $ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift forall a b. (a -> b) -> a -> b
    $ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift forall a b. (a -> b) -> a -> b
    $ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift forall a b. (a -> b) -> a -> b
    $ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift forall a b. (a -> b) -> a -> b
    $ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift forall a b. (a -> b) -> a -> b
    $ forall (m :: * -> *). Settings m -> CompletionFunc m
    complete Settings m
    settings (FilePath, FilePath)
    lcs

    -- | Run a line-reading application.  Uses 'defaultBehavior' to determine the
    -- interaction behavior.
    runInputTWithPrefs :: (MonadIO m, MonadMask m) => Prefs -> Settings m -> InputT m a -> m a
    runInputTWithPrefs :: forall (m :: * -> *) a.
    (MonadIO m, MonadMask m) =>
    Prefs -> Settings m -> InputT m a -> m a
    runInputTWithPrefs = forall (m :: * -> *) a.
    (MonadIO m, MonadMask m) =>
    Behavior -> Prefs -> Settings m -> InputT m a -> m a
    runInputTBehaviorWithPrefs Behavior
    defaultBehavior

    -- | 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.
    runInputT :: (MonadIO m, MonadMask m) => Settings m -> InputT m a -> m a
    runInputT :: forall (m :: * -> *) a.
    (MonadIO m, MonadMask m) =>
    Settings m -> InputT m a -> m a
    runInputT = forall (m :: * -> *) a.
    (MonadIO m, MonadMask m) =>
    Behavior -> Settings m -> InputT m a -> m a
    runInputTBehavior Behavior
    defaultBehavior

    -- | Returns 'True' if the current session uses terminal-style interaction.  (See 'Behavior'.)
    haveTerminalUI :: Monad m => InputT m Bool
    haveTerminalUI :: forall (m :: * -> *). Monad m => InputT m Bool
    haveTerminalUI = forall (m :: * -> *) a.
    ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    InputT forall a b. (a -> b) -> a -> b
    $ forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
    asks RunTerm -> Bool
    isTerminalStyle

    {- | Haskeline has two ways of interacting with the user:

     * \"Terminal-style\" interaction provides an rich user interface by connecting
       to the user's terminal (which may be different than 'stdin' or 'stdout').

     * \"File-style\" interaction treats the input as a simple stream of characters, for example
        when reading from a file or pipe.  Input functions (e.g., @getInputLine@) print the prompt to 'stdout'.

     A 'Behavior' is a method for deciding at run-time which type of interaction to use.

     For most applications (e.g., a REPL), 'defaultBehavior' should have the correct effect.
    -}
    data Behavior = Behavior (IO RunTerm)

    -- | Create and use a RunTerm, ensuring that it will be closed even if
    -- an async exception occurs during the creation or use.
    withBehavior :: (MonadIO m, MonadMask m) => Behavior -> (RunTerm -> m a) -> m a
    withBehavior :: forall (m :: * -> *) a.
    (MonadIO m, MonadMask m) =>
    Behavior -> (RunTerm -> m a) -> m a
    withBehavior (Behavior IO RunTerm
    run) RunTerm -> m a
    f = forall (m :: * -> *) a c b.
    MonadMask m =>
    m a -> (a -> m c) -> (a -> m b) -> m b
    bracket (forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO IO RunTerm
    run) (forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
    . RunTerm -> IO ()
    closeTerm) RunTerm -> m a
    f

    -- | 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.
    runInputTBehavior :: (MonadIO m, MonadMask m) => Behavior -> Settings m -> InputT m a -> m a
    runInputTBehavior :: forall (m :: * -> *) a.
    (MonadIO m, MonadMask m) =>
    Behavior -> Settings m -> InputT m a -> m a
    runInputTBehavior Behavior
    behavior Settings m
    settings InputT m a
    f = forall (m :: * -> *) a.
    (MonadIO m, MonadMask m) =>
    Behavior -> (RunTerm -> m a) -> m a
    withBehavior Behavior
    behavior forall a b. (a -> b) -> a -> b
    $ \RunTerm
    run -> do
        Prefs
    prefs <- if RunTerm -> Bool
    isTerminalStyle RunTerm
    run
                    then forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO IO Prefs
    readPrefsFromHome
                    else forall (m :: * -> *) a. Monad m => a -> m a
    return Prefs
    defaultPrefs
        forall (m :: * -> *) a.
    (MonadIO m, MonadMask m) =>
    Prefs -> Settings m -> RunTerm -> InputT m a -> m a
    execInputT Prefs
    prefs Settings m
    settings RunTerm
    run InputT m a
    f

    -- | Run a line-reading application.
    runInputTBehaviorWithPrefs :: (MonadIO m, MonadMask m)
        => Behavior -> Prefs -> Settings m -> InputT m a -> m a
    runInputTBehaviorWithPrefs :: forall (m :: * -> *) a.
    (MonadIO m, MonadMask m) =>
    Behavior -> Prefs -> Settings m -> InputT m a -> m a
    runInputTBehaviorWithPrefs Behavior
    behavior Prefs
    prefs Settings m
    settings InputT m a
    f
        = forall (m :: * -> *) a.
    (MonadIO m, MonadMask m) =>
    Behavior -> (RunTerm -> m a) -> m a
    withBehavior Behavior
    behavior forall a b. (a -> b) -> a -> b
    $ forall a b c. (a -> b -> c) -> b -> a -> c
    flip (forall (m :: * -> *) a.
    (MonadIO m, MonadMask m) =>
    Prefs -> Settings m -> RunTerm -> InputT m a -> m a
    execInputT Prefs
    prefs Settings m
    settings) InputT m a
    f

    -- | Helper function to feed the parameters into an InputT.
    execInputT :: (MonadIO m, MonadMask m) => Prefs -> Settings m -> RunTerm
                    -> InputT m a -> m a
    execInputT :: forall (m :: * -> *) a.
    (MonadIO m, MonadMask m) =>
    Prefs -> Settings m -> RunTerm -> InputT m a -> m a
    execInputT Prefs
    prefs Settings m
    settings RunTerm
    run (InputT ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    f)
        = forall r (m :: * -> *) a. r -> ReaderT r m a -> m a
    runReaderT' Settings m
    settings forall a b. (a -> b) -> a -> b
    $ forall r (m :: * -> *) a. r -> ReaderT r m a -> m a
    runReaderT' Prefs
    prefs
                forall a b. (a -> b) -> a -> b
    $ forall (m :: * -> *) a.
    MonadIO m =>
    ReaderT (IORef KillRing) m a -> m a
    runKillRing
                forall a b. (a -> b) -> a -> b
    $ forall (m :: * -> *) a.
    (MonadIO m, MonadMask m) =>
    Maybe FilePath -> Maybe Int -> ReaderT (IORef History) m a -> m a
    runHistoryFromFile (forall (m :: * -> *). Settings m -> Maybe FilePath
    historyFile Settings m
    settings) (Prefs -> Maybe Int
    maxHistorySize Prefs
    prefs)
                forall a b. (a -> b) -> a -> b
    $ forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
    runReaderT ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    f RunTerm
    run

    -- | Map a user interaction by modifying the base monad computation.
    mapInputT :: (forall b . m b -> m b) -> InputT m a -> InputT m a
    mapInputT :: forall (m :: * -> *) a.
    (forall b. m b -> m b) -> InputT m a -> InputT m a
    mapInputT forall b. m b -> m b
    f = forall (m :: * -> *) a.
    ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    InputT forall b c a. (b -> c) -> (a -> b) -> a -> c
    . forall (m :: * -> *) a (n :: * -> *) b r.
    (m a -> n b) -> ReaderT r m a -> ReaderT r n b
    mapReaderT (forall (m :: * -> *) a (n :: * -> *) b r.
    (m a -> n b) -> ReaderT r m a -> ReaderT r n b
    mapReaderT (forall (m :: * -> *) a (n :: * -> *) b r.
    (m a -> n b) -> ReaderT r m a -> ReaderT r n b
    mapReaderT
                                      (forall (m :: * -> *) a (n :: * -> *) b r.
    (m a -> n b) -> ReaderT r m a -> ReaderT r n b
    mapReaderT (forall (m :: * -> *) a (n :: * -> *) b r.
    (m a -> n b) -> ReaderT r m a -> ReaderT r n b
    mapReaderT forall b. m b -> m b
    f))))
                        forall b c a. (b -> c) -> (a -> b) -> a -> c
    . forall (m :: * -> *) a.
    InputT m a
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         a
    unInputT

    -- | 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.
    defaultBehavior :: Behavior
    defaultBehavior :: Behavior
    defaultBehavior = IO RunTerm -> Behavior
    Behavior IO RunTerm
    defaultRunTerm

    -- | Use file-style interaction, reading input from the given 'Handle'.
    useFileHandle :: Handle -> Behavior
    useFileHandle :: Handle -> Behavior
    useFileHandle = IO RunTerm -> Behavior
    Behavior forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Handle -> IO RunTerm
    fileHandleRunTerm

    -- | Use file-style interaction, reading input from the given file.
    useFile :: FilePath -> Behavior
    useFile :: FilePath -> Behavior
    useFile FilePath
    file = IO RunTerm -> Behavior
    Behavior forall a b. (a -> b) -> a -> b
    $ do
                Handle
    h <- FilePath -> IOMode -> IO Handle
    openBinaryFile FilePath
    file IOMode
    ReadMode
                RunTerm
    rt <- Handle -> IO RunTerm
    fileHandleRunTerm Handle
    h
                forall (m :: * -> *) a. Monad m => a -> m a
    return RunTerm
    rt { closeTerm :: IO ()
    closeTerm = RunTerm -> IO ()
    closeTerm RunTerm
    rt forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> Handle -> IO ()
    hClose Handle
    h}

    -- | Use terminal-style interaction whenever possible, even if 'stdin' and/or 'stdout' are not
    -- terminals.
    --
    -- If it cannot open the user's terminal, use file-style interaction, reading input from 'stdin'.
    preferTerm :: Behavior
    preferTerm :: Behavior
    preferTerm = IO RunTerm -> Behavior
    Behavior IO RunTerm
    terminalRunTerm

    -- | Read 'Prefs' from @~/.haskeline.@   If there is an error reading the file,
    -- the 'defaultPrefs' will be returned.
    readPrefsFromHome :: IO Prefs
    readPrefsFromHome :: IO Prefs
    readPrefsFromHome = forall (m :: * -> *) e a.
    (MonadCatch m, Exception e) =>
    (e -> m a) -> m a -> m a
    handle (\(IOException
    _::IOException) -> forall (m :: * -> *) a. Monad m => a -> m a
    return Prefs
    defaultPrefs) forall a b. (a -> b) -> a -> b
    $ do
        FilePath
    home <- IO FilePath
    getHomeDirectory
        FilePath -> IO Prefs
    readPrefs (FilePath
    home FilePath -> FilePath -> FilePath
    </> FilePath
    ".haskeline")