forked from sdiehl/haskell-linenoise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hs
33 lines (24 loc) · 748 Bytes
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
import Control.Monad (void)
import Control.Monad.IO.Class (liftIO)
import Control.Monad.State.Strict (get, modify)
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.IO as TIO
import Linenoise
type History = [Text]
type Repl a = ReplT () History IO a
runRepl :: Repl a -> History -> IO (a, History)
runRepl n = runReplT n ()
completer :: Text -> Repl [Text]
completer line = filter (Text.isPrefixOf line) <$> get
action :: Text -> Repl ReplDirective
action x = do
modify (x :)
liftIO (TIO.putStrLn x)
pure ReplContinue
repl :: Repl ()
repl = replM ReplContinue ">>> " action (byWord completer)
main :: IO ()
main = void (runRepl repl [])