blob: 8d79daa4458ab4fd86e62be18e48d620af1fd9b8 [file] [log] [blame]
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -03001#define _GNU_SOURCE
2#include <stdio.h>
3#include <stdlib.h>
4#include <newt.h>
5
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -03006#include "../debug.h"
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -03007#include "helpline.h"
8
9void ui_helpline__pop(void)
10{
11 newtPopHelpLine();
12}
13
14void ui_helpline__push(const char *msg)
15{
16 newtPushHelpLine(msg);
17}
18
Arnaldo Carvalho de Melo59e8fe32010-08-10 15:44:20 -030019void ui_helpline__vpush(const char *fmt, va_list ap)
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -030020{
21 char *s;
22
23 if (vasprintf(&s, fmt, ap) < 0)
24 vfprintf(stderr, fmt, ap);
25 else {
26 ui_helpline__push(s);
27 free(s);
28 }
29}
30
31void ui_helpline__fpush(const char *fmt, ...)
32{
33 va_list ap;
34
35 va_start(ap, fmt);
36 ui_helpline__vpush(fmt, ap);
37 va_end(ap);
38}
39
40void ui_helpline__puts(const char *msg)
41{
42 ui_helpline__pop();
43 ui_helpline__push(msg);
44}
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -030045
46void ui_helpline__init(void)
47{
48 ui_helpline__puts(" ");
49}
50
51char ui_helpline__last_msg[1024];
52
53int ui_helpline__show_help(const char *format, va_list ap)
54{
55 int ret;
56 static int backlog;
57
58 ret = vsnprintf(ui_helpline__last_msg + backlog,
59 sizeof(ui_helpline__last_msg) - backlog, format, ap);
60 backlog += ret;
61
62 if (ui_helpline__last_msg[backlog - 1] == '\n') {
63 ui_helpline__puts(ui_helpline__last_msg);
64 newtRefresh();
65 backlog = 0;
66 }
67
68 return ret;
69}