-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui_menu.c
More file actions
80 lines (64 loc) · 2.33 KB
/
ui_menu.c
File metadata and controls
80 lines (64 loc) · 2.33 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
#include <ncurses.h>
#include "custom_include/memory_info.h"
#include "custom_include/process_info.h"
#include "custom_include/sys_info.h"
#include "custom_include/battery_info.h"
void ui_menu() {
initscr();
noecho();
curs_set(0);
timeout(1000); // refresh every 1 sec
int mode = 0; // to be able to refresh menu items
keypad(stdscr, TRUE); // enable arrow keys
char *choices[] = { "Processes", "CPU Usage", "Memory Info", "Battery Info", "Exit" }; // options in menu
size_t len_menu = sizeof choices/ sizeof(char *);
int choice;
int highlight = 0;
while(1) {
clear();
// menu
if (mode == 0) {
for(int i = 0; i < len_menu; i++) {
mvprintw(1, 5, "--- ProcView Dashboard ---");
if(i == highlight)
attron(A_REVERSE); // highlight the selected option
mvprintw(i + 3, 5, "%s", choices[i]);
attroff(A_REVERSE);
}
} else { // DATA VIEW MODE
mvprintw(1, 5, "Monitoring: %s (Press 'b' to go back)", choices[highlight]);
if (highlight == 0) get_process_info();
else if (highlight == 1) get_sys_info();
else if (highlight == 2) get_memory_info();
else if (highlight == 3) get_battery_info();
mvprintw(LINES - 1, 5, "Last Update: [Live]");
}
// get user choice
choice = getch();
if (mode == 0) switch(choice) {
case KEY_UP:
highlight = (highlight == 0) ? len_menu-1 : highlight - 1;
break;
case KEY_DOWN:
highlight = (highlight == len_menu-1) ? 0 : highlight + 1;
break;
case KEY_RIGHT: // Fall through
case 10: // Enter key
clear(); // clear ui
mode = 1; // change ui
if(highlight == len_menu-1) // Exit selected
goto end;
break;
} else {
if (choice == 'b' || choice == 10 || choice == KEY_LEFT) { // 'b' or Enter to go back
clear();
refresh();
mode = 0;
}
}
refresh();
}
end:
endwin(); // restore terminal
return;
}