Created
February 15, 2012 23:22
-
-
Save wavewave/1839990 to your computer and use it in GitHub Desktop.
using dyre and gist together
This file contains hidden or 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
| {-# LANGUAGE DeriveDataTypeable #-} | |
| module CmdArgs where | |
| import System.Console.CmdArgs | |
| data MyArgs = MyArgs | |
| { welcome :: String } | |
| deriving (Show,Eq,Data,Typeable) | |
| myArgs :: MyArgs | |
| myArgs = MyArgs { welcome = def &= argPos 0 } | |
| mode :: MyArgs | |
| mode = modes [myArgs] |
This file contains hidden or 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 where | |
| import qualified Config.Dyre as Dyre | |
| import Config.Dyre.Relaunch | |
| import CmdArgs | |
| import System.Console.CmdArgs | |
| import System.IO | |
| data Config = Config { message :: String, errorMsg :: Maybe String } | |
| data State = State { bufferLines :: [String] } deriving (Read,Show) | |
| defaultConfig :: Config | |
| defaultConfig = Config "Dyre Example v0.1" Nothing | |
| showError :: Config -> String -> Config | |
| showError cfg msg = cfg { errorMsg = Just msg } | |
| realMain Config {message = message, errorMsg = errorMsg } = do | |
| param <- cmdArgs mode | |
| putStrLn (show param) | |
| (State buffer) <- restoreTextState $ State [] | |
| case errorMsg of | |
| Nothing -> return () | |
| Just em -> putStrLn $ "Error: " ++ em | |
| putStrLn message | |
| mapM putStrLn . reverse $ buffer | |
| putStrLn "> " >> hFlush stdout | |
| input <- getLine | |
| case input of | |
| "exit" -> return () | |
| "quit" -> return () | |
| other -> relaunchWithTextState (State $ other:buffer) Nothing | |
| dyreExample = Dyre.wrapMain $ Dyre.defaultParams | |
| { Dyre.projectName = "testExample" | |
| , Dyre.realMain = realMain | |
| , Dyre.showError = showError } | |
This file contains hidden or 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 |
This file contains hidden or 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 = "Dyre example v0.1 (Modified) test"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment