-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_win.cpp
73 lines (65 loc) · 2 KB
/
database_win.cpp
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
#include <iostream>
#include <ncurses.h>
#include <cstring>
#include <sqlite3.h>
#include "add_win.h"
#include "database.h"
#include "menu.h"
using namespace std;
int database_settings() {
// Initialize ncurses
initscr();
clear();
cbreak(); // Disable line buffering
noecho(); // Don't print user input
keypad(stdscr, TRUE); // Enable special keys handling
int startx, starty, width, height;
height = 13;
width = 30;
starty = (LINES - height) / 2 + 2; // Centering the window
startx = (COLS - width) / 2;
WINDOW* menu_win = newwin(height, width, starty, startx);
keypad(menu_win, TRUE); // Enable arrow keys in the window
const char* choices[] = {"Init Database", "Add Person","Delete Person", "Edit Person", "Export Database", "Option X", "Drop Database", "Back"};
int n_choices = sizeof(choices) / sizeof(choices[0]);
int highlight = 1;
int choice = 0;
int c;
while (true) {
print_menu(menu_win, highlight, choices, n_choices);
c = wgetch(menu_win);
switch (c) {
case KEY_UP:
if (highlight == 1)
highlight = n_choices;
else
--highlight;
break;
case KEY_DOWN:
if (highlight == n_choices)
highlight = 1;
else
++highlight;
break;
case 10: // Enter key
choice = highlight;
break;
default:
break;
}
if (choice == 0) {
//database_init();
} if (choice == 2) {
add_win();
} if (choice == 4) {
export_to_csv(db, "spreadsheet.csv");
} if (choice == 6) {
drop_all_tables(db);
}if (choice == n_choices) // Exit option selected
menu();
}
// Cleanup ncurses
delwin(menu_win); // Delete the menu window
endwin(); // End ncurses mode
return 0;
}