Skip to content

Instantly share code, notes, and snippets.

@wavewave
Created February 15, 2012 23:22
Show Gist options
  • Select an option

  • Save wavewave/1839990 to your computer and use it in GitHub Desktop.

Select an option

Save wavewave/1839990 to your computer and use it in GitHub Desktop.
using dyre and gist together
{-# 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]
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 }
import DyreExample
main = dyreExample defaultConfig
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