Skip to content

Commit 7c81444

Browse files
committed
HACKS: exit code propagation
1 parent 66229d5 commit 7c81444

File tree

11 files changed

+58
-22
lines changed

11 files changed

+58
-22
lines changed

src/cascadia/TerminalApp/App.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ namespace winrt::TerminalApp::implementation
939939
tabViewItem.PointerPressed({ this, &App::_OnTabClick });
940940

941941
// When the tab is closed, remove it from our list of tabs.
942-
newTab->Closed([tabViewItem, this]() {
942+
newTab->Closed([tabViewItem, this](auto&& arg) {
943943
_tabView.Dispatcher().RunAsync(CoreDispatcherPriority::Normal, [tabViewItem, this]() {
944944
_RemoveTabViewItem(tabViewItem);
945945
});

src/cascadia/TerminalApp/Pane.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ bool Pane::NavigateFocus(const Direction& direction)
286286
// - <none>
287287
// Return Value:
288288
// - <none>
289-
void Pane::_ControlClosedHandler()
289+
void Pane::_ControlClosedHandler(int32_t exitCode)
290290
{
291291
std::unique_lock lock{ _createCloseLock };
292292
// It's possible that this event handler started being executed, then before
@@ -301,10 +301,20 @@ void Pane::_ControlClosedHandler()
301301
return;
302302
}
303303

304-
if (_control.ShouldCloseOnExit())
304+
//if (_control.ShouldCloseOnExit())
305+
//{
306+
// Fire our Closed event to tell our parent that we should be removed.
307+
//_closedHandlers();
308+
//}
309+
if (exitCode == 0)
310+
{
311+
_closedHandlers(0);
312+
}
313+
else
305314
{
306-
// Fire our Closed event to tell our parent that we should be removed.
307-
_closedHandlers();
315+
wchar_t buffer[1024];
316+
StringCchPrintfW(buffer, 1024, L"\n[process exited with code %8.08x]", exitCode);
317+
_control.WriteOutput(buffer);
308318
}
309319
}
310320

@@ -317,7 +327,7 @@ void Pane::_ControlClosedHandler()
317327
void Pane::Close()
318328
{
319329
// Fire our Closed event to tell our parent that we should be removed.
320-
_closedHandlers();
330+
_closedHandlers(0);
321331
}
322332

323333
// Method Description:
@@ -654,13 +664,13 @@ void Pane::_CloseChild(const bool closeFirst)
654664
// - <none>
655665
void Pane::_SetupChildCloseHandlers()
656666
{
657-
_firstClosedToken = _firstChild->Closed([this]() {
667+
_firstClosedToken = _firstChild->Closed([this](auto&& arg) {
658668
_root.Dispatcher().RunAsync(CoreDispatcherPriority::Normal, [=]() {
659669
_CloseChild(true);
660670
});
661671
});
662672

663-
_secondClosedToken = _secondChild->Closed([this]() {
673+
_secondClosedToken = _secondChild->Closed([this](auto&& arg) {
664674
_root.Dispatcher().RunAsync(CoreDispatcherPriority::Normal, [=]() {
665675
_CloseChild(false);
666676
});

src/cascadia/TerminalApp/Pane.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class Pane : public std::enable_shared_from_this<Pane>
9090
void _CloseChild(const bool closeFirst);
9191

9292
void _FocusFirstChild();
93-
void _ControlClosedHandler();
93+
void _ControlClosedHandler(int32_t exitCode);
9494

9595
std::pair<float, float> _GetPaneSizes(const float& fullSize);
9696

src/cascadia/TerminalApp/Tab.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Tab::Tab(const GUID& profile, const TermControl& control)
1515
{
1616
_rootPane = std::make_shared<Pane>(profile, control, true);
1717

18-
_rootPane->Closed([=]() {
19-
_closedHandlers();
18+
_rootPane->Closed([=](auto&& arg) {
19+
_closedHandlers(arg);
2020
});
2121

2222
_MakeTabViewItem();

src/cascadia/TerminalConnection/ConhostConnection.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,10 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
205205
return 0;
206206
}
207207

208-
_disconnectHandlers();
208+
WaitForSingleObject(_piConhost.hProcess, INFINITE);
209+
DWORD dwExitCode{ 0 };
210+
GetExitCodeProcess(_piConhost.hProcess, &dwExitCode);
211+
_disconnectHandlers(dwExitCode);
209212
return (DWORD)-1;
210213
}
211214

src/cascadia/TerminalConnection/ITerminalConnection.idl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace Microsoft.Terminal.TerminalConnection
55
{
66
delegate void TerminalOutputEventArgs(String output);
7-
delegate void TerminalDisconnectedEventArgs();
7+
delegate void TerminalDisconnectedEventArgs(Int32 exitCode);
88

99
interface ITerminalConnection
1010
{

src/cascadia/TerminalControl/TermControl.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
122122
// DON'T CALL _InitializeTerminal here - wait until the swap chain is loaded to do that.
123123

124124
// Subscribe to the connection's disconnected event and call our connection closed handlers.
125-
_connection.TerminalDisconnected([=]() {
126-
_connectionClosedHandlers();
125+
_connection.TerminalDisconnected([=](auto&& arg) {
126+
_connectionClosedHandlers(arg);
127127
});
128128
}
129129

@@ -1223,6 +1223,11 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
12231223
_clipboardPasteHandlers(*this, *pasteArgs);
12241224
}
12251225

1226+
void TermControl::WriteOutput(hstring output)
1227+
{
1228+
_terminal->Write(output.c_str());
1229+
}
1230+
12261231
void TermControl::Close()
12271232
{
12281233
if (!_closing.exchange(true))

src/cascadia/TerminalControl/TermControl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
5252
int GetScrollOffset();
5353
int GetViewHeight() const;
5454

55+
void WriteOutput(hstring output);
56+
5557
void SwapChainChanged();
5658
~TermControl();
5759

src/cascadia/TerminalControl/TermControl.idl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace Microsoft.Terminal.TerminalControl
55
{
66
delegate void TitleChangedEventArgs(String newTitle);
7-
delegate void ConnectionClosedEventArgs();
7+
delegate void ConnectionClosedEventArgs(Int32 exitCode);
88
delegate void ScrollPositionChangedEventArgs(Int32 viewTop, Int32 viewHeight, Int32 bufferLength);
99
delegate void CopyToClipboardEventArgs(String copiedData);
1010

@@ -13,9 +13,7 @@ namespace Microsoft.Terminal.TerminalControl
1313
void HandleClipboardData(String data);
1414
}
1515

16-
[default_interface]
17-
runtimeclass TermControl
18-
{
16+
[default_interface] runtimeclass TermControl {
1917
TermControl();
2018
TermControl(Microsoft.Terminal.Settings.IControlSettings settings, Microsoft.Terminal.TerminalConnection.ITerminalConnection connection);
2119

@@ -43,5 +41,7 @@ namespace Microsoft.Terminal.TerminalControl
4341
Int32 GetScrollOffset();
4442
Int32 GetViewHeight();
4543
event ScrollPositionChangedEventArgs ScrollPositionChanged;
44+
45+
void WriteOutput(String output);
4646
}
4747
}

src/cascadia/TerminalCore/Terminal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void Terminal::Write(std::wstring_view stringView)
202202
// - true if we translated the key event, and it should not be processed any further.
203203
// - false if we did not translate the key, and it should be processed into a character.
204204
bool Terminal::SendKeyEvent(const WORD vkey, const ControlKeyStates states)
205-
{
205+
206206
if (_snapOnInput && _scrollOffset != 0)
207207
{
208208
auto lock = LockForWriting();

0 commit comments

Comments
 (0)