Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make VT enablement/disablement work properly #1699

Merged
merged 2 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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