On Thu, Nov 17, 2022 at 02:03:10AM +1100, Chet Ramey wrote:
> On 11/16/22 12:19 AM, Kevin Pulo wrote:
> >I noticed that in readline 8.0 and later, if there is no prompt and I
> >press Enter with an empty input line, readline does not output a
> >newline. Earlier versions of readline did output a newline in this
> >situation.
>
> Yes, since the cursor is at position 0 on an empty line, the readline
> redisplay suppresses the newline. This is the desired behavior when,
> for instance, you have multiple input lines and the cursor has just
> wrapped to the final line. Readline doesn't make a distinction between
> cases here, so your example also has the final newline suppressed.
>
> >Was this change deliberate? If so, is there a way to get the old
> >behaviour back (and if not, could an option be added)? If the change
> >was not intentional, can it be considered a bug and the behaviour
> >reverted?
>
> It's not a bug. It's a fix for this redisplay issue:
>
> https://lists.gnu.org/archive/html/bug-readline/2018-09/msg00004.html
Got it, thanks for clarifying.
I definitely encounter this issue much more often than entering a line
which happens to be exactly as wide as the terminal.
> I could see making an exception if there is only one input line. Let me
> look at that.
Yes, I would prefer if the newline suppression logic could be tweaked
to handle this specific case.
I tried the attached patch (which just adds "|| rl_end == 0" to the
conditional in question) against the current devel branch. Using
rlbasic to test the following 6 cases, it seems to be fine - the only
case that changed was the first (as desired).
1. empty input line
2. input line < screen width
3. input line == screen width (cursor at start of second line)
4. input line > screen width (cursor at end of second line)
5. input line == screen width (cursor moved back onto first line)
6. input line > screen width (cursor moved back onto first line)
Of course, there might be a cleaner way to do it, and there might also
be other affected scenarios (this code seems to have lots of edge
cases).
I would definitely be very appreciative if this patch (or equivalent /
better) could be merged - thanks!
Kev
diff --git a/display.c b/display.c
index 0e42930..7aa1409 100644
--- a/display.c
+++ b/display.c
@@ -3395,7 +3395,7 @@ _rl_update_final (void)
&last_face[_rl_screenwidth - 1 + woff], 1);
}
_rl_vis_botlin = 0;
- if (botline_length > 0 || _rl_last_c_pos > 0)
+ if (botline_length > 0 || _rl_last_c_pos > 0 || rl_end == 0)
rl_crlf ();
fflush (rl_outstream);
rl_display_fixed++;