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..0a2cbe8d1c 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(); @@ -80,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 411323ca88..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) @@ -102,7 +102,7 @@ namespace AppInstaller::CLI::Execution } if (style == VisualStyle::NoVT) { - m_isVTEnabled = false; + m_out->SetVTEnabled(false); } } @@ -213,11 +213,6 @@ namespace AppInstaller::CLI::Execution } } - bool Reporter::IsVTEnabled() const - { - return m_isVTEnabled && ConsoleModeRestore::Instance().IsVTEnabled(); - } - void Reporter::CloseOutputStream(bool forceDisable) { if (forceDisable) diff --git a/src/AppInstallerCLICore/ExecutionReporter.h b/src/AppInstallerCLICore/ExecutionReporter.h index 812ba1a876..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(); @@ -149,7 +147,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;