moduleSystem.Console.Haskeline.InputTwhereimportSystem.Console.Haskeline.Command.HistoryimportSystem.Console.Haskeline.MonadsasMonadsimportSystem.Console.Haskeline.PrefsimportSystem.Console.Haskeline.Command(Layout)importSystem.Console.Haskeline.CompletionimportSystem.Console.Haskeline.BackendimportSystem.Console.Haskeline.TermimportSystem.Directory(getHomeDirectory)importSystem.FilePath-- | Application-specific customizations to the user interface.dataSettingsm=Settings{complete::CompletionFuncm,-- ^ Custom tab completionhistoryFile::MaybeFilePath,handleSigINT::Bool-- ^ Throw an 'Interrupt'-- exception if the user presses Ctrl-C}-- | 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 may become unnecessary if another field-- depending on @m@ is added.setComplete::CompletionFuncm->Settingsm->SettingsmsetCompletefs=s{complete=f}-- | A monad transformer which carries all of the state and settings-- relevant to a line-reading application.newtypeInputTma=InputT{unInputT::ReaderT(RunTerm(InputCmdTm))(StateTHistory(ReaderTPrefs(ReaderT(Settingsm)m)))a}deriving(Monad,MonadIO,MonadStateHistory,MonadReaderPrefs,MonadReader(Settingsm),MonadReader(RunTerm(InputCmdTm)))instanceMonadTransInputTwherelift=InputT.lift.lift.lift.liftinstanceMonadExceptionm=>MonadException(InputTm)whereblock=InputT.block.unInputTunblock=InputT.unblock.unInputTcatchfh=InputT$Monads.catch(unInputTf)(unInputT.h)-- for internal use onlytypeInputCmdTm=ReaderTLayout(StateTHistLog(ReaderTPrefs(ReaderT(Settingsm)m)))instanceMonadIOm=>MonadLayout(InputCmdTm)whererunInputCmdT::forallma.MonadIOm=>InputCmdTma->InputTmarunInputCmdTf=InputT$dorun::RunTerm(InputCmdTm)<-asklayout<-liftIO$getLayoutrunlift$runHistLog$runReaderT'layoutfliftCmdT::Monadm=>ma->InputCmdTmaliftCmdT=lift.lift.lift.liftrunInputTWithPrefs::MonadExceptionm=>Prefs->Settingsm->InputTma->marunInputTWithPrefsprefssettings(InputTf)=liftIOmyRunTerm>>=\run->runReaderT'settings$runReaderT'prefs$runHistoryFromFile(historyFilesettings)(maxHistorySizeprefs)$runReaderTfrun-- | Run a line-reading application, reading user 'Prefs' from -- @~/.haskeline@runInputT::MonadExceptionm=>Settingsm->InputTma->marunInputTsettingsf=doprefs<-liftIOreadPrefsFromHomerunInputTWithPrefsprefssettingsf-- | Read 'Prefs' from @~/.haskeline.@ If there is an error reading the file,-- the 'defaultPrefs' will be returned.readPrefsFromHome::IOPrefsreadPrefsFromHome=handle(\_->returndefaultPrefs)$dohome<-getHomeDirectoryreadPrefs(home</>".haskeline")