helpline.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <pthread.h>
  6. #include "../../util/debug.h"
  7. #include "../helpline.h"
  8. #include "../ui.h"
  9. #include "../libslang.h"
  10. char ui_helpline__last_msg[1024];
  11. bool tui_helpline__set;
  12. static void tui_helpline__pop(void)
  13. {
  14. }
  15. static void tui_helpline__push(const char *msg)
  16. {
  17. const size_t sz = sizeof(ui_helpline__current);
  18. SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
  19. SLsmg_set_color(0);
  20. SLsmg_write_nstring((char *)msg, SLtt_Screen_Cols);
  21. SLsmg_refresh();
  22. strlcpy(ui_helpline__current, msg, sz);
  23. }
  24. static int tui_helpline__show(const char *format, va_list ap)
  25. {
  26. int ret;
  27. static int backlog;
  28. pthread_mutex_lock(&ui__lock);
  29. ret = vscnprintf(ui_helpline__last_msg + backlog,
  30. sizeof(ui_helpline__last_msg) - backlog, format, ap);
  31. backlog += ret;
  32. tui_helpline__set = true;
  33. if (ui_helpline__last_msg[backlog - 1] == '\n') {
  34. ui_helpline__puts(ui_helpline__last_msg);
  35. SLsmg_refresh();
  36. backlog = 0;
  37. }
  38. pthread_mutex_unlock(&ui__lock);
  39. return ret;
  40. }
  41. struct ui_helpline tui_helpline_fns = {
  42. .pop = tui_helpline__pop,
  43. .push = tui_helpline__push,
  44. .show = tui_helpline__show,
  45. };
  46. void ui_helpline__init(void)
  47. {
  48. helpline_fns = &tui_helpline_fns;
  49. ui_helpline__puts(" ");
  50. }