ui
This commit is contained in:
parent
498d1ce1b1
commit
3196f285fd
11
Makefile
11
Makefile
@ -1,12 +1,12 @@
|
||||
CC = g++
|
||||
CC_FLAGS = -std=c++23 -s -O3 -lncurses -lcurl -Wall -Wextra
|
||||
CC_FLAGS = -std=c++23 -s -O3 -lncurses -lcurl -lmenu -Wall -Wextra
|
||||
#debug flags:
|
||||
#CC_FLAGS = -ggdb -std=c++23 -lncurses -lcurl -Wall -Wextra
|
||||
|
||||
all: build/bin/bakatui
|
||||
|
||||
build/bin/bakatui: build/obj/main.o build/obj/net.o build/obj/helper_funcs.o
|
||||
$(CC) $(CC_FLAGS) build/obj/main.o build/obj/net.o build/obj/helper_funcs.o -o build/bin/bakatui
|
||||
build/bin/bakatui: build/obj/main.o build/obj/net.o build/obj/helper_funcs.o build/obj/main_menu.o
|
||||
$(CC) $(CC_FLAGS) build/obj/main.o build/obj/net.o build/obj/helper_funcs.o build/obj/main_menu.o -o build/bin/bakatui
|
||||
|
||||
build/obj/main.o: src/main.cpp
|
||||
mkdir -p build/obj
|
||||
@ -17,7 +17,10 @@ build/obj/net.o: src/net.cpp
|
||||
$(CC) $(CC_FLAGS) -c src/net.cpp -o build/obj/net.o
|
||||
|
||||
build/obj/helper_funcs.o: src/helper_funcs.cpp
|
||||
$(CC) $(CC_FLAGS) -c src/helper_funcs.cpp -o build/obj/helper_funcs.o
|
||||
$(CC) $(CC_FLAGS) -c src/helper_funcs.cpp -o build/obj/helper_funcs.o
|
||||
|
||||
build/obj/main_menu.o: src/main_menu.cpp
|
||||
$(CC) $(CC_FLAGS) -c src/main_menu.cpp -o build/obj/main_menu.o
|
||||
|
||||
clean:
|
||||
rm -fr build
|
27
src/main.cpp
27
src/main.cpp
@ -9,6 +9,7 @@
|
||||
#include <regex>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
#include "main_menu.h"
|
||||
|
||||
std::string baka_api_url;
|
||||
|
||||
@ -21,27 +22,10 @@ int main(int argc, char **argv) {
|
||||
|
||||
// error signal handlers
|
||||
signal(SIGSEGV, safe_exit);
|
||||
|
||||
main_menu();
|
||||
|
||||
/*initscr();
|
||||
|
||||
// creating a window;
|
||||
// with height = 15 and width = 10
|
||||
// also with start x axis 10 and start y axis = 20
|
||||
WINDOW *win = newwin(15, 17, 2, 10);
|
||||
refresh();
|
||||
|
||||
// making box border with default border styles
|
||||
box(win, 0, 0);
|
||||
|
||||
// move and print in window
|
||||
mvwprintw(win, 0, 1, "Greeter");
|
||||
mvwprintw(win, 1, 1, "Hello");
|
||||
|
||||
// refreshing the window
|
||||
wrefresh(win);
|
||||
|
||||
getch();
|
||||
endwin(); */
|
||||
/*
|
||||
std::cout << "enter school bakalari url:\n";
|
||||
while (true) {
|
||||
std::cout << "(or q to quit )";
|
||||
@ -75,6 +59,7 @@ int main(int argc, char **argv) {
|
||||
// std::cin >> password;
|
||||
|
||||
bakaapi::login(username, password);
|
||||
}
|
||||
|
||||
} */
|
||||
return 0;
|
||||
}
|
124
src/main_menu.cpp
Normal file
124
src/main_menu.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <curses.h>
|
||||
#include <menu.h>
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
||||
#define CTRLD 4
|
||||
|
||||
char *choices[] = {
|
||||
"login",
|
||||
"Grades",
|
||||
"shedule",
|
||||
"Komens",
|
||||
"Homework",
|
||||
"Absence",
|
||||
"Exit",
|
||||
(char *)NULL,
|
||||
};
|
||||
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);
|
||||
|
||||
void main_menu() {
|
||||
ITEM **my_items;
|
||||
int c;
|
||||
MENU *my_menu;
|
||||
WINDOW *my_menu_win;
|
||||
int n_choices, i;
|
||||
|
||||
/* Initialize curses */
|
||||
initscr();
|
||||
start_color();
|
||||
cbreak();
|
||||
noecho();
|
||||
keypad(stdscr, TRUE);
|
||||
init_pair(1, COLOR_RED, COLOR_BLACK);
|
||||
init_pair(2, COLOR_CYAN, COLOR_BLACK);
|
||||
|
||||
/* Create items */
|
||||
n_choices = ARRAY_SIZE(choices);
|
||||
my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
|
||||
for(i = 0; i < n_choices; ++i)
|
||||
my_items[i] = new_item(choices[i], choices[i]);
|
||||
|
||||
/* Crate menu */
|
||||
my_menu = new_menu((ITEM **)my_items);
|
||||
|
||||
/* Create the window to be associated with the menu */
|
||||
my_menu_win = newwin(12, 40, 4, 4);
|
||||
keypad(my_menu_win, TRUE);
|
||||
|
||||
/* Set main window and sub window */
|
||||
set_menu_win(my_menu, my_menu_win);
|
||||
set_menu_sub(my_menu, derwin(my_menu_win, 8, 38, 3, 1));
|
||||
set_menu_format(my_menu, 7, 1);
|
||||
|
||||
/* Set menu mark to the string " * " */
|
||||
set_menu_mark(my_menu, " * ");
|
||||
|
||||
/* Print a border around the main window and print a title */
|
||||
box(my_menu_win, 0, 0);
|
||||
print_in_middle(my_menu_win, 1, 0, 40, "Main Menu", COLOR_PAIR(1));
|
||||
mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
|
||||
mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38);
|
||||
mvwaddch(my_menu_win, 2, 39, ACS_RTEE);
|
||||
|
||||
/* Post the menu */
|
||||
post_menu(my_menu);
|
||||
wrefresh(my_menu_win);
|
||||
|
||||
attron(COLOR_PAIR(2));
|
||||
mvprintw(LINES - 2, 0, "Use PageUp and PageDown to scoll down or up a page of items");
|
||||
mvprintw(LINES - 1, 0, "Arrow Keys to navigate (F1 to Exit)");
|
||||
attroff(COLOR_PAIR(2));
|
||||
refresh();
|
||||
|
||||
while((c = wgetch(my_menu_win)) != KEY_F(1)) {
|
||||
switch(c)
|
||||
{ case KEY_DOWN:
|
||||
menu_driver(my_menu, REQ_DOWN_ITEM);
|
||||
break;
|
||||
case KEY_UP:
|
||||
menu_driver(my_menu, REQ_UP_ITEM);
|
||||
break;
|
||||
case KEY_NPAGE:
|
||||
menu_driver(my_menu, REQ_SCR_DPAGE);
|
||||
break;
|
||||
case KEY_PPAGE:
|
||||
menu_driver(my_menu, REQ_SCR_UPAGE);
|
||||
break;
|
||||
case 10: //ENTER
|
||||
|
||||
}
|
||||
wrefresh(my_menu_win);
|
||||
}
|
||||
|
||||
/* Unpost and free all the memory taken up */
|
||||
unpost_menu(my_menu);
|
||||
free_menu(my_menu);
|
||||
for(i = 0; i < n_choices; ++i)
|
||||
free_item(my_items[i]);
|
||||
endwin();
|
||||
}
|
||||
|
||||
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color)
|
||||
{ int length, x, y;
|
||||
float temp;
|
||||
|
||||
if(win == NULL)
|
||||
win = stdscr;
|
||||
getyx(win, y, x);
|
||||
if(startx != 0)
|
||||
x = startx;
|
||||
if(starty != 0)
|
||||
y = starty;
|
||||
if(width == 0)
|
||||
width = 80;
|
||||
|
||||
length = strlen(string);
|
||||
temp = (width - length)/ 2;
|
||||
x = startx + (int)temp;
|
||||
wattron(win, color);
|
||||
mvwprintw(win, y, x, "%s", string);
|
||||
wattroff(win, color);
|
||||
refresh();
|
||||
}
|
1
src/main_menu.h
Normal file
1
src/main_menu.h
Normal file
@ -0,0 +1 @@
|
||||
void main_menu();
|
@ -109,6 +109,8 @@ void login(std::string username, std::string password) {
|
||||
std::cout << "access token: " << access_token << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void refresh_access_token() {
|
||||
std::string savedir_path = std::getenv("HOME");
|
||||
savedir_path.append("/.local/share/bakatui");
|
||||
|
Loading…
x
Reference in New Issue
Block a user