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

@ -31,4 +31,12 @@ 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);
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;
@ -22,9 +22,9 @@ 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,124 +1,134 @@
#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
#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);
"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);
ITEM **my_items;
int c;
MENU *my_menu;
WINDOW *my_menu_win;
int n_choices, i;
/* 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]);
/* Initialize curses */
initscr();
start_color();
cbreak();
noecho();
keypad(stdscr, TRUE);
init_pair(1, COLOR_RED, COLOR_BLACK);
init_pair(2, COLOR_CYAN, COLOR_BLACK);
/* Crate menu */
my_menu = new_menu((ITEM **)my_items);
/* 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]);
/* 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, " * ");
/* Crate menu */
my_menu = new_menu((ITEM **)my_items);
/* 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();
/* Create the window to be associated with the menu */
my_menu_win = newwin(12, 40, 4, 4);
keypad(my_menu_win, TRUE);
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);
}
/* 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);
/* 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();
/* 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);
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);
/* 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 = 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_DOWN_ITEM);
break;
case KEY_PPAGE:
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);
}
/* 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;
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;
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();
length = strlen(string);
temp = (width - length) / 2;
x = startx + (int)temp;
wattron(win, color);
mvwprintw(win, y, x, "%s", string);
wattroff(win, color);
refresh();
}

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