Compare commits
No commits in common. "e5c2ae6da559df878fe4663cf80abc7da175b74d" and "452f6e079fc9119ddd57c04210aae7843f150833" have entirely different histories.
e5c2ae6da5
...
452f6e079f
3
.gitignore
vendored
3
.gitignore
vendored
@ -2,5 +2,4 @@
|
|||||||
.vscode
|
.vscode
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
core*
|
core*
|
||||||
build
|
build
|
||||||
test-data
|
|
49
Makefile
49
Makefile
@ -1,38 +1,29 @@
|
|||||||
# Compiler and flags
|
CC = g++
|
||||||
CPPC = g++
|
CC_FLAGS = -std=c++23 -s -O3 -lncurses -lcurl -lmenu -Wall -Wextra
|
||||||
CPPC_FLAGS = -std=c++23 -s -O3 -lncurses -lcurl -lmenu -lpanel -Wall -Wextra
|
#debug flags:
|
||||||
# Debug flags:
|
#CC_FLAGS = -ggdb -std=c++23 -lncurses -lcurl -lmenu -Wall -Wextra
|
||||||
# CPPC_FLAGS = -ggdb -std=c++23 -lncurses -lcurl -lmenu -lpanel -Wall -Wextra
|
|
||||||
|
|
||||||
|
all: build/bin/bakatui
|
||||||
|
|
||||||
SRC_PATH := src
|
build/bin/bakatui: build/obj/main.o build/obj/net.o build/obj/helper_funcs.o build/obj/main_menu.o build/obj/grades.o
|
||||||
OBJ_PATH := build/obj
|
$(CC) $(CC_FLAGS) build/obj/main.o build/obj/net.o build/obj/helper_funcs.o build/obj/main_menu.o build/obj/grades.o -o build/bin/bakatui
|
||||||
BIN_PATH := build/bin
|
|
||||||
|
|
||||||
|
build/obj/main.o: src/main.cpp
|
||||||
|
mkdir -p build/obj
|
||||||
|
mkdir -p build/bin
|
||||||
|
$(CC) $(CC_FLAGS) -c src/main.cpp -o build/obj/main.o
|
||||||
|
|
||||||
SRC_FILES := $(shell find $(SRC_PATH) -name '*.cpp')
|
build/obj/net.o: src/net.cpp
|
||||||
# Generate corresponding object file paths by replacing src/ with build/obj/
|
$(CC) $(CC_FLAGS) -c src/net.cpp -o build/obj/net.o
|
||||||
OBJ_FILES := $(patsubst $(SRC_PATH)/%.cpp,$(OBJ_PATH)/%.o,$(SRC_FILES))
|
|
||||||
|
|
||||||
|
build/obj/helper_funcs.o: src/helper_funcs.cpp
|
||||||
|
$(CC) $(CC_FLAGS) -c src/helper_funcs.cpp -o build/obj/helper_funcs.o
|
||||||
|
|
||||||
all: make-build-dir $(BIN_PATH)/bakatui
|
build/obj/main_menu.o: src/main_menu.cpp
|
||||||
|
$(CC) $(CC_FLAGS) -c src/main_menu.cpp -o build/obj/main_menu.o
|
||||||
|
|
||||||
make-build-dir:
|
|
||||||
mkdir -p $(OBJ_PATH)
|
|
||||||
mkdir -p $(OBJ_PATH)/marks
|
|
||||||
mkdir -p $(BIN_PATH)
|
|
||||||
|
|
||||||
|
|
||||||
$(BIN_PATH)/bakatui: $(OBJ_FILES)
|
|
||||||
$(CPPC) $(CPPC_FLAGS) $^ -o $@
|
|
||||||
|
|
||||||
|
|
||||||
$(OBJ_PATH)/%.o: $(SRC_PATH)/%.cpp
|
|
||||||
$(CPPC) $(CPPC_FLAGS) -c $< -o $@
|
|
||||||
|
|
||||||
|
build/obj/grades.o: src/grades/*.cpp
|
||||||
|
$(CC) $(CC_FLAGS) -c src/grades/*.cpp -o build/obj/grades.o
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -fr build
|
rm -fr build
|
||||||
|
|
||||||
.PHONY: all clean make-build-dir
|
|
0
src/grades/grades.h
Normal file
0
src/grades/grades.h
Normal file
6
src/grades/ui.cpp
Normal file
6
src/grades/ui.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include <curses.h>
|
||||||
|
#include <menu.h>
|
||||||
|
|
||||||
|
void grades_page() {
|
||||||
|
|
||||||
|
}
|
0
src/grades/ui.h
Normal file
0
src/grades/ui.h
Normal file
@ -2,8 +2,8 @@
|
|||||||
#include "color.h"
|
#include "color.h"
|
||||||
#include "helper_funcs.h"
|
#include "helper_funcs.h"
|
||||||
#include "main_menu.h"
|
#include "main_menu.h"
|
||||||
#include "marks/marks.h"
|
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
#include "helper_funcs.h"
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
@ -25,9 +25,6 @@ int main(int argc, char **argv) {
|
|||||||
// error signal handlers
|
// error signal handlers
|
||||||
signal(SIGSEGV, safe_exit);
|
signal(SIGSEGV, safe_exit);
|
||||||
|
|
||||||
marks_page();
|
|
||||||
/*
|
|
||||||
|
|
||||||
{
|
{
|
||||||
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");
|
||||||
@ -64,6 +61,6 @@ int main(int argc, char **argv) {
|
|||||||
get_input_and_login();
|
get_input_and_login();
|
||||||
}
|
}
|
||||||
main_menu();
|
main_menu();
|
||||||
*/
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
154
src/marks.cpp
154
src/marks.cpp
@ -1,154 +0,0 @@
|
|||||||
#include "marks.h"
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstring>
|
|
||||||
#include <curses.h>
|
|
||||||
#include <fstream>
|
|
||||||
#include <menu.h>
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include <panel.h>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using nlohmann::json;
|
|
||||||
|
|
||||||
// Thsi code is based on
|
|
||||||
// https://github.com/tony/NCURSES-Programming-HOWTO-examples/blob/master/16-panels
|
|
||||||
/*
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2016 Tony Narlock
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define NLINES 10
|
|
||||||
#define NCOLS 40
|
|
||||||
|
|
||||||
void init_wins(WINDOW **wins, int n, json marks_json);
|
|
||||||
void win_show(WINDOW *win, char *label, int label_color);
|
|
||||||
void print_in_middle(WINDOW *win, int starty, int startx, int width,
|
|
||||||
char *string, chtype color);
|
|
||||||
|
|
||||||
void marks_page() {
|
|
||||||
|
|
||||||
// DONT FORGET TO UNCOMMENT
|
|
||||||
// json resp_from_api = bakaapi::get_grades();
|
|
||||||
std::ifstream f("test-data/marks2.json");
|
|
||||||
json resp_from_api = json::parse(f);
|
|
||||||
|
|
||||||
WINDOW **my_wins;
|
|
||||||
size_t size_my_wins = resp_from_api["Subjects"].size();
|
|
||||||
my_wins = new (std::nothrow) WINDOW *[size_my_wins];
|
|
||||||
|
|
||||||
PANEL **my_panels;
|
|
||||||
size_t size_my_panels = resp_from_api["Subjects"].size();
|
|
||||||
my_panels = new (std::nothrow) PANEL *[size_my_panels];
|
|
||||||
|
|
||||||
PANEL *top;
|
|
||||||
int ch;
|
|
||||||
|
|
||||||
setlocale(LC_ALL, "");
|
|
||||||
/* Initialize curses */
|
|
||||||
initscr();
|
|
||||||
start_color();
|
|
||||||
cbreak();
|
|
||||||
noecho();
|
|
||||||
keypad(stdscr, TRUE);
|
|
||||||
|
|
||||||
/* Initialize all the colors */
|
|
||||||
for (size_t i = 0; i < 8; i++) {
|
|
||||||
init_pair(i, i, COLOR_BLACK);
|
|
||||||
}
|
|
||||||
|
|
||||||
init_wins(my_wins, resp_from_api["Subjects"].size(), resp_from_api);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < size_my_panels; i++) {
|
|
||||||
/* Attach a panel to each window Order is bottom up */
|
|
||||||
my_panels[i] = new_panel(my_wins[i]);
|
|
||||||
|
|
||||||
/* Set up the user pointers to the next panel */
|
|
||||||
if ((i + 1) < size_my_panels) {
|
|
||||||
set_panel_userptr(my_panels[i], my_panels[(i + 1)]);
|
|
||||||
} else {
|
|
||||||
set_panel_userptr(my_panels[i], my_panels[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the stacking order.
|
|
||||||
update_panels();
|
|
||||||
|
|
||||||
/* Show it on the screen */
|
|
||||||
attron(COLOR_PAIR(4));
|
|
||||||
mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F1 to Exit)");
|
|
||||||
attroff(COLOR_PAIR(4));
|
|
||||||
doupdate();
|
|
||||||
|
|
||||||
top = my_panels[2];
|
|
||||||
while ((ch = getch()) != KEY_F(1)) {
|
|
||||||
switch (ch) {
|
|
||||||
case 9:
|
|
||||||
top = (PANEL *)panel_userptr(top);
|
|
||||||
top_panel(top);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
update_panels();
|
|
||||||
doupdate();
|
|
||||||
}
|
|
||||||
endwin();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Put all the windows */
|
|
||||||
void init_wins(WINDOW **wins, int n, json marks_json) {
|
|
||||||
int x, y, i;
|
|
||||||
char label[1500];
|
|
||||||
|
|
||||||
y = 2;
|
|
||||||
x = 10;
|
|
||||||
uint8_t curent_color = 0;
|
|
||||||
for (i = 0; i < n; ++i) {
|
|
||||||
wins[i] = newwin(NLINES, NCOLS, y, x);
|
|
||||||
{
|
|
||||||
std::string sub_name = marks_json["Subjects"][i]["Subject"]["Name"];
|
|
||||||
std::string sub_avg_s = marks_json["Subjects"][i]["AverageText"];
|
|
||||||
|
|
||||||
sprintf(label, "%s - avg: %s", sub_name.c_str(), sub_avg_s.c_str());
|
|
||||||
}
|
|
||||||
curent_color++;
|
|
||||||
if (curent_color >= 7) {
|
|
||||||
curent_color = 1;
|
|
||||||
}
|
|
||||||
win_show(wins[i], label, curent_color);
|
|
||||||
x += 40;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Show the window with a border and a label */
|
|
||||||
void win_show(WINDOW *win, char *label, int label_color) {
|
|
||||||
int startx, starty, height, width;
|
|
||||||
|
|
||||||
getbegyx(win, starty, startx);
|
|
||||||
getmaxyx(win, height, width);
|
|
||||||
|
|
||||||
box(win, 0, 0);
|
|
||||||
mvwaddch(win, 2, 0, ACS_LTEE);
|
|
||||||
mvwhline(win, 2, 1, ACS_HLINE, width - 2);
|
|
||||||
mvwaddch(win, 2, width - 1, ACS_RTEE);
|
|
||||||
|
|
||||||
print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color));
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
void marks_page();
|
|
@ -1,12 +1,7 @@
|
|||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using nlohmann::json;
|
|
||||||
|
|
||||||
extern CURL *curl;
|
extern CURL *curl;
|
||||||
namespace bakaapi {
|
namespace bakaapi {
|
||||||
void login(std::string username, std::string password);
|
void login(std::string username, std::string password);
|
||||||
void refresh_access_token();
|
void refresh_access_token();
|
||||||
json get_grades();
|
|
||||||
} // namespace bakaapi
|
} // namespace bakaapi
|
Loading…
x
Reference in New Issue
Block a user