helpThe GNU Bourne-Again SHell - Support: sr #110543, prompt repeating instead of...

 
 

sr #110543: prompt repeating instead of wrapping when resizing window

Submitter:  None
Submitted:  Wed 22 Sep 2021 09:59:02 AM UTC
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  Done
Privacy:  Public Assigned to:  None
Originator Email:  -email is unavailable- Open/Closed:  Open
Operating System:  GNU/Linux
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       

 

( Jump to the original submission )

Tue 26 Oct 2021 03:20:45 PM UTC, comment #14: 

Dash, by default, does not do line editing at all. It isn't relevant unless it's built against a library that does line editing.

I can't say what redisplay algorithm the editline library uses when dash is built against it.

Chet Ramey <chet>
Project Administrator
Tue 19 Oct 2021 09:07:24 PM UTC, comment #13: 

Thanks for the clarification Chet.

I tried the same test with dash, on the same terminal. It does not have this issue. I understand dash doesn't use readline and has less features. Still, with PS1 set the same it does not have this prompt issue -- how can it know the correct physical cursor position but readline can't?

And going back to older bash 4.4 (and related readline version) I can't reproduce the issue. I'll retest once the patch is in stable and try to figure out better. I'll make a new issue if it's reproducible.

Anonymous
Fri 15 Oct 2021 01:52:55 PM UTC, comment #12: 

This very much depends on terminal (eumulator) behavior. For instance, running this on iTerm2 (macOS), the terminal itself clears out lines above the current physical cursor position so that eventually the prompt is the only thing on the screen. xterm, also on macos, does kind of the same thing but will display remnants of the previous screen contents in odd places.

The bottom line (hah) is that terminals leave the physical cursor in an inconsistent position, and readline is not always in column 0 when it assumes it is. There's no good way for readline to query this.

Chet Ramey <chet>
Project Administrator
Tue 05 Oct 2021 04:01:10 PM UTC, comment #11: 

@chet: I spotted the patch you did for this issue. I'm running the bash-devel-git version now (which I confirmed has this patch).

On Gnome Terminal (and other VTE based terminals) the issue is much improved with the patch!

  • If windows are resized slowly the issue no longer happens.
  • If windows are resized faster it still happens that the prompt is not fully erased before printing it anew. But afterwards, if the window is resized to be wider than the prompt it clears the entire (faulty) prompt.
  • I've captured a video to show the difference (resizing slowly vs resizing faster): https://i.imgur.com/CfVCbQy.mp4
  • And if the window is resized multiple times very quickly while it is smaller than the prompt, the entire terminal window can fill up with the prompt: https://i.imgur.com/Gr8HHDy.png

While with bash 5.1.8 I also have this issue on Alacritty, with the patch I can no longer reproduce it on Alacritty. Alacritty is GPU accelerated, Gnome Terminal isn't. Maybe that is what makes the difference.

@domson: thanks, I haven't gotten round to it yet. I'll try it next to see if the workaround also has this difference between Alacritty and Gnome Terminal.

Anonymous
Sun 03 Oct 2021 04:23:46 PM UTC, comment #10: 

comment #7:

> Okay, did that. And added `-lreadline` to solve some other error it gave. Now it complains about missing `main`. I don't what to do with examples/loadables/Makefile, or how to get from it what I need to add to gcc command. Final clue?
>


Did you manage to build?

Dominik Kummer <domson>
Sat 25 Sep 2021 10:22:23 PM UTC, comment #9: 

Readline redisplay after a SIGWINCH doesn't try to alter anything but the last line of the line its displaying, since you can never tell what terminal emulators will do with wrapping or rewrapping text on the rest of the display.

Readline keeps an array of prompt string offsets where it has to wrap the prompt to a new screen line. What's clear is that this needs to be updated upon receipt of a SIGWINCH if the screen width is less than the visible prompt length.

Without doing that, redisplay is going to lose track of where it is on the screen and eventually garble the display. For instance, it will eventually think it's in column 0 when the terminal emulator has wrapped the screen and it's on, say, column 35, assume that it does not need to clear the line, and reprint the prompt.

Readline only prints the prompt once -- if it thinks it's in column 0 and doesn't clear the line, it will appear that it's printing the prompt multiple times, but that's not what happens.

Chet Ramey <chet>
Project Administrator
Sat 25 Sep 2021 06:08:17 PM UTC, comment #8: 

Oh I see.

I have a very custom autotools setup so copy'n'paste won't do.

Please try to copy reprompt.c into your clone of bash/examples/loadables and add something like this:

ALLPROG += reprompt

reprompt:        reprompt.o
        $(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ rprompt.o $(SHOBJ_LIBS)

reprompt.o: reprompt.c

to the tail of examples/loadables/Makefile.in. I think now

cd $bashdir
mkdir build; cd build
../configure
make loadables

will do.

Dominik Kummer <domson>
Sat 25 Sep 2021 11:32:20 AM UTC, comment #7: 

Okay, did that. And added `-lreadline` to solve some other error it gave. Now it complains about missing `main`. I don't what to do with examples/loadables/Makefile, or how to get from it what I need to add to gcc command. Final clue?

$ gcc -lreadline -I/usr/include/bash/ -I/usr/include/bash/include/ -I/usr/include/bash/builtins/ -Ibash/lib -o reprompt reprompt.c
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../../lib/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status

Anonymous
Sat 25 Sep 2021 10:35:32 AM UTC, comment #6: 

btw on https://git.savannah.gnu.org/git/bash.git are lots of examples in examples/loadables
IMHO that's where the bash high-performance bottleneck fun really begins.

Dominik Kummer <domson>
Sat 25 Sep 2021 10:31:44 AM UTC, comment #5: 

you need to `git clone https://git.savannah.gnu.org/git/bash.git` and include its lib directory.

Dominik Kummer <domson>
Sat 25 Sep 2021 10:01:57 AM UTC, comment #4: 

Figuring out how to compile reprompt.c. I get stuck on the "readline/rlprivate.h" include.

Where do I get that file from? `pacman -F rlprivate.h` doesn't find me a package that has that file.

$ gcc -I/usr/include/bash/ -I/usr/include/bash/include/ -I/usr/include/bash/builtins/ -o reprompt reprompt.c
reprompt.c:31:10: fatal error: readline/rlprivate.h: No such file or directory
   31 | #include "readline/rlprivate.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

Anonymous
Fri 24 Sep 2021 01:19:30 PM UTC, comment #3: 

you're welcome.

Actually IMHO I think that the terminal emulator application should take care of this to keep responsibility transparent and clear :-)

sorry about the PROMPT_COMMAND. I use it to dynamically shorten the PS1 (e.g strip user name, shorten current dir, shorten git helper etc.) for very tiny windows on window resize. it works pretty well with the described technique.

Dominik Kummer <domson>
Fri 24 Sep 2021 12:22:17 PM UTC, comment #2: 

Thanks for the workaround, we'll give it a try.

With PS1 set to static text, no PROMPT_COMMAND, I hope we agree that bash / readline shouldn't be printing the prompt multiple times when the window is resized to smaller size.

This issue wasn't present on bash 4.4.20. Retested on Ubuntu 18.04.

Anonymous
Fri 24 Sep 2021 09:18:33 AM UTC, comment #1: 

# You can control this behavior as needed with

function Terminal::ps () {
  .. your custom prompt line according to window size ...
}

declare PROMPT_COMMAND='Terminal::ps'

# for dynamic line wrap on window change you also need a custom loadable builtin named 'reprompt'  I wrote. I add its source as attachment. you can build it like the example custom builtins in bash source.

enable -f "/path/to/reprompt" reprompt
trap '$PROMPT_COMMAND; reprompt "$PS1"; ' SIGWINCH

# reprompt just resets/clears the current line, nothing else.

(file #51958)

Dominik Kummer <domson>
Wed 22 Sep 2021 09:59:02 AM UTC, original submission:  
  • bash version: 5.1.8
  • readline version: 8.1.001
  • Distribution: Arch Linux
  • Issue also happens on Linux Mint 20.2 / Ubuntu 20.04 with bash version 5.0.17 and readline version 8.0.

If a terminal emulator window is resized such that its width becomes less than bash's prompt width, instead of the prompt wrapping to the next line the prompt is printed again on each resize. Hard to explain, I've made a short video of the issue: https://i.imgur.com/CrVOvgk.mp4

I can reproduce this issue with GNOME Terminal, Alacritty and Terminology. I think the terminal emulator isn't the cause.

For testing, and to rule out my config files playing a role, I ran this command to start a new bash with a very long prompt:

INPUTRC='/dev/null' PS1='a very, very, VERY, *V*E*R*Y* looooooooong prompt$ ' bash --noprofile --norc

If I start bash without using readline (with --noeditor flag) the issue isn't reproducible.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #51958:  reprompt.c added by domson (2KiB - text/x-csrc - reprompt custom loadable builtin)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by chet (Posted a comment)
  • -email is unavailable- added by domson (Updated the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

     

     

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-09-25 chet StatusNone Done
    2021-09-24 domson Attached File- Added reprompt.c, #51958

    Back to the top


    Powered by Savane 3.9