print.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "u.h"
  10. #include "lib.h"
  11. #include "mem.h"
  12. #include "dat.h"
  13. #include "fns.h"
  14. static int spinning;
  15. static char* wheel[4] = { "\b|", "\b/", "\b-", "\b\\", };
  16. static int spoke;
  17. void
  18. startwheel(void)
  19. {
  20. spoke = 1;
  21. consputs("|", 1);
  22. spinning = 1;
  23. }
  24. void
  25. turnwheel(int dir)
  26. {
  27. if(!spinning)
  28. return;
  29. spoke += dir;
  30. consputs(wheel[spoke & 3], 2);
  31. }
  32. void
  33. stopwheel(void)
  34. {
  35. consputs("\b", 1);
  36. spinning = 0;
  37. }
  38. int
  39. print(char* fmt, ...)
  40. {
  41. va_list arg;
  42. char buf[PRINTSIZE], *e, *p;
  43. p = buf;
  44. if(spinning)
  45. *p++ = '\b';
  46. va_start(arg, fmt);
  47. e = vseprint(p, buf+sizeof(buf), fmt, arg);
  48. va_end(arg);
  49. if(spinning && e < &buf[PRINTSIZE-2]){
  50. *e++ = ' ';
  51. *e = 0;
  52. }
  53. consputs(buf, e-buf);
  54. return e-buf;
  55. }
  56. static Lock fmtl;
  57. void
  58. _fmtlock(void)
  59. {
  60. lock(&fmtl);
  61. }
  62. void
  63. _fmtunlock(void)
  64. {
  65. unlock(&fmtl);
  66. }
  67. int
  68. _efgfmt(Fmt*)
  69. {
  70. return -1;
  71. }