Git output exact width of window is lost. #12659

Closed
opened 2026-01-31 03:21:21 +00:00 by claunia · 11 comments
Owner

Originally created by @jaykrell on GitHub (Feb 19, 2021).

Environment

Windows Terminal
Version: 1.5.10411.0

Steps to reproduce

Both with conhost and terminal, cmd, git show,
with expecting like:

+
+blah

and the last line happens to be the exact width of the window, the last line is not shown.

git log -p works.

Tweaking the window width at all in either direction works.

Expected behavior

Not this.

Actual behavior

Described above.

Originally created by @jaykrell on GitHub (Feb 19, 2021). # Environment Windows Terminal Version: 1.5.10411.0 # Steps to reproduce Both with conhost and terminal, cmd, git show, with expecting like: ``` + +blah ``` and the last line happens to be the exact width of the window, the last line is not shown. git log -p works. Tweaking the window width at all in either direction works. # Expected behavior Not this. # Actual behavior Described above.
claunia added the Product-ConhostArea-OutputIssue-BugResolution-External labels 2026-01-31 03:21:21 +00:00
Author
Owner

@jaykrell commented on GitHub (Feb 19, 2021):

I demonstrated this to /cc@Michael Niksa
Could be a git bug of course.

@jaykrell commented on GitHub (Feb 19, 2021): I demonstrated this to /cc@Michael Niksa Could be a git bug of course.
Author
Owner

@DHowett commented on GitHub (Feb 20, 2021):

/cc @miniksa

@DHowett commented on GitHub (Feb 20, 2021): /cc @miniksa
Author
Owner

@miniksa commented on GitHub (Feb 23, 2021):

So to repro this... you need to make a commit in your history that has a message the exact width of the window.

Like the exact edit in the file at the end of what git show would show is 120 characters wide and your window is 120 characters wide. Not just the commit message because git show will show that and then the delta in the file. And even then, git will add the + at the front of the line. So you likely need a 118 character long edited line that is added/removed as the last line of the commit.

Then set the window to 120 characters wide. Then call git show and it'll truncate/lose the last line and not display it.

If you resize the window larger or smaller than that exact length, it'll work with git show.

And git log -p... it always works correctly instead.

@miniksa commented on GitHub (Feb 23, 2021): So to repro this... you need to make a commit in your history that has a message the exact width of the window. Like the exact edit in the file at the end of what `git show` would show is 120 characters wide and your window is 120 characters wide. Not just the commit message because `git show` will show that and then the delta in the file. And even then, `git` will add the `+ ` at the front of the line. So you likely need a 118 character long edited line that is added/removed as the last line of the commit. Then set the window to 120 characters wide. Then call `git show` and it'll truncate/lose the last line and not display it. If you resize the window larger or smaller than that exact length, it'll work with `git show`. And `git log -p`... it always works correctly instead.
Author
Owner

@miniksa commented on GitHub (Feb 23, 2021):

In Jay's instance, it was like this

git show

commit b29d8988f9145aed19f3f30270951aaecb915856 (HEAD -> main)
Author: Michael Niksa <miniksa@microsoft.com>
Date:   Tue Feb 23 09:01:36 2021 -0800

    Test

diff --git a/README.md b/README.md
index aa9cfc4a..191a6f0a 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
 # Welcome to the Windows Terminal, Console and Command-Line repo
-

But if he did

git log -p

commit b29d8988f9145aed19f3f30270951aaecb915856 (HEAD -> main)
Author: Michael Niksa <miniksa@microsoft.com>
Date:   Tue Feb 23 09:01:36 2021 -0800

    Test

diff --git a/README.md b/README.md
index aa9cfc4a..191a6f0a 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
 # Welcome to the Windows Terminal, Console and Command-Line repo
-
+asdf when this line is printed with the plus on the front, it is the exact width of my window
commit 81d773d2bfad7c906a42e47dc12569ec892ace69
...

It showed that line that it truncated before (the one with the plus that was the exact width).

@miniksa commented on GitHub (Feb 23, 2021): In Jay's instance, it was like this > `git show` ``` commit b29d8988f9145aed19f3f30270951aaecb915856 (HEAD -> main) Author: Michael Niksa <miniksa@microsoft.com> Date: Tue Feb 23 09:01:36 2021 -0800 Test diff --git a/README.md b/README.md index aa9cfc4a..191a6f0a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Welcome to the Windows Terminal, Console and Command-Line repo - ``` > But if he did > `git log -p` ``` commit b29d8988f9145aed19f3f30270951aaecb915856 (HEAD -> main) Author: Michael Niksa <miniksa@microsoft.com> Date: Tue Feb 23 09:01:36 2021 -0800 Test diff --git a/README.md b/README.md index aa9cfc4a..191a6f0a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Welcome to the Windows Terminal, Console and Command-Line repo - +asdf when this line is printed with the plus on the front, it is the exact width of my window commit 81d773d2bfad7c906a42e47dc12569ec892ace69 ... ``` It showed that line that it truncated before (the one with the plus that was the exact width).
Author
Owner

@DHowett commented on GitHub (Feb 26, 2021):

@miniksa triaged to windows vnext.

@DHowett commented on GitHub (Feb 26, 2021): @miniksa triaged to windows vnext.
Author
Owner

@j4james commented on GitHub (Feb 26, 2021):

Are you sure this is our bug? I just took a look at what we're receiving in DoWriteConsole, and after it has written out that last line (with no line break), it sends \r\x1b[K, i.e. a carriage return and erase to end of line. So it's not surprising that the line is erased.

This only happens for me in a cmd shell though. If I run git show from a WSL bash shell it works fine. Looking at the output again in DoWriteConsole, we receive an additional \r\n after that last line is written out, and before the \r\x1b[K sequence, so the erase only clears the following line.

I'm wondering if maybe they're assuming Windows doesn't support delayed eol wrap (which would have been the case in the past), so they assume that writing in the last column on Windows is going to trigger a line break anyway, and thus don't send an "additional" line break.

@j4james commented on GitHub (Feb 26, 2021): Are you sure this is our bug? I just took a look at what we're receiving in `DoWriteConsole`, and after it has written out that last line (with no line break), it sends `\r\x1b[K`, i.e. a carriage return and erase to end of line. So it's not surprising that the line is erased. This only happens for me in a cmd shell though. If I run `git show` from a WSL bash shell it works fine. Looking at the output again in `DoWriteConsole`, we receive an additional `\r\n` after that last line is written out, and before the `\r\x1b[K` sequence, so the erase only clears the following line. I'm wondering if maybe they're assuming Windows doesn't support _delayed eol wrap_ (which would have been the case in the past), so they assume that writing in the last column on Windows is going to trigger a line break anyway, and thus don't send an "additional" line break.
Author
Owner

@miniksa commented on GitHub (Mar 2, 2021):

Are you sure this is our bug?

Nope. But I asked Jay to file it anyway so it's at least tracked SOMEWHERE.

Based on your investigation, James, it probably is a git issue.

@miniksa commented on GitHub (Mar 2, 2021): > Are you sure this is our bug? Nope. But I asked Jay to file it anyway so it's at least tracked SOMEWHERE. Based on your investigation, James, it probably is a git issue.
Author
Owner

@zadjii-msft commented on GitHub (Mar 3, 2021):

Okay great, I'm totally cool calling this a git issue. It'll need to be filed upstream (though, I don't know exactly where their issue tracker is off hand).

Thanks everyone!

@zadjii-msft commented on GitHub (Mar 3, 2021): Okay great, I'm totally cool calling this a git issue. It'll need to be filed upstream (though, I don't know exactly where their issue tracker is off hand). Thanks everyone!
Author
Owner

@lhecker commented on GitHub (Apr 23, 2021):

In git this is implemented in term_clear_line: 67e748cc61/pager.c (L193)
term_clear_line emits \r\x1b[K regardless of the operating system and it's called in the exact same 5 places in both git as well as git-for-windows.
Assuming that this doesn't occur under other terminals, should we reopen this issue then?

@lhecker commented on GitHub (Apr 23, 2021): In git this is implemented in `term_clear_line`: https://github.com/git-for-windows/git/blob/67e748cc61a2a389d04feedca7ae9cc63f2354b4/pager.c#L193 `term_clear_line` emits `\r\x1b[K` regardless of the operating system and it's called in the exact same 5 places in both git as well as git-for-windows. Assuming that this doesn't occur under other terminals, should we reopen this issue then?
Author
Owner

@lhecker commented on GitHub (Apr 23, 2021):

Actually I'm pretty sure that less (the pager that git uses by default) is the culprit here.
👉 14aa5bed96/screen.c (L214)

Someone should try this again with LESS_TERMCAP_am=0, but I'm pretty sure it's hardcoded to 1.
(I'm not sure whether MSDOS_COMPILER is defined under MSYS2 or not. I took a look at it, but I didn't quite understand how the compilation of less under MSYS2 works yet.)

@lhecker commented on GitHub (Apr 23, 2021): Actually I'm pretty sure that `less` (the pager that git uses by default) is the culprit here. 👉 https://github.com/gwsw/less/blob/14aa5bed9686d63b86e3d94c01665cb7716be123/screen.c#L214 Someone should try this again with [`LESS_TERMCAP_am=0`](https://github.com/gwsw/less/blob/14aa5bed9686d63b86e3d94c01665cb7716be123/screen.c#L1191), but [I'm pretty sure it's hardcoded to `1`](https://github.com/gwsw/less/blob/14aa5bed9686d63b86e3d94c01665cb7716be123/screen.c#L1084-L1085). (I'm not sure whether `MSDOS_COMPILER` is defined under MSYS2 or not. I took a look at it, but I didn't quite understand how the compilation of `less` under MSYS2 works yet.)
Author
Owner

@zadjii-msft commented on GitHub (Apr 23, 2021):

holy shit

I mean, yea, that looks like the source of the problem to me.

@zadjii-msft commented on GitHub (Apr 23, 2021): _holy shit_ I mean, yea, that looks like the source of the problem to me.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#12659