repline 0.1.6.0 → 0.1.7.0
raw patch · 3 files changed
+4/−185 lines, 3 filesdep −replinedep ~basedep ~containersdep ~mtlPVP ok
version bump matches the API change (PVP)
Dependencies removed: repline
Dependency ranges changed: base, containers, mtl, process
API changes (from Hackage documentation)
Files
- Example.hs +0/−129
- Simple.hs +0/−43
- repline.cabal +4/−13
− Example.hs
@@ -1,129 +0,0 @@-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE TypeSynonymInstances #-}--module Main where--import System.Console.Repline--import qualified Data.Set as Set-import Control.Monad.State.Strict--import Data.List (isPrefixOf)------------------------------------------------------------------------------------ Stateful Completion----------------------------------------------------------------------------------type IState = Set.Set String-type Repl1 a = HaskelineT (StateT IState IO) a---- Evaluation-cmd1 :: String -> Repl1 ()-cmd1 input = modify $ Set.insert input---- Completion-completer1 :: (Monad m, MonadState IState m) => WordCompleter m-completer1 n = do- ns <- get- return $ filter (isPrefixOf n) (Set.toList ns)---- Commands-help1 :: [String] -> Repl1 ()-help1 args = liftIO $ print $ "Help!" ++ show args--puts1 :: [String] -> Repl1 ()-puts1 args = modify $ Set.union (Set.fromList args)--opts1 :: [(String, [String] -> Repl1 ())]-opts1 = [- ("help", help1) -- :help- , ("puts", puts1) -- :puts- ]--init1 :: Repl1 ()-init1 = return ()---- Tab completion inside of StateT-repl1 :: IO ()-repl1 = flip evalStateT Set.empty- $ evalRepl "_proto> " cmd1 opts1 (Word completer1) init1------------------------------------------------------------------------------------ Command options----------------------------------------------------------------------------------type Repl2 a = HaskelineT IO a---- Evaluation-cmd2 :: String -> Repl2 ()-cmd2 input = liftIO $ print input---- Completion-comp2 :: Monad m => WordCompleter m-comp2 = listWordCompleter ["kirk", "spock", "mccoy"]---- Commands-help2 :: [String] -> Repl2 ()-help2 args = liftIO $ print $ "Help!" ++ show args--opts2 :: [(String, [String] -> Repl2 ())]-opts2 = [- ("help", help2)- ]--init2 :: Repl2 ()-init2 = liftIO $ putStrLn "Welcome!"--repl2 :: IO ()-repl2 = evalRepl "example2> " cmd2 opts2 (Word comp2) init2------------------------------------------------------------------------------------ Mixed Completion----------------------------------------------------------------------------------type Repl3 a = HaskelineT IO a---- Evaluation-cmd3 :: String -> Repl3 ()-cmd3 input = liftIO $ print input--defaultMatcher :: MonadIO m => [(String, CompletionFunc m)]-defaultMatcher = [- (":file" , fileCompleter)- , (":holiday" , listCompleter ["christmas", "thanksgiving", "festivus"])- ]--byWord :: Monad m => WordCompleter m-byWord n = do- let names = ["picard", "riker", "data", ":file", ":holiday"]- return $ filter (isPrefixOf n) names--files :: [String] -> Repl3 ()-files args = liftIO $ do- contents <- readFile (unwords args)- putStrLn contents--holidays :: [String] -> Repl3 ()-holidays [] = liftIO $ putStrLn "Enter a holiday."-holidays xs = liftIO $ do- putStrLn $ "Happy " ++ unwords xs ++ "!"--opts3 :: [(String, [String] -> Repl3 ())]-opts3 = [- ("file", files)- , ("holiday", holidays)- ]--init3 :: Repl3 ()-init3 = return ()--repl3 :: IO ()-repl3 = evalRepl "example3> " cmd3 opts3 (Prefix (wordCompleter byWord) defaultMatcher) init3----------------------------------------------------------------------------------------------------------------------------------------------------------------------main :: IO ()-main = repl1 >> repl2 >> repl3
− Simple.hs
@@ -1,43 +0,0 @@-module Main where--import Control.Monad.Trans-import System.Console.Repline--import System.Process (callCommand)-import Data.List (isPrefixOf)--type Repl a = HaskelineT IO a---- Evaluation : handle each line user inputs-cmd :: String -> Repl ()-cmd input = liftIO $ print input---- Tab Completion: return a completion for partial words entered-completer :: Monad m => WordCompleter m-completer n = do- let names = ["kirk", "spock", "mccoy"]- return $ filter (isPrefixOf n) names---- Commands-help :: [String] -> Repl ()-help args = liftIO $ print $ "Help: " ++ show args--say :: [String] -> Repl ()-say args = do- _ <- liftIO $ callCommand $ "cowsay" ++ " " ++ (unwords args)- return ()--options :: [(String, [String] -> Repl ())]-options = [- ("help", help) -- :help- , ("say", say) -- :say- ]--ini :: Repl ()-ini = liftIO $ putStrLn "Welcome!"--repl :: IO ()-repl = evalRepl ">>> " cmd options (Word0 completer) ini--main :: IO ()-main = repl
repline.cabal view
@@ -1,5 +1,5 @@ name: repline-version: 0.1.6.0+version: 0.1.7.0 synopsis: Haskeline wrapper for GHCi-like REPL interfaces. license: MIT license-file: LICENSE@@ -16,6 +16,7 @@ Description: Haskeline wrapper for GHCi-like REPL interfaces. Composable with normal mtl transformers.+ Source-Repository head Type: git Location: git@github.com:sdiehl/repline.git@@ -24,19 +25,9 @@ hs-source-dirs: src exposed-modules: System.Console.Repline build-depends:- base >= 4.6 && <4.10,+ base >= 4.6 && <5.0, containers >= 0.5 && <0.6, mtl >= 2.2 && <2.3,- process >= 1.2 && <1.5,+ process >= 1.2 && <2.0, haskeline >= 0.7 && <0.8 default-language: Haskell2010--executable Simple- default-language: Haskell2010- main-is: Simple.hs- build-depends: base, repline, process, mtl--executable Example- default-language: Haskell2010- main-is: Example.hs- build-depends: base, repline, mtl, containers