Loading...
1// SPDX-License-Identifier: GPL-2.0
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <linux/kernel.h>
6#include <linux/string.h>
7
8#include "../helpline.h"
9#include "../ui.h"
10#include "../libslang.h"
11
12char ui_helpline__last_msg[1024];
13bool tui_helpline__set;
14
15static void tui_helpline__pop(void)
16{
17}
18
19static 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 strlcpy(ui_helpline__current, msg, sz);
28}
29
30static int tui_helpline__show(const char *format, va_list ap)
31{
32 int ret;
33 static int backlog;
34
35 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') {
43 ui_helpline__puts(ui_helpline__last_msg);
44 SLsmg_refresh();
45 backlog = 0;
46 }
47 mutex_unlock(&ui__lock);
48
49 return ret;
50}
51
52struct ui_helpline tui_helpline_fns = {
53 .pop = tui_helpline__pop,
54 .push = tui_helpline__push,
55 .show = tui_helpline__show,
56};
57
58void ui_helpline__init(void)
59{
60 helpline_fns = &tui_helpline_fns;
61 ui_helpline__puts(" ");
62}
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>
8
9#include "../helpline.h"
10#include "../ui.h"
11#include "../libslang.h"
12
13char ui_helpline__last_msg[1024];
14bool tui_helpline__set;
15
16static void tui_helpline__pop(void)
17{
18}
19
20static void tui_helpline__push(const char *msg)
21{
22 const size_t sz = sizeof(ui_helpline__current);
23
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);
29}
30
31static int tui_helpline__show(const char *format, va_list ap)
32{
33 int ret;
34 static int backlog;
35
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;
40
41 tui_helpline__set = true;
42
43 if (ui_helpline__last_msg[backlog - 1] == '\n') {
44 ui_helpline__puts(ui_helpline__last_msg);
45 SLsmg_refresh();
46 backlog = 0;
47 }
48 pthread_mutex_unlock(&ui__lock);
49
50 return ret;
51}
52
53struct ui_helpline tui_helpline_fns = {
54 .pop = tui_helpline__pop,
55 .push = tui_helpline__push,
56 .show = tui_helpline__show,
57};
58
59void ui_helpline__init(void)
60{
61 helpline_fns = &tui_helpline_fns;
62 ui_helpline__puts(" ");
63}