Linux Perf
helpline.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <pthread.h>
6 
7 #include "../../util/debug.h"
8 #include "../helpline.h"
9 #include "../ui.h"
10 #include "../libslang.h"
11 
14 
15 static void tui_helpline__pop(void)
16 {
17 }
18 
19 static void tui_helpline__push(const char *msg)
20 {
21  const size_t sz = sizeof(ui_helpline__current);
22 
23  SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
24  SLsmg_set_color(0);
25  SLsmg_write_nstring((char *)msg, SLtt_Screen_Cols);
26  SLsmg_refresh();
27  strncpy(ui_helpline__current, msg, sz)[sz - 1] = '\0';
28 }
29 
30 static int tui_helpline__show(const char *format, va_list ap)
31 {
32  int ret;
33  static int backlog;
34 
35  pthread_mutex_lock(&ui__lock);
36  ret = vscnprintf(ui_helpline__last_msg + backlog,
37  sizeof(ui_helpline__last_msg) - backlog, format, ap);
38  backlog += ret;
39 
40  tui_helpline__set = true;
41 
42  if (ui_helpline__last_msg[backlog - 1] == '\n') {
44  SLsmg_refresh();
45  backlog = 0;
46  }
47  pthread_mutex_unlock(&ui__lock);
48 
49  return ret;
50 }
51 
54  .push = tui_helpline__push,
55  .show = tui_helpline__show,
56 };
57 
59 {
61  ui_helpline__puts(" ");
62 }
bool tui_helpline__set
Definition: helpline.c:13
static int tui_helpline__show(const char *format, va_list ap)
Definition: helpline.c:30
void ui_helpline__init(void)
Definition: helpline.c:58
char ui_helpline__current[512]
Definition: helpline.c:11
pthread_mutex_t ui__lock
Definition: setup.c:10
void(* pop)(void)
Definition: helpline.h:11
static void tui_helpline__pop(void)
Definition: helpline.c:15
void ui_helpline__puts(const char *msg)
Definition: helpline.c:66
char ui_helpline__last_msg[1024]
Definition: helpline.c:12
struct ui_helpline tui_helpline_fns
Definition: helpline.c:52
static void tui_helpline__push(const char *msg)
Definition: helpline.c:19
struct ui_helpline * helpline_fns
Definition: helpline.c:33