Skip to content

Commit f1b6d82

Browse files
committed
show actual progress
1 parent 1232413 commit f1b6d82

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

progress_bar.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#include "progress_bar.hpp"
22

33
#include <iomanip>
4+
#include <cmath>
45

5-
const size_t kMessageSize = 25;
6+
const size_t kMessageSize = 20;
67
const double kTotalPercentage = 100.0;
78
const size_t kCharacterWidthPercentage = 4;
89

@@ -55,7 +56,8 @@ int ProgressBar::GetConsoleWidth() {
5556
int ProgressBar::GetBarLength() {
5657
// get console width and according adjust the length of the progress bar
5758
return (GetConsoleWidth() - description_.size()
58-
- kCharacterWidthPercentage) / 2.;
59+
- kCharacterWidthPercentage
60+
- std::log10(total_ * 2) * 2) / 2.;
5961
}
6062

6163
void ProgressBar::ClearBarField() {
@@ -80,7 +82,7 @@ void ProgressBar::Progressed(uint64_t idx_) {
8082
int bar_size = GetBarLength();
8183

8284
// calculate percentage of progress
83-
double progress_percent = idx_* kTotalPercentage / total_;
85+
double progress_percent = idx_ * kTotalPercentage / total_;
8486

8587
// calculate the percentage value of a unit bar
8688
double percent_per_unit_bar = kTotalPercentage / bar_size;
@@ -100,7 +102,8 @@ void ProgressBar::Progressed(uint64_t idx_) {
100102
*out << "]" << std::setw(kCharacterWidthPercentage + 1)
101103
<< std::setprecision(1)
102104
<< std::fixed
103-
<< progress_percent << "%\r" << std::flush;
105+
<< progress_percent << "%, "
106+
<< progress_ << "/" << total_ << "\r" << std::flush;
104107
} catch (uint64_t e) {
105108
ClearBarField();
106109
std::cerr << "PROGRESS_BAR_EXCEPTION: _idx ("

0 commit comments

Comments
 (0)