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 :: CompletionFunc m
complete = CompletionFunc m
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 -> 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)
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))
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
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
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
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
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 = 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
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
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
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
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 = 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
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
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
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
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
defaultBehavior :: Behavior
defaultBehavior :: Behavior
defaultBehavior = IO RunTerm -> Behavior
Behavior IO RunTerm
defaultRunTerm
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
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}
preferTerm :: Behavior
preferTerm :: Behavior
preferTerm = IO RunTerm -> Behavior
Behavior IO RunTerm
terminalRunTerm
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")