helpline.c 1.1 KB

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