30 lines
857 B
C
30 lines
857 B
C
//
|
|
// Created by haraldwolff on 13.08.22.
|
|
//
|
|
|
|
#include <bs_tools.h>
|
|
#include <bs_progress.h>
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
|
|
int bs_progress_update(bs_engine_t *engine, bs_progress_steps_t step, long progress, long distance){
|
|
time_t now = time(NULL);
|
|
if (step != engine->progress.step){
|
|
engine->progress.step = step;
|
|
engine->progress.step_started = now;
|
|
}
|
|
|
|
if (engine->progress.last_screen_refresh != now) {
|
|
engine->progress.last_screen_refresh = now;
|
|
|
|
bs_time_t r;
|
|
bs_time_set(&r, progress ? (now - engine->progress.step_started) * (distance - progress) / progress : 0);
|
|
|
|
fprintf(stderr, "\rProgress: STEP: %x Progress=%ld Distance=%ld (%d%%) needs %02d:%02d:%02d", step, progress,
|
|
distance, distance ? (int) (100 * progress / distance) : 100, r.hours, r.minutes, r.seconds);
|
|
fflush(stderr);
|
|
}
|
|
return 0;
|
|
} |