aboutsummaryrefslogtreecommitdiff
path: root/display.cpp
blob: ef9918e59cc40cb465bb55e6d6390ceb35cddb98 (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "display.h"

#include <ncurses.h>


#include <vector>
#include <map>
#include <string>

using namespace std;

static int display = 0;

vector<string> tab_names;
map<string, WINDOW *> tab_windows;

static void create_tab(string name)
{
	tab_names.push_back(name);
	tab_windows[name] = newpad(1000,1000);
}


void init_display(void)
{
	initscr();
	start_color();

	cbreak(); /* character at a time input */
	noecho(); /* don't show the user input */
	keypad(stdscr, TRUE); /* enable cursor/etc keys */

	use_default_colors();

	create_tab("Overview");
	create_tab("Idle stats");
	create_tab("Frequency stats");
	create_tab("Device stats");
//	create_tab("Checklist");
//	create_tab("Actions");

	display = 1;
}

WINDOW *tab_bar = NULL;

static int current_tab;

void show_tab(unsigned int tab)
{
	WINDOW *win;
	unsigned int i;

	if (!display)
		return;

	if (tab_bar) {
		delwin(tab_bar);
		tab_bar = NULL;
	}	

	tab_bar = newwin(1, 0, 0, 0);


	wattrset(tab_bar, A_REVERSE);
	mvwprintw(tab_bar, 0,0, "%120s", "");
	mvwprintw(tab_bar, 0,0, "PowerTOP 1.99");


	current_tab = tab;

	for (i = 0; i < tab_names.size(); i++) {
			if (i == tab)
				wattrset(tab_bar, A_NORMAL);
			else
				wattrset(tab_bar, A_REVERSE);
			mvwprintw(tab_bar, 0, (i + 1) * 18, " %s ", tab_names[i].c_str());
	}
	
	wrefresh(tab_bar);

	win = tab_windows[tab_names[tab]];
	if (!win)
		return;

	prefresh(win, 0, 0, 1, 0, LINES - 3, COLS - 1);
}

void show_next_tab(void)
{
	if (!display)
		return;
	current_tab ++;
	if (current_tab >= (int)tab_names.size())
		current_tab = 0;
	show_tab(current_tab);
}

void show_prev_tab(void)
{
	if (!display)
		return;
	current_tab --;
	if (current_tab < 0)
		current_tab = tab_names.size() - 1;
	show_tab(current_tab);
}

void show_cur_tab(void)
{
	if (!display)
		return;
	show_tab(current_tab);
}