terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Add support for selective erase operations

Open j4james opened this issue 3 years ago • 3 comments
trafficstars

This PR adds support for the selective erase escape sequences: DECSED, DECSEL, and DECSCA. They provide a way of marking certain areas of the screen as "protected", so you can erase the content everywhere else without affecting those protected areas.

This adds another bit in the CharacterAttributes enum to track the protected status of each cell, and an operation triggered by the DECSCA sequence which can toggle that bit in the active attributes.

There there are two new erase operations triggered by the DECSED and DECSEL sequences, which work similar to the existing ED (erase in display) and EL (erase in line) operations, but which only apply to unprotected cells.

I've also updated the DECRQSS settings request, so you can query the active protected attribute status.

Validation Steps Performed

I've manually confirmed that we pass the selective erase tests in Vttest now, and I've also manually tested some more complicated edge cases and confirmed that we match the behavior of the hardware VT240 emulator in MAME.

For unit testing I've extended the existing erase tests to cover selective erase as an additional option, I've added a test covering the DECSCA sequence, and I've extended the DECRQSS adapter test to confirm the attribute reporting is working.

Closes #14029

j4james avatar Sep 20 '22 17:09 j4james

Also noted: part of making it transit ConPTY (if we were so inclined) would be to make triply sure the (ever-problematic) optimization to avoid sending empty spaces didn't optimize out a protection attribute :)

DHowett avatar Sep 20 '22 19:09 DHowett

Also noted: part of making it transit ConPTY (if we were so inclined) would be to make triply sure the (ever-problematic) optimization to avoid sending empty spaces didn't optimize out a protection attribute :)

The protected attributes don't need to pass over conpty, because all of the logic is happening on the conhost side (edit: I see now you already noted that in the comment above).

Although now that I think about it, it's possible the existence of a protected attribute might prevent spaces being optimized where they potentially could have been, but that shouldn't break anything. I have tested this in Windows Terminal, and haven't seen any problems.

Edit: Looking at the HasIdenticalVisualRepresentationForBlankSpace implementation here: https://github.com/microsoft/terminal/blob/1ce22a87e6fc204b5fd98642723aa0a51a503749/src/buffer/out/TextAttribute.hpp#L143-L152

Technically that _attrs == other._attrs test could potentially mask out the protected attribute, but I'm not sure I want to introduce any additional complexity here to optimise what is likely an uncommon edge case.

j4james avatar Sep 20 '22 20:09 j4james

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.

Do note that I've been instructed to only help merge pull requests of this repository that have been opened for at least 8 hours, a condition that will be fulfilled in about 4 hours 2 minutes. No worries though, I will be back when the time is right! :wink:

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 avatar Sep 20 '22 21:09 ghost

I'm assuming this is ready to merge.

@msftbot merge this in 10 minutes

EDIT: huh, looks like the bot isn't working? Merging!

carlos-zamora avatar Oct 07 '22 16:10 carlos-zamora

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

Handy links:

ghost avatar Jan 24 '23 18:01 ghost