-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstatusbar.c
More file actions
85 lines (81 loc) · 1.62 KB
/
statusbar.c
File metadata and controls
85 lines (81 loc) · 1.62 KB
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
static int statusfd = -1;
static char stext[512];
static int barpos = BARPOS;
static unsigned int bh = 1, by;
static void
updatebarpos(void) {
by = 0;
wax = 0;
way = 0;
wah = height;
if (statusfd == -1)
return;
if (barpos == BarTop) {
wah -= bh;
way += bh;
} else if (barpos == BarBot) {
wah -= bh;
by = wah;
}
}
static void
drawbar() {
wchar_t wbuf[sizeof stext];
int w, maxwidth = width - 2;
if (barpos == BarOff || !*stext)
return;
curs_set(0);
attrset(BAR_ATTR);
madtty_color_set(stdscr, BAR_FG, BAR_BG);
mvaddch(by, 0, '[');
if (mbstowcs(wbuf, stext, sizeof stext) == -1)
return;
if ((w = wcswidth(wbuf, maxwidth)) == -1)
return;
if (BAR_ALIGN == ALIGN_RIGHT) {
for (int i = 0; i + w < maxwidth; i++)
addch(' ');
}
addstr(stext);
if (BAR_ALIGN == ALIGN_LEFT) {
for (; w < maxwidth; w++)
addch(' ');
}
mvaddch(by, width - 1, ']');
attrset(NORMAL_ATTR);
if (sel)
curs_set(madtty_cursor(sel->term));
refresh();
}
static void
togglebar(const char *args[]) {
if (barpos == BarOff)
barpos = (BARPOS == BarOff) ? BarTop : BARPOS;
else
barpos = BarOff;
updatebarpos();
arrange();
drawbar();
}
static void
handle_statusbar() {
char *p;
int r;
switch (r = read(statusfd, stext, sizeof stext - 1)) {
case -1:
strncpy(stext, strerror(errno), sizeof stext - 1);
stext[sizeof stext - 1] = '\0';
statusfd = -1;
break;
case 0:
statusfd = -1;
break;
default:
stext[r] = '\0'; p = stext + strlen(stext) - 1;
for (; p >= stext && *p == '\n'; *p-- = '\0');
for (; p >= stext && *p != '\n'; --p);
if (p > stext)
strncpy(stext, p + 1, sizeof stext);
drawbar();
}
}