diff --git a/src/AppInstallerCLICore/ExecutionProgress.cpp b/src/AppInstallerCLICore/ExecutionProgress.cpp index 411597cd0a..27defe8b8c 100644 --- a/src/AppInstallerCLICore/ExecutionProgress.cpp +++ b/src/AppInstallerCLICore/ExecutionProgress.cpp @@ -76,13 +76,11 @@ namespace AppInstaller::CLI::Execution out << ' ' << bfd.Name; } - void SetColor(BaseStream& out, const TextFormat::Color& color, bool enabled) + void SetColor(BaseStream& out, const TextFormat::Color& color, bool foregroundOnly) { - if (enabled) - { - out << TextFormat::Foreground::Extended(color); - } - else + out << TextFormat::Foreground::Extended(color); + + if (!foregroundOnly) { constexpr uint8_t divisor = 3; @@ -91,11 +89,11 @@ namespace AppInstaller::CLI::Execution reduced.G /= divisor; reduced.B /= divisor; - out << TextFormat::Foreground::Extended(reduced); + out << TextFormat::Background::Extended(reduced); } } - void SetRainbowColor(BaseStream& out, size_t i, size_t max, bool enabled) + void SetRainbowColor(BaseStream& out, size_t i, size_t max, bool foregroundOnly) { TextFormat::Color rainbow[] = { @@ -125,13 +123,13 @@ namespace AppInstaller::CLI::Execution result = { AICLI_AVERAGE(R), AICLI_AVERAGE(G), AICLI_AVERAGE(B) }; } - SetColor(out, result, enabled); + SetColor(out, result, foregroundOnly); } } namespace details { - void ProgressVisualizerBase::ApplyStyle(size_t i, size_t max, bool enabled) + void ProgressVisualizerBase::ApplyStyle(size_t i, size_t max, bool foregroundOnly) { if (!UseVT()) { @@ -141,20 +139,13 @@ namespace AppInstaller::CLI::Execution switch (m_style) { case VisualStyle::Retro: - if (enabled) - { - m_out << TextFormat::Default; - } - else - { - m_out << TextFormat::Negative; - } + m_out << TextFormat::Default; break; case VisualStyle::Accent: - SetColor(m_out, TextFormat::Color::GetAccentColor(), enabled); + SetColor(m_out, TextFormat::Color::GetAccentColor(), foregroundOnly); break; case VisualStyle::Rainbow: - SetRainbowColor(m_out, i, max, enabled); + SetRainbowColor(m_out, i, max, foregroundOnly); break; default: LOG_HR(E_UNEXPECTED); @@ -334,21 +325,49 @@ namespace AppInstaller::CLI::Execution void ProgressBar::ShowProgressWithVT(uint64_t current, uint64_t maximum, ProgressType type) { + m_out << TextFormat::Default; + m_out << "\r "; if (maximum) { - const char* const blockOn = u8"\x2588"; + const char* const blocks[] = + { + u8" ", // block off + u8"\x258F", // block 1/8 + u8"\x258E", // block 2/8 + u8"\x258D", // block 3/8 + u8"\x258C", // block 4/8 + u8"\x258B", // block 5/8 + u8"\x258A", // block 6/8 + u8"\x2589", // block 7/8 + u8"\x2588" // block on + }; + const char* const blockOn = blocks[8]; + const char* const blockOff = blocks[0]; constexpr size_t blockWidth = 30; double percentage = static_cast(current) / maximum; size_t blocksOn = static_cast(std::floor(percentage * blockWidth)); + size_t partialBlockIndex = static_cast((percentage * blockWidth - blocksOn) * 8); TextFormat::Color accent = TextFormat::Color::GetAccentColor(); for (size_t i = 0; i < blockWidth; ++i) { - ApplyStyle(i, blockWidth, i < blocksOn); - m_out << blockOn; + ApplyStyle(i, blockWidth, false); + + if (i < blocksOn) + { + m_out << blockOn; + } + else if (i == blocksOn) + { + m_out << blocks[partialBlockIndex]; + } + else + { + m_out << blockOff; + } } m_out << TextFormat::Default; diff --git a/src/AppInstallerCLICore/ExecutionProgress.h b/src/AppInstallerCLICore/ExecutionProgress.h index a3c46dd7f4..ba959c358c 100644 --- a/src/AppInstallerCLICore/ExecutionProgress.h +++ b/src/AppInstallerCLICore/ExecutionProgress.h @@ -34,7 +34,7 @@ namespace AppInstaller::CLI::Execution bool UseVT() const { return m_enableVT && m_style != AppInstaller::Settings::VisualStyle::NoVT; } // Applies the selected visual style. - void ApplyStyle(size_t i, size_t max, bool enabled); + void ApplyStyle(size_t i, size_t max, bool foregroundOnly); private: bool m_enableVT = false; diff --git a/src/AppInstallerCLICore/VTSupport.cpp b/src/AppInstallerCLICore/VTSupport.cpp index 90939478d2..821b62ecc8 100644 --- a/src/AppInstallerCLICore/VTSupport.cpp +++ b/src/AppInstallerCLICore/VTSupport.cpp @@ -150,7 +150,12 @@ namespace AppInstaller::CLI::VirtualTerminal namespace Background { - + ConstructedSequence Extended(const Color& color) + { + std::ostringstream result; + result << AICLI_VT_CSI "48;2;" << static_cast(color.R) << ';' << static_cast(color.G) << ';' << static_cast(color.B) << 'm'; + return ConstructedSequence{ result.str() }; + } } ConstructedSequence Hyperlink(const std::string& text, const std::string& ref) diff --git a/src/AppInstallerCLICore/VTSupport.h b/src/AppInstallerCLICore/VTSupport.h index 2c024dbcb7..54934e574f 100644 --- a/src/AppInstallerCLICore/VTSupport.h +++ b/src/AppInstallerCLICore/VTSupport.h @@ -128,7 +128,7 @@ namespace AppInstaller::CLI::VirtualTerminal namespace Background { - + ConstructedSequence Extended(const Color& color); } ConstructedSequence Hyperlink(const std::string& text, const std::string& ref);