repline

[ library, mit, user-interfaces ] [ Propose Tags ]

Haskeline wrapper for GHCi-like REPL interfaces. Composable with normal mtl transformers.


[Skip to Readme]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.1.2.0, 0.1.3.0, 0.1.4.0, 0.1.5.0, 0.1.6.0, 0.1.7.0, 0.2.0.0, 0.2.1.0, 0.2.2.0, 0.3.0.0, 0.4.0.0, 0.4.2.0
Dependencies base (>=4.6 && <4.7), containers (>=0.5 && <0.6), haskeline (>=0.7 && <0.8), mtl (>=2.2 && <2.3) [details]
License MIT
Copyright 2014 Stephen Diehl
Author Stephen Diehl
Maintainer stephen.m.diehl@gmail.com
Category User Interfaces
Bug tracker https://github.com/sdiehl/repline/issues
Source repo head: git clone git@github.com:sdiehl/repline.git
Uploaded by sdiehl at 2014-09-21T01:21:07Z
Distributions Arch:0.4.2.0, Debian:0.2.2.0, Fedora:0.4.2.0, LTSHaskell:0.4.2.0, NixOS:0.4.2.0, Stackage:0.4.2.0
Reverse Dependencies 5 direct, 60 indirect [details]
Downloads 19373 total (125 in the last 30 days)
Rating 2.25 (votes: 2) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for repline-0.1.0.0

[back to package description]

Repline

Slightly higher level wrapper for creating GHCi-like REPL monads that are composable with normal MTL transformers. Mostly exists because I got tired of implementing the same interface for simple shells over and over, and because vanilla Haskeline has a kind of quirky API.

Build Status

Usage

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"]
  let matches = filter (isPrefixOf n) names
  return $ map simpleCompletion matches

-- Commands
help :: [String] -> Repl ()
help args = liftIO $ print $ "Help: " ++ show args

say :: [String] -> Repl ()
say args = do
  _ <- liftIO $ system $ "cowsay" ++ " " ++ (unwords args)
  return ()


options :: [(String, [String] -> Repl ())]
options = [
    ("help", help)  -- :help
  , ("say", say)    -- :say
  ]


ini :: Repl ()
ini = liftIO $ putStrLn "Welcome!"

main :: IO ()
main = evalRepl ">>> " cmd options (Word completer) ini

Trying it out:

$ runhaskell Main.hs
Welcome!
>>> <TAB>
kirk spock mccoy

>>> k<TAB>
kirk

>>> spam
"spam"

>>> :say Hello Haskell
 _______________ 
< Hello Haskell >
 --------------- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Installation

$ cabal install repline

License

Copyright (c) 2014, Stephen Diehl Released under the MIT License