helpline.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. char ui_helpline__last_msg[1024];
  10. static void tui_helpline__pop(void)
  11. {
  12. }
  13. static void tui_helpline__push(const char *msg)
  14. {
  15. const size_t sz = sizeof(ui_helpline__current);
  16. SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
  17. SLsmg_set_color(0);
  18. SLsmg_write_nstring((char *)msg, SLtt_Screen_Cols);
  19. SLsmg_refresh();
  20. strncpy(ui_helpline__current, msg, sz)[sz - 1] = '\0';
  21. }
  22. static int tui_helpline__show(const char *format, va_list ap)
  23. {
  24. int ret;
  25. static int backlog;
  26. pthread_mutex_lock(&ui__lock);
  27. ret = vscnprintf(ui_helpline__last_msg + backlog,
  28. sizeof(ui_helpline__last_msg) - backlog, format, ap);
  29. backlog += ret;
  30. if (ui_helpline__last_msg[backlog - 1] == '\n') {
  31. ui_helpline__puts(ui_helpline__last_msg);
  32. SLsmg_refresh();
  33. backlog = 0;
  34. }
  35. pthread_mutex_unlock(&ui__lock);
  36. return ret;
  37. }
  38. struct ui_helpline tui_helpline_fns = {
  39. .pop = tui_helpline__pop,
  40. .push = tui_helpline__push,
  41. .show = tui_helpline__show,
  42. };
  43. void ui_helpline__init(void)
  44. {
  45. helpline_fns = &tui_helpline_fns;
  46. ui_helpline__puts(" ");
  47. }