helpline.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "gtk.h"
  5. #include "../ui.h"
  6. #include "../helpline.h"
  7. #include "../../util/debug.h"
  8. static void gtk_helpline_pop(void)
  9. {
  10. if (!perf_gtk__is_active_context(pgctx))
  11. return;
  12. gtk_statusbar_pop(GTK_STATUSBAR(pgctx->statbar),
  13. pgctx->statbar_ctx_id);
  14. }
  15. static void gtk_helpline_push(const char *msg)
  16. {
  17. if (!perf_gtk__is_active_context(pgctx))
  18. return;
  19. gtk_statusbar_push(GTK_STATUSBAR(pgctx->statbar),
  20. pgctx->statbar_ctx_id, msg);
  21. }
  22. static int gtk_helpline_show(const char *fmt, va_list ap)
  23. {
  24. int ret;
  25. char *ptr;
  26. static int backlog;
  27. ret = vscnprintf(ui_helpline__current + backlog,
  28. sizeof(ui_helpline__current) - backlog, fmt, ap);
  29. backlog += ret;
  30. /* only first line can be displayed */
  31. ptr = strchr(ui_helpline__current, '\n');
  32. if (ptr && (ptr - ui_helpline__current) <= backlog) {
  33. *ptr = '\0';
  34. ui_helpline__puts(ui_helpline__current);
  35. backlog = 0;
  36. }
  37. return ret;
  38. }
  39. static struct ui_helpline gtk_helpline_fns = {
  40. .pop = gtk_helpline_pop,
  41. .push = gtk_helpline_push,
  42. .show = gtk_helpline_show,
  43. };
  44. void perf_gtk__init_helpline(void)
  45. {
  46. helpline_fns = &gtk_helpline_fns;
  47. }