Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/sdiehl/haskell-linenoise
- Owner: sdiehl
- License: bsd-2-clause
- Created: 2014-09-30T03:05:31.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-11-22T15:24:56.000Z (about 7 years ago)
- Last Synced: 2023-03-11T04:30:00.612Z (almost 2 years ago)
- Topics: haskell, linenoise, readline
- Language: C
- Size: 23.4 KB
- Stars: 10
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.Repltype Repl = ReplT IO
completer :: String -> [String]
completer ('h':_) = ["hello", "hello there"]
completer _ = []repl :: Repl ()
repl = replM ">>> " outputStrLn completermain :: 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) compsaction :: String -> Repl ()
action x = do
modify $ (x:)
liftIO $ putStrLn xrepl :: 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