From 4aca8fb5a47e3a2fc53bdc2ecce38c5e12cc08a9 Mon Sep 17 00:00:00 2001 From: Alexander Zhylin Date: Tue, 2 Jun 2026 14:51:52 +0300 Subject: [PATCH] ui: shows percentages in progress bar --- TODO.md | 2 +- src/file_processor.c | 4 ++-- src/widget/progress_bar.c | 22 ++++++++++++++-------- src/widget/progress_bar.h | 2 +- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/TODO.md b/TODO.md index 7ca0858..6e31356 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,7 @@ # TODO: ## Current: -- [ ] Show download/upload progress in percentages +- [x] Show download/upload progress in percentages - [ ] File upload multiline description (window) - [ ] Sorting in the file list - [ ] Resume download diff --git a/src/file_processor.c b/src/file_processor.c index 5fd9bc6..8b8933e 100644 --- a/src/file_processor.c +++ b/src/file_processor.c @@ -131,7 +131,7 @@ void file_download(file_args_t *f_args, query_args_t *q_args) { if (qlen) { it_count++; if (!(it_count % it_interval)) { - pb->procent = progress; + pb->percentage = progress; d->needs_update = true; } else { q_args->buf_used = 0; @@ -205,7 +205,7 @@ int32_t file_upload_start(query_args_t *q_args) { } else { \ it_count++; \ if (!(it_count % it_interval)) { \ - pb->procent = progress; \ + pb->percentage = progress; \ d->needs_update = true; \ } \ q_args->file->rest -= wlen; \ diff --git a/src/widget/progress_bar.c b/src/widget/progress_bar.c index f40f5c7..faf43ca 100644 --- a/src/widget/progress_bar.c +++ b/src/widget/progress_bar.c @@ -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); w_pgb_ui_t *pb = malloc(sizeof(w_pgb_ui_t)); w_init(&pb->w, w_parent, win, ""); - pb->procent = 0; + pb->percentage = 0; pb->text[0] = '\0'; pb->w.sz.y = 4; 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)); + /* top line */ mvwhline(win, margin_y, margin_x, 0, pb->w.sz.x - 1); - float procent = pb->procent; - procent /= 100; - int32_t filled_num = procent * pb->w.sz.x; + int center = pb->w.sz.x / 2 - 3; + + 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) { 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, ""); } @@ -43,12 +49,12 @@ void w_pgb_ui_draw(w_pgb_ui_t *pb) { // bottom line 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 + 1, margin_x, 0, 1); mvwvline(win, margin_y + 2, margin_x, 0, 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 + 1, margin_x + pb->w.sz.x - 2, 0, 1); mvwvline(win, margin_y + 2, margin_x + pb->w.sz.x - 2, 0, 1); diff --git a/src/widget/progress_bar.h b/src/widget/progress_bar.h index 869ad74..907860a 100644 --- a/src/widget/progress_bar.h +++ b/src/widget/progress_bar.h @@ -8,7 +8,7 @@ typedef struct { w_t w; - int32_t procent; + int32_t percentage; char text[24]; } w_pgb_ui_t;