powerline-shell icon indicating copy to clipboard operation
powerline-shell copied to clipboard

Common Corner Case where Prompt Background bleeds into Input Field

Open bytebeast opened this issue 9 years ago • 13 comments

Prompt that is longer than terminal size and wraps around, draws the background after prompt incorrectly after prompt reaches bottom of terminal.

Environment:

  • Iterm2 Build 3.0.10
  • MacOSX El Capitan 10.11.16
  • Python 2.7.12
  • Bash 4.4.0

I have been able to reproduce on several mac laptops. How to reproduce:

  1. Enter a super long directory that wraps around
  2. Keep pressing enter on keyboard until prompt reaches bottom of terminal.

Can someone try and reproduce, and let me know i'm not crazy.

bytebeast avatar Sep 19 '16 16:09 bytebeast

I'm also able to reproduce using Mac Terminal Version 2.7.

bytebeast avatar Oct 04 '16 19:10 bytebeast

selection_016

b-ryan avatar Feb 22 '18 14:02 b-ryan

Interestingly, I didn't have this issue when I initially tried to reproduce it. But normally I use the "flat" display mode so I don't have the unicode arrows in my prompt. I should test whether this is a contributing factor.

b-ryan avatar Feb 22 '18 14:02 b-ryan

doesn't seem to be the unicode characters. I was not experiencing this when I originally attempted to reproduce because using the newline segment prevents the issue.

After more testing it appears to be related to the use of colors. I stripped out the code that adds any colors and the issue disappears. Still need to dig further into this.

b-ryan avatar Feb 23 '18 04:02 b-ryan

I am inclined to think this is a bug with bash or some other underlying system. I have been testing with a very simple PS1 with colors:

    PS1='\[\e[48;05;10m\] \w \[\e[0m\]'

Which results in the same error. That prompt just sets the background color, prints the current directory, then resets the background color. I am getting the same bleeding with it.

b-ryan avatar Feb 23 '18 15:02 b-ryan

Ok, I believe I found a solution:

export PS1='\[\033[48;05;10m\] \w \[\033[0m\]\[\033[0K'

Will need to test a bit more.

bytebeast avatar Feb 23 '18 17:02 bytebeast

Woah interesting. I am curious how you found that. I tried searching around for this problem but didn't come up with anything.

b-ryan avatar Feb 23 '18 17:02 b-ryan

Here we go ( see the Clear Line bullet point ):

Hmm , I think the search was for "ansi color vt100 color codes lines wrap" that came up with that search result.

bytebeast avatar Feb 23 '18 17:02 bytebeast

This appears to fix it:

diff --git a/powerline_shell/__init__.py b/powerline_shell/__init__.py
index 68eb227..603b425 100644
--- a/powerline_shell/__init__.py
+++ b/powerline_shell/__init__.py
@@ -90,7 +90,7 @@ class Powerline(object):
         self.cwd = get_valid_cwd()
         mode = config.get("mode", "patched")
         self.color_template = self.color_templates[args.shell]
-        self.reset = self.color_template % '[0m'
+        self.reset = self.color_template % '[0m\]\[\e[0K'
         self.lock = Powerline.symbols[mode]['lock']
         self.network = Powerline.symbols[mode]['network']
         self.separator = Powerline.symbols[mode]['separator']

bytebeast avatar Feb 23 '18 19:02 bytebeast

Looks about right based on what you've provide so far. This will need some extensive testing, including against other shells.

b-ryan avatar Feb 23 '18 20:02 b-ryan

I have the same issue, after applying the suggested patch, things seem to be working correctly. I am running bash 4.4.12 on Ubuntu 17.10.

Zalgo2462 avatar Mar 08 '18 22:03 Zalgo2462

The proposed fix broke things on Mac (#389 )

b-ryan avatar Apr 22 '18 16:04 b-ryan

As a local fix in one's bashrc - we can add in the _update_ps1 function (from the README). PS1=${PS1//\[0m/[0m\\]\\[\\e[0K}

Essentially it is doing the thing from bytebeast's comment as a postfix (note the extra \ for escaping \ )

This change works for me!

shivampotdar avatar Feb 22 '24 09:02 shivampotdar