aboutsummaryrefslogtreecommitdiffstats
path: root/display.c
blob: 8bde0219e7278f73789f000c8d5f9b93ef17682d (plain) (blame)
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
#include "display.h"

#include <curses.h>

#include "err.h"
#include "log.h"
#include "mem.h"
#include "utils.h"
#include "version.h"
#include "wm.h"

void color_pair_init()
{
	init_pair(COLOR_PAIR_STATUS_BAR, COLOR_BLACK, COLOR_WHITE);
	init_pair(COLOR_PAIR_PROGRESS, COLOR_YELLOW, COLOR_BLUE);
	init_pair(COLOR_PAIR_TEXT_INFO, COLOR_WHITE, COLOR_BLUE);
	init_pair(COLOR_PAIR_FM_HL, COLOR_BLACK, COLOR_WHITE);
	init_pair(COLOR_PAIR_FM_DIR, COLOR_CYAN, COLOR_BLACK);
	init_pair(COLOR_PAIR_BORDER, COLOR_WHITE, COLOR_BLUE);
}

terminal *ncurses_init()
{
	initscr();
	raw();
	curs_set(0);
	if (!has_colors()) {
		log_write(LOG_WARN, "Terminal does not support colors");
	}

	start_color();
	color_pair_init();
	terminal *t = wm_init();
	keypad(ROOT_WIN, TRUE);
	return t;
}

void draw_stat_bar(terminal *t, const char *sys_version)
{
	window *stat_bar =
	    wm_create_new_w(t, "stat_bar", 1, t->maxx, t->maxy - 1, 0);
	if (!stat_bar || !stat_bar->win)
		return;
	wattron(stat_bar->win, COLOR_PAIR(COLOR_PAIR_STATUS_BAR));
	mvwprintw(stat_bar->win, 0, 0, "%*s", t->maxx, "");
	mvwprintw(stat_bar->win, 0, 0, "SF v%s | %s", PROGRAM_VERSION,
		  sys_version);
	wattroff(stat_bar->win, COLOR_PAIR(COLOR_PAIR_STATUS_BAR));

	wrefresh(stat_bar->win);
}

void wprintw_colorful(WINDOW *w, int attr, const char *format, ...)
{
	va_list ap;
	va_start(ap, format);
	wattron(w, COLOR_PAIR(attr));
	vw_printw(w, format, ap);
	wattroff(w, COLOR_PAIR(attr));
	va_end(ap);
}