minor changes : )
Some checks failed
/ sync-to-origin (push) Has been cancelled

This commit is contained in:
PoliEcho 2024-12-05 13:52:31 +01:00
parent ac3b0dd59d
commit 1a882baab6
3 changed files with 51 additions and 9 deletions

View File

@ -34,6 +34,7 @@ void safe_exit(int code) {
} }
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
endwin();
exit(code); exit(code);
} }
@ -110,3 +111,20 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width,
wattroff(win, color); wattroff(win, color);
refresh(); refresh();
} }
const std::string WHITESPACE = " \n\r\t\f\v";
std::string ltrim(const std::string &s) {
size_t start = s.find_first_not_of(WHITESPACE);
return (start == std::string::npos) ? "" : s.substr(start);
}
std::string rtrim(const std::string &s) {
size_t end = s.find_last_not_of(WHITESPACE);
return (end == std::string::npos) ? "" : s.substr(0, end + 1);
}
std::string rm_tr_le_whitespace(const std::string &s) {
return rtrim(ltrim(s));
}

View File

@ -6,3 +6,4 @@ std::string SoRAuthFile(bool save, std::string data);
void get_input_and_login(); void get_input_and_login();
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);
std::string rm_tr_le_whitespace(const std::string &s);

View File

@ -1,5 +1,6 @@
#include "marks.h" #include "marks.h"
#include "helper_funcs.h" #include "helper_funcs.h"
#include <cstddef>
#include <cstdint> #include <cstdint>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
@ -41,7 +42,7 @@ SOFTWARE.
#define NCOLS 40 #define NCOLS 40
void init_wins(WINDOW **wins, int n, json marks_json); 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, int width);
void marks_page() { void marks_page() {
@ -70,7 +71,7 @@ void marks_page() {
keypad(stdscr, TRUE); keypad(stdscr, TRUE);
/* Initialize all the colors */ /* Initialize all the colors */
for (size_t i = 0; i < 8; i++) { for (uint8_t i = 0; i < 8; i++) {
init_pair(i, i, COLOR_BLACK); init_pair(i, i, COLOR_BLACK);
} }
@ -97,7 +98,7 @@ void marks_page() {
attroff(COLOR_PAIR(4)); attroff(COLOR_PAIR(4));
doupdate(); doupdate();
top = my_panels[2]; top = my_panels[resp_from_api["Subjects"].size() - 1];
while ((ch = getch()) != KEY_F(1)) { while ((ch = getch()) != KEY_F(1)) {
switch (ch) { switch (ch) {
case 9: case 9:
@ -109,6 +110,8 @@ void marks_page() {
doupdate(); doupdate();
} }
endwin(); endwin();
delete[] my_wins;
delete[] my_panels;
} }
/* Put all the windows */ /* Put all the windows */
@ -131,17 +134,36 @@ void init_wins(WINDOW **wins, int n, json marks_json) {
if (curent_color >= 7) { if (curent_color >= 7) {
curent_color = 1; curent_color = 1;
} }
win_show(wins[i], label, curent_color);
x += 40; // search what mark or label is longest
size_t max_text_length = strlen(label);
for (int i = 0; i < marks_json["Subjects"][n]["Marks"][i].size(); i++) {
size_t tocomp =
rm_tr_le_whitespace(marks_json["Subjects"][n]["Marks"][i]["Caption"])
.length();
if (max_text_length < tocomp) {
max_text_length = tocomp;
}
tocomp =
rm_tr_le_whitespace(marks_json["Subjects"][n]["Marks"][i]["Theme"])
.length();
if (max_text_length < tocomp) {
max_text_length = tocomp;
}
}
int width = max_text_length + 4;
win_show(wins[i], label, curent_color, width);
x += width + 10;
} }
} }
/* Show the window with a border and a label */ /* Show the window with a border and a label */
void win_show(WINDOW *win, char *label, int label_color) { void win_show(WINDOW *win, char *label, int label_color, int width) {
int startx, starty, height, width; int startx, starty, height;
height = 20; height = 20;
wresize(win, height, strlen(label) + 4); wresize(win, height, width);
getbegyx(win, starty, startx); getbegyx(win, starty, startx);
getmaxyx(win, height, width); getmaxyx(win, height, width);
@ -152,4 +174,5 @@ void win_show(WINDOW *win, char *label, int label_color) {
mvwaddch(win, 2, width - 1, ACS_RTEE); mvwaddch(win, 2, width - 1, ACS_RTEE);
print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color)); print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color));
print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color));
} }