Merge tag 'block-5.9-2020-08-14' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / tools / perf / ui / tui / helpline.c
blob298d6af82fddd5d47fa27cf7217caab44368f4d5
1 // SPDX-License-Identifier: GPL-2.0
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <pthread.h>
6 #include <linux/kernel.h>
7 #include <linux/string.h>
9 #include "../helpline.h"
10 #include "../ui.h"
11 #include "../libslang.h"
13 char ui_helpline__last_msg[1024];
14 bool tui_helpline__set;
16 static void tui_helpline__pop(void)
20 static void tui_helpline__push(const char *msg)
22 const size_t sz = sizeof(ui_helpline__current);
24 SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
25 SLsmg_set_color(0);
26 SLsmg_write_nstring((char *)msg, SLtt_Screen_Cols);
27 SLsmg_refresh();
28 strlcpy(ui_helpline__current, msg, sz);
31 static int tui_helpline__show(const char *format, va_list ap)
33 int ret;
34 static int backlog;
36 pthread_mutex_lock(&ui__lock);
37 ret = vscnprintf(ui_helpline__last_msg + backlog,
38 sizeof(ui_helpline__last_msg) - backlog, format, ap);
39 backlog += ret;
41 tui_helpline__set = true;
43 if (ui_helpline__last_msg[backlog - 1] == '\n') {
44 ui_helpline__puts(ui_helpline__last_msg);
45 SLsmg_refresh();
46 backlog = 0;
48 pthread_mutex_unlock(&ui__lock);
50 return ret;
53 struct ui_helpline tui_helpline_fns = {
54 .pop = tui_helpline__pop,
55 .push = tui_helpline__push,
56 .show = tui_helpline__show,
59 void ui_helpline__init(void)
61 helpline_fns = &tui_helpline_fns;
62 ui_helpline__puts(" ");