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

Immediately flush a frame when we encounter a string we don't understand #2665

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix build, Add comments
  • Loading branch information
zadjii-msft committed Sep 4, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 9ca8b98863d2975cdffbf53422e6a6a12903da37
17 changes: 17 additions & 0 deletions src/cascadia/TerminalCore/TerminalDispatch.cpp
Original file line number Diff line number Diff line change
@@ -30,6 +30,23 @@ void TerminalDispatch::PrintString(const wchar_t* const rgwch, const size_t cch)
_terminalApi.PrintString({ rgwch, cch });
}

// Method Description:
// - Called when the ITermDispatch or output parser was unable to handle a
// particular VT sequence. This string should be forwarded along to the
// terminal, if there is one, so the terminal has a chance to process the
// string.
// - This function is only ever implemented in the console codebase. The
// Terminal doesn't need to pass anything along to anyone.
// Arguments:
// - <unused>
// Return Value:
// - true always.
bool TerminalDispatch::PassThroughString(const wchar_t* const /*rgwch*/, const size_t /*cch*/)
{
// Do nothing.
return true;
}

bool TerminalDispatch::CursorPosition(const unsigned int uiLine,
const unsigned int uiColumn)
{
1 change: 1 addition & 0 deletions src/cascadia/TerminalCore/TerminalDispatch.hpp
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ class TerminalDispatch : public Microsoft::Console::VirtualTerminal::TermDispatc
virtual void Execute(const wchar_t wchControl) override;
virtual void Print(const wchar_t wchPrintable) override;
virtual void PrintString(const wchar_t* const rgwch, const size_t cch) override;
bool PassThroughString(const wchar_t* const rgwch, const size_t cch) override;

bool SetGraphicsRendition(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::GraphicsOptions* const rgOptions,
const size_t cOptions) override;
16 changes: 12 additions & 4 deletions src/host/VtIo.cpp
Original file line number Diff line number Diff line change
@@ -345,16 +345,24 @@ bool VtIo::IsUsingVt() const
return hr;
}

// Method Description:
// - Used to write a string straight to the terminal, via the attached VT renderer.
// - When used for passing-through VT sequences we didn't understand, the caller
// should make sure to call Renderer::PaintFrame before calling this, to
// ensure the buffered state of the current frame is flushed before we write
// this sequence. If you don't do that, this string will appear out-of-order
// from the buffered state (see microsoft/terminal#2011)
// Arguments:
// - rgwch: The start of the string of characters to write to the terminal
// - cch: The number of characters to write
// Return Value:
// - <none>
void VtIo::PassThroughString(const wchar_t* const rgwch, const size_t cch)
{
if (_pVtRenderEngine)
{
std::wstring wstr{ rgwch, cch };
// This
LOG_IF_FAILED(_pVtRenderEngine->WriteTerminalW(wstr));
// TODO: if this happens and then for the following frame, we decide
// _nothing_ should happen, then we'll wait until an actual frame
// triggers to write this string out. we probably don't want that.
}
}

15 changes: 15 additions & 0 deletions src/host/getset.cpp
Original file line number Diff line number Diff line change
@@ -2181,6 +2181,21 @@ void DoSrvPrivateMoveToBottom(SCREEN_INFORMATION& screenInfo)
CATCH_RETURN();
}

// Method Description:
// - Attempts to pass the given string through to the connected terminal.
// - If we're in conpty mode, the string will be written to the terminal,
// _AFTER_ first calling PaintFrame to render our current state. We do this
// because the string we're about to pass through to the terminal might be
// dependent upon state that's currently buffered in this frame. This way, we
// can flush the buffered state to the terminal, before writing the string to
// the terminal.
// - If we're not in conpty mode, we'll eat the string, doing nothing with it.
// - See microsoft/terminal#2011 for more context.
// Arguments:
// - rgwch: The start of the string of characters to write to the terminal
// - cch: The number of characters to write
// Return Value:
// - <none>
void DoSrvPrivatePassThroughString(const wchar_t* const rgwch, const size_t cch) noexcept
{
Globals& g = ServiceLocator::LocateGlobals();
8 changes: 8 additions & 0 deletions src/host/outputStream.cpp
Original file line number Diff line number Diff line change
@@ -787,6 +787,14 @@ BOOL ConhostInternalGetSet::PrivateSetDefaultBackground(const COLORREF value) co
return SUCCEEDED(DoSrvPrivateSetDefaultBackgroundColor(value));
}

// Method Description:
// - Connects the PrivatePassThroughString call directly into our Driver Message servicing
// call inside Conhost.exe. See DoSrvPrivatePassThroughString for details.
// Arguments:
// - rgwch: The start of the string of characters to write to the terminal
// - cch: The number of characters to write
// Return Value:
// - TRUE always.
BOOL ConhostInternalGetSet::PrivatePassThroughString(const wchar_t* const rgwch, const size_t cch) const noexcept
{
// return SUCCEEDED(DoSrvPrivatePassThroughString(rgwch, cch));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a comment

10 changes: 10 additions & 0 deletions src/terminal/adapter/adaptDispatch.cpp
Original file line number Diff line number Diff line change
@@ -79,6 +79,16 @@ void AdaptDispatch::PrintString(const wchar_t* const rgwch, const size_t cch)
CATCH_LOG();
}

// Method Description:
// - Called when the ITermDispatch or output parser was unable to handle a
// particular VT sequence. This string should be forwarded along to the
// terminal, if there is one, so the terminal has a chance to process the
// string.
// Arguments:
// - rgwch: The start of the string of characters to write to the terminal
// - cch: The number of characters to write
// Return Value:
// - true if the console was able to handle (or eat) the provided string
bool AdaptDispatch::PassThroughString(const wchar_t* const rgwch, const size_t cch)
{
return !!_conApi->PrivatePassThroughString(rgwch, cch);
6 changes: 6 additions & 0 deletions src/terminal/adapter/ut_adapter/adapterTest.cpp
Original file line number Diff line number Diff line change
@@ -809,6 +809,12 @@ class TestGetSet final : public ConGetSet
return _fPrivateSetDefaultBackgroundResult;
}

BOOL PrivatePassThroughString(const wchar_t* const /*rgwch*/, const size_t /*cch*/) const noexcept override
{
Log::Comment(L"PrivatePassThroughString MOCK called...");
return TRUE;
}

void _IncrementCoordPos(_Inout_ COORD* pcoord)
{
pcoord->X++;
6 changes: 6 additions & 0 deletions src/terminal/parser/ft_fuzzwrapper/echoDispatch.cpp
Original file line number Diff line number Diff line change
@@ -21,3 +21,9 @@ void EchoDispatch::Execute(const wchar_t wchControl)
{
wprintf(L"Execute: 0x%x\r\n", wchControl);
}

bool EchoDispatch::PassThroughString(const wchar_t* const rgwch, const size_t cch)
{
wprintf(L"PassThroughString: \"%s\" (%zd chars)\r\n", rgwch, cch);
return true;
}
1 change: 1 addition & 0 deletions src/terminal/parser/ft_fuzzwrapper/echoDispatch.hpp
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ namespace Microsoft
void Print(const wchar_t wchPrintable) override;
void PrintString(const wchar_t* const rgwch, const size_t cch) override;
void Execute(const wchar_t wchControl) override;
bool PassThroughString(const wchar_t* const rgwch, const size_t cch) override;
};
}
}
10 changes: 10 additions & 0 deletions src/terminal/parser/ut_parser/OutputEngineTest.cpp
Original file line number Diff line number Diff line change
@@ -47,6 +47,11 @@ class DummyDispatch final : public TermDispatch
virtual void PrintString(const wchar_t* const /*rgwch*/, const size_t /*cch*/) override
{
}

bool PassThroughString(const wchar_t* const /*rgwch*/, const size_t /*cch*/) override
{
return false;
}
};

class Microsoft::Console::VirtualTerminal::OutputEngineTest final
@@ -612,6 +617,11 @@ class StatefulDispatch final : public TermDispatch
{
}

virtual bool PassThroughString(const wchar_t* const /*rgwch*/, const size_t /*cch*/) override
{
return false;
}

StatefulDispatch() :
_uiCursorDistance{ 0 },
_uiLine{ 0 },