blob: a0f24c7115c59f891fa894739ef4da157a9e33cf [file] [log] [blame]
Namhyung Kim688f2f52012-11-13 22:30:32 +09001#include "../cache.h"
2#include "progress.h"
3
Arnaldo Carvalho de Melo4d3001f2013-10-23 15:40:38 -03004static void null_progress__update(struct ui_progress *p __maybe_unused)
Namhyung Kim688f2f52012-11-13 22:30:32 +09005{
6}
7
Arnaldo Carvalho de Melo4779a2e2013-10-23 14:08:48 -03008static struct ui_progress_ops null_progress__ops =
Namhyung Kim688f2f52012-11-13 22:30:32 +09009{
Arnaldo Carvalho de Melo4779a2e2013-10-23 14:08:48 -030010 .update = null_progress__update,
Namhyung Kim688f2f52012-11-13 22:30:32 +090011};
12
Arnaldo Carvalho de Melo4779a2e2013-10-23 14:08:48 -030013struct ui_progress_ops *ui_progress__ops = &null_progress__ops;
Namhyung Kim688f2f52012-11-13 22:30:32 +090014
Arnaldo Carvalho de Melo4d3001f2013-10-23 15:40:38 -030015void ui_progress__update(struct ui_progress *p, u64 adv)
Namhyung Kim688f2f52012-11-13 22:30:32 +090016{
Arnaldo Carvalho de Melo4d3001f2013-10-23 15:40:38 -030017 p->curr += adv;
18
19 if (p->curr >= p->next) {
20 p->next += p->step;
21 ui_progress__ops->update(p);
22 }
23}
24
25void ui_progress__init(struct ui_progress *p, u64 total, const char *title)
26{
27 p->curr = 0;
28 p->next = p->step = total / 16;
29 p->total = total;
30 p->title = title;
31
Namhyung Kim688f2f52012-11-13 22:30:32 +090032}
Namhyung Kima5580f32012-11-13 22:30:34 +090033
34void ui_progress__finish(void)
35{
Arnaldo Carvalho de Melo4779a2e2013-10-23 14:08:48 -030036 if (ui_progress__ops->finish)
37 ui_progress__ops->finish();
Namhyung Kima5580f32012-11-13 22:30:34 +090038}