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

Check enablement state for all output write operations #1581

Merged
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
19 changes: 15 additions & 4 deletions src/AppInstallerCLICore/ChannelStreams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ namespace AppInstaller::CLI::Execution
return *this;
}

void BaseStream::Close()
void BaseStream::RestoreDefault()
{
m_enabled = false;
if (m_VTUpdated)
{
Write(TextFormat::Default, true);
}
}

void BaseStream::Disable()
{
m_enabled = false;
}

OutputStream::OutputStream(BaseStream& out, bool enabled, bool VTEnabled) :
m_out(out),
m_enabled(enabled),
Expand Down Expand Up @@ -114,8 +118,15 @@ namespace AppInstaller::CLI::Execution

OutputStream& OutputStream::operator<<(const std::filesystem::path& path)
{
ApplyFormat();
m_out << path.u8string();
if (m_enabled)
{
if (m_VTEnabled)
{
ApplyFormat();
}
m_out << path.u8string();
}
return *this;

}
}
13 changes: 9 additions & 4 deletions src/AppInstallerCLICore/ChannelStreams.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ namespace AppInstaller::CLI::Execution
BaseStream& operator<<(const VirtualTerminal::Sequence& sequence);
BaseStream& operator<<(const VirtualTerminal::ConstructedSequence& sequence);

void Close();
void RestoreDefault();

void Disable();

private:
template <typename T>
Expand Down Expand Up @@ -100,11 +102,14 @@ namespace AppInstaller::CLI::Execution
// informs the output that there is no localized version to use.
// TODO: Convert the rest of the code base and uncomment to enforce localization.
//static_assert(details::IsApprovedForOutput<std::decay_t<T>>::value, "This type may not be localized, see comment for more information");
if (m_VTEnabled)
if (m_enabled)
{
ApplyFormat();
if (m_VTEnabled)
{
ApplyFormat();
}
m_out << t;
}
m_out << t;
return *this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerCLICore/ExecutionContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ namespace AppInstaller::CLI::Execution
// Unless we want to spin a separate thread for all work, we have to just exit here.
if (m_CtrlSignalCount >= 2)
{
Reporter.CloseOutputStream();
Reporter.CloseOutputStream(true);
Logging::Telemetry().LogCommandTermination(hr, file, line);
std::exit(hr);
}
Expand Down
8 changes: 6 additions & 2 deletions src/AppInstallerCLICore/ExecutionReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,12 @@ namespace AppInstaller::CLI::Execution
return m_isVTEnabled && ConsoleModeRestore::Instance().IsVTEnabled();
}

void Reporter::CloseOutputStream()
void Reporter::CloseOutputStream(bool forceDisable)
{
m_out->Close();
if (forceDisable)
{
m_out->Disable();
hackean-msft marked this conversation as resolved.
Show resolved Hide resolved
}
m_out->RestoreDefault();
}
}
2 changes: 1 addition & 1 deletion src/AppInstallerCLICore/ExecutionReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ namespace AppInstaller::CLI::Execution
// Cancels the in progress task.
void CancelInProgressTask(bool force);

void CloseOutputStream();
void CloseOutputStream(bool forceDisable = false);
hackean-msft marked this conversation as resolved.
Show resolved Hide resolved

void SetProgressSink(IProgressSink* sink)
{
Expand Down