why doesn't i work today
This commit is contained in:
parent
3196f285fd
commit
2d35ee060c
4
Makefile
4
Makefile
@ -1,7 +1,7 @@
|
|||||||
CC = g++
|
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:
|
#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
|
all: build/bin/bakatui
|
||||||
|
|
||||||
|
|||||||
@ -32,3 +32,11 @@ void safe_exit(int code) {
|
|||||||
|
|
||||||
exit(code);
|
exit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string bool_to_string(bool bool_in) {
|
||||||
|
if (bool_in) {
|
||||||
|
return "true";
|
||||||
|
} else {
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,2 +1,3 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
void safe_exit(int code);
|
void safe_exit(int code);
|
||||||
|
std::string bool_to_string(bool bool_in);
|
||||||
11
src/main.cpp
11
src/main.cpp
@ -1,6 +1,7 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
#include "helper_funcs.h"
|
#include "helper_funcs.h"
|
||||||
|
#include "main_menu.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
@ -9,7 +10,6 @@
|
|||||||
#include <regex>
|
#include <regex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "main_menu.h"
|
|
||||||
|
|
||||||
std::string baka_api_url;
|
std::string baka_api_url;
|
||||||
|
|
||||||
@ -23,8 +23,8 @@ int main(int argc, char **argv) {
|
|||||||
// error signal handlers
|
// error signal handlers
|
||||||
signal(SIGSEGV, safe_exit);
|
signal(SIGSEGV, safe_exit);
|
||||||
|
|
||||||
main_menu();
|
// main_menu();
|
||||||
|
// bakaapi::is_logged_in();
|
||||||
/*
|
/*
|
||||||
std::cout << "enter school bakalari url:\n";
|
std::cout << "enter school bakalari url:\n";
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -46,7 +46,7 @@ int main(int argc, char **argv) {
|
|||||||
if (baka_api_url.back() != '/') {
|
if (baka_api_url.back() != '/') {
|
||||||
baka_api_url.append("/");
|
baka_api_url.append("/");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
{
|
{
|
||||||
std::string username;
|
std::string username;
|
||||||
std::cout << "enter username: ";
|
std::cout << "enter username: ";
|
||||||
@ -59,7 +59,6 @@ int main(int argc, char **argv) {
|
|||||||
// std::cin >> password;
|
// std::cin >> password;
|
||||||
|
|
||||||
bakaapi::login(username, password);
|
bakaapi::login(username, password);
|
||||||
|
}
|
||||||
} */
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1,124 +1,134 @@
|
|||||||
|
#include "helper_funcs.h"
|
||||||
|
#include "net.h"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
|
#include <iostream>
|
||||||
#include <menu.h>
|
#include <menu.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
||||||
#define CTRLD 4
|
#define CTRLD 4
|
||||||
|
|
||||||
char *choices[] = {
|
char *choices[] = {
|
||||||
"login",
|
"login", "Grades", "shedule", "Komens",
|
||||||
"Grades",
|
"Homework", "Absence", "Exit", (char *)NULL,
|
||||||
"shedule",
|
};
|
||||||
"Komens",
|
void print_in_middle(WINDOW *win, int starty, int startx, int width,
|
||||||
"Homework",
|
char *string, chtype color);
|
||||||
"Absence",
|
|
||||||
"Exit",
|
|
||||||
(char *)NULL,
|
|
||||||
};
|
|
||||||
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);
|
|
||||||
|
|
||||||
void main_menu() {
|
void main_menu() {
|
||||||
ITEM **my_items;
|
ITEM **my_items;
|
||||||
int c;
|
int c;
|
||||||
MENU *my_menu;
|
MENU *my_menu;
|
||||||
WINDOW *my_menu_win;
|
WINDOW *my_menu_win;
|
||||||
int n_choices, i;
|
int n_choices, i;
|
||||||
|
|
||||||
/* Initialize curses */
|
/* Initialize curses */
|
||||||
initscr();
|
initscr();
|
||||||
start_color();
|
start_color();
|
||||||
cbreak();
|
cbreak();
|
||||||
noecho();
|
noecho();
|
||||||
keypad(stdscr, TRUE);
|
keypad(stdscr, TRUE);
|
||||||
init_pair(1, COLOR_RED, COLOR_BLACK);
|
init_pair(1, COLOR_RED, COLOR_BLACK);
|
||||||
init_pair(2, COLOR_CYAN, COLOR_BLACK);
|
init_pair(2, COLOR_CYAN, COLOR_BLACK);
|
||||||
|
|
||||||
/* Create items */
|
/* Create items */
|
||||||
n_choices = ARRAY_SIZE(choices);
|
n_choices = ARRAY_SIZE(choices);
|
||||||
my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
|
my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
|
||||||
for(i = 0; i < n_choices; ++i)
|
for (i = 0; i < n_choices; ++i)
|
||||||
my_items[i] = new_item(choices[i], choices[i]);
|
my_items[i] = new_item(choices[i], choices[i]);
|
||||||
|
|
||||||
/* Crate menu */
|
/* Crate menu */
|
||||||
my_menu = new_menu((ITEM **)my_items);
|
my_menu = new_menu((ITEM **)my_items);
|
||||||
|
|
||||||
/* Create the window to be associated with the menu */
|
/* Create the window to be associated with the menu */
|
||||||
my_menu_win = newwin(12, 40, 4, 4);
|
my_menu_win = newwin(12, 40, 4, 4);
|
||||||
keypad(my_menu_win, TRUE);
|
keypad(my_menu_win, TRUE);
|
||||||
|
|
||||||
/* Set main window and sub window */
|
/* Set main window and sub window */
|
||||||
set_menu_win(my_menu, my_menu_win);
|
set_menu_win(my_menu, my_menu_win);
|
||||||
set_menu_sub(my_menu, derwin(my_menu_win, 8, 38, 3, 1));
|
set_menu_sub(my_menu, derwin(my_menu_win, 8, 38, 3, 1));
|
||||||
set_menu_format(my_menu, 7, 1);
|
set_menu_format(my_menu, 7, 1);
|
||||||
|
|
||||||
/* Set menu mark to the string " * " */
|
/* Set menu mark to the string " * " */
|
||||||
set_menu_mark(my_menu, " * ");
|
set_menu_mark(my_menu, " * ");
|
||||||
|
|
||||||
/* Print a border around the main window and print a title */
|
/* Print a border around the main window and print a title */
|
||||||
box(my_menu_win, 0, 0);
|
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 */
|
char title_text[40] = "Main Menu - login status: ";
|
||||||
post_menu(my_menu);
|
// strcat(title_text, bool_to_string(bakaapi::is_logged_in()).c_str());
|
||||||
wrefresh(my_menu_win);
|
|
||||||
|
|
||||||
attron(COLOR_PAIR(2));
|
print_in_middle(my_menu_win, 1, 0, 40, title_text, COLOR_PAIR(1));
|
||||||
mvprintw(LINES - 2, 0, "Use PageUp and PageDown to scoll down or up a page of items");
|
mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
|
||||||
mvprintw(LINES - 1, 0, "Arrow Keys to navigate (F1 to Exit)");
|
mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38);
|
||||||
attroff(COLOR_PAIR(2));
|
mvwaddch(my_menu_win, 2, 39, ACS_RTEE);
|
||||||
refresh();
|
|
||||||
|
|
||||||
while((c = wgetch(my_menu_win)) != KEY_F(1)) {
|
/* Post the menu */
|
||||||
switch(c)
|
post_menu(my_menu);
|
||||||
{ case KEY_DOWN:
|
wrefresh(my_menu_win);
|
||||||
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
|
|
||||||
|
|
||||||
}
|
attron(COLOR_PAIR(2));
|
||||||
wrefresh(my_menu_win);
|
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();
|
||||||
|
|
||||||
/* Unpost and free all the memory taken up */
|
while ((c = getch()) != KEY_F(1)) {
|
||||||
unpost_menu(my_menu);
|
switch (c) {
|
||||||
free_menu(my_menu);
|
case KEY_DOWN:
|
||||||
for(i = 0; i < n_choices; ++i)
|
menu_driver(my_menu, REQ_DOWN_ITEM);
|
||||||
free_item(my_items[i]);
|
break;
|
||||||
endwin();
|
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)
|
void print_in_middle(WINDOW *win, int starty, int startx, int width,
|
||||||
{ int length, x, y;
|
char *string, chtype color) {
|
||||||
float temp;
|
int length, x, y;
|
||||||
|
float temp;
|
||||||
|
|
||||||
if(win == NULL)
|
if (win == NULL)
|
||||||
win = stdscr;
|
win = stdscr;
|
||||||
getyx(win, y, x);
|
getyx(win, y, x);
|
||||||
if(startx != 0)
|
if (startx != 0)
|
||||||
x = startx;
|
x = startx;
|
||||||
if(starty != 0)
|
if (starty != 0)
|
||||||
y = starty;
|
y = starty;
|
||||||
if(width == 0)
|
if (width == 0)
|
||||||
width = 80;
|
width = 80;
|
||||||
|
|
||||||
length = strlen(string);
|
length = strlen(string);
|
||||||
temp = (width - length)/ 2;
|
temp = (width - length) / 2;
|
||||||
x = startx + (int)temp;
|
x = startx + (int)temp;
|
||||||
wattron(win, color);
|
wattron(win, color);
|
||||||
mvwprintw(win, y, x, "%s", string);
|
mvwprintw(win, y, x, "%s", string);
|
||||||
wattroff(win, color);
|
wattroff(win, color);
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
@ -109,8 +109,6 @@ void login(std::string username, std::string password) {
|
|||||||
std::cout << "access token: " << access_token << std::endl;
|
std::cout << "access token: " << access_token << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void refresh_access_token() {
|
void refresh_access_token() {
|
||||||
std::string savedir_path = std::getenv("HOME");
|
std::string savedir_path = std::getenv("HOME");
|
||||||
savedir_path.append("/.local/share/bakatui");
|
savedir_path.append("/.local/share/bakatui");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user