module DDNS.Utils
( trim
+ , getInputLine'
+ , getInputLineWithDefault
)
where
+import System.Console.Haskeline
+
+
trim :: Maybe String -> Maybe String
trim Nothing = Nothing
trim (Just xs) = case trimTail $ trimHead xs of
trimHead ys = ys
trimTail = reverse . trimHead . reverse
+
+getInputLine' :: MonadException m => String -> InputT m String
+getInputLine' prompt
+ = do ret <- getInputLine prompt
+ case trim ret of
+ Just ret' -> return ret'
+ Nothing -> fail "No input"
+
+getInputLineWithDefault :: MonadException m => String -> String -> InputT m String
+getInputLineWithDefault prompt defaultStr
+ = do ret <- getInputLine prompt
+ case trim ret of
+ Just ret' -> return ret'
+ Nothing -> return defaultStr