helpline.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 struct ui_helpline gtk_helpline_fns = {
  22. .pop = gtk_helpline_pop,
  23. .push = gtk_helpline_push,
  24. };
  25. void perf_gtk__init_helpline(void)
  26. {
  27. helpline_fns = &gtk_helpline_fns;
  28. }
  29. int perf_gtk__show_helpline(const char *fmt, va_list ap)
  30. {
  31. int ret;
  32. char *ptr;
  33. static int backlog;
  34. ret = vscnprintf(ui_helpline__current + backlog,
  35. sizeof(ui_helpline__current) - backlog, fmt, ap);
  36. backlog += ret;
  37. /* only first line can be displayed */
  38. ptr = strchr(ui_helpline__current, '\n');
  39. if (ptr && (ptr - ui_helpline__current) <= backlog) {
  40. *ptr = '\0';
  41. ui_helpline__puts(ui_helpline__current);
  42. backlog = 0;
  43. }
  44. return ret;
  45. }