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

Multi-line REPL input #134

Open
byorgey opened this issue Oct 1, 2021 · 18 comments · May be fixed by #2092
Open

Multi-line REPL input #134

byorgey opened this issue Oct 1, 2021 · 18 comments · May be fixed by #2092
Labels
C-Moderate Effort Should take a moderate amount of time to address. G-REPL An issue having to do with the REPL. L-Language Server Issues relating to the LSP implementation that talks to editors. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. T-Editors Involves editor support. T-UI Involves the user interface. Z-Feature A new feature to be added to the game. Z-User Experience This issue seeks to make the game more enjoyable to play.

Comments

@byorgey
Copy link
Member

byorgey commented Oct 1, 2021

It would be nice if somehow you could enter expressions at the REPL using multiple lines. In theory, this should be easy, since the input form itself does not care whether it contains newline characters. The difficulty is how we distinguish between entering a newline and executing the contents of the REPL.

Originally, I thought to allow Enter at the REPL to type normal newlines, and use a special keystroke like Shift-Enter or Ctrl-Enter to execute it (like what Jupyter notebook does). However, Shift-Enter and Ctrl-Enter are problematic in the terminal; in most terminals they just send a regular Enter key event. This makes no sense whatsoever, but that's the way things are. =( One solution is to use a different special key (Ctrl-J? Ctrl-M?) for entering a newline; though that seems dangerous because it would be too easy to forget and hit Enter when you meant to add a new line. Or probably better would be to come up with some other special key to execute (accidentally entering a newline when you meant to execute is no big deal). It just might be annoying to always have to hit some other key combination every time you want to execute. Maybe it could be an opt-in feature.

Very open to other solutions as well!

@byorgey byorgey added Z-User Experience This issue seeks to make the game more enjoyable to play. Z-Feature A new feature to be added to the game. C-Moderate Effort Should take a moderate amount of time to address. T-UI Involves the user interface. G-REPL An issue having to do with the REPL. labels Oct 1, 2021
@jrvieira
Copy link

jrvieira commented Oct 1, 2021

Some REPLS assume newlines when current input does not validate in some way.

A simple solution to swarm would be to assume a newline iff there are any unmatched brackets or parens. Typing '{<Enter>' is very intuitive and we'd have the added advantage of quickly signaling "unmatched whatever" errors to the user while providing optimal UX, letting the user quickly solve the problem instead of forcing a retype.

To consider:

  • Multiline input presentation when browsing command history.

@byorgey
Copy link
Member Author

byorgey commented Oct 1, 2021

This is the way the Python REPL works so I was curious what Python does re: multiline input when browsing the command history. The answer is that it just browses through all previous input line by line, regardless of whether the lines were entered by themselves or together with other lines. This seems like a reasonably simple solution.

@jrvieira
Copy link

jrvieira commented Oct 1, 2021

It would be important to have a way of clearing all input while in the middle of writing a multiline command. I think having CTRL-c doing this would be the expected behaviour and it plays well with #44 since you're not supposed to write while base is actively running a computation (right?). This way, CTRL-c either cancels execution or clears all current input.

@byorgey
Copy link
Member Author

byorgey commented Oct 1, 2021

Right, you can't enter anything while base is actively running a computation. (If someone asked for the ability to start typing something even while the base is still running a computation, I would say no, just build a robot to do the computation for you instead.)

@Anrock
Copy link

Anrock commented Oct 1, 2021

AFAIK some repl used \n\n to execute things. So single enter starts a new line and if you press enter on a new line instead of typing more code REPL executes whatever you already typed.

@xsebek xsebek mentioned this issue Oct 15, 2021
@byorgey byorgey added the S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. label Feb 18, 2022
@byorgey
Copy link
Member Author

byorgey commented Feb 18, 2022

This would still be cool, though I think it's pretty low priority since one can easily just put multi-line definitions in a file and then run it.

@byorgey
Copy link
Member Author

byorgey commented May 4, 2022

Reading over this issue again, I think if we do this at all, "enter creates a new line; hitting enter twice in a row executes" (as in Anrock's comment) is probably the best solution. But with nice editor support there doesn't seem to be that much impetus for allowing multi-line REPL input.

@TristanCacqueray
Copy link
Collaborator

Note that bash features C-x C-e to edit multi-line command in $EDITOR.

@byorgey
Copy link
Member Author

byorgey commented Jun 24, 2022

That seems like a nice idea: some special key shortcut to either open an external editor, or just to open an editor in the REPL window (brick has built-in support for an editor widget).

@byorgey byorgey added the L-Language Server Issues relating to the LSP implementation that talks to editors. label Sep 2, 2022
@byorgey
Copy link
Member Author

byorgey commented Sep 2, 2022

Added a Language Server tag --- this doesn't directly have to do with LSP, but more generally it relates to external editor support.

@byorgey
Copy link
Member Author

byorgey commented Jan 10, 2023

Coming back around to review old issues. @xsebek , @kostmo , @TristanCacqueray , how often have you wanted multi-line REPL input in Swarm? Personally, I have been playing a lot in classic mode recently and I have never wanted it. I am tempted to just close this as won't fix.

@kostmo
Copy link
Member

kostmo commented Jan 10, 2023

Personally I find the multi-line input experience in both Python and Haskell REPLs to be infuriating. So I probably wouldn't use it much in Swarm.

@xsebek
Copy link
Member

xsebek commented Jan 10, 2023

I want it a lot. 🙂

In Swarm I often run into the edge of screen, so being able to extend it to few lines would improve the experience significantly.

My experience with REPL in ZSH is much more positive, so that could play a role.

@byorgey
Copy link
Member Author

byorgey commented Jan 10, 2023

OK, well, I think @xsebek just volunteered to implement this issue. 😆

@TristanCacqueray
Copy link
Collaborator

I agree with @kostmo, so I would vote won't fix, but it can be useful too.

@byorgey byorgey added the T-Editors Involves editor support. label Nov 2, 2023
@xsebek xsebek linked a pull request Jul 31, 2024 that will close this issue
@xsebek
Copy link
Member

xsebek commented Jul 31, 2024

A neat feature would be to automatically start multiline on unclosed def. ZSH does it for for and if:

> for i in *; do                                                                                         
for>  echo $i
for> done  

This would allow easily writing longer functions in REPL. Not sure if that is easy to tell from parser failure though.

@xsebek
Copy link
Member

xsebek commented Jul 31, 2024

Note that bash features C-x C-e to edit multi-line command in $EDITOR.

This could be a complementary feature - you could write in your editor and then quickly fix typos in brick multiline editor in REPL. Most importantly we need to be able to show multiline REPL input.

@xsebek
Copy link
Member

xsebek commented Jul 31, 2024

Hah, I just remebered I tried to set up REPL through the Web API:

So with a little modification, you can already send multiline commands to the REPL written in your EDITOR:

#!/usr/bin/env bash

PORT="5357"
HOST="localhost"
tmpfile="$(mktemp -d)/run.sw"
EDITOR="${EDITOR:-vim}"

$EDITOR $tmpfile

curl --header "Content-Type: text/plain;charset=utf-8" --data "$(cat $tmpfile)" $HOST:$PORT/code/run

But without further support it is a bit broken - previous command brings up just first line, so we currently have the annoying experience @kostmo described.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Moderate Effort Should take a moderate amount of time to address. G-REPL An issue having to do with the REPL. L-Language Server Issues relating to the LSP implementation that talks to editors. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. T-Editors Involves editor support. T-UI Involves the user interface. Z-Feature A new feature to be added to the game. Z-User Experience This issue seeks to make the game more enjoyable to play.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants