Compare commits

..

No commits in common. "master" and "v0.8.1" have entirely different histories.

6 changed files with 20 additions and 99 deletions

View File

@ -10,6 +10,5 @@
> - [x] Login
> - [x] Marks
> - [x] Timetable
> - [x] Komens
> - [ ] Komens
> - [ ] Absence
> - [ ] Homework

View File

@ -1,7 +1,7 @@
#include <string_view>
#ifndef VERSION
#define VERSION "0.8.2"
#define VERSION "0.8.1"
#define NAME "bakatui"
inline constexpr auto hash_djb2a(const std::string_view sv) {
@ -12,7 +12,7 @@ inline constexpr auto hash_djb2a(const std::string_view sv) {
return hash;
}
inline constexpr auto operator""_sh(const char *str, size_t len) {
inline constexpr auto operator"" _sh(const char *str, size_t len) {
return hash_djb2a(std::string_view{str, len});
}

View File

@ -5,12 +5,10 @@
#include "types.h"
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <curses.h>
#include <cwchar>
#include <future>
#include <menu.h>
#include <ncurses.h>
#include <nlohmann/json.hpp>
@ -201,42 +199,12 @@ void komens_page(koment_type type) {
clrtoeol();
refresh();
char progress_bar[20];
std::fill(progress_bar, progress_bar + 20, '.');
LimitedInt progress_index(0, 0, sizeof(progress_bar) - 1);
// Download the attachment
auto future = std::async(
std::launch::async, bakaapi::download_attachment,
bakaapi::download_attachment(
resp_from_api["Messages"][item_index(current_item(
komens_choise_menu.menu))]["Attachments"][index]["Id"]
.get<std::string>(),
path);
while (true) {
if (future.wait_for(std::chrono::seconds(1)) ==
std::future_status::ready) {
// Future has completed
int result = future.get();
if (result != 0) {
attron(COLOR_PAIR(COLOR_RED));
mvprintw(LINES - 1, 0, "Download failed with error code: %d",
result);
attroff(COLOR_PAIR(COLOR_RED));
} else {
attron(COLOR_PAIR(COLOR_GREEN));
mvprintw(LINES - 1, 0, "Download completed successfully");
attroff(COLOR_PAIR(COLOR_GREEN));
}
break;
} else {
progress_bar[progress_index] = '#';
// Future is still running
mvprintw(LINES - 1, 0, "%s", progress_bar);
progress_bar[progress_index] = '.';
progress_index++;
}
}
komens_print_usage_message();
}
}
@ -305,7 +273,7 @@ void insert_content(WINDOW *content_win, WINDOW *attachment_win,
mvwprintw(attachment_win, j + 1, 0, "%zu>", j + 1);
wattroff(attachment_win, COLOR_PAIR(COLOR_MAGENTA));
}
{ // remove duplicating edges
{ // remove duplicating spaces
unsigned short attachment_win_top, attachment_win_left,
attachment_win_height, attachment_win_width;
getbegyx(attachment_win, attachment_win_top, attachment_win_left);
@ -316,10 +284,6 @@ void insert_content(WINDOW *content_win, WINDOW *attachment_win,
}
refresh();
wrefresh(attachment_win);
} else {
// remove attachment window if there are no attachments
wclear(attachment_win);
wrefresh(attachment_win);
}
}

View File

@ -99,9 +99,8 @@ void main_menu() {
choicesFuncs[item_index(current_item(main_menu.menu))]();
current_allocated = &main_menu_allocated;
pos_menu_cursor(main_menu.menu);
wrefresh(main_menu.win);
refresh();
redrawwin(main_menu.win);
wrefresh(main_menu.win);
break;
}
wrefresh(main_menu.win);

View File

@ -38,7 +38,6 @@ void win_show(WINDOW *win, const wchar_t *label, const int label_color,
void marks_page() {
current_allocated = &marks_allocated;
curs_set(0);
// thanks to lambda i can make this const
const json resp_from_api = [&]() -> json {
@ -133,7 +132,6 @@ void marks_page() {
endwin();
clear();
delete_all(&marks_allocated);
curs_set(1);
}
/* Put all the windows */

View File

@ -6,7 +6,6 @@
#include "net.h"
#include "types.h"
#include <bits/chrono.h>
#include <climits>
#include <cstdint>
#include <cstdio>
#include <ctime>
@ -27,16 +26,6 @@ using nlohmann::json;
#define DEFAULT_OFFSET 3
#define REMOVED_COLOR_PAIR COLOR_GREEN
#define ROOMCHANGED_COLOR_PAIR COLOR_MAGENTA
#define SUBSTITUTION_COLOR_PAIR COLOR_YELLOW
#define ADDED_COLOR_PAIR COLOR_BLUE
#define HELP_TEXT \
"Arrows/hjkl to select | ENTER to show info | p/n to select weeks |F1 to " \
"exit"
#define HELP_TEXT_LENGTH sizeof(HELP_TEXT) - 1
std::vector<allocation> timetable_allocated;
const wchar_t *day_abriviations[] = {nullptr, L"Mo", L"Tu", L"We",
@ -290,32 +279,9 @@ reload_for_new_week:
}
}
attron(COLOR_PAIR(COLOR_BLUE));
mvprintw(LINES - 2, 0, HELP_TEXT);
attroff(COLOR_PAIR(COLOR_BLUE));
{
constexpr char *change_types[] = {"Canceled/Removed", "RoomChanged",
"Substitution", "Added"};
constexpr uint8_t change_types_colors[] = {
REMOVED_COLOR_PAIR, ROOMCHANGED_COLOR_PAIR, SUBSTITUTION_COLOR_PAIR,
ADDED_COLOR_PAIR};
for (uint8_t i = 0; i < ARRAY_SIZE(change_types); i++) {
init_pair(UCHAR_MAX - i, COLOR_BLACK, change_types_colors[i]);
}
uint8_t text_offset = 1;
for (uint8_t i = 0; i < ARRAY_SIZE(change_types); i++) {
attron(COLOR_PAIR(UCHAR_MAX - i));
mvprintw(LINES - 2, HELP_TEXT_LENGTH + text_offset, "%s",
change_types[i]);
attroff(COLOR_PAIR(UCHAR_MAX - i));
text_offset += strlen(change_types[i]) + 1;
}
}
attron(COLOR_PAIR(COLOR_BLUE));
mvprintw(LINES - 2, 0,
"Arrows/hjkl to select | ENTER to show info | p/n to select weeks "
"|F1 to exit");
{
std::tm end_week = local_time;
std::tm start_week = local_time;
@ -330,14 +296,13 @@ reload_for_new_week:
.get<uint8_t>();
// Calculate days back to start day (handles week wraparound)
uint8_t days_back = (current_wday >= start_day)
? (current_wday - start_day)
: (current_wday + 7 - start_day);
int days_back = (current_wday >= start_day)
? (current_wday - start_day)
: (current_wday + 7 - start_day);
// Calculate days forward to end day (handles week wraparound)
uint8_t days_forward = (current_wday <= end_day)
? (end_day - current_wday)
: (end_day + 7 - current_wday);
int days_forward = (current_wday <= end_day) ? (end_day - current_wday)
: (end_day + 7 - current_wday);
// Adjust dates
start_week.tm_mday -= days_back;
@ -654,24 +619,20 @@ void draw_cells(uint8_t num_of_columns, uint8_t num_of_days,
hash_djb2a(atom->at("Change")["ChangeType"].get<std::string>())) {
case "Canceled"_sh:
case "Removed"_sh:
wattron(cells[i][j], COLOR_PAIR(REMOVED_COLOR_PAIR));
wattron(cells[i][j], COLOR_PAIR(COLOR_GREEN));
box(cells[i][j], 0, 0);
wattroff(cells[i][j], COLOR_PAIR(REMOVED_COLOR_PAIR));
wattroff(cells[i][j], COLOR_PAIR(COLOR_GREEN));
break;
case "RoomChanged"_sh:
wattron(cells[i][j], COLOR_PAIR(ROOMCHANGED_COLOR_PAIR));
box(cells[i][j], 0, 0);
wattroff(cells[i][j], COLOR_PAIR(ROOMCHANGED_COLOR_PAIR));
break;
case "Substitution"_sh:
wattron(cells[i][j], COLOR_PAIR(SUBSTITUTION_COLOR_PAIR));
wattron(cells[i][j], COLOR_PAIR(COLOR_YELLOW));
box(cells[i][j], 0, 0);
wattroff(cells[i][j], COLOR_PAIR(SUBSTITUTION_COLOR_PAIR));
wattroff(cells[i][j], COLOR_PAIR(COLOR_YELLOW));
break;
case "Added"_sh:
wattron(cells[i][j], COLOR_PAIR(ADDED_COLOR_PAIR));
wattron(cells[i][j], COLOR_PAIR(COLOR_BLUE));
box(cells[i][j], 0, 0);
wattroff(cells[i][j], COLOR_PAIR(ADDED_COLOR_PAIR));
wattroff(cells[i][j], COLOR_PAIR(COLOR_BLUE));
break;
default:
// TODO add error handling