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

Manually copy trailing attributes on a resize #12637

Merged
25 commits merged into from
Mar 21, 2022
Merged

Conversation

zadjii-msft
Copy link
Member

@zadjii-msft zadjii-msft commented Mar 7, 2022

THE WHITE WHALE

This is a fairly naive fix for this bug. It's not terribly performant,
but neither is resize in the first place.

When the buffer gets resized, typically we only copy the text up to the
MeasureRight point, the last printable char in the row. Then we'd just
use the last char's attributes to fill the remainder of the row.

Instead, this PR changes how reflow behaves when it gets to the end of
the row. After we finish copying text, then manually walk through the
attributes at the end of the row, and copy them over. This ensures that
cells that just have a colored space in them get copied into the new
buffer as well, and we don't just blat the last character's attributes
into the rest of the row. We'll do a similar thing once we get to the
last printable char in the buffer, copying the remaining attributes.

This could DEFINITELY be more performant. I think this current
implementation walks the attrs on every cell, then appends the new
attrs to the new ATTR_ROW. That could be optimized by just using the
actual iterator. The copy after the last printable char bit is also
especially bad in this regard. That could likely be a blind copy - I
just wanted to get this into the world.

Finally, we now copy the final attributes to the correct buffer: the new
one. We used to copy them to the old buffer, which we were about to
destroy.

Validation

I'll add more gifs in the morning, not enough time to finish spinning a
release Terminal build with this tonight.

Closes #32 🎉🎉🎉🎉🎉🎉🎉🎉🎉
Closes #12567

@ghost ghost 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 Impact-Visual It look bad. Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Priority-3 A description (P3) Product-Conhost For issues in the Console codebase labels Mar 7, 2022
@github-actions

This comment was marked as resolved.

@DHowett
Copy link
Member

DHowett commented Mar 9, 2022

What if we resize down to the righthand edge of a color and then back to the left. Does it expand that color to the edge forever?

@zadjii-msft
Copy link
Member Author

What if we resize down to the righthand edge of a color and then back to the left. Does it expand that color to the edge forever?

Yea, that does. So that's the same as it was before:
gh-32-last-color-expands-000

That could probably be fixed by the proposed "'bookend' with default attrs at the end of the attrs from the pre-resize buffer" idea, which I haven't tested. In that case, resizing down to the white w above would work as expected, then resizing back out would have default attrs.

@j4james
Copy link
Collaborator

j4james commented Mar 10, 2022

I think I quite like it the way you have it now actually. This way if you've cleared the screen with a different background color, it should retain that color for the full width when you resize (or so I assume). But I don't think the default bookend idea would be bad either - both have their pros and cons.

It's also worth noting that Gnome Terminal seems to treat cells with non-default attributes as wrappable content (even when they're just spaces). But that behaves quite weirdly when you've cleared the screen with a non-default color. I'm not a fan of that approach myself, but I don't think it's unreasonable either.

@lhecker
Copy link
Member

lhecker commented Mar 10, 2022

BTW regarding performance: This PR increases the CPU cost of TextBuffer::Reflow by about 18% if my 120x9001 buffer is full with enwik8. About half of the cost is due to InsertCharacter however, which is a bit silly anyways and can be improved by doing batch-insertions. I'm not concerned about this change from that POV.

@DHowett
Copy link
Member

DHowett commented Mar 10, 2022

@msftbot make sure @miniksa signs off

@ghost ghost added the AutoMerge Marked for automatic merge by the bot when requirements are met label Mar 10, 2022
@ghost
Copy link

ghost commented Mar 10, 2022

Hello @DHowett!

Because you've given me some instructions on how to help merge this pull request, I'll be modifying my merge approach. Here's how I understand your requirements for merging this pull request:

  • I'll only merge this pull request if it's approved by @miniksa

If this doesn't seem right to you, you can tell me to cancel these instructions and use the auto-merge policy that has been configured for this repository. Try telling me "forget everything I just told you".

@DHowett
Copy link
Member

DHowett commented Mar 10, 2022

That could be optimized by just using the actual iterator.

How expensive would you estimate doing it this way would be? Code-time-wise?

@zadjii-msft
Copy link
Member Author

How expensive would you estimate doing it this way would be? Code-time-wise?

I could probably spend half a day sanity checking if that would take half a day or many days and bail if it's too hard. After {the esb bug, the nav view one, the win11 backports, the ppt} in the queue.

@DHowett
Copy link
Member

DHowett commented Mar 17, 2022

Test harness is crashing -- not sure if it is this PR's fault

Error: TAEF: [HRESULT 0x800706BE] A failure occurred while running a test operation: 'SelectionInputTests::ClassSetup'. (The process hosting the test code was unexpectedly terminated with exit code 0x0000DEAD while invoking a test operation.)

@DHowett
Copy link
Member

DHowett commented Mar 18, 2022

Test failure is not from this PR, and is addressed in #17274

@miniksa
Copy link
Member

miniksa commented Mar 18, 2022

Fix the test, of course. But otherwise, I'm happy.

@DHowett
Copy link
Member

DHowett commented Mar 21, 2022

Image from PR body

gh-32-did-I-do-it

@DHowett DHowett added AutoMerge Marked for automatic merge by the bot when requirements are met and removed AutoMerge Marked for automatic merge by the bot when requirements are met labels Mar 21, 2022
@ghost
Copy link

ghost commented Mar 21, 2022

Hello @DHowett!

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 855e136 into main Mar 21, 2022
@ghost ghost deleted the dev/migrie/b/32-attempt-2 branch March 21, 2022 17:02
DHowett pushed a commit that referenced this pull request Mar 28, 2022
## THE WHITE WHALE

This is a fairly naive fix for this bug. It's not terribly performant,
but neither is resize in the first place.

When the buffer gets resized, typically we only copy the text up to the
`MeasureRight` point, the last printable char in the row. Then we'd just
use the last char's attributes to fill the remainder of the row.

Instead, this PR changes how reflow behaves when it gets to the end of
the row. After we finish copying text, then manually walk through the
attributes at the end of the row, and copy them over. This ensures that
cells that just have a colored space in them get copied into the new
buffer as well, and we don't just blat the last character's attributes
into the rest of the row. We'll do a similar thing once we get to the
last printable char in the buffer, copying the remaining attributes.

This could DEFINITELY be more performant. I think this current
implementation walks the attrs _on every cell_, then appends the new
attrs to the new ATTR_ROW. That could be optimized by just using the
actual iterator. The copy after the last printable char bit is also
especially bad in this regard. That could likely be a blind copy - I
just wanted to get this into the world.

Finally, we now copy the final attributes to the correct buffer: the new
one.  We used to copy them to the _old_ buffer, which we were about to
destroy.

## Validation

I'll add more gifs in the morning, not enough time to finish spinning a
release Terminal build with this tonight.

Closes #32 🎉🎉🎉🎉🎉🎉🎉🎉🎉
Closes #12567

(cherry picked from commit 855e136)
DHowett pushed a commit that referenced this pull request Mar 28, 2022
## THE WHITE WHALE

This is a fairly naive fix for this bug. It's not terribly performant,
but neither is resize in the first place.

When the buffer gets resized, typically we only copy the text up to the
`MeasureRight` point, the last printable char in the row. Then we'd just
use the last char's attributes to fill the remainder of the row.

Instead, this PR changes how reflow behaves when it gets to the end of
the row. After we finish copying text, then manually walk through the
attributes at the end of the row, and copy them over. This ensures that
cells that just have a colored space in them get copied into the new
buffer as well, and we don't just blat the last character's attributes
into the rest of the row. We'll do a similar thing once we get to the
last printable char in the buffer, copying the remaining attributes.

This could DEFINITELY be more performant. I think this current
implementation walks the attrs _on every cell_, then appends the new
attrs to the new ATTR_ROW. That could be optimized by just using the
actual iterator. The copy after the last printable char bit is also
especially bad in this regard. That could likely be a blind copy - I
just wanted to get this into the world.

Finally, we now copy the final attributes to the correct buffer: the new
one.  We used to copy them to the _old_ buffer, which we were about to
destroy.

## Validation

I'll add more gifs in the morning, not enough time to finish spinning a
release Terminal build with this tonight.

Closes #32 🎉🎉🎉🎉🎉🎉🎉🎉🎉
Closes #12567

(cherry picked from commit 855e136)
@ghost
Copy link

ghost commented Apr 19, 2022

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

Handy links:

@ghost
Copy link

ghost commented Apr 19, 2022

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

Handy links:

DHowett pushed a commit that referenced this pull request Jun 24, 2022
## THE WHITE WHALE

This is a fairly naive fix for this bug. It's not terribly performant,
but neither is resize in the first place.

When the buffer gets resized, typically we only copy the text up to the
`MeasureRight` point, the last printable char in the row. Then we'd just
use the last char's attributes to fill the remainder of the row.

Instead, this PR changes how reflow behaves when it gets to the end of
the row. After we finish copying text, then manually walk through the
attributes at the end of the row, and copy them over. This ensures that
cells that just have a colored space in them get copied into the new
buffer as well, and we don't just blat the last character's attributes
into the rest of the row. We'll do a similar thing once we get to the
last printable char in the buffer, copying the remaining attributes.

This could DEFINITELY be more performant. I think this current
implementation walks the attrs _on every cell_, then appends the new
attrs to the new ATTR_ROW. That could be optimized by just using the
actual iterator. The copy after the last printable char bit is also
especially bad in this regard. That could likely be a blind copy - I
just wanted to get this into the world.

Finally, we now copy the final attributes to the correct buffer: the new
one.  We used to copy them to the _old_ buffer, which we were about to
destroy.

## Validation

I'll add more gifs in the morning, not enough time to finish spinning a
release Terminal build with this tonight.

Closes #32 🎉🎉🎉🎉🎉🎉🎉🎉🎉
Closes #12567

(cherry picked from commit 855e136)
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-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Area-Rendering Text rendering, emoji, complex glyph & font-fallback issues AutoMerge Marked for automatic merge by the bot when requirements are met Impact-Visual It look bad. Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Priority-3 A description (P3) Product-Conhost For issues in the Console codebase
Projects
None yet
5 participants