From fbd50af8afb2d0bcdd7b4a252515c6d7fe729e84 Mon Sep 17 00:00:00 2001 From: Michael Niksa Date: Tue, 21 Sep 2021 08:47:17 -0700 Subject: [PATCH] Change exit code to hex; Fix format spec (#11123) Process exit code now shows as hex not decimal. Format specification needs length "10" not "8" because the leading '0x' generated by the # symbol counts as part of the length. ## PR Checklist * [x] Closes annoyance at looking up process exit codes * [x] I work here. * [x] Checked manually ## Validation Steps Performed - [x] Ran it, opened tab, opened another CMD tab, ran `exit ` and observed hex pattern --- src/cascadia/TerminalConnection/ConptyConnection.cpp | 8 ++++++-- .../TerminalConnection/Resources/en-US/Resources.resw | 8 ++++---- .../TerminalConnection/TerminalConnection.vcxproj | 8 +++++--- .../TerminalConnection/TerminalConnection.vcxproj.filters | 1 + 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/cascadia/TerminalConnection/ConptyConnection.cpp b/src/cascadia/TerminalConnection/ConptyConnection.cpp index 5c2373fd2..b6ad2ce7f 100644 --- a/src/cascadia/TerminalConnection/ConptyConnection.cpp +++ b/src/cascadia/TerminalConnection/ConptyConnection.cpp @@ -16,6 +16,10 @@ #include "LibraryResources.h" using namespace ::Microsoft::Console; +using namespace std::string_view_literals; + +// Format is: "DecimalResult (HexadecimalForm)" +static constexpr auto _errorFormat = L"{0} ({0:#010x})"sv; // Notes: // There is a number of ways that the Conpty connection can be terminated (voluntarily or not): @@ -417,7 +421,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation const auto hr = wil::ResultFromCaughtException(); winrt::hstring failureText{ fmt::format(std::wstring_view{ RS_(L"ProcessFailedToLaunch") }, - gsl::narrow_cast(hr), + fmt::format(_errorFormat, hr), _commandline) }; _TerminalOutputHandlers(failureText); @@ -444,7 +448,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation { try { - winrt::hstring exitText{ fmt::format(std::wstring_view{ RS_(L"ProcessExited") }, status) }; + winrt::hstring exitText{ fmt::format(std::wstring_view{ RS_(L"ProcessExited") }, fmt::format(_errorFormat, status)) }; _TerminalOutputHandlers(L"\r\n"); _TerminalOutputHandlers(exitText); } diff --git a/src/cascadia/TerminalConnection/Resources/en-US/Resources.resw b/src/cascadia/TerminalConnection/Resources/en-US/Resources.resw index d32f59269..7af3cf590 100644 --- a/src/cascadia/TerminalConnection/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalConnection/Resources/en-US/Resources.resw @@ -205,15 +205,15 @@ [process exited with code {0}] - The first argument {0} is the (positive) error code of the process. When there is no error, the number ZERO will be displayed. + The first argument {0} is the error code of the process. When there is no error, the number ZERO will be displayed. - [error {0:#08x} when launching `{1}'] - The first argument {0...} is the hexadecimal error code. The second argument {1} is the user-specified path to a program. + [error {0} when launching `{1}'] + The first argument {0} is the error code. The second argument {1} is the user-specified path to a program. If this string is broken to multiple lines, it will not be displayed properly. Could not access starting directory "{0}" The first argument {0} is a path to a directory on the filesystem, as provided by the user. - \ No newline at end of file + diff --git a/src/cascadia/TerminalConnection/TerminalConnection.vcxproj b/src/cascadia/TerminalConnection/TerminalConnection.vcxproj index 5cfd57c40..f594bc46f 100644 --- a/src/cascadia/TerminalConnection/TerminalConnection.vcxproj +++ b/src/cascadia/TerminalConnection/TerminalConnection.vcxproj @@ -56,7 +56,9 @@ - + + Designer + @@ -88,11 +90,11 @@ - $(IntDir)..\OpenConsoleProxy;%(AdditionalIncludeDirectories) + $(IntDir)..\OpenConsoleProxy;%(AdditionalIncludeDirectories) $(OpenConsoleCommonOutDir)\conptylib.lib;%(AdditionalDependencies) - + \ No newline at end of file diff --git a/src/cascadia/TerminalConnection/TerminalConnection.vcxproj.filters b/src/cascadia/TerminalConnection/TerminalConnection.vcxproj.filters index 12a9cc6c4..a7d2f9092 100644 --- a/src/cascadia/TerminalConnection/TerminalConnection.vcxproj.filters +++ b/src/cascadia/TerminalConnection/TerminalConnection.vcxproj.filters @@ -32,6 +32,7 @@ +