@hackage readline-in-other-words0.1.0.2

Readline effect for in-other-words.

readline-in-other-words

GitHub Actions Hackage

This package provides a few in-other-words effects that collectively provide the full functionality of haskeline. See Haskeline's documentation for additional usage information.

Example Usage

This is all it takes to write a miniature repl using this library:

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}

module Main where

import Control.Effect
import Control.Effect.Readline

repl :: Effs '[Readline, HandleInterrupt] m => m ()
repl = handleInterrupt (outputStrLn "Interrupt!" *> repl) $
  withInterrupt $ do
    mline <- getInputLine "> "
    case mline of
      Nothing -> pure ()
      Just line -> outputStrLn line *> repl

main :: IO ()
main = runM $ runReadline defaultSettings repl

This will echo whatever text you write, and catches interrupts announcing that they occurred and preventing the program from terminating. This example is also available as the echo-repl target in examples/Echo.hs.

Contributions

Bug reports and PRs are welcome.