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

View File

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