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