Namhyung Kim | 688f2f5 | 2012-11-13 22:30:32 +0900 | [diff] [blame] | 1 | #include "../cache.h" |
| 2 | #include "progress.h" |
| 3 | |
Arnaldo Carvalho de Melo | 4d3001f | 2013-10-23 15:40:38 -0300 | [diff] [blame] | 4 | static void null_progress__update(struct ui_progress *p __maybe_unused) |
Namhyung Kim | 688f2f5 | 2012-11-13 22:30:32 +0900 | [diff] [blame] | 5 | { |
| 6 | } |
| 7 | |
Arnaldo Carvalho de Melo | 4779a2e | 2013-10-23 14:08:48 -0300 | [diff] [blame] | 8 | static struct ui_progress_ops null_progress__ops = |
Namhyung Kim | 688f2f5 | 2012-11-13 22:30:32 +0900 | [diff] [blame] | 9 | { |
Arnaldo Carvalho de Melo | 4779a2e | 2013-10-23 14:08:48 -0300 | [diff] [blame] | 10 | .update = null_progress__update, |
Namhyung Kim | 688f2f5 | 2012-11-13 22:30:32 +0900 | [diff] [blame] | 11 | }; |
| 12 | |
Arnaldo Carvalho de Melo | 4779a2e | 2013-10-23 14:08:48 -0300 | [diff] [blame] | 13 | struct ui_progress_ops *ui_progress__ops = &null_progress__ops; |
Namhyung Kim | 688f2f5 | 2012-11-13 22:30:32 +0900 | [diff] [blame] | 14 | |
Arnaldo Carvalho de Melo | 4d3001f | 2013-10-23 15:40:38 -0300 | [diff] [blame] | 15 | void ui_progress__update(struct ui_progress *p, u64 adv) |
Namhyung Kim | 688f2f5 | 2012-11-13 22:30:32 +0900 | [diff] [blame] | 16 | { |
Arnaldo Carvalho de Melo | 4d3001f | 2013-10-23 15:40:38 -0300 | [diff] [blame] | 17 | p->curr += adv; |
| 18 | |
| 19 | if (p->curr >= p->next) { |
| 20 | p->next += p->step; |
| 21 | ui_progress__ops->update(p); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | void 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 Kim | 688f2f5 | 2012-11-13 22:30:32 +0900 | [diff] [blame] | 32 | } |
Namhyung Kim | a5580f3 | 2012-11-13 22:30:34 +0900 | [diff] [blame] | 33 | |
| 34 | void ui_progress__finish(void) |
| 35 | { |
Arnaldo Carvalho de Melo | 4779a2e | 2013-10-23 14:08:48 -0300 | [diff] [blame] | 36 | if (ui_progress__ops->finish) |
| 37 | ui_progress__ops->finish(); |
Namhyung Kim | a5580f3 | 2012-11-13 22:30:34 +0900 | [diff] [blame] | 38 | } |