helpline.c 1.2 KB

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