Compare commits
4 Commits
v0.8.1
...
e51088eb26
| Author | SHA1 | Date | |
|---|---|---|---|
| e51088eb26 | |||
| ad6f748899 | |||
| 1d0d4e2362 | |||
| a35242b420 |
@@ -10,5 +10,6 @@
|
|||||||
> - [x] Login
|
> - [x] Login
|
||||||
> - [x] Marks
|
> - [x] Marks
|
||||||
> - [x] Timetable
|
> - [x] Timetable
|
||||||
> - [ ] Komens
|
> - [x] Komens
|
||||||
> - [ ] Absence
|
> - [ ] Absence
|
||||||
|
> - [ ] Homework
|
||||||
|
|||||||
+38
-2
@@ -5,10 +5,12 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <cwchar>
|
#include <cwchar>
|
||||||
|
#include <future>
|
||||||
#include <menu.h>
|
#include <menu.h>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
@@ -199,12 +201,42 @@ void komens_page(koment_type type) {
|
|||||||
clrtoeol();
|
clrtoeol();
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
|
char progress_bar[20];
|
||||||
|
std::fill(progress_bar, progress_bar + 20, '.');
|
||||||
|
LimitedInt progress_index(0, 0, sizeof(progress_bar) - 1);
|
||||||
// Download the attachment
|
// Download the attachment
|
||||||
bakaapi::download_attachment(
|
auto future = std::async(
|
||||||
|
std::launch::async, bakaapi::download_attachment,
|
||||||
resp_from_api["Messages"][item_index(current_item(
|
resp_from_api["Messages"][item_index(current_item(
|
||||||
komens_choise_menu.menu))]["Attachments"][index]["Id"]
|
komens_choise_menu.menu))]["Attachments"][index]["Id"]
|
||||||
.get<std::string>(),
|
.get<std::string>(),
|
||||||
path);
|
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();
|
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);
|
mvwprintw(attachment_win, j + 1, 0, "%zu>", j + 1);
|
||||||
wattroff(attachment_win, COLOR_PAIR(COLOR_MAGENTA));
|
wattroff(attachment_win, COLOR_PAIR(COLOR_MAGENTA));
|
||||||
}
|
}
|
||||||
{ // remove duplicating spaces
|
{ // remove duplicating edges
|
||||||
unsigned short attachment_win_top, attachment_win_left,
|
unsigned short attachment_win_top, attachment_win_left,
|
||||||
attachment_win_height, attachment_win_width;
|
attachment_win_height, attachment_win_width;
|
||||||
getbegyx(attachment_win, attachment_win_top, attachment_win_left);
|
getbegyx(attachment_win, attachment_win_top, attachment_win_left);
|
||||||
@@ -284,6 +316,10 @@ void insert_content(WINDOW *content_win, WINDOW *attachment_win,
|
|||||||
}
|
}
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
|
wrefresh(attachment_win);
|
||||||
|
} else {
|
||||||
|
// remove attachment window if there are no attachments
|
||||||
|
wclear(attachment_win);
|
||||||
wrefresh(attachment_win);
|
wrefresh(attachment_win);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user