MCPcopy Create free account
hub / github.com/KTH-RPL/dufomap / BlockProgressScaleWriter

Class BlockProgressScaleWriter

src/indicators.hpp:1801–1826  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1799}
1800
1801class BlockProgressScaleWriter {
1802public:
1803 BlockProgressScaleWriter(std::ostream &os, size_t bar_width) : os(os), bar_width(bar_width) {}
1804
1805 std::ostream &write(float progress) {
1806 std::string fill_text{"█"};
1807 std::vector<std::string> lead_characters{" ", "▏", "▎", "▍", "▌", "▋", "▊", "▉"};
1808 auto value = (std::min)(1.0f, (std::max)(0.0f, progress / 100.0f));
1809 auto whole_width = std::floor(value * bar_width);
1810 auto remainder_width = fmod((value * bar_width), 1.0f);
1811 auto part_width = std::floor(remainder_width * lead_characters.size());
1812 std::string lead_text = lead_characters[size_t(part_width)];
1813 if ((bar_width - whole_width - 1) < 0)
1814 lead_text = "";
1815 for (size_t i = 0; i < whole_width; ++i)
1816 os << fill_text;
1817 os << lead_text;
1818 for (size_t i = 0; i < (bar_width - whole_width - 1); ++i)
1819 os << " ";
1820 return os;
1821 }
1822
1823private:
1824 std::ostream &os;
1825 size_t bar_width = 0;
1826};
1827
1828class ProgressScaleWriter {
1829public:

Callers

nothing calls this directly

Calls 1

sizeMethod · 0.80

Tested by

no test coverage detected