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

Class IndeterminateProgressScaleWriter

src/indicators.hpp:1872–1913  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1870};
1871
1872class IndeterminateProgressScaleWriter {
1873public:
1874 IndeterminateProgressScaleWriter(std::ostream &os, size_t bar_width, const std::string &fill,
1875 const std::string &lead)
1876 : os(os), bar_width(bar_width), fill(fill), lead(lead) {}
1877
1878 std::ostream &write(size_t progress) {
1879 for (size_t i = 0; i < bar_width;) {
1880 std::string next;
1881 size_t current_display_width = 0;
1882
1883 if (i < progress) {
1884 next = fill;
1885 current_display_width = unicode::display_width(fill);
1886 } else if (i == progress) {
1887 next = lead;
1888 current_display_width = unicode::display_width(lead);
1889 } else {
1890 next = fill;
1891 current_display_width = unicode::display_width(fill);
1892 }
1893
1894 i += current_display_width;
1895
1896 if (i > bar_width) {
1897 // `next` is larger than the allowed bar width
1898 // fill with empty space instead
1899 os << std::string((bar_width - (i - current_display_width)), ' ');
1900 break;
1901 }
1902
1903 os << next;
1904 }
1905 return os;
1906 }
1907
1908private:
1909 std::ostream &os;
1910 size_t bar_width = 0;
1911 std::string fill;
1912 std::string lead;
1913};
1914
1915} // namespace details
1916} // namespace indicators

Callers

nothing calls this directly

Calls 1

display_widthFunction · 0.85

Tested by

no test coverage detected