From 02181623d1c379660f96e381d2e89f3d16574914 Mon Sep 17 00:00:00 2001 From: JohnMcPMS Date: Fri, 12 Nov 2021 14:42:05 -0800 Subject: [PATCH 1/2] Make VT enablement/disablement work properly --- src/AppInstallerCLICore/ChannelStreams.cpp | 5 +++++ src/AppInstallerCLICore/ChannelStreams.h | 2 ++ src/AppInstallerCLICore/ExecutionReporter.cpp | 4 ++-- src/AppInstallerCLICore/ExecutionReporter.h | 1 - 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/AppInstallerCLICore/ChannelStreams.cpp b/src/AppInstallerCLICore/ChannelStreams.cpp index 79a2ebed83..1fa1ec7d28 100644 --- a/src/AppInstallerCLICore/ChannelStreams.cpp +++ b/src/AppInstallerCLICore/ChannelStreams.cpp @@ -41,6 +41,11 @@ namespace AppInstaller::CLI::Execution return *this; } + void BaseStream::SetVTEnabled(bool enabled) + { + m_VTEnabled = enabled; + } + void BaseStream::RestoreDefault() { if (m_VTUpdated) diff --git a/src/AppInstallerCLICore/ChannelStreams.h b/src/AppInstallerCLICore/ChannelStreams.h index 2a0f323cc6..41c5949369 100644 --- a/src/AppInstallerCLICore/ChannelStreams.h +++ b/src/AppInstallerCLICore/ChannelStreams.h @@ -57,6 +57,8 @@ namespace AppInstaller::CLI::Execution BaseStream& operator<<(const VirtualTerminal::Sequence& sequence); BaseStream& operator<<(const VirtualTerminal::ConstructedSequence& sequence); + void SetVTEnabled(bool enabled); + void RestoreDefault(); void Disable(); diff --git a/src/AppInstallerCLICore/ExecutionReporter.cpp b/src/AppInstallerCLICore/ExecutionReporter.cpp index 411323ca88..313d41a036 100644 --- a/src/AppInstallerCLICore/ExecutionReporter.cpp +++ b/src/AppInstallerCLICore/ExecutionReporter.cpp @@ -102,7 +102,7 @@ namespace AppInstaller::CLI::Execution } if (style == VisualStyle::NoVT) { - m_isVTEnabled = false; + m_out->SetVTEnabled(false); } } @@ -215,7 +215,7 @@ namespace AppInstaller::CLI::Execution bool Reporter::IsVTEnabled() const { - return m_isVTEnabled && ConsoleModeRestore::Instance().IsVTEnabled(); + return ConsoleModeRestore::Instance().IsVTEnabled(); } void Reporter::CloseOutputStream(bool forceDisable) diff --git a/src/AppInstallerCLICore/ExecutionReporter.h b/src/AppInstallerCLICore/ExecutionReporter.h index 812ba1a876..fbb1ad7356 100644 --- a/src/AppInstallerCLICore/ExecutionReporter.h +++ b/src/AppInstallerCLICore/ExecutionReporter.h @@ -149,7 +149,6 @@ namespace AppInstaller::CLI::Execution Channel m_channel = Channel::Output; std::shared_ptr m_out; std::istream& m_in; - bool m_isVTEnabled = true; std::optional m_style; std::optional m_spinner; std::optional m_progressBar; From be0a045a8b6b9caab62f33419cbbd1129fb41a0a Mon Sep 17 00:00:00 2001 From: JohnMcPMS Date: Fri, 12 Nov 2021 15:24:48 -0800 Subject: [PATCH 2/2] Little more polish --- src/AppInstallerCLICore/ChannelStreams.h | 2 +- src/AppInstallerCLICore/ExecutionReporter.cpp | 13 ++++--------- src/AppInstallerCLICore/ExecutionReporter.h | 2 -- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/AppInstallerCLICore/ChannelStreams.h b/src/AppInstallerCLICore/ChannelStreams.h index 41c5949369..0a2cbe8d1c 100644 --- a/src/AppInstallerCLICore/ChannelStreams.h +++ b/src/AppInstallerCLICore/ChannelStreams.h @@ -82,7 +82,7 @@ namespace AppInstaller::CLI::Execution // Holds output formatting information. struct OutputStream { - OutputStream(BaseStream& out, bool enabled, bool VTEnabled); + OutputStream(BaseStream& out, bool enabled, bool VTEnabled = true); // Adds a format to the current value. void AddFormat(const VirtualTerminal::Sequence& sequence); diff --git a/src/AppInstallerCLICore/ExecutionReporter.cpp b/src/AppInstallerCLICore/ExecutionReporter.cpp index 313d41a036..66adad14ad 100644 --- a/src/AppInstallerCLICore/ExecutionReporter.cpp +++ b/src/AppInstallerCLICore/ExecutionReporter.cpp @@ -19,7 +19,7 @@ namespace AppInstaller::CLI::Execution const Sequence& PromptEmphasis = TextFormat::Foreground::Bright; Reporter::Reporter(std::ostream& outStream, std::istream& inStream) : - Reporter(std::make_shared(outStream, true, IsVTEnabled()), inStream) + Reporter(std::make_shared(outStream, true, ConsoleModeRestore::Instance().IsVTEnabled()), inStream) { SetProgressSink(this); } @@ -27,8 +27,8 @@ namespace AppInstaller::CLI::Execution Reporter::Reporter(std::shared_ptr outStream, std::istream& inStream) : m_out(outStream), m_in(inStream), - m_progressBar(std::in_place, *m_out, IsVTEnabled()), - m_spinner(std::in_place, *m_out, IsVTEnabled()) + m_progressBar(std::in_place, *m_out, ConsoleModeRestore::Instance().IsVTEnabled()), + m_spinner(std::in_place, *m_out, ConsoleModeRestore::Instance().IsVTEnabled()) { SetProgressSink(this); } @@ -74,7 +74,7 @@ namespace AppInstaller::CLI::Execution OutputStream Reporter::GetBasicOutputStream() { - return {*m_out, m_channel == Channel::Output, IsVTEnabled() }; + return {*m_out, m_channel == Channel::Output }; } void Reporter::SetChannel(Channel channel) @@ -213,11 +213,6 @@ namespace AppInstaller::CLI::Execution } } - bool Reporter::IsVTEnabled() const - { - return ConsoleModeRestore::Instance().IsVTEnabled(); - } - void Reporter::CloseOutputStream(bool forceDisable) { if (forceDisable) diff --git a/src/AppInstallerCLICore/ExecutionReporter.h b/src/AppInstallerCLICore/ExecutionReporter.h index fbb1ad7356..258d496208 100644 --- a/src/AppInstallerCLICore/ExecutionReporter.h +++ b/src/AppInstallerCLICore/ExecutionReporter.h @@ -140,8 +140,6 @@ namespace AppInstaller::CLI::Execution private: Reporter(std::shared_ptr outStream, std::istream& inStream); - // Gets whether VT is enabled for this reporter. - bool IsVTEnabled() const; // Gets a stream for output for internal use. OutputStream GetBasicOutputStream();