progress.c 704 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "../cache.h"
  2. #include "progress.h"
  3. static void null_progress__update(struct ui_progress *p __maybe_unused)
  4. {
  5. }
  6. static struct ui_progress_ops null_progress__ops =
  7. {
  8. .update = null_progress__update,
  9. };
  10. struct ui_progress_ops *ui_progress__ops = &null_progress__ops;
  11. void ui_progress__update(struct ui_progress *p, u64 adv)
  12. {
  13. p->curr += adv;
  14. if (p->curr >= p->next) {
  15. p->next += p->step;
  16. ui_progress__ops->update(p);
  17. }
  18. }
  19. void ui_progress__init(struct ui_progress *p, u64 total, const char *title)
  20. {
  21. p->curr = 0;
  22. p->next = p->step = total / 16;
  23. p->total = total;
  24. p->title = title;
  25. }
  26. void ui_progress__finish(void)
  27. {
  28. if (ui_progress__ops->finish)
  29. ui_progress__ops->finish();
  30. }