ui: shows percentages in progress bar
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# TODO:
|
# TODO:
|
||||||
|
|
||||||
## Current:
|
## Current:
|
||||||
- [ ] Show download/upload progress in percentages
|
- [x] Show download/upload progress in percentages
|
||||||
- [ ] File upload multiline description (window)
|
- [ ] File upload multiline description (window)
|
||||||
- [ ] Sorting in the file list
|
- [ ] Sorting in the file list
|
||||||
- [ ] Resume download
|
- [ ] Resume download
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ void file_download(file_args_t *f_args, query_args_t *q_args) {
|
|||||||
if (qlen) {
|
if (qlen) {
|
||||||
it_count++;
|
it_count++;
|
||||||
if (!(it_count % it_interval)) {
|
if (!(it_count % it_interval)) {
|
||||||
pb->procent = progress;
|
pb->percentage = progress;
|
||||||
d->needs_update = true;
|
d->needs_update = true;
|
||||||
} else {
|
} else {
|
||||||
q_args->buf_used = 0;
|
q_args->buf_used = 0;
|
||||||
@@ -205,7 +205,7 @@ int32_t file_upload_start(query_args_t *q_args) {
|
|||||||
} else { \
|
} else { \
|
||||||
it_count++; \
|
it_count++; \
|
||||||
if (!(it_count % it_interval)) { \
|
if (!(it_count % it_interval)) { \
|
||||||
pb->procent = progress; \
|
pb->percentage = progress; \
|
||||||
d->needs_update = true; \
|
d->needs_update = true; \
|
||||||
} \
|
} \
|
||||||
q_args->file->rest -= wlen; \
|
q_args->file->rest -= wlen; \
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ w_pgb_ui_t *w_pgb_ui_init(WINDOW **win, w_t *w_parent) {
|
|||||||
WINDOW *win_par = *(w_parent->w_parent->parent_win);
|
WINDOW *win_par = *(w_parent->w_parent->parent_win);
|
||||||
w_pgb_ui_t *pb = malloc(sizeof(w_pgb_ui_t));
|
w_pgb_ui_t *pb = malloc(sizeof(w_pgb_ui_t));
|
||||||
w_init(&pb->w, w_parent, win, "");
|
w_init(&pb->w, w_parent, win, "");
|
||||||
pb->procent = 0;
|
pb->percentage = 0;
|
||||||
pb->text[0] = '\0';
|
pb->text[0] = '\0';
|
||||||
pb->w.sz.y = 4;
|
pb->w.sz.y = 4;
|
||||||
pb->w.sz.x = getmaxx(win_par) / 10 * 9;
|
pb->w.sz.x = getmaxx(win_par) / 10 * 9;
|
||||||
@@ -25,17 +25,23 @@ void w_pgb_ui_draw(w_pgb_ui_t *pb) {
|
|||||||
|
|
||||||
wattrset(win, COLOR_PAIR(modal_color_pair));
|
wattrset(win, COLOR_PAIR(modal_color_pair));
|
||||||
|
|
||||||
|
/* top line */
|
||||||
mvwhline(win, margin_y, margin_x, 0, pb->w.sz.x - 1);
|
mvwhline(win, margin_y, margin_x, 0, pb->w.sz.x - 1);
|
||||||
|
|
||||||
float procent = pb->procent;
|
int center = pb->w.sz.x / 2 - 3;
|
||||||
procent /= 100;
|
|
||||||
int32_t filled_num = procent * pb->w.sz.x;
|
mvwprintw(win, margin_y, margin_x + center, "| %d%% |", pb->percentage);
|
||||||
|
|
||||||
|
float percentage = pb->percentage;
|
||||||
|
percentage /= 100;
|
||||||
|
int32_t filled_num = percentage * pb->w.sz.x;
|
||||||
if (filled_num > 2) {
|
if (filled_num > 2) {
|
||||||
filled_num -= 2;
|
filled_num -= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < 3; i++) {
|
|
||||||
wattrset(win, COLOR_PAIR(1) | A_REVERSE);
|
wattrset(win, COLOR_PAIR(1) | A_REVERSE);
|
||||||
|
|
||||||
|
for (int i = 1; i < 3; i++) { /* two lines */
|
||||||
mvwprintw(win, margin_y + i, margin_x + 1, "%*s", filled_num, "");
|
mvwprintw(win, margin_y + i, margin_x + 1, "%*s", filled_num, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,12 +49,12 @@ void w_pgb_ui_draw(w_pgb_ui_t *pb) {
|
|||||||
|
|
||||||
// bottom line
|
// bottom line
|
||||||
mvwhline(win, margin_y + 3, margin_x, 0, pb->w.sz.x - 1);
|
mvwhline(win, margin_y + 3, margin_x, 0, pb->w.sz.x - 1);
|
||||||
// left
|
// left corners
|
||||||
mvwvline(win, margin_y, margin_x, ACS_ULCORNER, 1);
|
mvwvline(win, margin_y, margin_x, ACS_ULCORNER, 1);
|
||||||
mvwvline(win, margin_y + 1, margin_x, 0, 1);
|
mvwvline(win, margin_y + 1, margin_x, 0, 1);
|
||||||
mvwvline(win, margin_y + 2, margin_x, 0, 1);
|
mvwvline(win, margin_y + 2, margin_x, 0, 1);
|
||||||
mvwvline(win, margin_y + 3, margin_x, ACS_LLCORNER, 1);
|
mvwvline(win, margin_y + 3, margin_x, ACS_LLCORNER, 1);
|
||||||
// right
|
// right corners
|
||||||
mvwvline(win, margin_y, margin_x + pb->w.sz.x - 2, ACS_URCORNER, 1);
|
mvwvline(win, margin_y, margin_x + pb->w.sz.x - 2, ACS_URCORNER, 1);
|
||||||
mvwvline(win, margin_y + 1, margin_x + pb->w.sz.x - 2, 0, 1);
|
mvwvline(win, margin_y + 1, margin_x + pb->w.sz.x - 2, 0, 1);
|
||||||
mvwvline(win, margin_y + 2, margin_x + pb->w.sz.x - 2, 0, 1);
|
mvwvline(win, margin_y + 2, margin_x + pb->w.sz.x - 2, 0, 1);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
w_t w;
|
w_t w;
|
||||||
int32_t procent;
|
int32_t percentage;
|
||||||
char text[24];
|
char text[24];
|
||||||
} w_pgb_ui_t;
|
} w_pgb_ui_t;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user