Preserve progress when continuing console output

This commit is contained in:
Daniel Wolf 2019-01-02 14:26:38 +01:00
parent d0c9a294e9
commit e325917abe
2 changed files with 5 additions and 2 deletions

View File

@ -16,6 +16,7 @@ using boost::optional;
NiceStderrSink::NiceStderrSink(Level minLevel) :
minLevel(minLevel),
progress(0.0),
innerSink(make_shared<StdErrSink>(make_shared<SimpleConsoleFormatter>()))
{}
@ -26,7 +27,8 @@ void NiceStderrSink::receive(const logging::Entry& entry) {
startProgressIndication();
} else if (const ProgressEntry* progressEntry = dynamic_cast<const ProgressEntry*>(&entry)) {
assert(progressBar);
progressBar->reportProgress(progressEntry->getProgress());
progress = progressEntry->getProgress();
progressBar->reportProgress(progress);
} else if (dynamic_cast<const SuccessEntry*>(&entry)) {
interruptProgressIndication();
std::cerr << "Done." << std::endl;
@ -54,7 +56,7 @@ void NiceStderrSink::interruptProgressIndication() {
void NiceStderrSink::resumeProgressIndication() {
std::cerr << "Progress (cont'd): ";
progressBar = boost::in_place();
progressBar = boost::in_place(progress);
progressBar->setClearOnDestruction(false);
}

View File

@ -17,6 +17,7 @@ private:
void resumeProgressIndication();
logging::Level minLevel;
double progress;
boost::optional<ProgressBar> progressBar;
std::shared_ptr<Sink> innerSink;
};