Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
15b0344dc8 | |||
73fed3df0e | |||
6b3d47ceed | |||
89c67035ca | |||
0486d9fb22 | |||
e51088eb26 | |||
ad6f748899 | |||
1d0d4e2362 | |||
a35242b420 |
@ -10,5 +10,6 @@
|
||||
> - [x] Login
|
||||
> - [x] Marks
|
||||
> - [x] Timetable
|
||||
> - [ ] Komens
|
||||
> - [x] Komens
|
||||
> - [ ] Absence
|
||||
> - [ ] Homework
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <string_view>
|
||||
#ifndef VERSION
|
||||
|
||||
#define VERSION "0.8.1"
|
||||
#define VERSION "0.8.2"
|
||||
#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});
|
||||
}
|
||||
|
||||
|
@ -5,10 +5,12 @@
|
||||
#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>
|
||||
@ -199,12 +201,42 @@ 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
|
||||
bakaapi::download_attachment(
|
||||
auto future = std::async(
|
||||
std::launch::async, 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();
|
||||
}
|
||||
}
|
||||
@ -273,7 +305,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 spaces
|
||||
{ // remove duplicating edges
|
||||
unsigned short attachment_win_top, attachment_win_left,
|
||||
attachment_win_height, attachment_win_width;
|
||||
getbegyx(attachment_win, attachment_win_top, attachment_win_left);
|
||||
@ -284,6 +316,10 @@ 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);
|
||||
}
|
||||
}
|
||||
|
@ -99,8 +99,9 @@ void main_menu() {
|
||||
choicesFuncs[item_index(current_item(main_menu.menu))]();
|
||||
current_allocated = &main_menu_allocated;
|
||||
pos_menu_cursor(main_menu.menu);
|
||||
refresh();
|
||||
wrefresh(main_menu.win);
|
||||
refresh();
|
||||
redrawwin(main_menu.win);
|
||||
break;
|
||||
}
|
||||
wrefresh(main_menu.win);
|
||||
|
@ -38,6 +38,7 @@ 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 {
|
||||
@ -132,6 +133,7 @@ void marks_page() {
|
||||
endwin();
|
||||
clear();
|
||||
delete_all(&marks_allocated);
|
||||
curs_set(1);
|
||||
}
|
||||
|
||||
/* Put all the windows */
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "net.h"
|
||||
#include "types.h"
|
||||
#include <bits/chrono.h>
|
||||
#include <climits>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
@ -26,6 +27,16 @@ 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",
|
||||
@ -279,9 +290,32 @@ reload_for_new_week:
|
||||
}
|
||||
}
|
||||
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");
|
||||
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));
|
||||
{
|
||||
std::tm end_week = local_time;
|
||||
std::tm start_week = local_time;
|
||||
@ -296,13 +330,14 @@ reload_for_new_week:
|
||||
.get<uint8_t>();
|
||||
|
||||
// Calculate days back to start day (handles week wraparound)
|
||||
int days_back = (current_wday >= start_day)
|
||||
? (current_wday - start_day)
|
||||
: (current_wday + 7 - start_day);
|
||||
uint8_t days_back = (current_wday >= start_day)
|
||||
? (current_wday - start_day)
|
||||
: (current_wday + 7 - start_day);
|
||||
|
||||
// Calculate days forward to end day (handles week wraparound)
|
||||
int days_forward = (current_wday <= end_day) ? (end_day - current_wday)
|
||||
: (end_day + 7 - current_wday);
|
||||
uint8_t days_forward = (current_wday <= end_day)
|
||||
? (end_day - current_wday)
|
||||
: (end_day + 7 - current_wday);
|
||||
|
||||
// Adjust dates
|
||||
start_week.tm_mday -= days_back;
|
||||
@ -619,20 +654,24 @@ 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(COLOR_GREEN));
|
||||
wattron(cells[i][j], COLOR_PAIR(REMOVED_COLOR_PAIR));
|
||||
box(cells[i][j], 0, 0);
|
||||
wattroff(cells[i][j], COLOR_PAIR(COLOR_GREEN));
|
||||
wattroff(cells[i][j], COLOR_PAIR(REMOVED_COLOR_PAIR));
|
||||
break;
|
||||
case "RoomChanged"_sh:
|
||||
case "Substitution"_sh:
|
||||
wattron(cells[i][j], COLOR_PAIR(COLOR_YELLOW));
|
||||
wattron(cells[i][j], COLOR_PAIR(ROOMCHANGED_COLOR_PAIR));
|
||||
box(cells[i][j], 0, 0);
|
||||
wattroff(cells[i][j], COLOR_PAIR(COLOR_YELLOW));
|
||||
wattroff(cells[i][j], COLOR_PAIR(ROOMCHANGED_COLOR_PAIR));
|
||||
break;
|
||||
case "Substitution"_sh:
|
||||
wattron(cells[i][j], COLOR_PAIR(SUBSTITUTION_COLOR_PAIR));
|
||||
box(cells[i][j], 0, 0);
|
||||
wattroff(cells[i][j], COLOR_PAIR(SUBSTITUTION_COLOR_PAIR));
|
||||
break;
|
||||
case "Added"_sh:
|
||||
wattron(cells[i][j], COLOR_PAIR(COLOR_BLUE));
|
||||
wattron(cells[i][j], COLOR_PAIR(ADDED_COLOR_PAIR));
|
||||
box(cells[i][j], 0, 0);
|
||||
wattroff(cells[i][j], COLOR_PAIR(COLOR_BLUE));
|
||||
wattroff(cells[i][j], COLOR_PAIR(ADDED_COLOR_PAIR));
|
||||
break;
|
||||
default:
|
||||
// TODO add error handling
|
||||
|
Loading…
x
Reference in New Issue
Block a user