Merge tag 'dt' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
[platform/adaptation/renesas_rcar/renesas_kernel.git] / tools / perf / ui / tui / helpline.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <pthread.h>
5
6 #include "../../util/debug.h"
7 #include "../helpline.h"
8 #include "../ui.h"
9 #include "../libslang.h"
10
11 static void tui_helpline__pop(void)
12 {
13 }
14
15 static void tui_helpline__push(const char *msg)
16 {
17         const size_t sz = sizeof(ui_helpline__current);
18
19         SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
20         SLsmg_set_color(0);
21         SLsmg_write_nstring((char *)msg, SLtt_Screen_Cols);
22         SLsmg_refresh();
23         strncpy(ui_helpline__current, msg, sz)[sz - 1] = '\0';
24 }
25
26 struct ui_helpline tui_helpline_fns = {
27         .pop    = tui_helpline__pop,
28         .push   = tui_helpline__push,
29 };
30
31 void ui_helpline__init(void)
32 {
33         helpline_fns = &tui_helpline_fns;
34         ui_helpline__puts(" ");
35 }
36
37 char ui_helpline__last_msg[1024];
38
39 int ui_helpline__show_help(const char *format, va_list ap)
40 {
41         int ret;
42         static int backlog;
43
44         pthread_mutex_lock(&ui__lock);
45         ret = vscnprintf(ui_helpline__last_msg + backlog,
46                         sizeof(ui_helpline__last_msg) - backlog, format, ap);
47         backlog += ret;
48
49         if (ui_helpline__last_msg[backlog - 1] == '\n') {
50                 ui_helpline__puts(ui_helpline__last_msg);
51                 SLsmg_refresh();
52                 backlog = 0;
53         }
54         pthread_mutex_unlock(&ui__lock);
55
56         return ret;
57 }