clicker.c 555 B

1234567891011121314151617181920212223242526272829303132
  1. /*-
  2. * G_clicker()
  3. *
  4. * Print a clock hand (one of '|', '/', '-', '\') to stderr.
  5. * Used in place of G_percent for unknown number of iterations
  6. *
  7. */
  8. #include <stdio.h>
  9. #include <grass/gis.h>
  10. static struct state {
  11. int prev;
  12. } state;
  13. static struct state *st = &state;
  14. void G_clicker(void)
  15. {
  16. static const char clicks[] = "|/-\\";
  17. int format = G_info_format();
  18. if (format == G_INFO_FORMAT_SILENT || G_verbose() < 1)
  19. return;
  20. st->prev++;
  21. st->prev %= 4;
  22. fprintf(stderr, "%1c\b", clicks[st->prev]);
  23. fflush(stderr);
  24. }