marks base
This commit is contained in:
parent
1bc3dc9537
commit
e5c2ae6da5
@ -1,8 +1,15 @@
|
|||||||
#include "marks.h"
|
#include "marks.h"
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
|
#include <fstream>
|
||||||
#include <menu.h>
|
#include <menu.h>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
#include <panel.h>
|
#include <panel.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using nlohmann::json;
|
||||||
|
|
||||||
// Thsi code is based on
|
// Thsi code is based on
|
||||||
// https://github.com/tony/NCURSES-Programming-HOWTO-examples/blob/master/16-panels
|
// https://github.com/tony/NCURSES-Programming-HOWTO-examples/blob/master/16-panels
|
||||||
@ -33,17 +40,30 @@ SOFTWARE.
|
|||||||
#define NLINES 10
|
#define NLINES 10
|
||||||
#define NCOLS 40
|
#define NCOLS 40
|
||||||
|
|
||||||
void init_wins(WINDOW **wins, int n);
|
void init_wins(WINDOW **wins, int n, json marks_json);
|
||||||
void win_show(WINDOW *win, char *label, int label_color);
|
void win_show(WINDOW *win, char *label, int label_color);
|
||||||
void print_in_middle(WINDOW *win, int starty, int startx, int width,
|
void print_in_middle(WINDOW *win, int starty, int startx, int width,
|
||||||
char *string, chtype color);
|
char *string, chtype color);
|
||||||
|
|
||||||
void marks_page() {
|
void marks_page() {
|
||||||
WINDOW *my_wins[3];
|
|
||||||
PANEL *my_panels[3];
|
// 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;
|
PANEL *top;
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
|
setlocale(LC_ALL, "");
|
||||||
/* Initialize curses */
|
/* Initialize curses */
|
||||||
initscr();
|
initscr();
|
||||||
start_color();
|
start_color();
|
||||||
@ -52,24 +72,25 @@ void marks_page() {
|
|||||||
keypad(stdscr, TRUE);
|
keypad(stdscr, TRUE);
|
||||||
|
|
||||||
/* Initialize all the colors */
|
/* Initialize all the colors */
|
||||||
init_pair(1, COLOR_RED, COLOR_BLACK);
|
for (size_t i = 0; i < 8; i++) {
|
||||||
init_pair(2, COLOR_GREEN, COLOR_BLACK);
|
init_pair(i, i, COLOR_BLACK);
|
||||||
init_pair(3, COLOR_BLUE, COLOR_BLACK);
|
}
|
||||||
init_pair(4, COLOR_CYAN, COLOR_BLACK);
|
|
||||||
|
|
||||||
init_wins(my_wins, 3);
|
init_wins(my_wins, resp_from_api["Subjects"].size(), resp_from_api);
|
||||||
|
|
||||||
/* Attach a panel to each window */ /* Order is bottom up */
|
for (size_t i = 0; i < size_my_panels; i++) {
|
||||||
my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */
|
/* Attach a panel to each window Order is bottom up */
|
||||||
my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */
|
my_panels[i] = new_panel(my_wins[i]);
|
||||||
my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */
|
|
||||||
|
|
||||||
/* Set up the user pointers to the next panel */
|
/* Set up the user pointers to the next panel */
|
||||||
set_panel_userptr(my_panels[0], my_panels[1]);
|
if ((i + 1) < size_my_panels) {
|
||||||
set_panel_userptr(my_panels[1], my_panels[2]);
|
set_panel_userptr(my_panels[i], my_panels[(i + 1)]);
|
||||||
set_panel_userptr(my_panels[2], my_panels[0]);
|
} else {
|
||||||
|
set_panel_userptr(my_panels[i], my_panels[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Update the stacking order. 2nd panel will be on top */
|
// Update the stacking order.
|
||||||
update_panels();
|
update_panels();
|
||||||
|
|
||||||
/* Show it on the screen */
|
/* Show it on the screen */
|
||||||
@ -93,16 +114,26 @@ void marks_page() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Put all the windows */
|
/* Put all the windows */
|
||||||
void init_wins(WINDOW **wins, int n) {
|
void init_wins(WINDOW **wins, int n, json marks_json) {
|
||||||
int x, y, i;
|
int x, y, i;
|
||||||
char label[80];
|
char label[1500];
|
||||||
|
|
||||||
y = 2;
|
y = 2;
|
||||||
x = 10;
|
x = 10;
|
||||||
|
uint8_t curent_color = 0;
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
wins[i] = newwin(NLINES, NCOLS, y, x);
|
wins[i] = newwin(NLINES, NCOLS, y, x);
|
||||||
sprintf(label, "Window Number %d", i + 1);
|
{
|
||||||
win_show(wins[i], label, i + 1);
|
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;
|
x += 40;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,3 +0,0 @@
|
|||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
using nlohmann::json;
|
|
@ -1,7 +1,12 @@
|
|||||||
#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