-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Remove unneeded VT-specific control character handling #4289
Conversation
…ng of VT control characters.
… in the dispatcher.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This scares me, especially the bits about the delayed EOL wrap bits, but I think that this will work right.
@msftbot make sure @miniksa signs off on this |
Hello @zadjii-msft! 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:
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". |
I'll get to this on Tuesday probably. We have Monday off and I'm watching the NFC game right now like @zadjii-msft should be given the Packers are still in it. :P |
Ahaha yea, I was just filling the time between the games 😝 ༼ つ ◕_◕ ༽つ TAKE MY ENERGY PACKERS ༼ つ ◕_◕ ༽つ EDIT: oof |
@zadjii-msft, oof indeed. Also, sorry, Tuesday turned out to be Performance Review day, so I spent all day procrastinating on and writing it. Looking now. I intend to double check the changes against the historical versions of |
I was hoping you'd be able to do that! Ideally we could eventually get this back to exactly how it was in the v1 conhost, once we've got a dedicated stream writer for VT mode (i.e. #780). But if you have any concerns about these changes, I was going to suggest maybe splitting it up into separates PRs? The most important change is probably the first commit, because that fixes #3971. The rest are really edge-case bugs that are unlikely to be encountered in practice. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are mostly notes to myself. I'm still reviewing and I don't want GH to choke and lose them somehow.
I'm not concerned about splitting them up. @zadjii-msft and @DHowett-MSFT are probably rightfully afraid of this area, but making a big mess all at once was my signature thing in this space a few years ago. So just give me a bit to walk through. I'd rather work the whole problem at once instead of chasing 5 PRs. |
Also I will likely finish in the morning because I have to go pick up the kiddo from daycare soon. |
…the SCREEN_INFORMATION class now.
Yes, yes, @zadjii-msft, I hear you. |
OK, just looking through It looks like: Usages of WriteCharsLegacyThe API is only used in 2 ways, flags wise:
And the usages only fall into two categories:
Inventory of callers:
Commentary
ActionsPart 1
Part 2This focuses on the 2A item,
Conclusion
cc: #780 |
…d so that functionality can be reused.
…g can be removed from the _WriteBuffer method.
@miniksa: Regarding the notes above, I think there are couple of things you may be overlooking in part 1, which we'd need to address before we could replace
The first two are probably not that big a deal, but I can see the margin handling becoming a bit of a nightmare again. |
I wrote it out hoping you would spot considerations I missed like that and we could discuss further. Thanks! Here's my thoughts on each: For 1, I think delayed EOL wrap should maybe be the default behavior there and the true legacy ways (the ones coming in through the API) should force-advance and then backspace once to get the non-delayed behavior. For 2, there's an alternate function of For 3, One of the parameters to Any of that sound reasonable? Am I still blind to something? |
I'm not sure about this. How would you force-advance? You couldn't write out something like a space, because you need it to be non-destructive. And you couldn't just use CR/LF to move to the next line because you assumedly want the line to be marked as "wrapped" for resizing purposes. I suspect it might be easier in the end to have a flag for this. Although maybe that's not necessary if the legacy code never goes this route. Maybe it's fine if the delayed wrap is always applied here?
Conceptually I like this, but I'm not certain it's the right approach. As I understand it,
An optional bounding rectangle sounds good. However, bear in mind that it's not really equivalent to the default buffer boundaries. If you're constrained by the margin boundaries, then a scroll event requires that you shift part of the buffer content, whereas a regular scroll would move the viewport origin or cycle the buffer. Also, if you've started off outside the margin boundaries, then you're not constrained by them, but you are constrained by the viewport boundary. Only in that case, you don't scroll when you reach the bottom of the viewport, but I think you do still wrap at the right viewport boundary. It's complicated. Also, I expect we'll want to keep at least some of this functionality in a separate method so it can be reused by other operations. In particular linefeeds need to implement the exact same margin/scrolling behaviour as wrapped text. That said, as long as you're aware of all the issues, I don't think it's necessary we figure out the perfect plan in advance. It often helps to just dive in and start writing something, and if you don't like how it turns out, you can always start again. Eventually you'll settle on the solution you find least offensive. At least, that's what I do. ;) |
Hm, I was thinking that it might not need to be non-destructive. For instance, the case where we're writing to the bottom right corner of the buffer, the next operation once it leaves the right edge is to go down a line and "rotate the circular buffer" which destroys the contents of the line that's about to swap in. But I suppose if we're NOT in the absolute bottom-right corner of the buffer, only the right edge of a viewport, that we wouldn't necessarily want to destroy the value in the 0th column of the next line. So everywhere except X=Max,Y=Max it would have to be non-destructive.
Yeah perhaps it's best that it's either a flag or something then.
Nnnnn. More flags. Or something. I don't like the idea of adding more and more and more flags and would hope we could just find a systematic way out of this. Perhaps the initial naive implementation just calls it repeatedly until everything is consumed. Then we optimize later. The assorted
Ah, yes. Perhaps the passed bounding rectangle for writing is also the range that is used for the
Yes. Yes. Generally I've had the most success just mucking about with it piece by piece and evolving it over time. Let's just make progress here. If you're OK without 100% pre-planning, so am I. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do this, @j4james! Approved.
I'm going to try a re-run on the thing hoping that it remerges against master. But if not, we need to merge master in to see if the flakiness subsides. I'd click the button, but I royally screwed up your branch last time, @j4james. |
Quick. I'm merging it before the system looks at it funny and fails again. |
Hello @miniksa! Because this pull request has the 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 (
|
🎉 Handy links: |
🎉 Once again, thanks for the contribution! This pull request was included in a set of conhost changes that was just |
Summary of the Pull Request
This PR removes all of the VT-specific functionality from the
WriteCharsLegacy
function that dealt with control characters, since those controls are now handled in the state machine when in VT mode. It also removes most of the control character handling from theTerminal::_WriteBuffer
method for the same reason.References
This is a followup to PR #4171
PR Checklist
Detailed Description of the Pull Request / Additional comments
There are four changes to the
WriteCharsLegacy
implementation:The
TAB
character had special case handling in VT mode which is now no longer required. This fixes a bug in the Python REPL editor (when run from a cmd shell in Windows Terminal), which would prevent you tabbing past the end of the line. It also fixes Backspacing a tab character in conpty causes visual corruption #3971.Following on from point 1, the
WC_NONDESTRUCTIVE_TAB
flag could also now be removed. It only ever applied in VT mode, in which case theTAB
character isn't handled inWriteCharsLegacy
, so there isn't a need for a non-destructive version.There used to be special case handling for a
BS
character at the beginning of the line when in VT mode, and that is also no longer required. This fixes an edge-case bug which would prevent a glyph being output for code point 8 whenENABLE_PROCESSED_OUTPUT
was disabled.There was quite a lot of special case handling for control characters in the "end-of-line wrap" implementation, which is no longer required. This fixes a bug which would prevent "low ASCII" characters from wrapping when output at the end of a line.
Then in the
Terminal::_WriteBuffer
implementation, I've simply removed all control character handling, except forLF
. The Terminal is always in VT mode, so the control characters are always handled by the state machine. The exception for theLF
character is simply because it doesn't have a proper implementation yet, so it still passes the character through to_WriteBuffer
. That will get cleaned up eventually, but I thought that could wait for a later PR.Finally, with the removal of the VT mode handling in
WriteCharsLegacy
, there was no longer a need for theSCREEN_INFORMATION::InVTMode
method to be publicly accessible. That has now been made private.Validation Steps Performed
I've only tested manually, making sure the conhost and Windows Terminal still basically work, and confirming that the above-mentioned bugs are fixed by these changes.