haskeline-repl 0.3.0.0 → 0.4.0.0
raw patch · 2 files changed
+27/−13 lines, 2 filesdep +safePVP ok
version bump matches the API change (PVP)
Dependencies added: safe
API changes (from Hackage documentation)
+ System.Console.Repl: defaultCommands :: [Command a]
+ System.Console.Repl: replWith :: Prompt -> (InputLine -> IO a) -> [Command a] -> IO ()
+ System.Console.Repl: type Command a = (String, InputLine -> IO Bool)
Files
- haskeline-repl.cabal +3/−2
- src/System/Console/Repl.hs +24/−11
haskeline-repl.cabal view
@@ -1,5 +1,5 @@ name: haskeline-repl-version: 0.3.0.0+version: 0.4.0.0 -- synopsis: description: A convenient Haskeline wrapper homepage: https://github.com/githubuser/haskeline-repl#readme@@ -19,7 +19,8 @@ build-depends: base >= 4.7 && < 5, haskeline, mtl,- ansi-terminal+ ansi-terminal,+ safe default-language: Haskell2010 source-repository head
src/System/Console/Repl.hs view
@@ -1,26 +1,39 @@ module System.Console.Repl where +import Control.Monad import Control.Monad.Trans+import Safe import System.Console.ANSI import System.Console.Haskeline type Prompt = String type InputLine = String+type Command a = (String, InputLine -> IO Bool) +defaultCommands :: [Command a]+defaultCommands =+ [(":q", const $ return False)]++ repl :: Prompt -> (InputLine -> IO a) -> IO () repl prompt f =+ replWith prompt f defaultCommands+++replWith :: Prompt -> (InputLine -> IO a) -> [Command a] -> IO ()+replWith prompt f commands = runInputT defaultSettings loop- where- loop = do- line <- getInputLine prompt- case line of- Just ":q" ->- return ()- Just input -> do- liftIO $ f input- loop- Nothing ->- return ()+ where loop =+ getInputLine prompt >>= maybe (return ()) pickCommand++ pickCommand input =+ case headMay (words input) >>= (`lookup` commands) of+ Just cmd -> do+ continue <- liftIO $ cmd input+ when continue loop+ Nothing -> do+ liftIO $ f input+ loop printError err = do