Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange characters are shown in the terminal after git config -e --global #3579

Closed
dscho opened this issue Dec 8, 2021 · 10 comments · Fixed by git-for-windows/msys2-runtime#36
Assignees
Milestone

Comments

@dscho
Copy link
Member

dscho commented Dec 8, 2021

When using MSYS2 runtime v3.3.3 in a regular Git Bash, after git config -e --global launched vim and the editor was closed, seemingly random characters are "ghost-typed".

This might be a "funny" interaction between the MSYS2 runtime, MinTTY and vim.

Concretely, I see 1R77;30502;0c10;rgb:bfbf/bfbf/bfbf11;rgb:0000/0000/0000 being "ghost-typed" every time Git has called vi for editing a file.

To be precise, the hexdump -C output is this:

00000000  1b 5b 32 3b 32 52 1b 5b  33 3b 31 52 1b 5b 3e 37  |.[2;2R.[3;1R.[>7|
00000010  37 3b 33 30 35 30 32 3b  30 63 1b 5d 31 30 3b 72  |7;30502;0c.]10;r|
00000020  67 62 3a 62 66 62 66 2f  62 66 62 66 2f 62 66 62  |gb:bfbf/bfbf/bfb|
00000030  66 07 1b 5d 31 31 3b 72  67 62 3a 30 30 30 30 2f  |f..]11;rgb:0000/|
00000040  30 30 30 30 2f 30 30 30  30 07                    |0000/0000.|

Originally reported in git-for-windows/build-extra#399 (comment)

@dscho dscho self-assigned this Dec 8, 2021
@dscho
Copy link
Member Author

dscho commented Dec 8, 2021

Turns out that there is a much easier way to trigger this: launch vim through git-cmd.exe, like so:

$ /git-cmd.exe --command=/usr/bin/vim.exe ~/.gitconfig; hexdump -C

Side note: Maybe unrelated, but maybe not, if the file to be edited is empty, there are no strange characters showing up. If it is not empty, but less than a screen-full of content, only something like \x1b[2;2R\x1b[3;1R or even only \x1b[2;2R is "ghost-typed". If the file is longer, I see the more characters than that, including the rgb parts showing up.

Another side note: if TERM is set to screen, I do not see those characters, only if it is set to xterm or to cygwin.

@dscho
Copy link
Member Author

dscho commented Dec 8, 2021

/git-cmd.exe --command=/usr/bin/vim.exe ~/.gitconfig; hexdump -C

The idea behind this is, of course, to launch the MSYS2 program vim from the MSYS2 program bash via the non-MSYS2 program git-cmd. That's got to do something with the problem.

@dscho
Copy link
Member Author

dscho commented Dec 8, 2021

Another data point: the problem occurs with https://repo.msys2.org/msys/x86_64/msys2-runtime-3.2.0-13-x86_64.pkg.tar.zst, but not with https://repo.msys2.org/msys/x86_64/msys2-runtime-3.1.7-8-x86_64.pkg.tar.zst (those are the most adjacent versions still available on repo.msys2.org).

@chrisbra
Copy link

chrisbra commented Dec 8, 2021

Is that with mintty?

00000000  1b 5b 32 3b 32 52 1b 5b  33 3b 31 52 1b 5b 3e 37  |.[2;2R.[3;1R.[>7|
00000010  37 3b 33 30 35 30 32 3b  30 63 1b 5d 31 30 3b 72  |7;30502;0c.]10;r|
00000020  67 62 3a 62 66 62 66 2f  62 66 62 66 2f 62 66 62  |gb:bfbf/bfbf/bfb|
00000030  66 07 1b 5d 31 31 3b 72  67 62 3a 30 30 30 30 2f  |f..]11;rgb:0000/|
00000040  30 30 30 30 2f 30 30 30  30 07                    |0000/0000.|

Okay let's see:

  • CSI2;2R and CSI3;3R -> Cursor Position Report. Vim uses that to detect wide characters IIRC
    (see :h t_u7)
  • CSI[>77;30502;0c -> Terminal Version String (Vim tries to identify the terminal type)
  • ESC]10;rgb:bfbf/bfbf/bfbf Terminal Foreground Color (see :h v:termrfgresp)
  • ESC]11;rgb:0000/0000/0000 Terminal Background Color (see :h vtermrbgresp)

I think Vim would only send those, if a terminal pretends to be xterm (so $TERM=xterm), if I recall correctly. Not sure why vim wouldn't consume those on startup. Perhaps those are returned too late?

All of those request strings can be explicitly disabled, see :h t_RV and below for disabling those.

@dscho
Copy link
Member Author

dscho commented Dec 8, 2021

Is that with mintty?

Yes.

I think Vim would only send those, if a terminal pretends to be xterm (so $TERM=xterm), if I recall correctly.

That would make sense.

Not sure why vim wouldn't consume those on startup.

Precisely! Very rarely, I even see vim being confused by these sequences being sent to vim, directly after opening a file.

Perhaps those are returned too late?

That's a safe guess, I think. I see e.g. this hack in the Cygwin runtime that has an arbitrary, hard-coded timeout, but this particular code seems not to be involved with the breakage.

All of those request strings can be explicitly disabled, see :h t_RV and below for disabling those.

That's good to know! If all else fails, I will have to do that for Git for Windows.

My preference, though, would be to figure out where the MSYS2/Cygwin runtime is broken as of v3.2.0.

@dscho
Copy link
Member Author

dscho commented Dec 10, 2021

So after spending a lot of time, I managed to identify the commit that introduced the regression: git-for-windows/msys2-runtime@f206417.

Unfortunately, it looks as if that commit tries to do many things at the same time. At least to me, the intention is not at all clear. Even worse, I cannot put my finger on the spot that causes the strange characters to be sent to the terminal instead of vim. The commit message gives me an idea what is going wrong, but the diff is indecipherable.

@tyan0 any insights from your side?

@dscho
Copy link
Member Author

dscho commented Dec 10, 2021

@tyan0 any insights from your side?

Thank you for this reply. The included patch works around the issue. I will now work on integrating it (even if I am still unhappy to say that even the diff failed to clarify the problem and the solution, conceptually).

dscho pushed a commit to dscho/msys2-runtime that referenced this issue Dec 10, 2021
When launching an MSYS2 process via a non-MSYS2 process, the response
for, say, a CSI [ 6n (Device Status Report) sent from that MSYS2 process
was sometimes not sent (or sent only partially) to the process but to
the terminal instead.

This regression was introduced in f206417 (Cygwin: pty: Reduce
unecessary input transfer., 2021-02-11).

While it is not yet completely clear why, this patch fixes this. The
explanation is left for the commit message that Takashi will craft for
the Cygwin project, but we will take this patch early into the MSYS2/Git
for Windows projects.

This addresses git-for-windows/git#3579
@dscho
Copy link
Member Author

dscho commented Dec 10, 2021

Our trusted Azure Pipeline is building and uploading the msys2-runtime package.

@dscho dscho added this to the Next release milestone Dec 10, 2021
lazka pushed a commit to msys2/msys2-runtime that referenced this issue Dec 10, 2021
When launching an MSYS2 process via a non-MSYS2 process, the response
for, say, a CSI [ 6n (Device Status Report) sent from that MSYS2 process
was sometimes not sent (or sent only partially) to the process but to
the terminal instead.

This regression was introduced in f206417 (Cygwin: pty: Reduce
unecessary input transfer., 2021-02-11).

While it is not yet completely clear why, this patch fixes this. The
explanation is left for the commit message that Takashi will craft for
the Cygwin project, but we will take this patch early into the MSYS2/Git
for Windows projects.

This addresses git-for-windows/git#3579
@dscho
Copy link
Member Author

dscho commented Dec 10, 2021

Our trusted Azure Pipeline is building and uploading the msys2-runtime package.

And it succeeded!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants