terminal/src/host
Leon Liang fe3f528827
Show a double width cursor for double width characters (#5319)
# Summary of the Pull Request
This PR will allow the cursor to be double width when on top of a double width character. This required changing `IsCursorDoubleWidth` to check whether the glyph the cursor's on top of is double width. This code is exactly the same as the original PR that addressed this issue in #2932. That one got reverted at some point due to the crashes related to it, but due to a combination of Terminal having come further since that PR and other changes to address use-after-frees, some of the crashes may/may not be relevant now. The ones that seemed to be relevant/repro-able, I attempt to address in this PR.

The `IsCursorDoubleWidth` check would fail during the `TextBuffer::Reflow` call inside of `Terminal::UserResize` occasionally, particularly when `newCursor.EndDeferDrawing()` is called. This is because when we tell the newCursor to `EndDefer`, the renderer will attempt to redraw the cursor. As part of this redraw, it'll ask if `IsCursorDoubleWidth`, and if the renderer managed to ask this before `UserResize` swapped out the old buffer with the new one from `Reflow`, the renderer will be asking the old buffer if its out-of-bounds cursor is double width. This was pretty easily repro'd using `cmatrix -u0` and resizing the window like a madman.

As a solution, I've moved the Start/End DeferDrawing calls out of `Reflow` and into `UserResize`. This way, I can "clamp" the portion of the code where the newBuffer is getting created and reflowed and swapped into the Terminal buffer, and only allow the renderer to draw once the swap is done. This also means that ConHost's `ResizeWithReflow` needed to change slightly.

In addition, I've added a WriteLock to `SetCursorOn`. It was mentioned as a fix for a crash in #2965 (although I can't repro), and I also figured it would be good to try to emulate where ConHost locks with regards to Cursor operations, and this seemed to be one that we were missing.

## PR Checklist
* [x] Closes #2713
* [x] CLA signed
* [x] Tests added/passed

## Validation Steps Performed
Manual validation that the cursor is indeed chonky, added a test case to check that we are correctly saying that the cursor is double width (not too sure if I put it in the right place). Also open to other test case ideas and thoughts on what else I should be careful for since I am quite nervous about what other crashes might occur.
2020-04-15 19:23:06 +00:00
..
dll Unify and clean up the common build properties (#3429) 2019-11-05 14:29:11 -08:00
exe Add experimental retro terminal effects (#3468) 2019-12-12 13:44:01 +00:00
ft_host Change NULL to nullptr since they are pointers (#4960) 2020-03-20 20:35:12 +00:00
ft_integrity Fix a bunch of spelling errors across the project (#4295) 2020-02-10 20:40:01 +00:00
ft_uia Remove unneeded whitespace (#5162) 2020-03-30 14:33:32 +00:00
lib Migrate Search module as a shared component for Terminal Search (#3279) 2019-11-14 14:36:41 -08:00
ut_host Update the virtual bottom location if the cursor moves below it (#5317) 2020-04-14 13:20:30 -07:00
ut_lib Unify and clean up the common build properties (#3429) 2019-11-05 14:29:11 -08:00
_output.cpp Fix FillConsoleOutputCharacterA crash (#4309) 2020-02-10 14:09:08 -08:00
_output.h Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
_stream.cpp Correct scrolling invalidation region for tmux in pty w/ bitmap (#5122) 2020-03-27 22:37:23 +00:00
_stream.h Unify UTF-8 handling using til::u8u16 & revise WriteConsoleAImpl (#4422) 2020-02-03 18:06:55 -08:00
alias.cpp Fix a bunch of spelling errors across the project (#4295) 2020-02-10 20:40:01 +00:00
alias.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
ApiRoutines.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
cmdline.cpp Replace macros with constexpr part 2 (#3416) 2019-11-04 07:37:47 -06:00
cmdline.h Remove unneeded VT-specific control character handling (#4289) 2020-01-29 19:18:46 +00:00
CommandListPopup.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
CommandListPopup.hpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
CommandNumberPopup.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
CommandNumberPopup.hpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
conapi.h Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
conareainfo.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
conareainfo.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
conattrs.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
conddkrefs.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
conhost.rcv Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
conhostv2_traceviewpp.tvpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
conimeinfo.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
conimeinfo.h Fix a bunch of spelling errors across the project (#4295) 2020-02-10 20:40:01 +00:00
conserv.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
ConsoleArguments.cpp Add support for "reflow"ing the Terminal buffer (#4741) 2020-03-12 17:43:37 -07:00
ConsoleArguments.hpp Add support for "reflow"ing the Terminal buffer (#4741) 2020-03-12 17:43:37 -07:00
consoleInformation.cpp Move MouseInput from TermAdapter to TermInput (#4848) 2020-03-12 22:25:43 +00:00
conv.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
convarea.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
conwinuserrefs.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
CopyFromCharPopup.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
CopyFromCharPopup.hpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
CopyToCharPopup.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
CopyToCharPopup.hpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
CursorBlinker.cpp Change NULL to nullptr since they are pointers (#4960) 2020-03-20 20:35:12 +00:00
CursorBlinker.hpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
dbcs.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
dbcs.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
directio.cpp Replace some macros with constexpr (#3362) 2019-11-01 10:33:09 -07:00
directio.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
dirs Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
exemain.cpp Change NULL to nullptr since they are pointers (#4960) 2020-03-20 20:35:12 +00:00
getset.cpp Reimplement the VT tab stop functionality (#5173) 2020-04-01 12:49:27 +00:00
getset.h Reimplement the VT tab stop functionality (#5173) 2020-04-01 12:49:27 +00:00
globals.cpp Add just the test infrastructure bits from #4354 (#4382) 2020-01-29 16:33:06 +00:00
globals.h Add just the test infrastructure bits from #4354 (#4382) 2020-01-29 16:33:06 +00:00
handle.cpp Removed using namespace directive from header files (#955) 2019-05-30 11:14:21 -07:00
handle.h Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
history.cpp Merged PR 4447792: Fix two bugs with DOSKEY 2020-03-19 18:14:52 +00:00
history.h Replace macros with constexpr part 2 (#3416) 2019-11-04 07:37:47 -06:00
host-common.vcxitems Migrate Search module as a shared component for Terminal Search (#3279) 2019-11-14 14:36:41 -08:00
IIoProvider.hpp Fix a bunch of spelling errors across the project (#4295) 2020-02-10 20:40:01 +00:00
init.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
init.hpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
input.cpp ci: run spell check in CI, fix remaining issues (#4799) 2020-03-25 11:02:53 -07:00
input.h Replace macros with constexpr part 2 (#3416) 2019-11-04 07:37:47 -06:00
inputBuffer.cpp ci: run spell check in CI, fix remaining issues (#4799) 2020-03-25 11:02:53 -07:00
inputBuffer.hpp Move MouseInput from TermAdapter to TermInput (#4848) 2020-03-12 22:25:43 +00:00
inputKeyInfo.cpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
inputReadHandleData.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
inputReadHandleData.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
misc.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
misc.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
ntprivapi.cpp Change NULL to nullptr since they are pointers (#4960) 2020-03-20 20:35:12 +00:00
ntprivapi.hpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
output.cpp Fix a bunch of spelling errors across the project (#4295) 2020-02-10 20:40:01 +00:00
output.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
outputStream.cpp Reimplement the VT tab stop functionality (#5173) 2020-04-01 12:49:27 +00:00
outputStream.hpp Reimplement the VT tab stop functionality (#5173) 2020-04-01 12:49:27 +00:00
popup.cpp Get rid of the SCREEN_INFORMATION::LineChar array (#3371) 2019-10-31 10:12:41 -05:00
popup.h Replace some macros with constexpr (#3362) 2019-11-01 10:33:09 -07:00
precomp.cpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
precomp.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
PtySignalInputThread.cpp Fix a bunch of spelling errors across the project (#4295) 2020-02-10 20:40:01 +00:00
PtySignalInputThread.hpp Revert locking changes (#3488) 2019-11-08 13:44:52 -08:00
readData.cpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
readData.hpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
readDataCooked.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
readDataCooked.hpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
readDataDirect.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
readDataDirect.hpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
readDataRaw.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
readDataRaw.hpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
registry.cpp Fix a bunch of spelling errors across the project (#4295) 2020-02-10 20:40:01 +00:00
registry.hpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
renderData.cpp ci: run spell check in CI, fix remaining issues (#4799) 2020-03-25 11:02:53 -07:00
renderData.hpp Properly represent block selections in UIA (#4991) 2020-03-18 21:03:51 +00:00
renderFontDefaults.cpp Allow FontInfo{,Base,Desired} to store a font name > 32 wch (#3107) 2019-10-14 21:23:45 -07:00
renderFontDefaults.hpp Allow FontInfo{,Base,Desired} to store a font name > 32 wch (#3107) 2019-10-14 21:23:45 -07:00
res.rc Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
resource.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
runft.bat Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
runtests.bat Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
runut.bat Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
ScreenBufferRenderTarget.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
ScreenBufferRenderTarget.hpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
screenInfo.cpp Show a double width cursor for double width characters (#5319) 2020-04-15 19:23:06 +00:00
screenInfo.hpp Reimplement the VT tab stop functionality (#5173) 2020-04-01 12:49:27 +00:00
scrolling.cpp Accessibility: Set-up UIA Tree (#1691) 2019-07-29 15:21:15 -07:00
scrolling.hpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
selection.cpp Move rect expansion to textbuffer; refactor selection code (#4560) 2020-02-27 16:42:26 -08:00
selection.hpp Move rect expansion to textbuffer; refactor selection code (#4560) 2020-02-27 16:42:26 -08:00
selectionInput.cpp Fix a bunch of spelling errors across the project (#4295) 2020-02-10 20:40:01 +00:00
selectionState.cpp Fix a bunch of spelling errors across the project (#4295) 2020-02-10 20:40:01 +00:00
server.h Move MouseInput from TermAdapter to TermInput (#4848) 2020-03-12 22:25:43 +00:00
settings.cpp Fix a bunch of spelling errors across the project (#4295) 2020-02-10 20:40:01 +00:00
settings.hpp Add support for the DECSCNM screen mode (#3817) 2020-01-22 22:29:50 +00:00
sources.inc Merged PR 4182306: [Git2Git] Merged PR 4182266: conhost: don't use D3DCompiler on inside-windows builds (and delete the shaders) 2020-01-23 00:42:56 +00:00
sources.test.inc Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
srvinit.cpp Change NULL to nullptr since they are pointers (#4960) 2020-03-20 20:35:12 +00:00
srvinit.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
stream.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
stream.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
telemetry.cpp Fix a bunch of spelling errors across the project (#4295) 2020-02-10 20:40:01 +00:00
telemetry.hpp Fix a bunch of spelling errors across the project (#4295) 2020-02-10 20:40:01 +00:00
tracing.cpp UIA: Fix GetVisibleRanges() and add Tracing (#4495) 2020-02-20 23:50:43 +00:00
tracing.hpp UIA: Fix GetVisibleRanges() and add Tracing (#4495) 2020-02-20 23:50:43 +00:00
utf8ToWideCharParser.cpp Fix a bunch of spelling errors across the project (#4295) 2020-02-10 20:40:01 +00:00
utf8ToWideCharParser.hpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
utils.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
utils.hpp Fix a bunch of spelling errors across the project (#4295) 2020-02-10 20:40:01 +00:00
VtInputThread.cpp Enable Passthrough for VT Input Mode in ConPty (#4856) 2020-03-10 22:07:14 +00:00
VtInputThread.hpp Unify UTF-8 handling using til::u8u16 & revise WriteConsoleAImpl (#4422) 2020-02-03 18:06:55 -08:00
VtIo.cpp Add support for "reflow"ing the Terminal buffer (#4741) 2020-03-12 17:43:37 -07:00
VtIo.hpp Add support for "reflow"ing the Terminal buffer (#4741) 2020-03-12 17:43:37 -07:00
writeData.cpp Removed using namespace directive from header files (#955) 2019-05-30 11:14:21 -07:00
writeData.hpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00