From 58e1c7354f3bf50e0158a7eca057a1cbf60d3974 Mon Sep 17 00:00:00 2001 From: JamesTiah <91830137+WhatsACloud@users.noreply.github.com> Date: Fri, 17 Jan 2025 18:29:38 +0800 Subject: [PATCH 1/2] Fix "Ctrl+Break can leave the WSL shell in an unusable state" --- src/cascadia/TerminalControl/ControlCore.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index b46da5236af..0eb75aced37 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -483,6 +483,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation { // Ask the hosting application to give us a new connection. RestartTerminalRequested.raise(*this, nullptr); + SendInput(L"reset\n"); return true; } } From e5cd4eda0cc5464ddfc2055797e496f20b3c53fe Mon Sep 17 00:00:00 2001 From: JamesTiah <91830137+WhatsACloud@users.noreply.github.com> Date: Mon, 20 Jan 2025 16:21:14 +0800 Subject: [PATCH 2/2] used internal API for fix instead Uses internal API instead of directly inputting "reset" into terminal, thus fixing bug across all or at least most terminal types. --- src/cascadia/TerminalControl/ControlCore.cpp | 2 +- src/cascadia/TerminalCore/Terminal.cpp | 8 ++++++++ src/cascadia/TerminalCore/Terminal.hpp | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index 0eb75aced37..7826e7d7906 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -483,7 +483,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation { // Ask the hosting application to give us a new connection. RestartTerminalRequested.raise(*this, nullptr); - SendInput(L"reset\n"); + _terminal->HardReset(); return true; } } diff --git a/src/cascadia/TerminalCore/Terminal.cpp b/src/cascadia/TerminalCore/Terminal.cpp index c77ab1ab764..0eaac979fab 100644 --- a/src/cascadia/TerminalCore/Terminal.cpp +++ b/src/cascadia/TerminalCore/Terminal.cpp @@ -71,6 +71,14 @@ void Terminal::CreateFromSettings(ICoreSettings settings, UpdateSettings(settings); } +void Terminal::HardReset() +{ + + IStateMachineEngine& baseEngine = _stateMachine->Engine(); + const auto lock = LockForReading(); + baseEngine.ActionEscDispatch(VTID("c")); +} + // Method Description: // - Update our internal properties to match the new values in the provided // CoreSettings object. diff --git a/src/cascadia/TerminalCore/Terminal.hpp b/src/cascadia/TerminalCore/Terminal.hpp index 8ac499c97e2..1b9a7b4c33b 100644 --- a/src/cascadia/TerminalCore/Terminal.hpp +++ b/src/cascadia/TerminalCore/Terminal.hpp @@ -5,6 +5,7 @@ #include +#include "../../terminal/adapter/adaptDispatch.hpp" #include "../../inc/DefaultSettings.h" #include "../../buffer/out/textBuffer.hpp" #include "../../renderer/inc/IRenderData.hpp" @@ -177,6 +178,8 @@ class Microsoft::Terminal::Core::Terminal final : void UserScrollViewport(const int viewTop) override; int GetScrollOffset() noexcept override; + void HardReset(); + void TrySnapOnInput() override; bool IsTrackingMouseInput() const noexcept; bool ShouldSendAlternateScroll(const unsigned int uiButton, const int32_t delta) const noexcept;