Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sdiehl/haskell-linenoise

Lightweight readline library for Haskell
https://github.com/sdiehl/haskell-linenoise

haskell linenoise readline

Last synced: about 2 months ago
JSON representation

Lightweight readline library for Haskell

Awesome Lists containing this project

README

        

Repl
----

[![Build Status](https://travis-ci.org/sdiehl/haskell-linenoise.svg?branch=master)](https://travis-ci.org/sdiehl/haskell-linenoise)

Initial work on a lightweight readline library for Haskell based on the ``linenoise`` library. Designed from
the ground up to work more smoothly with modern monad transformers and exceptions libraries.

```haskell
import System.Console.Repl

type Repl = ReplT IO

completer :: String -> [String]
completer ('h':_) = ["hello", "hello there"]
completer _ = []

repl :: Repl ()
repl = replM ">>> " outputStrLn completer

main :: IO ()
main = runRepl repl defaultSettings
```

Can compose with the regular State monad, for instance to do stateful tab completion. Something which is
painful with Haskeline.

```haskell
import System.Console.Repl
import Control.Monad.State.Strict
import Data.List (isPrefixOf)

type Repl = ReplT (StateT [String] IO)

completer :: String -> Repl [String]
completer line = do
comps <- get
return $ filter (isPrefixOf line) comps

action :: String -> Repl ()
action x = do
modify $ (x:)
liftIO $ putStrLn x

repl :: Repl ()
repl = replM ">>> " action (byWord completer)

main :: IO ()
main = evalStateT (runRepl repl defaultSettings) []
```

License
-------

Includes the source code for linenoise. Released under the BSD license.

Copyright (c) 2014-2017, Stephen Diehl