why doesn't i work today

This commit is contained in:
PoliEcho 2024-11-12 21:31:33 +01:00
parent 3196f285fd
commit 2d35ee060c
7 changed files with 133 additions and 115 deletions

View File

@ -1,7 +1,7 @@
CC = g++
CC_FLAGS = -std=c++23 -s -O3 -lncurses -lcurl -lmenu -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
CC_FLAGS = -ggdb -std=c++23 -lncurses -lcurl -lmenu -Wall -Wextra
all: build/bin/bakatui

View File

@ -32,3 +32,11 @@ void safe_exit(int code) {
exit(code);
}
std::string bool_to_string(bool bool_in) {
if (bool_in) {
return "true";
} else {
return "false";
}
}

View File

@ -1,2 +1,3 @@
#include <string>
void safe_exit(int code);
std::string bool_to_string(bool bool_in);

View File

@ -1,6 +1,7 @@
#include "main.h"
#include "color.h"
#include "helper_funcs.h"
#include "main_menu.h"
#include "net.h"
#include <csignal>
#include <curl/curl.h>
@ -9,7 +10,6 @@
#include <regex>
#include <string>
#include <unistd.h>
#include "main_menu.h"
std::string baka_api_url;
@ -23,8 +23,8 @@ int main(int argc, char **argv) {
// error signal handlers
signal(SIGSEGV, safe_exit);
main_menu();
// main_menu();
// bakaapi::is_logged_in();
/*
std::cout << "enter school bakalari url:\n";
while (true) {
@ -46,7 +46,7 @@ int main(int argc, char **argv) {
if (baka_api_url.back() != '/') {
baka_api_url.append("/");
}
*/
{
std::string username;
std::cout << "enter username: ";
@ -59,7 +59,6 @@ int main(int argc, char **argv) {
// std::cin >> password;
bakaapi::login(username, password);
} */
}
return 0;
}

View File

@ -1,22 +1,21 @@
#include "helper_funcs.h"
#include "net.h"
#include <cstdlib>
#include <cstring>
#include <curses.h>
#include <iostream>
#include <menu.h>
#include <string>
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
#define CTRLD 4
char *choices[] = {
"login",
"Grades",
"shedule",
"Komens",
"Homework",
"Absence",
"Exit",
(char *)NULL,
"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 print_in_middle(WINDOW *win, int starty, int startx, int width,
char *string, chtype color);
void main_menu() {
ITEM **my_items;
@ -57,7 +56,11 @@ void main_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));
char title_text[40] = "Main Menu - login status: ";
// strcat(title_text, bool_to_string(bakaapi::is_logged_in()).c_str());
print_in_middle(my_menu_win, 1, 0, 40, title_text, 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);
@ -67,27 +70,33 @@ void main_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 - 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:
while ((c = getch()) != 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);
menu_driver(my_menu, REQ_DOWN_ITEM);
break;
case KEY_PPAGE:
menu_driver(my_menu, REQ_SCR_UPAGE);
menu_driver(my_menu, REQ_UP_ITEM);
break;
case 10: // ENTER
move(20, 0);
clrtoeol();
mvprintw(20, 0, "Item selected is : %s",
item_name(current_item(my_menu)));
pos_menu_cursor(my_menu);
break;
}
wrefresh(my_menu_win);
}
@ -100,8 +109,9 @@ void main_menu() {
endwin();
}
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color)
{ int length, x, y;
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)

View File

@ -109,8 +109,6 @@ 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");

View File

@ -2,4 +2,6 @@
#include <string>
namespace bakaapi {
void login(std::string username, std::string password);
}
void refresh_access_token();
bool is_logged_in();
} // namespace bakaapi