| 1826 | }; |
| 1827 | |
| 1828 | class ProgressScaleWriter { |
| 1829 | public: |
| 1830 | ProgressScaleWriter(std::ostream &os, size_t bar_width, const std::string &fill, |
| 1831 | const std::string &lead, const std::string &remainder) |
| 1832 | : os(os), bar_width(bar_width), fill(fill), lead(lead), remainder(remainder) {} |
| 1833 | |
| 1834 | std::ostream &write(float progress) { |
| 1835 | auto pos = static_cast<size_t>(progress * bar_width / 100.0); |
| 1836 | for (size_t i = 0, current_display_width = 0; i < bar_width;) { |
| 1837 | std::string next; |
| 1838 | |
| 1839 | if (i < pos) { |
| 1840 | next = fill; |
| 1841 | current_display_width = unicode::display_width(fill); |
| 1842 | } else if (i == pos) { |
| 1843 | next = lead; |
| 1844 | current_display_width = unicode::display_width(lead); |
| 1845 | } else { |
| 1846 | next = remainder; |
| 1847 | current_display_width = unicode::display_width(remainder); |
| 1848 | } |
| 1849 | |
| 1850 | i += current_display_width; |
| 1851 | |
| 1852 | if (i > bar_width) { |
| 1853 | // `next` is larger than the allowed bar width |
| 1854 | // fill with empty space instead |
| 1855 | os << std::string((bar_width - (i - current_display_width)), ' '); |
| 1856 | break; |
| 1857 | } |
| 1858 | |
| 1859 | os << next; |
| 1860 | } |
| 1861 | return os; |
| 1862 | } |
| 1863 | |
| 1864 | private: |
| 1865 | std::ostream &os; |
| 1866 | size_t bar_width = 0; |
| 1867 | std::string fill; |
| 1868 | std::string lead; |
| 1869 | std::string remainder; |
| 1870 | }; |
| 1871 | |
| 1872 | class IndeterminateProgressScaleWriter { |
| 1873 | public: |
nothing calls this directly
no test coverage detected