sdiehl / repline Goto Github PK
View Code? Open in Web Editor NEWHaskeline wrapper for GHCi-like REPL interfaces
License: MIT License
Haskeline wrapper for GHCi-like REPL interfaces
License: MIT License
In line 89 of System.Console.Repline, not enough arguments have been applied to evalRepl
:
main = evalRepl (pure ">>> ") cmd options (Just ':') (Word completer) ini
This is standard behavior for internet chats and highly convenient
$ cabal haddock -w ghc-8.4.4
...
src/System/Console/Repline.hs:247:3: error:
parse error on input ‘-- | banner function’
|
247 | -- | banner function
| ^^^^^^^^^^^^^^^^^^^^
@basile-henry mentioned this in https://github.com/dhall-lang/dhall-haskell/pull/1867/files#r441794458.
I'd recommend checking haddock-compatibility in CI BTW.
I was trying to get Repline
working in a project of mine and wasn't able to get command options to work. So I made a test stack project where I copy pasted in the exact Simple
example code and still the command options did not work:
Welcome!
>>>
kirk spock mccoy
>>> kirk
"kirk "
>>> spam
"spam"
>>> :say Hello Haskell
":say Hello Haskell"
>>> :help arg1 arg2 arg3
":help arg1 arg2 arg3"
I'm using thelts-14.13
resolver. Here is a link to my sample project:
https://github.com/ssbothwell/replinetest
At the moment the master branch has a cabal file, which states version 0.2.0.0
but there is a version 0.2.1.0 on hackage.
I am confused? Where is the git repo for the code of version 0.2.1.0?
Right now, repline-0.2.2.0
imports System.Console.Haskeline.MonadException
, which only exists in haskeline < 0.8.0.0
Thanks!
vanessa@vanessa-desktop ~/git-builds/junk/repline-0.2.2.0 🌸 cabal build --constraint='haskeline >= 0.8.0.0'
Resolving dependencies...
Build profile: -w ghc-8.8.2 -O1
In order, the following will be built (use -v for more details):
- repline-0.2.2.0 (lib) (configuration changed)
Configuring library for repline-0.2.2.0..
Preprocessing library for repline-0.2.2.0..
Building library for repline-0.2.2.0..
[1 of 1] Compiling System.Console.Repline ( src/System/Console/Repline.hs, /home/vanessa/git-builds/junk/repline-0.2.2.0/dist-newstyle/build/x86_64-linux/ghc-8.8.2/repline-0.2.2.0/build/System/Console/Repline.o ) [System.Console.Haskeline changed]
src/System/Console/Repline.hs:142:1: error:
Could not load module ‘System.Console.Haskeline.MonadException’
It is a member of the hidden package ‘haskeline-0.7.5.0’.
Perhaps you need to add ‘haskeline’ to the build-depends in your .cabal file.
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
142 | import System.Console.Haskeline.MonadException
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Since it's not needed with newer versions of base
anyway
Since haskeline < 0.8
doesn't support GHC 8.10, that should also unblock compatibility with GHC 8.10.
I have a small project I'd like to transition from using raw haskeline to this library. However, I make a lot of use of getInputChar
directly to do things like ask the user a yes/no follow-up question after a command, and the lifted version defined in the MonadHaskeline
class isn't exported. In fact, as far as I can tell, it isn't ever used in this library apart from defining other instances of MonadHaskeline. Is there a good reason not to use getInputChar
directly with repline, or perhaps a more idiomatic solution to the problem of getting follow-up answers?
Currently, there's a way to toggle multiline mode based on matching a specific commmand:
>>> :multi
... continuation
However, it would be nice to provide a way to toggle this mode based on parsing information, to make something like the following work
>>> incomplete expression (
... so REPL enters multiline mode )
A possible API for this would be:
beginMultiline :: HaskelineT m ()
endMultiline :: HaskelineT m ()
-- returns a list of lines since the enclosing beginMultiline
-- alternatively, this could be managed by the caller
multilineContext :: HaskelineT m [String]
allowing something like
cmd :: Command (HaskelineT IO)
cmd s = do
context <- multilineContext
if Parser.isIncomplete (context ++ [s])
then beginMultiline
else do
endMultiline
-- process (context ++ [s]) as a multi-line chunk
Stephen-man, all of your arguments against blockchain come from
a) envy
b) hence, bitterness
don't they?
Are they driven by the fact that you missed bitcoin for $0.1 in the past? As such, the only thing left for you is to critisize cryptocurrencies.
And don't recognize the crypto. Fight.
GHC 8.8 comes with a new and notably breaking version of haskeline
that switches from using a bespoke MonadException
to using the exceptions
type class troika.
I am looking for a way to execute an rc file during initialisation phase.
Right now, all I can do is call "command" manually, but there is no
way to invoke the options parser manually. I'd have to reimplement options
parsing myself, which seems wrong.
The goal is to have something like .ghci, where :commands would also work as expected.
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?
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>
Sometimes I wish to store the history somewhere like ~/.local/
, this will be more convenient for a shell-like application.
However, I've noticed that currently the history-related configurations seem to be hardcoded:
repline/src/System/Console/Repline.hs
Lines 403 to 404 in acd6fd3
I think it would be nice if I could control these options while conserving all the niceties that come with this wrapper :)
Anyway, thanks a lot for making this project! 🙏
I would like to rewrite one of my program from python to haskell. My program relies on https://github.com/python-cmd2/cmd2 and makes extensive use of cmd2 autocompletion based on python's argparse parsers.
I was wondering if there was a similar possibility (out of the box) with repline to accept an optparse-applicative parser and autocompletes that Parser ?
If not do you know any similar library that would do it ?
I get the following error when I give one (or multiple) space as an option: ": "
>>> :
src/System/Console/Repline.hs:207:15-37: Irrefutable pattern failed for pattern cmd : args
I can have a go at fixing it, I just thought I would report the issue first in case I don't get a fix for it.
Can we provide a way to exit from repl by Command like :quit
in GHCi?
I'm ready to implement this
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.