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
data Settings m = Settings {forall (m :: * -> *). Settings m -> CompletionFunc m
complete :: CompletionFunc m,
forall (m :: * -> *). Settings m -> Maybe FilePath
historyFile :: Maybe FilePath,
forall (m :: * -> *). Settings m -> Bool
autoAddHistory :: Bool
}
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}
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
(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)
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. 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. FilePath -> m a
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 = 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))
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
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
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
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
type InputCmdT m = StateT Layout (UndoT (StateT HistLog (ReaderT (IORef KillRing)
(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
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
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
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
data Behavior = Behavior (IO RunTerm)
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
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
readPrefsFromHome
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
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
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
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
defaultBehavior :: Behavior
defaultBehavior :: Behavior
defaultBehavior = IO RunTerm -> Behavior
Behavior IO RunTerm
defaultRunTerm
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
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}
preferTerm :: Behavior
preferTerm :: Behavior
preferTerm = IO RunTerm -> Behavior
Behavior IO RunTerm
terminalRunTerm
readPrefsFromHome :: IO Prefs
readPrefsFromHome :: IO Prefs
readPrefsFromHome = (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
home <- IO FilePath
getHomeDirectory
readPrefs (home </> ".haskeline")