Skip to content

Terminal layout issue (column count seems off by one ?) #411

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

Closed
AloyseTech opened this issue Apr 15, 2019 · 22 comments · Fixed by #2816
Closed

Terminal layout issue (column count seems off by one ?) #411

AloyseTech opened this issue Apr 15, 2019 · 22 comments · Fixed by #2816
Assignees
Labels
Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Area-VT Virtual Terminal sequence support Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Tag-Fix Doesn't match tag requirements Priority-2 A description (P2) Product-Conhost For issues in the Console codebase Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Milestone

Comments

@AloyseTech
Copy link

  • Your Windows build number: (Type ver at a Windows Command Prompt)
    Microsoft Windows [version 10.0.17763.437]

  • What you're doing and what's happening: (Copy & paste specific commands and their output, or include screen shots)
    using git command line in the terminal in a zsh shell
    git command output layout is messed up (seems like the number of column of the terminal is off by one)
    git_messed

  • What's wrong / what should be happening instead:
    Wen I open a Ubuntu terminal with WSL, the git commend output layout is messed up. I have to use reset and it fixes the layout in the following commands.

@ghost ghost added the Needs-Tag-Fix Doesn't match tag requirements label May 17, 2019
@miniksa miniksa added Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Area-Rendering Text rendering, emoji, complex glyph & font-fallback issues Area-VT Virtual Terminal sequence support Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Repro We can't figure out how to make this happen. Please help find a simplified repro. Product-Conhost For issues in the Console codebase and removed Mass-Chaos labels May 17, 2019
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label May 18, 2019
@miniksa miniksa added Needs-Tag-Fix Doesn't match tag requirements and removed Needs-Repro We can't figure out how to make this happen. Please help find a simplified repro. labels May 18, 2019
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label May 18, 2019
@j4james
Copy link
Collaborator

j4james commented Jul 2, 2019

I believe this is an issue with tab stops. It seems that the wsl shell starts up with no tab stops set by default, so when you output a tab, the cursor jumps right to the end of the line.

You can reproduce this with a simple printf "\tX\n". You'd expect that to output the X in column 9, but instead it ends up at the end of the line.

Interestingly the cmd.exe shell doesn't appear to have this problem - it's initialized with tab stops every 8 columns as you'd expect. And if you start a bash shell from the cmd shell then that will have the tab stops set correctly too.

@zadjii-msft
Copy link
Member

I'm pretty sure we mucked with this very recently.
image

Because conhost is insane, we actually have two different sets of tab stops - the VT ones that are used for apps that are using ENABLE_VIRTUAL_TERMINAL_PROCESSING and not cooked reads (ex wsl.exe). These are the ones that were broken here. When an app is using cooked reads (ex cmd.exe), we actually have a separate set of tab-stop logic that's used. The brave could look at the function WriteCharsLegacy to see how the cmd.exe-like tabstops work.

@zadjii-msft zadjii-msft added this to the 19H1 milestone Jul 3, 2019
@zadjii-msft
Copy link
Member

I want to say this is fixed in the latest release, but I can't get the original case to repro. @AloyseTech can you see if updating Windows fixes this?

@zadjii-msft zadjii-msft added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jul 3, 2019
@AloyseTech
Copy link
Author

I still have the issue on Windows 10 17763.557. Do I need to update WSL alone somehow?

@ghost ghost added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Jul 3, 2019
@zadjii-msft
Copy link
Member

@AloyseTech Oh, I mean you need to update Windows 10 to 18362

@AloyseTech
Copy link
Author

I've just updated to 10.0.18362 (don't know why I was still on the other version), but the problem is still here...

@zadjii-msft
Copy link
Member

Good to know! I'll move it to the right milestone and investigate soontm

@zadjii-msft zadjii-msft modified the milestones: 19H1, 20H1 Jul 3, 2019
@zadjii-msft zadjii-msft removed Area-Rendering Text rendering, emoji, complex glyph & font-fallback issues Needs-Attention The core contributors need to come back around and look at this ASAP. labels Jul 3, 2019
@zadjii-msft
Copy link
Member

Hmm. I can't seem to repro this:
image

Is there anything else about your configuration that might be causing this? Are you maybe running screen or tmux? maybe there's something else that you had previously running in the terminal that left it in a corrupted state? Maybe it's something in your zsh config?

@zadjii-msft zadjii-msft added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Sep 5, 2019
@ghost ghost removed the No-Recent-Activity This issue/PR is going stale and may be auto-closed without further activity. label Sep 10, 2019
@zadjii-msft
Copy link
Member

Honestly I have no idea. Does this repro in other shells? If it doesn't, we can narrow it down to zsh, otherwise we'll have to investigate something else. Since I can't repro this on my own right now, we're going to need to find out what bit of config somewhere is causing this to happen.

@zadjii-msft zadjii-msft added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Attention The core contributors need to come back around and look at this ASAP. labels Sep 11, 2019
@j4james
Copy link
Collaborator

j4james commented Sep 11, 2019

I can still reproduce this with a recent local build (commit 537258a).

The trick is to have the VirtualTerminalLevel registry entry set to 1. Then start a shell from the tools directory with openbash, and execute the test case printf "\tX\n".

With VirtualTerminalLevel set to 0 it works (i.e. the X is in column 9). When set to 1, it's at the end of the line.

@j4james
Copy link
Collaborator

j4james commented Sep 11, 2019

OK, I think I know what's going on. By default the ENABLE_VIRTUAL_TERMINAL_PROCESSING mode isn't set in the SCREEN_INFORMATION constructor, unless the VirtualTerminalLevel registry is set to a non-zero value:

if (gci.GetVirtTermLevel() != 0)
{
OutputMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
}

Later on SetConsoleOutputModeImpl is called with ENABLE_VIRTUAL_TERMINAL_PROCESSING, and that's when the tab stops would usually be initialized, but that only happens if the flag wasn't already set.

// if we're moving from VT off->on
else if (WI_IsFlagSet(dwNewMode, ENABLE_VIRTUAL_TERMINAL_PROCESSING) &&
WI_IsFlagClear(dwOldMode, ENABLE_VIRTUAL_TERMINAL_PROCESSING))
{
screenInfo.SetDefaultVtTabStops();
}

Bottom line, if the ENABLE_VIRTUAL_TERMINAL_PROCESSING was already set in the constructor (because of the registry entry), then the default tab stops don't get initialized.

@zadjii-msft
Copy link
Member

Woah. Well that's messed up.

Seems like the easy fix is if we're constructing the buffer with ENABLE_VIRTUAL_TERMINAL_PROCESSING, we should just initialize those tab stops too. Thanks for debugging this @j4james!

@zadjii-msft zadjii-msft added Priority-2 A description (P2) and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Sep 11, 2019
@zadjii-msft zadjii-msft self-assigned this Sep 16, 2019
zadjii-msft added a commit that referenced this issue Sep 19, 2019
zadjii-msft added a commit that referenced this issue Sep 19, 2019
@ghost ghost added the In-PR This issue has a related PR label Sep 19, 2019
@ghost ghost added the Needs-Tag-Fix Doesn't match tag requirements label Sep 19, 2019
zadjii-msft added a commit that referenced this issue Sep 19, 2019
* fixes #411

* update this comment to actually match

* run this test in isolation so it doesn't break other tests, @DHowett-MSFT

* This fixes the test that's broken?

  Kinda raises more questions tbh
@ghost ghost added Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. and removed In-PR This issue has a related PR labels Sep 19, 2019
DHowett-MSFT pushed a commit that referenced this issue Sep 23, 2019
* fixes #411

* update this comment to actually match

* run this test in isolation so it doesn't break other tests, @DHowett-MSFT

* This fixes the test that's broken?

  Kinda raises more questions tbh

(cherry picked from commit dfaaa44)
@ghost
Copy link

ghost commented Sep 24, 2019

🎉This issue was addressed in #2816, which has now been successfully released as Windows Terminal Preview v0.5.2661.0.:tada:

Handy links:

@AloyseTech
Copy link
Author

@zadjii-msft I still have the issue after updating everything I could update. I installed the Terminal Preview as well. Maybe I misunderstanding something, but when I launch WSL terminal via the Ubuntu icon, the terminal TAB is still messed up...
On the left I use Terminal (Preview) and on the right I launch Ubuntu direcly via the shortcut :
image

@zadjii-msft
Copy link
Member

@AloyseTech What Windows version are you using? This was fixed for the Terminal in 0.5, but I'm not sure the Windows release that will fix the legacy/inbox console has actually been released yet.

@AloyseTech
Copy link
Author

@zadjii-msft I'm running Windows 10 1909 18363.592

@zadjii-msft
Copy link
Member

... I'm realizing now I have now idea how our version numbers work for the last two releases. @DHowett-MSFT I think #2816 landed in Vb, would that be 18363.592 publicly, or is it not out yet?

@DHowett-MSFT
Copy link
Contributor

Alas! 18363 is "19H2", a targeted set of backports to 19H1. 😄

@AloyseTech
Copy link
Author

So the fix is not yet ready, right?

@zadjii-msft
Copy link
Member

@AloyseTech Nope, looks like it's not. I'm not sure what the next major Windows release build number will be, but that should have the fix.

ghost pushed a commit that referenced this issue Apr 1, 2020
## Summary of the Pull Request

This is essentially a rewrite of the VT tab stop functionality, implemented entirely within the `AdaptDispatch` class. This significantly simplifies the `ConGetSet` interface, and should hopefully make it easier to share the functionality with the Windows Terminal VT implementation in the future.

By removing the dependence on the `SCREEN_INFORMATION` class, it fixes the problem of the the tab state not being preserved when switching between the main and alternate buffers. And the new architecture also fixes problems with the tabs not being correctly initialized when the screen is resized.

## References

This fixes one aspect of issue #3545.
It also supersedes the fix for #411 (PR #2816).
I'm hoping the simplification of `ConGetSet` will help with #3849.

## PR Checklist
* [x] Closes #4669
* [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [x] Tests added/passed
* [ ] Requires documentation to be updated
* [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

## Detailed Description of the Pull Request / Additional comments

In the new tab architecture, there is now a `vector<bool>` (__tabStopColumns_), which tracks whether any particular column is a tab stop or not. There is also a __initDefaultTabStops_ flag indicating whether the default tab stop positions need to be initialised when the screen is resized.

The way this works, the vector is initially empty, and only initialized (to the current width of the screen) when it needs to be used. When the vector grows in size, the __initDefaultTabStops_ flag determines whether the new columns are set to false, or if every 8th column is set to true.

By default we want the latter behaviour - newly revealed columns should have default tab stops assigned to them - so __initDefaultTabStops_ is set to true. However, after a `TBC 3` operation (i.e. we've cleared all tab stops), there should be no tab stops in any newly revealed columns, so __initDefaultTabStops_ is set to false.

Note that the __tabStopColumns_ vector is never made smaller when the window is shrunk, and that way it can preserve the state of tab stops that are off screen, but which may come into range if the window is made bigger again.

However, we can can still reset the vector completely after an `RIS` or `TBC 3` operation, since the state can then be reconstructed automatically based on just the __initDefaultTabStops_ flag.

## Validation Steps Performed

The original screen buffer tests had to be rewritten to set and query the tab stop state using escape sequences rather than interacting with the `SCREEN_INFORMATION` class directly, but otherwise the structure of most tests remained largely the same.

However, the alt buffer test was significantly rewritten, since the original behaviour was incorrect, and the initialization test was dropped completely, since it was no longer applicable. The adapter tests were also dropped, since they were testing the `ConGetSet` interface which has now been removed.

I also had to make an addition to the method setup of the screen buffer tests (making sure the viewport was appropriately initialized), since there were some tests (unrelated to tab stops) that were previously dependent on the state being set in the tab initialization test which has now been removed.

I've manually tested the issue described in #4669 and confirmed that the tabs now produce the correct spacing after a resize.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Area-VT Virtual Terminal sequence support Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Tag-Fix Doesn't match tag requirements Priority-2 A description (P2) Product-Conhost For issues in the Console codebase Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants