Remove code duplication: move _print_duration to details + small fixes

This commit is contained in:
hyperxor
2020-01-19 21:53:43 +03:00
parent 4f9796e904
commit 0dec563049
4 changed files with 59 additions and 99 deletions

View File

@@ -142,28 +142,6 @@ private:
template <typename Indicator, size_t count> friend class MultiProgress;
std::atomic<bool> _multi_progress_mode{false};
std::ostream &_print_duration(std::ostream &os, std::chrono::nanoseconds ns) {
using namespace std;
using namespace std::chrono;
typedef duration<int, ratio<86400>> days;
char fill = os.fill();
os.fill('0');
auto d = duration_cast<days>(ns);
ns -= d;
auto h = duration_cast<hours>(ns);
ns -= h;
auto m = duration_cast<minutes>(ns);
ns -= m;
auto s = duration_cast<seconds>(ns);
if (d.count() > 0)
os << setw(2) << d.count() << "d:";
if (h.count() > 0)
os << setw(2) << h.count() << "h:";
os << setw(2) << m.count() << "m:" << setw(2) << s.count() << 's';
os.fill(fill);
return os;
};
void _save_start_time() {
if ((_show_elapsed_time || _show_remaining_time) && !_saved_start_time) {
_start_time_point = std::chrono::high_resolution_clock::now();
@@ -208,7 +186,7 @@ private:
if (_show_elapsed_time) {
std::cout << " [";
_print_duration(std::cout, elapsed);
details::print_duration(std::cout, elapsed);
}
if (_show_remaining_time) {
@@ -219,7 +197,7 @@ private:
auto eta = std::chrono::nanoseconds(
_progress > 0 ? static_cast<long long>(elapsed.count() * 100 / _progress) : 0);
auto remaining = eta > elapsed ? (eta - elapsed) : (elapsed - eta);
_print_duration(std::cout, remaining);
details::print_duration(std::cout, remaining);
std::cout << "]";
} else {
if (_show_elapsed_time)