Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL does not continue when the abort function is used #49

Open
SeungUkLee opened this issue Nov 19, 2023 · 0 comments
Open

REPL does not continue when the abort function is used #49

SeungUkLee opened this issue Nov 19, 2023 · 0 comments

Comments

@SeungUkLee
Copy link

Thank you for creating a great library.

In docs, the abort function is said to abort and continue the REPL loop.

It works normally in the Command, but REPL does not restart in Options.

Is it intended?

Example code:
import           Control.Monad.IO.Class (liftIO)
import           Data.List              (isPrefixOf)
import           System.Console.Repline

main :: IO ()
main = mainLoop

type Repl a = HaskelineT IO a

mainLoop :: IO ()
mainLoop = evalReplOpts replopts
  where
    replopts = ReplOpts
      { banner           = const (pure ">>> ")
      , command          = cmds
      , options          = opts
      , prefix           = Just ':'
      , multilineCommand = Nothing
      , tabComplete      = Word0 completer
      , initialiser      = ini
      , finaliser        = final
      }

final :: Repl ExitDecision
final = do
  liftIO $ putStrLn "GoodBye!\n"
  return Exit

ini :: Repl ()
ini = liftIO $ putStrLn "Hello, REPL"

cmds :: String -> Repl ()
cmds str = do
  liftIO $ print str
  abort

opts :: Options (HaskelineT IO)
opts =
  [ ("foo", foo)
  ]

completer :: Monad m => WordCompleter m
completer n = do
  let opts = [":foo"]
  return $ filter (isPrefixOf n) opts

foo :: String -> Repl ()
foo args = do
  liftIO $ print args
  abort

expected:

>>> :foo hello
"hello"
>>>

actual:

>>> :foo hello
"hello"
ghci> 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant