    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(getXdgDirectory, XdgDirectory(XdgConfig), doesFileExist, 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 = 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 -> b) -> InputT m a -> InputT m b)
    -> (forall a b. a -> InputT m b -> InputT m a)
    -> Functor (InputT m)
    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
    $cfmap :: forall (m :: * -> *) a b.
    Functor m =>
    (a -> b) -> InputT m a -> InputT m b
    fmap :: forall a b. (a -> b) -> InputT m a -> InputT m b
    $c<$ :: forall (m :: * -> *) a b.
    Functor m =>
    a -> InputT m b -> InputT m a
    <$ :: forall a b. a -> InputT m b -> InputT m a
    Functor, Functor (InputT m)
    Functor (InputT m) =>
    (forall a. a -> InputT m a)
    -> (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 a b. InputT m a -> InputT m b -> InputT m b)
    -> (forall a b. InputT m a -> InputT m b -> InputT m a)
    -> Applicative (InputT m)
    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
    $cpure :: forall (m :: * -> *) a. Applicative m => a -> InputT m a
    pure :: forall a. a -> InputT m a
    $c<*> :: forall (m :: * -> *) a b.
    Applicative m =>
    InputT m (a -> b) -> InputT m a -> InputT m b
    <*> :: forall a b. InputT m (a -> b) -> InputT m a -> InputT m b
    $cliftA2 :: forall (m :: * -> *) a b c.
    Applicative m =>
    (a -> b -> c) -> InputT m a -> InputT m b -> InputT m c
    liftA2 :: forall a b c.
    (a -> b -> c) -> InputT m a -> InputT m b -> InputT m c
    $c*> :: forall (m :: * -> *) a b.
    Applicative m =>
    InputT m a -> InputT m b -> InputT m b
    *> :: 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 a
    <* :: forall a b. InputT m a -> InputT m b -> InputT m a
    Applicative, Applicative (InputT m)
    Applicative (InputT m) =>
    (forall a b. InputT m a -> (a -> InputT m b) -> InputT m b)
    -> (forall a b. InputT m a -> InputT m b -> InputT m b)
    -> (forall a. a -> InputT m a)
    -> Monad (InputT m)
    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
    $c>>= :: forall (m :: * -> *) a b.
    Monad m =>
    InputT m a -> (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 -> InputT m b -> InputT m b
    >> :: forall a b. InputT m a -> InputT m b -> InputT m b
    $creturn :: forall (m :: * -> *) a. Monad m => a -> InputT m a
    return :: forall a. a -> InputT m a
    Monad, Monad (InputT m)
    Monad (InputT m) =>
    (forall a. IO a -> InputT m a) -> MonadIO (InputT m)
    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
    $cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> InputT m a
    liftIO :: forall a. IO a -> InputT m a
    MonadIO,
                                          Monad (InputT m)
    Monad (InputT m) =>
    (forall e a. (HasCallStack, Exception e) => e -> InputT m a)
    -> MonadThrow (InputT m)
    forall e a. (HasCallStack, Exception e) => e -> InputT m a
    forall (m :: * -> *).
    Monad m =>
    (forall e a. (HasCallStack, Exception e) => e -> m a)
    -> MonadThrow m
    forall (m :: * -> *). MonadThrow m => Monad (InputT m)
    forall (m :: * -> *) e a.
    (MonadThrow m, HasCallStack, Exception e) =>
    e -> InputT m a
    $cthrowM :: forall (m :: * -> *) e a.
    (MonadThrow m, HasCallStack, Exception e) =>
    e -> InputT m a
    throwM :: forall e a. (HasCallStack, Exception e) => e -> InputT m a
    MonadThrow, MonadThrow (InputT m)
    MonadThrow (InputT m) =>
    (forall e a.
     (HasCallStack, Exception e) =>
     InputT m a -> (e -> InputT m a) -> InputT m a)
    -> MonadCatch (InputT m)
    forall e a.
    (HasCallStack, Exception e) =>
    InputT m a -> (e -> InputT m a) -> InputT m a
    forall (m :: * -> *). MonadCatch m => MonadThrow (InputT m)
    forall (m :: * -> *) e a.
    (MonadCatch m, HasCallStack, Exception e) =>
    InputT m a -> (e -> InputT m a) -> InputT m a
    forall (m :: * -> *).
    MonadThrow m =>
    (forall e a.
     (HasCallStack, Exception e) =>
     m a -> (e -> m a) -> m a)
    -> MonadCatch m
    $ccatch :: forall (m :: * -> *) e a.
    (MonadCatch m, HasCallStack, Exception e) =>
    InputT m a -> (e -> InputT m a) -> InputT m a
    catch :: forall e a.
    (HasCallStack, Exception e) =>
    InputT m a -> (e -> InputT m a) -> InputT m a
    MonadCatch, MonadCatch (InputT m)
    MonadCatch (InputT m) =>
    (forall b.
     HasCallStack =>
     ((forall a. InputT m a -> InputT m a) -> InputT m b) -> InputT m b)
    -> (forall b.
        HasCallStack =>
        ((forall a. InputT m a -> InputT m a) -> InputT m b) -> InputT m b)
    -> (forall a b c.
        HasCallStack =>
        InputT m a
        -> (a -> ExitCase b -> InputT m c)
        -> (a -> InputT m b)
        -> InputT m (b, c))
    -> MonadMask (InputT m)
    forall b.
    HasCallStack =>
    ((forall a. InputT m a -> InputT m a) -> InputT m b) -> InputT m b
    forall a b c.
    HasCallStack =>
    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, HasCallStack) =>
    ((forall a. InputT m a -> InputT m a) -> InputT m b) -> InputT m b
    forall (m :: * -> *) a b c.
    (MonadMask m, HasCallStack) =>
    InputT m a
    -> (a -> ExitCase b -> InputT m c)
    -> (a -> InputT m b)
    -> InputT m (b, c)
    forall (m :: * -> *).
    MonadCatch m =>
    (forall b. HasCallStack => ((forall a. m a -> m a) -> m b) -> m b)
    -> (forall b.
        HasCallStack =>
        ((forall a. m a -> m a) -> m b) -> m b)
    -> (forall a b c.
        HasCallStack =>
        m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c))
    -> MonadMask m
    $cmask :: forall (m :: * -> *) b.
    (MonadMask m, HasCallStack) =>
    ((forall a. InputT m a -> InputT m a) -> InputT m b) -> InputT m b
    mask :: forall b.
    HasCallStack =>
    ((forall a. InputT m a -> InputT m a) -> InputT m b) -> InputT m b
    $cuninterruptibleMask :: forall (m :: * -> *) b.
    (MonadMask m, HasCallStack) =>
    ((forall a. InputT m a -> InputT m a) -> InputT m b) -> InputT m b
    uninterruptibleMask :: forall b.
    HasCallStack =>
    ((forall a. InputT m a -> InputT m a) -> InputT m b) -> InputT m b
    $cgeneralBracket :: forall (m :: * -> *) a b c.
    (MonadMask m, HasCallStack) =>
    InputT m a
    -> (a -> ExitCase b -> InputT m c)
    -> (a -> InputT m b)
    -> InputT m (b, c)
    generalBracket :: forall a b c.
    HasCallStack =>
    InputT m a
    -> (a -> ExitCase b -> InputT m c)
    -> (a -> InputT m b)
    -> InputT m (b, c)
    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 = ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    forall (m :: * -> *) a.
    ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    InputT (ReaderT
       RunTerm
       (ReaderT
          (IORef History)
          (ReaderT
             (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
       a
     -> InputT m a)
    -> (m a
        -> ReaderT
             RunTerm
             (ReaderT
                (IORef History)
                (ReaderT
                   (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
             a)
    -> m a
    -> InputT m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReaderT
      (IORef History)
      (ReaderT (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)))
      a
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         a
    forall (m :: * -> *) a. Monad m => m a -> ReaderT RunTerm m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (ReaderT
       (IORef History)
       (ReaderT (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)))
       a
     -> ReaderT
          RunTerm
          (ReaderT
             (IORef History)
             (ReaderT
                (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
          a)
    -> (m a
        -> ReaderT
             (IORef History)
             (ReaderT (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)))
             a)
    -> m a
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReaderT (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)) a
    -> ReaderT
         (IORef History)
         (ReaderT (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)))
         a
    forall (m :: * -> *) a.
    Monad m =>
    m a -> ReaderT (IORef History) m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (ReaderT
       (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)) a
     -> ReaderT
          (IORef History)
          (ReaderT (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)))
          a)
    -> (m a
        -> ReaderT
             (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)) a)
    -> m a
    -> ReaderT
         (IORef History)
         (ReaderT (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)))
         a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReaderT Prefs (ReaderT (Settings m) m) a
    -> ReaderT
         (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)) a
    forall (m :: * -> *) a.
    Monad m =>
    m a -> ReaderT (IORef KillRing) m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (ReaderT Prefs (ReaderT (Settings m) m) a
     -> ReaderT
          (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)) a)
    -> (m a -> ReaderT Prefs (ReaderT (Settings m) m) a)
    -> m a
    -> ReaderT
         (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)) a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReaderT (Settings m) m a
    -> ReaderT Prefs (ReaderT (Settings m) m) a
    forall (m :: * -> *) a. Monad m => m a -> ReaderT Prefs m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (ReaderT (Settings m) m a
     -> ReaderT Prefs (ReaderT (Settings m) m) a)
    -> (m a -> ReaderT (Settings m) m a)
    -> m a
    -> ReaderT Prefs (ReaderT (Settings m) m) a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . m a -> ReaderT (Settings m) m a
    forall (m :: * -> *) a. Monad m => m a -> ReaderT (Settings m) m a
    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. HasCallStack => FilePath -> InputT m a
    fail = m a -> InputT m a
    forall (m :: * -> *) a. Monad m => m a -> InputT m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadTrans t, Monad m) =>
    m a -> t m a
    lift (m a -> InputT m a) -> (FilePath -> m a) -> FilePath -> InputT m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . FilePath -> m a
    forall a. HasCallStack => FilePath -> m a
    forall (m :: * -> *) a.
    (MonadFail m, HasCallStack) =>
    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 = ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    forall (m :: * -> *) a.
    ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    InputT ((a
     -> ReaderT
          RunTerm
          (ReaderT
             (IORef History)
             (ReaderT
                (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
          a)
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         a
    forall a.
    (a
     -> ReaderT
          RunTerm
          (ReaderT
             (IORef History)
             (ReaderT
                (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
          a)
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         a
    forall (m :: * -> *) a. MonadFix m => (a -> m a) -> m a
    mfix (InputT m a
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         a
    forall (m :: * -> *) a.
    InputT m a
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         a
    unInputT (InputT m a
     -> ReaderT
          RunTerm
          (ReaderT
             (IORef History)
             (ReaderT
                (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
          a)
    -> (a -> InputT m a)
    -> a
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         a
    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 = ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      b
    -> InputT m b
    forall (m :: * -> *) a.
    ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    InputT (ReaderT
       RunTerm
       (ReaderT
          (IORef History)
          (ReaderT
             (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
       b
     -> InputT m b)
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         b
    -> InputT m b
    forall a b. (a -> b) -> a -> b
    $ do
        runTerm <- ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      RunTerm
    forall r (m :: * -> *). MonadReader r m => m r
    ask
        history <- ask
        killRing <- ask
        prefs <- ask
        settings <- ask
        lift $ lift $ lift $ lift $ lift $ inner $
            flip runReaderT settings .
            flip runReaderT prefs .
            flip runReaderT killRing .
            flip runReaderT history .
            flip runReaderT runTerm .
            unInputT

    -- | Get the current line input history.
    getHistory :: MonadIO m => InputT m History
    getHistory :: forall (m :: * -> *). MonadIO m => InputT m History
    getHistory = ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      History
    -> InputT m History
    forall (m :: * -> *) a.
    ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    InputT ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      History
    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 = ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      ()
    -> InputT m ()
    forall (m :: * -> *) a.
    ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    InputT (ReaderT
       RunTerm
       (ReaderT
          (IORef History)
          (ReaderT
             (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
       ()
     -> InputT m ())
    -> (History
        -> ReaderT
             RunTerm
             (ReaderT
                (IORef History)
                (ReaderT
                   (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
             ())
    -> History
    -> InputT m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . History
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         ()
    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 = ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      ()
    -> InputT m ()
    forall (m :: * -> *) a.
    ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    InputT (ReaderT
       RunTerm
       (ReaderT
          (IORef History)
          (ReaderT
             (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
       ()
     -> InputT m ())
    -> ((History -> History)
        -> ReaderT
             RunTerm
             (ReaderT
                (IORef History)
                (ReaderT
                   (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
             ())
    -> (History -> History)
    -> InputT m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (History -> History)
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         ()
    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 = ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    forall (m :: * -> *) a.
    ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    InputT (ReaderT
       RunTerm
       (ReaderT
          (IORef History)
          (ReaderT
             (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
       a
     -> InputT m a)
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         a
    -> InputT m a
    forall a b. (a -> b) -> a -> b
    $ do
        layout <- IO Layout
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         Layout
    forall a.
    IO a
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO Layout
     -> ReaderT
          RunTerm
          (ReaderT
             (IORef History)
             (ReaderT
                (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
          Layout)
    -> IO Layout
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         Layout
    forall a b. (a -> b) -> a -> b
    $ TermOps -> IO Layout
    getLayout TermOps
    tops
        history <- get
        lift $ lift $ evalStateT' (histLog history) $ runUndoT $ evalStateT' layout f

    instance (MonadIO m, MonadMask m) => CommandMonad (InputCmdT m) where
        runCompletion :: (FilePath, FilePath) -> InputCmdT m (FilePath, [Completion])
    runCompletion (FilePath, FilePath)
    lcs = do
            settings <- StateT
      Layout
      (StateT
         Undo
         (StateT
            HistLog
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)))))
      (Settings m)
    forall r (m :: * -> *). MonadReader r m => m r
    ask
            lift $ lift $ lift $ lift $ lift $ lift $ complete settings 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 = Behavior -> Prefs -> Settings m -> InputT m a -> m a
    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 = Behavior -> Settings m -> InputT m a -> m a
    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 = ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      Bool
    -> InputT m Bool
    forall (m :: * -> *) a.
    ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    InputT (ReaderT
       RunTerm
       (ReaderT
          (IORef History)
          (ReaderT
             (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
       Bool
     -> InputT m Bool)
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         Bool
    -> InputT m Bool
    forall a b. (a -> b) -> a -> b
    $ (RunTerm -> Bool)
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         Bool
    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 = m RunTerm -> (RunTerm -> m ()) -> (RunTerm -> m a) -> m a
    forall (m :: * -> *) a c b.
    (HasCallStack, MonadMask m) =>
    m a -> (a -> m c) -> (a -> m b) -> m b
    bracket (IO RunTerm -> m RunTerm
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO IO RunTerm
    run) (IO () -> m ()
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO () -> m ()) -> (RunTerm -> IO ()) -> RunTerm -> m ()
    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 = Behavior -> (RunTerm -> m a) -> m a
    forall (m :: * -> *) a.
    (MonadIO m, MonadMask m) =>
    Behavior -> (RunTerm -> m a) -> m a
    withBehavior Behavior
    behavior ((RunTerm -> m a) -> m a) -> (RunTerm -> m a) -> m a
    forall a b. (a -> b) -> a -> b
    $ \RunTerm
    run -> do
        prefs <- if RunTerm -> Bool
    isTerminalStyle RunTerm
    run
                    then IO Prefs -> m Prefs
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO IO Prefs
    readUserPrefs
                    else Prefs -> m Prefs
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Prefs
    defaultPrefs
        execInputT prefs settings run 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
        = Behavior -> (RunTerm -> m a) -> m a
    forall (m :: * -> *) a.
    (MonadIO m, MonadMask m) =>
    Behavior -> (RunTerm -> m a) -> m a
    withBehavior Behavior
    behavior ((RunTerm -> m a) -> m a) -> (RunTerm -> m a) -> m a
    forall a b. (a -> b) -> a -> b
    $ (RunTerm -> InputT m a -> m a) -> InputT m a -> RunTerm -> m a
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip (Prefs -> Settings m -> RunTerm -> InputT m a -> m a
    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)
        = Settings m -> ReaderT (Settings m) m a -> m a
    forall r (m :: * -> *) a. r -> ReaderT r m a -> m a
    runReaderT' Settings m
    settings (ReaderT (Settings m) m a -> m a)
    -> ReaderT (Settings m) m a -> m a
    forall a b. (a -> b) -> a -> b
    $ Prefs
    -> ReaderT Prefs (ReaderT (Settings m) m) a
    -> ReaderT (Settings m) m a
    forall r (m :: * -> *) a. r -> ReaderT r m a -> m a
    runReaderT' Prefs
    prefs
                (ReaderT Prefs (ReaderT (Settings m) m) a
     -> ReaderT (Settings m) m a)
    -> ReaderT Prefs (ReaderT (Settings m) m) a
    -> ReaderT (Settings m) m a
    forall a b. (a -> b) -> a -> b
    $ ReaderT (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)) a
    -> ReaderT Prefs (ReaderT (Settings m) m) a
    forall (m :: * -> *) a.
    MonadIO m =>
    ReaderT (IORef KillRing) m a -> m a
    runKillRing
                (ReaderT
       (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)) a
     -> ReaderT Prefs (ReaderT (Settings m) m) a)
    -> ReaderT
         (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)) a
    -> ReaderT Prefs (ReaderT (Settings m) m) a
    forall a b. (a -> b) -> a -> b
    $ Maybe FilePath
    -> Maybe Int
    -> ReaderT
         (IORef History)
         (ReaderT (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)))
         a
    -> ReaderT
         (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)) a
    forall (m :: * -> *) a.
    (MonadIO m, MonadMask m) =>
    Maybe FilePath -> Maybe Int -> ReaderT (IORef History) m a -> m a
    runHistoryFromFile (Settings m -> Maybe FilePath
    forall (m :: * -> *). Settings m -> Maybe FilePath
    historyFile Settings m
    settings) (Prefs -> Maybe Int
    maxHistorySize Prefs
    prefs)
                (ReaderT
       (IORef History)
       (ReaderT (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)))
       a
     -> ReaderT
          (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)) a)
    -> ReaderT
         (IORef History)
         (ReaderT (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)))
         a
    -> ReaderT
         (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)) a
    forall a b. (a -> b) -> a -> b
    $ ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> RunTerm
    -> ReaderT
         (IORef History)
         (ReaderT (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)))
         a
    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 = ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    forall (m :: * -> *) a.
    ReaderT
      RunTerm
      (ReaderT
         (IORef History)
         (ReaderT
            (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
      a
    -> InputT m a
    InputT (ReaderT
       RunTerm
       (ReaderT
          (IORef History)
          (ReaderT
             (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
       a
     -> InputT m a)
    -> (InputT m a
        -> ReaderT
             RunTerm
             (ReaderT
                (IORef History)
                (ReaderT
                   (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
             a)
    -> InputT m a
    -> InputT m a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (ReaderT
       (IORef History)
       (ReaderT (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)))
       a
     -> ReaderT
          (IORef History)
          (ReaderT (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)))
          a)
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         a
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         a
    forall (m :: * -> *) a (n :: * -> *) b r.
    (m a -> n b) -> ReaderT r m a -> ReaderT r n b
    mapReaderT ((ReaderT
       (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)) a
     -> ReaderT
          (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)) a)
    -> ReaderT
         (IORef History)
         (ReaderT (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)))
         a
    -> ReaderT
         (IORef History)
         (ReaderT (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)))
         a
    forall (m :: * -> *) a (n :: * -> *) b r.
    (m a -> n b) -> ReaderT r m a -> ReaderT r n b
    mapReaderT ((ReaderT Prefs (ReaderT (Settings m) m) a
     -> ReaderT Prefs (ReaderT (Settings m) m) a)
    -> ReaderT
         (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)) a
    -> ReaderT
         (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m)) a
    forall (m :: * -> *) a (n :: * -> *) b r.
    (m a -> n b) -> ReaderT r m a -> ReaderT r n b
    mapReaderT
                                      ((ReaderT (Settings m) m a -> ReaderT (Settings m) m a)
    -> ReaderT Prefs (ReaderT (Settings m) m) a
    -> ReaderT Prefs (ReaderT (Settings m) m) a
    forall (m :: * -> *) a (n :: * -> *) b r.
    (m a -> n b) -> ReaderT r m a -> ReaderT r n b
    mapReaderT ((m a -> m a)
    -> ReaderT (Settings m) m a -> ReaderT (Settings m) m a
    forall (m :: * -> *) a (n :: * -> *) b r.
    (m a -> n b) -> ReaderT r m a -> ReaderT r n b
    mapReaderT m a -> m a
    forall b. m b -> m b
    f))))
                        (ReaderT
       RunTerm
       (ReaderT
          (IORef History)
          (ReaderT
             (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
       a
     -> ReaderT
          RunTerm
          (ReaderT
             (IORef History)
             (ReaderT
                (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
          a)
    -> (InputT m a
        -> ReaderT
             RunTerm
             (ReaderT
                (IORef History)
                (ReaderT
                   (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
             a)
    -> InputT m a
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . InputT m a
    -> ReaderT
         RunTerm
         (ReaderT
            (IORef History)
            (ReaderT
               (IORef KillRing) (ReaderT Prefs (ReaderT (Settings m) m))))
         a
    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 (IO RunTerm -> Behavior)
    -> (Handle -> IO RunTerm) -> Handle -> 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 (IO RunTerm -> Behavior) -> IO RunTerm -> Behavior
    forall a b. (a -> b) -> a -> b
    $ do
                h <- FilePath -> IOMode -> IO Handle
    openBinaryFile FilePath
    file IOMode
    ReadMode
                rt <- fileHandleRunTerm h
                return rt { closeTerm = closeTerm rt >> hClose 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 @$XDG_CONFIG_HOME/haskeline/haskeline@ if present
    -- ortherwise @~/.haskeline.@ If there is an error reading the file,
    -- the 'defaultPrefs' will be returned.
    readUserPrefs :: IO Prefs
    readUserPrefs :: IO Prefs
    readUserPrefs = (IOException -> IO Prefs) -> IO Prefs -> IO Prefs
    forall (m :: * -> *) e a.
    (HasCallStack, MonadCatch m, Exception e) =>
    (e -> m a) -> m a -> m a
    handle (\(IOException
    _::IOException) -> Prefs -> IO Prefs
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Prefs
    defaultPrefs) (IO Prefs -> IO Prefs) -> IO Prefs -> IO Prefs
    forall a b. (a -> b) -> a -> b
    $ do
        xdg    <- XdgDirectory -> FilePath -> IO FilePath
    getXdgDirectory XdgDirectory
    XdgConfig (FilePath
    "haskeline/haskeline")
        exists <- doesFileExist xdg
        home   <- getHomeDirectory
        readPrefs (if exists then xdg else (home </> ".haskeline"))