-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add a command line REPL. #11
base: master
Are you sure you want to change the base?
Conversation
The creation date in the source file is older because part of this was re-used from another REPL I made.
Thanks for the contribution! I was previously ambivalent about shipping a In the future, we could also encourage engine bindings to ship a similar CLI - for example, a Unfortunately, I'm encountering a bug which is preventing me from testing this pull request. When running on Windows 10, MSYS2 Mingw 64-bit console, the output is:
I get the same error when running a trivial crate which just calls Would it be possible for you (or anybody else) to install MSYS2 and see whether you can replicate the bug? If the bug is consistent, I'm afraid I won't be able to take this pull request further unless the |
I’ll look into it, will have to start up a Windows machine. |
I can reproduce it reliably. The problem happens only when running inside the Cygwin console: when running under PowerShell or CMD.EXE as you mention, it works fine. I’ve filed an issue with linefeed’s author: murarth/linefeed#68 The next step is to see whether other readline-style libraries for Rust have the same issue. |
This might be a widespread problem: I’m checking alternatives, and for instance in rustyline it says:
Others don’t specify that. Two of them, Terminal Wizardry and Runtastic Prompt mention only that they support Windows, the others don’t say even that. |
Here are the problems with supporting Mintty in rustyline from their issue tracker:
|
After some experimentation today, it looks like the I still think that either finding or fixing a |
I’ve bee looking into this. The problem is that the application would need to check at run time whether it’s in Mintty, and if so use a different code path, either for each line, or duplicate the whole loop. You could have two binaries, one for Mintty and one for everyone else, but I doubt that’s what you want. Does it work if you launch it with winpty? |
Just tried out a minimal Unfortunately, it looks like I would be very averse to any workaround which requires manual intervention from the user. Spinning up a REPL is likely to be the very first thing that many new users try - making sure that it "just works" is very high priority. MinGW is a first-class supported platform for Rust, and Mintty is the default shell for a new MinGW installation, so unfortunately we probably can't just ignore it. I'm inclined to let this pull request block on murarth/linefeed#68 and kkawakam/rustyline#203 for the time being. It doesn't seem like this issue is fundamentally unfixable (?), and it would be a shame to waste a lot of effort on a workaround if it ends up being patched in a dependency. If both issues stay inactive for a while, I'll try to find the time to figure out a patch myself. |
I agree on the importance of “just works”. The way things are is fine for my own use, but it would be a pity to leave this hanging. Could you do that? |
I suspect that if we find one that doesn’t support Windows, that would be the one that works on Mintty. |
Funnily enough, I was testing Between us, so far we've tested GNU
Looks like this problem hasn't already been solved for us, sadly. I'm confused by the fact that, even in the C ecosystem, a working |
Yes, I suspect that if it was solvable, someone would have done it. But it involves dealing with layered hacks accumulated over decades, and at some point you just can’t make something work with all of them at the same time. I’m still trying to find some way, just for the challenge. |
Wait, does Edit: ah, no, it’s just |
I’ve finished the refactoring needed to implement a back-up REPL method: if the primary ( Additionally, now it works perfectly well inside Emacs’ shell mode, except for retrieving the command history because Emacs does it own handling of the cursor, but anything you enter through it still gets stored and can be retrieved later in a console session. The idea is to squash the two commits into one later, but for now I thought it would be good to have them separate for further testing. |
Ketos, that other Rust LISP, is made like that but I changed it in my local copy because it has the problem of bringing in all the dependencies even if you just want to use it as a library. |
I really appreciate the work you've done so far, and I don't want to discourage you, but I just want to clarify something before you put too much effort into this:
I'm not certain that a raw-stdin REPL would be better than nothing. In other words, it might be a blocker to merging this pull request. Raw stdin on Mintty is unusable, even more so than for other terminal emulators, because Mintty has a malfunctioning text cursor. The arrow keys, and PageUp/PageDown, all just move the cursor to random locations and trash the text buffer. I don't have access to information about how many Rust game developers are using Mintty, like me. If it were 1% of GameLisp's audience, I'd be happy to merge this, but if it were 20%, it would have too much of an impact on peoples' first opinion of the language. There's a danger that the Mintty usage might be surprisingly high, because game developers are more likely to develop on Windows. I think Git Bash uses Mintty, too. On the other hand, WSL seems to be getting more and more popular since I set up my current toolchain... so we genuinely have no way of knowing how many people might be inconvenienced by this 🙃. The only statistic I can find is that, in the 2019 Rust developer survey, 24% of all Rust development occurred on Windows. Can't extrapolate very much from that.
That's unfortunate. Looks like there's an RFC that would fix this, but it's currently stalled. |
Yes, I see that and I’ve been in similar situations before. It is better than nothing in the sense that frontends that do their own buffer handling before sending it to stdin can access it in that way. And I think that the current message and switching to raw-stdin gives out a better impression than crashing. As for effort, that’s no problem at all. Just wanted to be sure that we weren’t missing some easy solution, and by now it’s clear we have exhausted our leads so I’ll let it rest for now. |
A little more research: Cygwin, Mintty and MinGW recently migrated to the brand new ConPTY API on Windows 10, which should make Mintty into a more full-featured terminal emulator. This feature was disabled by default a month ago because it was "just a bit too buggy", and it's the topic of ongoing discussion. It can be experimentally re-enabled by running Hopefully this feature will be enabled by default soon enough, in which case we'll be able to move ahead without any changes on our end. Documenting the need to update to a bleeding-edge version of Mintty will be a pain, but it's not the end of the world. It's possible to manually detect whether or not we're running in Mintty, and even detect Mintty's version, so we could potentially just print a warning message at startup. I have found one other lead: the |
Aha - looks like It might be possible for us to embed Alternatively, we could try to call Windows' ConPTY API ourselves. |
Easier to find when reading the directory listing looking for the REPL.
While we figure this out, it turns out that putting the REPL in the top workspace makes at least |
This is just a simple read-eval-print loop without hot reloading or stack trace manipulation: I just noticed #8 but decided to submit this anyway because it is already useful for me and might be for others too, until the real REPL is ready.
If this isn’t approprite in-tree that’s no problem because it’s trivial to make it load the
glsp
crate from crates.io instead of the parent directory.