Skip to content

Commit

Permalink
Make VT enablement/disablement work properly (microsoft#1699)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMcPMS authored Nov 15, 2021
1 parent 9b66b2d commit 88f6265
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
5 changes: 5 additions & 0 deletions src/AppInstallerCLICore/ChannelStreams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ namespace AppInstaller::CLI::Execution
return *this;
}

void BaseStream::SetVTEnabled(bool enabled)
{
m_VTEnabled = enabled;
}

void BaseStream::RestoreDefault()
{
if (m_VTUpdated)
Expand Down
4 changes: 3 additions & 1 deletion src/AppInstallerCLICore/ChannelStreams.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
15 changes: 5 additions & 10 deletions src/AppInstallerCLICore/ExecutionReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ 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);
}

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);
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -102,7 +102,7 @@ namespace AppInstaller::CLI::Execution
}
if (style == VisualStyle::NoVT)
{
m_isVTEnabled = false;
m_out->SetVTEnabled(false);
}
}

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions src/AppInstallerCLICore/ExecutionReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,13 @@ 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();

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;
Expand Down

0 comments on commit 88f6265

Please sign in to comment.