module HolyProject.MontyPython
( bk
, you
, ask
)
where
import System.Console.ANSI
import System.IO (hFlush, stdout)
import Data.Maybe (fromJust,isJust)
bk :: String -> IO ()
bk str = colorPutStr Green ("Bridgekeeper: " ++ str ++ "\n")
you :: String -> IO ()
you str = colorPutStr Yellow ("Sir Yourself: " ++ str ++ "\n")
colorPutStr :: Color -> String -> IO ()
colorPutStr color str = do
setSGR [ SetColor Foreground Dull color
, SetConsoleIntensity NormalIntensity
]
putStr str
setSGR []
ask :: String
-> Maybe String
-> IO String
ask info hint = do
bk $ "What is your " ++ info ++ "?" ++
maybe "" (\h -> " ("++h++")") hint
putStr "> "
hFlush stdout
answer <- getLine
putStrLn ""
return $ if (answer == "") && isJust hint
then fromJust hint
else answer