diff --git a/src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp b/src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp index fee9dc57fa..8b02fa346c 100644 --- a/src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp +++ b/src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp @@ -234,6 +234,8 @@ class TerminalCoreUnitTests::ConptyRoundtripTests final TEST_METHOD(TestNoExtendedAttrsOptimization); TEST_METHOD(TestNoBackgroundAttrsOptimization); + TEST_METHOD(TestShellIntegrationFlickering); + private: bool _writeCallback(const char* const pch, const size_t cch); void _flushFirstFrame(); diff --git a/src/host/screenInfo.cpp b/src/host/screenInfo.cpp index c6249b0459..d75c8b608a 100644 --- a/src/host/screenInfo.cpp +++ b/src/host/screenInfo.cpp @@ -2349,7 +2349,10 @@ void SCREEN_INFORMATION::SetTerminalConnection(_In_ VtEngine* const pTtyConnecti if (pTtyConnection) { engine.SetTerminalConnection(pTtyConnection, - std::bind(&StateMachine::FlushToTerminal, _stateMachine.get())); + [this]() -> bool { + ServiceLocator::LocateGlobals().pRender->NotifyPaintFrame(); + return _stateMachine->FlushToTerminal(); + }); } else { diff --git a/src/renderer/vt/XtermEngine.cpp b/src/renderer/vt/XtermEngine.cpp index 13bcca7ab0..08d14497ea 100644 --- a/src/renderer/vt/XtermEngine.cpp +++ b/src/renderer/vt/XtermEngine.cpp @@ -537,7 +537,7 @@ CATCH_RETURN(); // To fix this, flush here, so this string is sent to the connected terminal // application. - return _Flush(); + return S_OK; // _Flush(); } // Method Description: diff --git a/src/renderer/vt/invalidate.cpp b/src/renderer/vt/invalidate.cpp index d6dd1b9db3..5c497d3cf6 100644 --- a/src/renderer/vt/invalidate.cpp +++ b/src/renderer/vt/invalidate.cpp @@ -120,6 +120,12 @@ CATCH_RETURN(); _circled = circled; } + // If we flushed for any reason other than circling, we don't need to push + // the buffer out on EndPaint. We're doing this because we encountered some + // VT sequence that required we sync the state of the buffers before passing + // it through. + _noFlushOnEnd = !circled; + _trace.TraceTriggerCircling(*pForcePaint); return S_OK; diff --git a/src/renderer/vt/paint.cpp b/src/renderer/vt/paint.cpp index 3eb561f97f..d9d0bc2cbe 100644 --- a/src/renderer/vt/paint.cpp +++ b/src/renderer/vt/paint.cpp @@ -43,6 +43,12 @@ using namespace Microsoft::Console::Types; _cursorMoved, _wrappedRow); + //if (_buffer.size() > 0 && _quickReturn) + //{ + // RETURN_IF_FAILED(_Flush()); + // return S_FALSE; + //} + return _quickReturn ? S_FALSE : S_OK; } @@ -94,7 +100,14 @@ using namespace Microsoft::Console::Types; RETURN_IF_FAILED(_MoveCursor(_deferredCursorPos)); } - RETURN_IF_FAILED(_Flush()); + if (_noFlushOnEnd) + { + _noFlushOnEnd = false; + } + else + { + RETURN_IF_FAILED(_Flush()); + } return S_OK; } @@ -538,10 +551,11 @@ using namespace Microsoft::Console::Types; // Write the actual text string. If we're using a soft font, the character // set should have already been selected, so we just need to map our internal // representation back to ASCII (handled by the _WriteTerminalDrcs method). - if (_usingSoftFont) [[unlikely]] - { - RETURN_IF_FAILED(VtEngine::_WriteTerminalDrcs({ _bufferLine.data(), cchActual })); - } + if (_usingSoftFont) + [[unlikely]] + { + RETURN_IF_FAILED(VtEngine::_WriteTerminalDrcs({ _bufferLine.data(), cchActual })); + } else { RETURN_IF_FAILED(VtEngine::_WriteTerminalUtf8({ _bufferLine.data(), cchActual })); diff --git a/src/renderer/vt/vtrenderer.hpp b/src/renderer/vt/vtrenderer.hpp index a7cdb7326e..2bd5eb57f3 100644 --- a/src/renderer/vt/vtrenderer.hpp +++ b/src/renderer/vt/vtrenderer.hpp @@ -139,6 +139,7 @@ namespace Microsoft::Console::Render bool _resizeQuirk{ false }; bool _passthrough{ false }; + bool _noFlushOnEnd{ false }; std::optional _newBottomLineBG{ std::nullopt }; [[nodiscard]] HRESULT _WriteFill(const size_t n, const char c) noexcept; diff --git a/src/terminal/parser/OutputStateMachineEngine.cpp b/src/terminal/parser/OutputStateMachineEngine.cpp index 48625cd5af..55c2ec39b1 100644 --- a/src/terminal/parser/OutputStateMachineEngine.cpp +++ b/src/terminal/parser/OutputStateMachineEngine.cpp @@ -168,6 +168,7 @@ bool OutputStateMachineEngine::ActionPassThroughString(const std::wstring_view s if (_pTtyConnection != nullptr) { const auto hr = _pTtyConnection->WriteTerminalW(string); + LOG_IF_FAILED(hr); success = SUCCEEDED(hr); }