-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.c
54 lines (47 loc) · 960 Bytes
/
status.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
#include <curses.h>
#include <string.h>
#include "status.h"
#include "utils.h"
/**
* The status text, in a cyclic buffer.
*/
static char status_box[STATUS_LINES][SCREENWIDTH - STATUS_X];
/**
* The index into the status buffer
*/
static unsigned int head = 0;
/**
* Whether the buffer is full or not
*/
static bool full = false;
/**
* Print a line to the status box
*/
void status_push(const char * fmt, ...) {
va_list ap;
va_start(ap, fmt);
vsnprintf(status_box[head], SCREENWIDTH - STATUS_X, fmt, ap);
va_end(ap);
head = (head + 1) % STATUS_LINES;
if(head == 0) {
full = true;
}
}
/**
* Print the status box
*/
void display_status() {
if(full) {
unsigned int i = head;
unsigned int j = 0;
do {
mvaddstr(STATUS_TOP + j, STATUS_X, status_box[i]);
i = (i + 1) % STATUS_LINES;
j++;
} while(i != head);
} else {
for(unsigned int i = 0; i < head; i++) {
mvaddstr(STATUS_TOP + i, STATUS_X, status_box[i]);
}
}
}