helpline.c 954 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "../debug.h"
  5. #include "helpline.h"
  6. #include "ui.h"
  7. char ui_helpline__current[512];
  8. static void nop_helpline__pop(void)
  9. {
  10. }
  11. static void nop_helpline__push(const char *msg __maybe_unused)
  12. {
  13. }
  14. static struct ui_helpline default_helpline_fns = {
  15. .pop = nop_helpline__pop,
  16. .push = nop_helpline__push,
  17. };
  18. struct ui_helpline *helpline_fns = &default_helpline_fns;
  19. void ui_helpline__pop(void)
  20. {
  21. helpline_fns->pop();
  22. }
  23. void ui_helpline__push(const char *msg)
  24. {
  25. helpline_fns->push(msg);
  26. }
  27. void ui_helpline__vpush(const char *fmt, va_list ap)
  28. {
  29. char *s;
  30. if (vasprintf(&s, fmt, ap) < 0)
  31. vfprintf(stderr, fmt, ap);
  32. else {
  33. ui_helpline__push(s);
  34. free(s);
  35. }
  36. }
  37. void ui_helpline__fpush(const char *fmt, ...)
  38. {
  39. va_list ap;
  40. va_start(ap, fmt);
  41. ui_helpline__vpush(fmt, ap);
  42. va_end(ap);
  43. }
  44. void ui_helpline__puts(const char *msg)
  45. {
  46. ui_helpline__pop();
  47. ui_helpline__push(msg);
  48. }