Skip to content

Commit

Permalink
Make sure DCS strings are flushed to conpty when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
j4james committed May 5, 2024
1 parent 3996806 commit 1b546e0
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 13 deletions.
10 changes: 7 additions & 3 deletions src/renderer/vt/XtermEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,10 @@ CATCH_RETURN();
// proper utf-8 string, depending on our mode.
// Arguments:
// - wstr - wstring of text to be written
// - flush - set to true if the the string should be flushed immediately
// Return Value:
// - S_OK or suitable HRESULT error from either conversion or writing pipe.
[[nodiscard]] HRESULT XtermEngine::WriteTerminalW(const std::wstring_view wstr) noexcept
[[nodiscard]] HRESULT XtermEngine::WriteTerminalW(const std::wstring_view wstr, const bool flush) noexcept
{
RETURN_IF_FAILED(_fUseAsciiOnly ?
VtEngine::_WriteTerminalAscii(wstr) :
Expand All @@ -535,8 +536,11 @@ CATCH_RETURN();
// cause flickering (where we've buffered some state but not the whole
// "frame" as specified by the app). We'll just immediately buffer this
// sequence, and flush it when the render thread comes around to paint the
// frame normally.

// frame normally, unless a flush has been explicitly requested.
if (flush)
{
_flushImpl();
}
return S_OK;
}

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/vt/XtermEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace Microsoft::Console::Render

[[nodiscard]] HRESULT InvalidateScroll(const til::point* const pcoordDelta) noexcept override;

[[nodiscard]] HRESULT WriteTerminalW(const std::wstring_view str) noexcept override;
[[nodiscard]] HRESULT WriteTerminalW(const std::wstring_view str, const bool flush) noexcept override;

[[nodiscard]] HRESULT SetWindowVisibility(const bool showOrHide) noexcept override;

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/vt/vtrenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace Microsoft::Console::Render
[[nodiscard]] HRESULT RequestCursor() noexcept;
[[nodiscard]] HRESULT InheritCursor(const til::point coordCursor) noexcept;
[[nodiscard]] HRESULT WriteTerminalUtf8(const std::string_view str) noexcept;
[[nodiscard]] virtual HRESULT WriteTerminalW(const std::wstring_view str) noexcept = 0;
[[nodiscard]] virtual HRESULT WriteTerminalW(const std::wstring_view str, const bool flush = false) noexcept = 0;
void SetTerminalOwner(Microsoft::Console::VirtualTerminal::VtIo* const terminalOwner);
void SetResizeQuirk(const bool resizeQuirk);
void SetLookingForDSRCallback(std::function<void(bool)> pfnLooking) noexcept;
Expand Down
2 changes: 1 addition & 1 deletion src/terminal/adapter/adaptDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4882,7 +4882,7 @@ ITermDispatch::StringHandler AdaptDispatch::_CreatePassthroughHandler()
{
buffer += L'\\';
}
engine.ActionPassThroughString(buffer);
engine.ActionPassThroughString(buffer, true);
buffer.clear();
}
return !endOfString;
Expand Down
2 changes: 1 addition & 1 deletion src/terminal/parser/IStateMachineEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Microsoft::Console::VirtualTerminal
virtual bool ActionPrint(const wchar_t wch) = 0;
virtual bool ActionPrintString(const std::wstring_view string) = 0;

virtual bool ActionPassThroughString(const std::wstring_view string) = 0;
virtual bool ActionPassThroughString(const std::wstring_view string, const bool flush = false) = 0;

virtual bool ActionEscDispatch(const VTID id) = 0;
virtual bool ActionVt52EscDispatch(const VTID id, const VTParameters parameters) = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/terminal/parser/InputStateMachineEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,10 @@ bool InputStateMachineEngine::ActionPrintString(const std::wstring_view string)
// string of characters given.
// Arguments:
// - string - string to dispatch.
// - flush - not applicable to the input state machine.
// Return Value:
// - true iff we successfully dispatched the sequence.
bool InputStateMachineEngine::ActionPassThroughString(const std::wstring_view string)
bool InputStateMachineEngine::ActionPassThroughString(const std::wstring_view string, const bool /*flush*/)
{
if (_pDispatch->IsVtInputEnabled())
{
Expand Down
2 changes: 1 addition & 1 deletion src/terminal/parser/InputStateMachineEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ namespace Microsoft::Console::VirtualTerminal

bool ActionPrintString(const std::wstring_view string) override;

bool ActionPassThroughString(const std::wstring_view string) override;
bool ActionPassThroughString(const std::wstring_view string, const bool flush) override;

bool ActionEscDispatch(const VTID id) override;

Expand Down
5 changes: 3 additions & 2 deletions src/terminal/parser/OutputStateMachineEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,15 @@ bool OutputStateMachineEngine::ActionPrintString(const std::wstring_view string)
// we don't know what to do with it)
// Arguments:
// - string - string to dispatch.
// - flush - set to true if the the string should be flushed immediately.
// Return Value:
// - true iff we successfully dispatched the sequence.
bool OutputStateMachineEngine::ActionPassThroughString(const std::wstring_view string)
bool OutputStateMachineEngine::ActionPassThroughString(const std::wstring_view string, const bool flush)
{
auto success = true;
if (_pTtyConnection != nullptr)
{
const auto hr = _pTtyConnection->WriteTerminalW(string);
const auto hr = _pTtyConnection->WriteTerminalW(string, flush);
LOG_IF_FAILED(hr);
success = SUCCEEDED(hr);
}
Expand Down
2 changes: 1 addition & 1 deletion src/terminal/parser/OutputStateMachineEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace Microsoft::Console::VirtualTerminal

bool ActionPrintString(const std::wstring_view string) override;

bool ActionPassThroughString(const std::wstring_view string) override;
bool ActionPassThroughString(const std::wstring_view string, const bool flush) override;

bool ActionEscDispatch(const VTID id) override;

Expand Down
2 changes: 1 addition & 1 deletion src/terminal/parser/ut_parser/StateMachineTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Microsoft::Console::VirtualTerminal::TestStateMachineEngine : public IStat
return true;
};

bool ActionPassThroughString(const std::wstring_view string) override
bool ActionPassThroughString(const std::wstring_view string, const bool /*flush*/) override
{
passedThrough += string;
return true;
Expand Down

1 comment on commit 1b546e0

@github-actions
Copy link

Choose a reason for hiding this comment

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

@check-spelling-bot Report

🔴 Please review

See the 📜action log or 📝 job summary for details.

❌ Errors Count
❌ forbidden-pattern 2
❌ ignored-expect-variant 3

See ❌ Event descriptions for more information.

Previously acknowledged words that are now absent CRLFs Redir wcsicmp 🫥
Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary

This includes both expected items (2207) from .github/actions/spelling/expect/04cdb9b77d6827c0202f51acd4205b017015bfff.txt
.github/actions/spelling/expect/alphabet.txt
.github/actions/spelling/expect/expect.txt
.github/actions/spelling/expect/web.txt and unrecognized words (0)

Dictionary Entries Covers Uniquely
cspell:cpp/src/lang-jargon.txt 11 1 1
cspell:swift/src/swift.txt 53 1 1
cspell:gaming-terms/dict/gaming-terms.txt 59 1 1
cspell:monkeyc/src/monkeyc_keywords.txt 123 1 1
cspell:cryptocurrencies/cryptocurrencies.txt 125 1 1

Consider adding them (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

      with:
        extra_dictionaries:
          cspell:cpp/src/lang-jargon.txt
          cspell:swift/src/swift.txt
          cspell:gaming-terms/dict/gaming-terms.txt
          cspell:monkeyc/src/monkeyc_keywords.txt
          cspell:cryptocurrencies/cryptocurrencies.txt

To stop checking additional dictionaries, add (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

check_extra_dictionaries: ''

Please sign in to comment.