helpline.c 1.1 KB

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