Created
January 9, 2011 15:02
-
-
Save kei-q/771740 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DyreExample | |
( Config(..) | |
, defaultConfig | |
, dyreExample | |
) where | |
import qualified Config.Dyre as Dyre (wrapMain, defaultParams, Params(..)) | |
import Config.Dyre.Relaunch (restoreTextState, relaunchMaster, saveTextState) | |
import System.IO (hFlush, stdout) | |
dyreExample = Dyre.wrapMain $ Dyre.defaultParams | |
{ Dyre.projectName = "dyreExample" | |
, Dyre.realMain = realMain | |
, Dyre.showError = showError | |
} | |
data Config = Config { message :: String, errorMsg :: Maybe String } | |
defaultConfig :: Config | |
defaultConfig = Config "Dyre Example v0.1" Nothing | |
data State = State { bufferLines :: [String] } deriving (Read, Show) | |
realMain config@Config{message = message, errorMsg = errorMsg } = do | |
(State buffer) <- restoreTextState $ State [] | |
case errorMsg of | |
Nothing -> main' buffer | |
Just em -> putStrLn ("Error: " ++ em) >> main' buffer | |
where | |
main' buffer = do | |
putStrLn message | |
mapM putStrLn . reverse $ buffer | |
putStr "> " >> hFlush stdout | |
input <- getLine | |
case input of | |
"exit" -> return () | |
"recompile" -> relaunchMaster Nothing | |
other -> saveTextState (State $ other:buffer) >> realMain config | |
showError :: Config -> String -> Config | |
showError cfg msg = cfg { errorMsg = Just msg } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DyreExample | |
main = dyreExample $ defaultConfig { message = "modified" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DyreExample | |
main = dyreExample $ defaultConfig { message = "sample" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment