X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=blackboard-dns.git;a=blobdiff_plain;f=DDNS%2FUtils.hs;h=b1b5687b674dece01e91071cbbfecf9c19e2481b;hp=9c32824c0828722226b0c89e68ecb29984a0f0f1;hb=1abf9ad51c79257c0bce8e134fdd48a2ff0ef373;hpb=20021ec127c5574db472d88ff47cbf7e656969f4 diff --git a/DDNS/Utils.hs b/DDNS/Utils.hs index 9c32824..b1b5687 100644 --- a/DDNS/Utils.hs +++ b/DDNS/Utils.hs @@ -1,8 +1,13 @@ 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 @@ -14,3 +19,17 @@ 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