winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 88f6265a355676961e5f6ce936c4d26af61c3829
parent 9b66b2d1854f09223a0b032191f9ef3c1183b770
Author: JohnMcPMS <johnmcp@microsoft.com>
Date:   Mon, 15 Nov 2021 13:09:45 -0800

Make VT enablement/disablement work properly (#1699)


Diffstat:
Msrc/AppInstallerCLICore/ChannelStreams.cpp | 5+++++
Msrc/AppInstallerCLICore/ChannelStreams.h | 4+++-
Msrc/AppInstallerCLICore/ExecutionReporter.cpp | 15+++++----------
Msrc/AppInstallerCLICore/ExecutionReporter.h | 3---
4 files changed, 13 insertions(+), 14 deletions(-)

diff --git 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 @@ -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 @@ -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<BaseStream>(outStream, true, IsVTEnabled()), inStream) + Reporter(std::make_shared<BaseStream>(outStream, true, ConsoleModeRestore::Instance().IsVTEnabled()), inStream) { SetProgressSink(this); } @@ -27,8 +27,8 @@ namespace AppInstaller::CLI::Execution Reporter::Reporter(std::shared_ptr<BaseStream> 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 @@ -140,8 +140,6 @@ namespace AppInstaller::CLI::Execution private: Reporter(std::shared_ptr<BaseStream> 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<BaseStream> m_out; std::istream& m_in; - bool m_isVTEnabled = true; std::optional<AppInstaller::Settings::VisualStyle> m_style; std::optional<IndefiniteSpinner> m_spinner; std::optional<ProgressBar> m_progressBar;