Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent flickering in nushell due to FTCS marks #14677

Merged
merged 10 commits into from
May 11, 2023
5 changes: 4 additions & 1 deletion src/host/screenInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2349,7 +2349,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.
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
//
// 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).
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved

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.
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
_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]]
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
{
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 @@ -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);
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
success = SUCCEEDED(hr);
}
Expand Down