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

Correct scrolling invalidation region for tmux in pty w/ bitmap #5122

Merged
7 commits merged into from
Mar 27, 2020

Conversation

miniksa
Copy link
Member

@miniksa miniksa commented Mar 25, 2020

Correct scrolling invalidation region for tmux in pty w/ bitmap

Add tracing for circling and scrolling operations. Fix improper
invalidation within AdjustCursorPosition routine in the subsection about
scrolling down at the bottom with a set of margins enabled.

References

Detailed Description of the Pull Request / Additional comments

  • This occurs when there is a scroll region restriction applied and a
    newline operation is performed to attempt to spin the contents of just
    the scroll region. This is a frequent behavior of tmux.
  • Right now, the Terminal doesn't support any sort of "scroll content"
    operation, so what happens here generally speaking is that the PTY in
    the ConHost will repaint everything when this happens.
  • The PTY when doing AdjustCursorPosition with a scroll region
    restriction would do the following things:
  1. Slide literally everything in the direction it needed to go to take
    advantage of rotating the circular buffer. (This would force a
    repaint in PTY as the PTY always forces repaint when the buffer
    circles.)
  2. Copy the lines that weren't supposed to move back to where they were
    supposed to go.
  3. Backfill the "revealed" region that encompasses what was supposed to
    be the newline.
  • The invalidations for the three operations above were:
  1. Invalidate the number of rows of the delta at the top of the buffer
    (this part was wrong)
  2. Invalidate the lines that got copied back into position (probably
    unnecessary, but OK)
  3. Invalidate the revealed/filled-with-spaces line (this is good).
  • When we were using a simple single rectangle for invalidation, the
    union of the top row of the buffer from 1 and the bottom row of the
    buffer from 2 (and 3 was irrelevant as it was already unioned it)
    resulted in repainting the entire buffer and all was good.

  • When we switched to a bitmap, it dutifully only repainted the top line
    and the bottom two lines as the middle ones weren't a consequence of
    intersect.

  • The logic was wrong. We shouldn't be invalidating rows-from-the-top
    for the amount of the delta. The 1 part should be invalidating
    everything BUT the lines that were invalidated in parts 2 and 3.
    (Arguably part 2 shouldn't be happening at all, but I'm not optimizing
    for that right now.)

  • So this solves it by restoring an entire screen repaint for this sort
    of slide data operation by giving the correct number of invalidated
    lines to the bitmap.

Validation Steps Performed

Closes #5104

…idation within AdjustCursorPosition routine in the subsection about scrolling down at the bottom with a set of margins enabled.
@miniksa
Copy link
Member Author

miniksa commented Mar 25, 2020

Still needs some sort of automated test and for me to finish the description...

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

I'm waiting for tests, but sure sounds fine to me

src/renderer/vt/tracing.cpp Show resolved Hide resolved
src/renderer/vt/XtermEngine.cpp Outdated Show resolved Hide resolved
@zadjii-msft zadjii-msft added Area-Rendering Text rendering, emoji, complex glyph & font-fallback issues Product-Conpty For console issues specifically related to conpty labels Mar 25, 2020
@miniksa
Copy link
Member Author

miniksa commented Mar 25, 2020

Tests on Friday. Gotta be done for the day.

…g to ETW. Change the scroll member variable to a til::point and math that directly (and add the operators and related tests to til::point).
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

I like everything here, but I'll patiently wait for the tests Friday :)

@miniksa
Copy link
Member Author

miniksa commented Mar 27, 2020

Future notes that may need work items (needs discussion):

  • We could implement a scrolling region communication between the PTY and the Terminal so we wouldn't have to invalidate all of this and re-communicate it all.
  • We don't really need to be invalidating the modeline. It's just a consequence of "move everything up and then some things back down." This would mean improving the algorithm in AdjustCursorPosition to maybe just send all operations that it wants to do directly to a scroll method and let it handle the optimization if it should circle things itself.
  • We probably shouldn't be having the PTY emit a command for turning on the cursor for no good reason during some of this output.
  • There's likely an extraneous cursor positioning message from the PTY as well.
  • All of this will become less relevant as we focus more and more on letting pass-through occur.

@miniksa miniksa marked this pull request as ready for review March 27, 2020 21:26
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

tests ❤️

@DHowett-MSFT DHowett-MSFT changed the title Correct invalidation region for tmux in ConPTY under new bitmap invalidation pattern Correct scrolling invalidation region for tmux in pty w/ bitmap Mar 27, 2020
@DHowett-MSFT DHowett-MSFT added the AutoMerge Marked for automatic merge by the bot when requirements are met label Mar 27, 2020
@ghost
Copy link

ghost commented Mar 27, 2020

Hello @DHowett-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 ef80f66 into master Mar 27, 2020
@ghost ghost deleted the dev/miniksa/tmux_draw branch March 27, 2020 22:37
zadjii-msft added a commit that referenced this pull request Mar 30, 2020
  It was unhappy with the exact line lengths and this change
ghost pushed a commit that referenced this pull request Apr 9, 2020
Now that the Terminal is doing a better job of actually marking which
lines were and were not wrapped, we're not always copying lines as
"wrapped" when they should be. We're more correctly marking lines as not
wrapped, when previously we'd leave them marked wrapped.

The real problem is here in the `ScrollFrame` method - we'd manually
newline the cursor to make the terminal's viewport shift down to a new
line. If we had to scroll the viewport for a _wrapped_ line, this would
cause the Terminal to mark that line as broken, because conpty would
emit an extra `\n` that didn't actually exist.

This more correctly implements `ScrollFrame`. Now, well move where we
"thought" the cursor was, so when we get to the next `PaintBufferLine`,
if the cursor needs to newline for the next line, it'll newline, but if
we're in the middle of a wrapped line, we'll just keep printing the
wrapped line.

A couple follow up bugs were found to be caused by the same bad logic.
See #5039 and #5161 for more details on the investigations there.

## References

* #4741 RwR, which probably made this worse
* #5122, which I branched off of 
* #1245, #357 - a pair of other conpty wrapped lines bugs
* #5228 - A followup issue for this PR

## PR Checklist
* [x] Closes #5113
* [x] Closes #5180 (by fixing DECRST 25)
* [x] Closes #5039
* [x] Closes #5161 (by ensuring we only `removeSpaces` on the actual
  bottom line)
* [x] I work here
* [x] Tests added/passed
* [n/a] Requires documentation to be updated

## Validation Steps Performed

* Checked the cases from #1245, #357 to validate that they still work
* Added more and more tests for these scenarios, and then I added MORE
  tests
* The entire team played with this in selfhost builds
DHowett-MSFT pushed a commit that referenced this pull request Apr 21, 2020
Improve wide glyph support in UIA (GH-4946)
Add enhanced key support for ConPty (GH-5021)
Set DxRenderer non-text alias mode (GH-5149)
Reduce CursorChanged Events for Accessibility (GH-5196)
Add more object ID tracing for Accessibility (GH-5215)
Add SS3 cursor key encoding to ConPty (GH-5383)
UIA: Prevent crash from invalid UTR endpoint comparison (GH-5399)
Make CodepointWidthDetector::GetWidth faster (CC-3727)
add til::math, use it for float conversions to point, size (GH-5150)
Add support for renderer backoff, don't FAIL_FAST on 3x failures, add UI (GH-5353)
Fix a deadlock and a bounding rects issue in UIA (GH-5385)
Don't duplicate spaces from potentially-wrapped EOL-deferred lines (GH-5398)
Reimplement the VT tab stop functionality (CC-5173)
Clamp parameter values to a maximum of 32767. (CC-5200)
Prevent the cursor type being reset when changing the visibility (CC-5251)
Make RIS switch back to the main buffer (CC-5248)
Add support for the DSR-OS operating status report (CC-5300)
Update the virtual bottom location if the cursor moves below it (CC-5317)
ci: run spell check in CI, fix remaining issues (CC-4799) (CC-5352)
Set Cascadia Code as default font (GH-5121)
Show a double width cursor for double width characters (GH-5319)
Delegate all character input to the character event handler (CC-4192)
Update til::bitmap to use dynamic_bitset<> + libpopcnt (GH-5092)
Merged PR 4465022: [Git2Git] Merged PR 4464559: Console: Ingest OSS changes up to e055079
Correct scrolling invalidation region for tmux in pty w/ bitmap (GH-5122)
Render row-by-row instead of invalidating entire screen (GH-5185)
Make conechokey use ReadConsoleInputW by default (GH-5148)
Manually pass mouse wheel messages to TermControls (GH-5131)
This fixes C-M-space for WSL but not for Win32, but I'm not sure there's a problem in Win32 quite yet. (GH-5208)
Fix copying wrapped lines by implementing better scrolling (GH-5181)
Emit lines wrapped due to spaces at the end correctly (GH-5294)
Remove unneeded whitespace (CC-5162)
@ghost
Copy link

ghost commented Apr 22, 2020

🎉Windows Terminal Preview v0.11.1121.0 has been released which incorporates this pull request.:tada:

Handy links:

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 Product-Conpty For console issues specifically related to conpty
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Screen content does not update in tmux
3 participants