Cygwin wraps text back on to the same line, causing text to be overwritten

余生颓废 提交于 2021-02-07 14:38:45

问题


I have cygwin installed on my Windows 7 box and I have been running into a problem where when I type a command it will occasionally be wrapped back onto the same line, deleting the bash prompt. Here is an example:

wrapping example

The command in question is command "201" (4 lines from the bottom). I included the others for context.

The text of the command I was typing was

git commit -m "Forced LF line endings."

(Note: I am posting this with mostly git commands, but the problem occurs with any command. I have not noticed a pattern yet.)

It jumped to the start of the line and started to overwrite my prompt.

When I push the up arrow (to view the history) the result is even weirder:

enter image description here

(Note the cursor is many characters past the end of the command.) When I try to backspace the cursor from that position, I can only go back this far:

enter image description here

Then when I go up into the history from that backspaced line, I get this:

enter image description here

The command starts from the end of the text that is displayed. (This is consistent for the entire history) But when I go up in the history to the faulty git commit ... it displays as it did before with the overwritten text but when I go past it, it deletes a line of the prompt and displays the previous entry in the history the same way it was doing it before (a la image 2).

When I was creating my PS1 variable I has odd output like this, but I have since closed my brackets and things and don't think that is causing the issue. However if you would like to see my .bash_profile (that sets the PS1) feel free to see it on GitHub. It is really short.

I have tried searching for the issue and can only find a few cygwin email archives about the line wrapping in xterm, but no solutions.

PS: As I was pushing the latest .bash_profile, in order to link it, I ran into the problem again when I typed git add .bash_profile and hit enter, it ran the command but returned the cursor to the start of the same command instead of printing a new prompt. Then when I as writing another commit line, it did the same as the first image, but it blacked out the rest of the line (It wrapped the line, but overwrote the entire line and not just the first few chars.)


回答1:


See http://manpages.ubuntu.com/manpages/lucid/man1/bash.1.html#contenttoc26:

\[

begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt

\]

end a sequence of non-printing characters

If you don't enclose non-printing characters (e.g. color sequences) in your prompt with these their length is counted as part of the prompt's length, eventually resulting in the symptoms that you describe.




回答2:


It doesn't occur frequently to me. When it does, I just type in 'kill -WINCH $$' into the cygwin terminal and it fixes the problem. link to source



来源:https://stackoverflow.com/questions/20697195/cygwin-wraps-text-back-on-to-the-same-line-causing-text-to-be-overwritten

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!