module FortyTwo.Prompts.Input (inputWithDefault, input) where
import FortyTwo.Renderers.Question (renderQuestion)
import FortyTwo.Utils (clearLines, flush)
import FortyTwo.Constants (emptyString)
inputWithDefault :: String -> String -> IO String
inputWithDefault question defaultAnswer = do
putStrLn emptyString
renderQuestion question defaultAnswer emptyString
putStr " "
flush
answer <- getLine
clearLines 1
if null answer then do
renderQuestion question emptyString defaultAnswer
return defaultAnswer
else do
renderQuestion question emptyString answer
return answer
input :: String -> IO String
input question = inputWithDefault question emptyString