roc icon indicating copy to clipboard operation
roc copied to clipboard

Allow multi-line editing in REPL

Open Anton-4 opened this issue 5 years ago β€’ 11 comments

Some languages have multi-line editing using some special symbols to indicate another line is going to follow. Others detect if what is entered is a parseble expression or statement, this could be a pain to implement.

My personal preference goes to Shift+Enter, which is commonly used to go to the next line without submitting when using text-areas.

I'll ask in the chat before implementing.

Anton-4 avatar Nov 21 '20 17:11 Anton-4

Is it linked with #2666?

ghigt avatar Oct 03 '22 11:10 ghigt

Yes indeed. Having this implemented would be a significant improvement in repl UX.

Anton-4 avatar Oct 03 '22 12:10 Anton-4

We use rustyline for generic repl features. This rustyline example adapted for Shift+Enter might be all that's needed. Are you interested in giving that a try @ghigt?

Anton-4 avatar Oct 03 '22 12:10 Anton-4

Yes, I tried it before, but while this works

rl.bind_sequence(
    KeyEvent(KeyCode::Char('s'), Modifiers::CTRL),
    EventHandler::Simple(Cmd::Newline),
);

This is handled by the default Enter behavior:

rl.bind_sequence(
    KeyEvent(KeyCode::Enter, Modifiers::SHIFT),
    EventHandler::Simple(Cmd::Newline),
);

ghigt avatar Oct 03 '22 12:10 ghigt

Oh I see, can you file an issue for that on the rustyline repo?

Anton-4 avatar Oct 03 '22 14:10 Anton-4

https://github.com/kkawakam/rustyline/issues/653

ghigt avatar Oct 03 '22 14:10 ghigt

Thanks @ghigt!

Anton-4 avatar Oct 03 '22 14:10 Anton-4

His response makes sens, do you think about an alternative?

ghigt avatar Oct 03 '22 16:10 ghigt

Interesting, Ctrl+s is probably good.

Anton-4 avatar Oct 03 '22 17:10 Anton-4

I don't want to enter into a battle πŸ˜‡, but I associate Ctrl+s with "save", is there a particular reason that I don't know for the s key?

I would associate a newline with Ctrl+n or Ctrl+o (like in vim mode).

ghigt avatar Oct 03 '22 17:10 ghigt

The main thing I like about Ctrl+s is that it is easy to reach single-handedly.

Anton-4 avatar Oct 04 '22 11:10 Anton-4

@Anton-4 recommend this be closed as completed. Just using enter on an expression that isn't complete seems to work fine.

% roc repl

  The rockin’ roc repl
────────────────────────

Enter an expression, or :help, or :q to quit.

Β» greeting : Str
… greeting = "Hi"

"Hi" : Str            # greeting

Β» 

lukewilliamboswell avatar Dec 15 '22 23:12 lukewilliamboswell

Thanks for notifying me @lukewilliamboswell :)

Anton-4 avatar Dec 16 '22 18:12 Anton-4