terminal/src/host/ut_host
James Holderness 53b6f143b3 Improve the DECSC/DECRC implementation (#3160)
The current DECSC implementation only saves the cursor position and
origin mode. This PR improves that functionality with additional support
for saving the SGR attributes, as well as the active character set.

It also fixes the way the saved state interacts with the alt buffer
(private mode 1049), triggering a save when switching to the alt buffer,
and a restore when switching back, and tracking the alt buffer state
independently from the main state.

In order to properly save and restore the SGR attributes, we first
needed to add a pair of APIs in the `ConGetSet` interface which could
round-trip the attributes with full 32-bit colors (the existing methods
only work with legacy attributes).

I then added a struct in the `AdaptDispatch` implementation to make it
easier to manage all of the parameters that needed to be saved. This
includes the cursor position and origin mode that we were already
tracking, and now also the SGR text attributes and the active character
set (via the `TermOutput` class).

Two instances of this structure are required, since changes made to the
saved state in the alt buffer need to be tracked separately from changes
in the main buffer. I've added a boolean property that specifies whether
we're in the alt buffer or not, and use that to decide which of the two
instances we're working with.

I also needed to explicitly trigger a save when switching to the alt
buffer, and a restore when switching back, since we weren't already
doing that (the existing implementation gave the impression that the
state was saved, because each buffer has its own cursor position, but
that doesn't properly match the XTerm behaviour).

For the state tracking itself, we've now got two additional properties -
the SGR attributes, which we obtain via the new private API, and the
active character set, which we get from a local `AdaptDispatch` field.
I'm saving the whole `TermOutput` class for the character set, since I'm
hoping that will make it automatically supports future enhancements. 

When restoring the cursor position, there is also now a fix to handle
the relative origin mode correctly. If the margins are changed between
the position being saved and restored, it's possible for the cursor to
end up outside of the new margins, which would be illegal. So there is
now an additional step that clamps the Y coordinate within the margin
boundaries if the origin mode is relative.

# Validation

I've added a couple of screen buffer tests which check that the various
parameters are saved and restored as expected, as well as checking that
the Y coordinate is clamped appropriately when the relative origin mode
is set.

I've also tested manually with vttest and confirmed that the
_SAVE/RESTORE CURSOR_ test (the last page of the _Test of screen
features_)) is now working a lot better than it used to.

Closes #148.
2019-11-05 13:35:50 -08:00
..
AliasTests.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
ApiRoutinesTests.cpp Remove unwanted DECSTBM clipping (#2764) 2019-09-23 16:16:54 -07:00
AttrRowTests.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
CharRowBaseTests.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
ClipboardTests.cpp Always use a VK in MapVirtualKeyW(..., MAPVK_VK_TO_VSC) (#3199) 2019-10-17 14:58:41 -07:00
CodepointWidthDetectorTests.cpp Replace CodepointWidthDetector's runtime table with a static one (#2368) 2019-08-16 10:54:17 -07:00
CommandLineTests.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
CommandListPopupTests.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
CommandNumberPopupTests.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
ConsoleArgumentsTests.cpp Fix the conhost command line not being properly escaped (#1815) 2019-07-11 19:38:56 -07:00
CopyFromCharPopupTests.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
CopyToCharPopupTests.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
DbcsTests.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
DefaultResource.rc Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
HistoryTests.cpp Replace macros with constexpr part 2 (#3416) 2019-11-04 07:37:47 -06:00
Host.UnitTests.vcxproj Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
Host.UnitTests.vcxproj.filters Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
InitTests.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
InputBufferTests.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
OutputCellIteratorTests.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
PopupTestHelper.hpp Replace macros with constexpr part 2 (#3416) 2019-11-04 07:37:47 -06:00
product.pbxproj Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
ReadWaitTests.cpp Removed using namespace directive from header files (#955) 2019-05-30 11:14:21 -07:00
RendererTests.cpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
ScreenBufferTests.cpp Improve the DECSC/DECRC implementation (#3160) 2019-11-05 13:35:50 -08:00
SearchTests.cpp Removed using namespace directive from header files (#955) 2019-05-30 11:14:21 -07:00
SelectionTests.cpp Initialize the VT tab stops when a buffer is created in VT mode (#2816) 2019-09-19 15:23:07 -05:00
sources Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
sources.dep Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
testmd.definition inbox: reflect incoming changes up to uxp aa5182a2 (#1916) 2019-07-10 12:40:51 -07:00
TextBufferIteratorTests.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
TextBufferTests.cpp make filling chars (and, thus, erase line/char) unset wrap (#2831) 2019-09-30 18:16:31 -07:00
TitleTests.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
Utf8ToWideCharParserTests.cpp Compensate for non-minimal UTF-8 encodings (#3380) 2019-10-31 10:50:34 -07:00
Utf16ParserTests.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
UtilsTests.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
ViewportTests.cpp Make the RIS command clear the display and scrollback correctly (#2367) 2019-08-27 18:45:38 -07:00
VtIoTests.cpp Rework locking and eventing during startup and shutdown to alleviate some VT issues (#2525) 2019-09-20 15:43:11 -07:00
VtRendererTests.cpp Manipulate Xterm256Engine's extended attr state properly (#3282) 2019-10-24 11:52:36 -07:00