forked from erkyrath/glkterm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtmessag.c
89 lines (73 loc) · 1.88 KB
/
gtmessag.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* gtmessag.c: The message line at the bottom of the screen
for GlkTerm, curses.h implementation of the Glk API.
Designed by Andrew Plotkin <[email protected]>
http://www.eblong.com/zarf/glk/index.html
*/
#include "gtoption.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curses.h>
#include "glk.h"
#include "glkterm.h"
/* Nothing fancy here. We store a string, and print it on the bottom line.
If pref_messageline is FALSE, none of these functions do anything. */
static char *msgbuf = NULL;
static int msgbuflen = 0;
static int msgbuf_size = 0;
void gli_msgline_warning(char *msg)
{
char buf[256];
if (!pref_messageline)
return;
sprintf(buf, "Glk library error: %s", msg);
gli_msgline(buf);
}
void gli_msgline(char *msg)
{
int len;
if (!pref_messageline)
return;
if (!msg)
msg = "";
len = strlen(msg);
if (!msgbuf) {
msgbuf_size = len+80;
msgbuf = (char *)malloc(msgbuf_size * sizeof(char));
}
else if (len+1 > msgbuf_size) {
while (len+1 > msgbuf_size)
msgbuf_size *= 2;
msgbuf = (char *)realloc(msgbuf, msgbuf_size * sizeof(char));
}
if (!msgbuf)
return;
strcpy(msgbuf, msg);
msgbuflen = len;
gli_msgline_redraw();
}
void gli_msgline_redraw()
{
if (!pref_messageline)
return;
if (msgbuflen == 0) {
move(content_box.bottom, 0);
clrtoeol();
}
else {
int ix, len;
move(content_box.bottom, 0);
addch(' ');
addch(' ');
attron(A_REVERSE);
if (msgbuflen > content_box.right-3)
len = content_box.right-3;
else
len = msgbuflen;
for (ix=0; ix<len; ix++) {
addch(msgbuf[ix]);
}
attrset(0);
clrtoeol();
}
}