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

Fix conpty not emitting colored spaces on the VERY FIRST frame #13665

Merged
4 commits merged into from
Aug 8, 2022

Conversation

zadjii-msft
Copy link
Member

This bug arose from a "race condition" in the first frame handling of conpty. We'd try to optimize out spaces if we've cleared the entire frame (which always happens on the first frame). However, doing that even for colored spaces meant that things like powerline prompts could be emitted to conhost during the first frame, and we'd optimize the spaces out. That's silly.

This is hard to repro naturally, but this comment has another repro I used
#8341 (comment)

Modified to facilitate simpler testing, it looks like:

Before

image

After

image

Co-authored by @DHowett

@ghost ghost added Area-Rendering Text rendering, emoji, complex glyph & font-fallback issues Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-3 A description (P3) Product-Conpty For console issues specifically related to conpty labels Aug 3, 2022
@github-actions

This comment has been minimized.

_clearedAllThisFrame ||
(_newBottomLine && printingBottomLine && bgMatched));
const auto cchActual = removeSpaces ? nonSpaceLength : cchLine;
static const TextAttribute defaultAttrs{};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been so long that I can't recall whether I wrote this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you had it inline:

const auto cchActual = removeSpaces ? nonSpaceLength : cchLine;
static const TextAttribute defaultAttrs{};
const bool removeSpaces = !lineWrapped && (useEraseChar // we determined earlier that ECH is optimal
|| (_clearedAllThisFrame && _lastTextAttributes == defaultAttrs) // OR we cleared the last frame to the default attributes (specifically)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I ever recommended this on account of its fragility, and I meant to ask @j4james if this seemed ... uh, reasonable?

Sorry, I'm still a bit brain-fogged

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HONESTLY I'm just opening the pr because I was in the area. I tried it for #13229, and it didn't work for that. However, it seemed overall reasonable, so filed this for discussion to get some feedback, mostly from @j4james.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know know the conpty code very well, so I'm unsure if it's guaranteed that _clearedAllThisFrame would mean the screen was cleared with the default attributes. Is that correct? It's not possible for conpty to inherit colors from somewhere in the first frame, like maybe when nesting conpty sessions?

But if you're sure the screen was cleared with default attributes, and we're now writing out text with default attributes, then I think that would imply it's safe to remove spaces.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the only place _clearedAllThisFrame = true is set is in the first paint of StartPaint, when yea, the screen was cleared with the defaults. I don't think nesting conpty would change that - even if you did color 46, wsl, cmd.exe in a Terminal cmd instance, that second conpty would spawn with default attrs.

That sounds good enough to me!

@DHowett
Copy link
Member

DHowett commented Aug 5, 2022

awesome. now just spellbot it!

@danieldusharm
Copy link

Should the test case include a frame with white space characters? For example a terminal prompt containing a /n

@zadjii-msft zadjii-msft added the AutoMerge Marked for automatic merge by the bot when requirements are met label Aug 8, 2022
@ghost
Copy link

ghost commented Aug 8, 2022

Hello @zadjii-msft!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 210a98e into main Aug 8, 2022
@ghost ghost deleted the dev/migrie/b/8341-by-itself branch August 8, 2022 11:48
DHowett pushed a commit that referenced this pull request Aug 8, 2022
This bug arose from a "race condition" in the first frame handling of conpty. We'd try to optimize out spaces if we've cleared the entire frame (which always happens on the first frame). However, doing that even for colored spaces meant that things like powerline prompts could be emitted to conhost during the first frame, and we'd optimize the spaces out. That's silly.

This is hard to repro naturally, but this comment has another repro I used
#8341 (comment)

Modified to facilitate simpler testing, it looks like:

#### Before
![image](https://user-images.githubusercontent.com/18356694/182680119-bb22179c-a328-43f3-b64a-0d1d5773b813.png)

#### After
![image](https://user-images.githubusercontent.com/18356694/182680159-805964c5-c4cc-411a-8865-3866fca8d6e9.png)

* [x] Closes #8341
* [x] Tests added

Co-authored by @DHowett

(cherry picked from commit 210a98e)
Service-Card-Id: 84836597
Service-Version: 1.15
ghost pushed a commit that referenced this pull request Aug 17, 2022
PR #13665 reverted this part of paint.cpp to a time before #13097 and #12975.
This commit restores those changes.
@ghost
Copy link

ghost commented Aug 17, 2022

🎉Windows Terminal v1.14.228 has been released which incorporates this pull request.:tada:

Handy links:

@ghost
Copy link

ghost commented Aug 17, 2022

🎉Windows Terminal Preview v1.15.228 has been released which incorporates this pull request.:tada:

Handy links:

daniel-liuzzi added a commit to daniel-liuzzi/dotfiles that referenced this pull request Aug 22, 2022
PKRoma pushed a commit to PKRoma/Terminal that referenced this pull request Oct 15, 2022
…soft#13665)

This bug arose from a "race condition" in the first frame handling of conpty. We'd try to optimize out spaces if we've cleared the entire frame (which always happens on the first frame). However, doing that even for colored spaces meant that things like powerline prompts could be emitted to conhost during the first frame, and we'd optimize the spaces out. That's silly.

This is hard to repro naturally, but this comment has another repro I used
microsoft#8341 (comment)

Modified to facilitate simpler testing, it looks like:

![image](https://user-images.githubusercontent.com/18356694/182680119-bb22179c-a328-43f3-b64a-0d1d5773b813.png)

![image](https://user-images.githubusercontent.com/18356694/182680159-805964c5-c4cc-411a-8865-3866fca8d6e9.png)

* [x] Closes microsoft#8341
* [x] Tests added

Co-authored by @DHowett

(cherry picked from commit 210a98e)
Service-Card-Id: 84836596
Service-Version: 1.14
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Rendering Text rendering, emoji, complex glyph & font-fallback issues AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-3 A description (P3) Product-Conpty For console issues specifically related to conpty
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spaces added to prompt on shell launch (PowerShell/pwsh)
5 participants