Skip to content

Commit

Permalink
PRE-MERGE #14677 Prevent flickering in nushell due to FTCS marks
Browse files Browse the repository at this point in the history
  • Loading branch information
DHowett committed Apr 6, 2023
2 parents 3dd9790 + a70aae0 commit ef7f1eb
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/host/screenInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2323,7 +2323,10 @@ void SCREEN_INFORMATION::SetTerminalConnection(_In_ VtEngine* const pTtyConnecti
if (pTtyConnection)
{
engine.SetTerminalConnection(pTtyConnection,
std::bind(&StateMachine::FlushToTerminal, _stateMachine.get()));
[&stateMachine = *_stateMachine]() -> bool {
ServiceLocator::LocateGlobals().pRender->NotifyPaintFrame();
return stateMachine.FlushToTerminal();
});
}
else
{
Expand Down
12 changes: 9 additions & 3 deletions src/renderer/vt/XtermEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,16 @@ CATCH_RETURN();
// decided to pass through would have gotten buffered here until the next
// actual frame is triggered.
//
// To fix this, flush here, so this string is sent to the connected terminal
// application.
// Originally, we would _Flush() here, so this string (and anything buffered) is sent to the connected
// terminal application. As of GH#13710, we won't. We'll just buffer the string.
//
// Now, we've added a NotifyPaintFrame to the state machine's
// FlushToTerminal callback. That callback will allow us to add this wstr to
// the buffer now, without pushing the entire buffer out to the pipe right
// now. The NotifyPaintFrame in that callback will ensure that a Flush
// definitely _does_ happen (after this whole string is processed).

return _Flush();
return S_OK;
}

// Method Description:
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/vt/invalidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 18 additions & 2 deletions src/renderer/vt/paint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,22 @@ using namespace Microsoft::Console::Types;
RETURN_IF_FAILED(_MoveCursor(_deferredCursorPos));
}

RETURN_IF_FAILED(_Flush());
// If this frame was triggered because we encountered a VT sequence which
// required the buffered state to get printed, we don't want to flush this
// frame to the pipe. That might result in us rendering half the output of a
// particular frame (as emitted by the client).
//
// Instead, we'll leave this frame in _buffer, and just keep appending to
// it as needed.
if (_noFlushOnEnd)
[[unlikely]]
{
_noFlushOnEnd = false;
}
else
{
RETURN_IF_FAILED(_Flush());
}

return S_OK;
}
Expand Down Expand Up @@ -538,7 +553,8 @@ 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]]
if (_usingSoftFont)
[[unlikely]]
{
RETURN_IF_FAILED(VtEngine::_WriteTerminalDrcs({ _bufferLine.data(), cchActual }));
}
Expand Down
1 change: 1 addition & 0 deletions src/renderer/vt/vtrenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ namespace Microsoft::Console::Render

bool _resizeQuirk{ false };
bool _passthrough{ false };
bool _noFlushOnEnd{ false };
std::optional<TextColor> _newBottomLineBG{ std::nullopt };

[[nodiscard]] HRESULT _WriteFill(const size_t n, const char c) noexcept;
Expand Down
1 change: 1 addition & 0 deletions src/terminal/parser/OutputStateMachineEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,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);
}
Expand Down

0 comments on commit ef7f1eb

Please sign in to comment.