blob: 5db4432ff12a0d3c538da300ae66a98c9622dfd8 [file] [log] [blame]
Namhyung Kim0985a942012-08-16 17:14:54 +09001#include <stdio.h>
2#include <string.h>
3
Namhyung Kim4bb16462012-08-16 17:14:52 +09004#include "gtk.h"
Namhyung Kim0985a942012-08-16 17:14:54 +09005#include "../ui.h"
Namhyung Kim4bb16462012-08-16 17:14:52 +09006#include "../helpline.h"
Namhyung Kim0985a942012-08-16 17:14:54 +09007#include "../../util/debug.h"
Namhyung Kim4bb16462012-08-16 17:14:52 +09008
9static void gtk_helpline_pop(void)
10{
11 if (!perf_gtk__is_active_context(pgctx))
12 return;
13
14 gtk_statusbar_pop(GTK_STATUSBAR(pgctx->statbar),
15 pgctx->statbar_ctx_id);
16}
17
18static void gtk_helpline_push(const char *msg)
19{
20 if (!perf_gtk__is_active_context(pgctx))
21 return;
22
23 gtk_statusbar_push(GTK_STATUSBAR(pgctx->statbar),
24 pgctx->statbar_ctx_id, msg);
25}
26
27static struct ui_helpline gtk_helpline_fns = {
28 .pop = gtk_helpline_pop,
29 .push = gtk_helpline_push,
30};
31
32void perf_gtk__init_helpline(void)
33{
34 helpline_fns = &gtk_helpline_fns;
35}
Namhyung Kim0985a942012-08-16 17:14:54 +090036
37int perf_gtk__show_helpline(const char *fmt, va_list ap)
38{
39 int ret;
40 char *ptr;
41 static int backlog;
42
43 ret = vscnprintf(ui_helpline__current + backlog,
44 sizeof(ui_helpline__current) - backlog, fmt, ap);
45 backlog += ret;
46
47 /* only first line can be displayed */
48 ptr = strchr(ui_helpline__current, '\n');
49 if (ptr && (ptr - ui_helpline__current) <= backlog) {
50 *ptr = '\0';
51 ui_helpline__puts(ui_helpline__current);
52 backlog = 0;
53 }
54
55 return ret;
56}