Closed Oldes closed 7 years ago
Here is what I did in my Rebol version to fix it: https://github.com/Oldes/r3/commit/2ad2f1d2e3663c689133ee34b215105e2036fba2
Thanks, that's certainly an improvement. Enough so that it makes things better enough that I'd even say it's of benefit without discussion.
But...of course, there's got to be discussion. :-/ It seems to me that this means needing to review the behavior of empty line terminating input. Because more often than not, pasted input will have blank lines.
(The empty line terminating was introduced to help get people untrapped from unclosed input. R3-Alpha reacted to Ctrl-C by printing [escape] even though the readline continued, then just interrupted the evaluator once the code tried to run. I notice Red uses Escape to get out of this input mode, and ignores Ctrl-C there.)
If you can't tell if code is coming from a paste or not, one way to detect a paste would be to measure how long it takes a line to arrive. If the time between getting two subsequent newlines is short enough, assume it wasn't typed...so keep accumulating lines for input. Or something like that.
And it does suggest raising the priority of making Ctrl-C (or perhaps better, escape?) actually exit the readline loop at the moment you push it. Escape is presumably easier.
(Upshot being: okay, of course I don't mind participation of this kind...I'm just worried about it turning into processing complaints...in areas not related to the project goals. I'm more worried about my morale than anything. In fact, my avoidance of this part of the code is because I have hoped that once enough console behavior is moved to Rebol from C (still to do: line history)...then it would be easier to replace entirely with something small that has UTF-8 support (e.g. linenoise.)
Well...so what happened is sort of what I was afraid of...which is that once I start looking at the questions I start getting tangled in it.
I started out just trying to solve the escape/Ctrl-C stuff, since there needs to be a way to get out of multiline if you need to. Upshot is that it's important to distinguish canceling a script's execution from escaping from an input. Consider:
>> if blank? line: input [print "Escape pressed, but script kept running"]
I'm about to press escape right here->
Escape pressed, but script kept running
== _
>> line: input | print "But Ctrl-C should stop this from printing..."
I'm about to press Ctrl-C right here->
[interrupted by Ctrl-C or HALT instruction]
So that distinction is important, and of course there were a lot of details there. Ctrl-C doesn't interrupt input in Rebol2 or Red (odd, since they control the message pumps...). I wound up digging around in a lot of it until I found out what some of the limits were, and of course Windows was a complete pain as it usually is...
Ultimately I wound up going ahead and adding UTF-8 input support (needs to have work done on the cursor navigation and such, but there are more pressing things). And I gave it a decent sprucing up so people have half a chance of improving it:
I have mixed feelings about getting myself mixed up with this kind of stuff. But maybe you have a point that taking a bit of time doing what I consider to be "stupid" and I'm way overqualified for can have an impact on the overall usefulness. It may well be that I feel these changes pay for themselves quickly, despite not being all that fun to do.
So thanks for the inspiration.
Also, if you are compelled by things-related-to-consoles, you might be interested in how the userspace console handles skinning. Even things like infinite loops in the userspace function to report cancellation:
https://chat.stackoverflow.com/transcript/message/40013617#40013617
Relevant commits:
https://github.com/metaeducation/ren-c/pull/646 https://github.com/metaeducation/ren-c/pull/647
See advice to Red:
https://chat.stackoverflow.com/transcript/message/39999849#39999849
Although ren-c console has multi-line support, which works for user input from keyboard, pasting multi-line code is not working correctly.
For example copy such a code:
and paste it into console and it looks incorrectly like:
after pressing enter, there is an error: