Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
34cea7f7 | 2 | #include "../cache.h" |
7da5c85d NK |
3 | #include "../progress.h" |
4 | #include "../libslang.h" | |
5 | #include "../ui.h" | |
4779a2e9 | 6 | #include "tui.h" |
7da5c85d | 7 | #include "../browser.h" |
34cea7f7 | 8 | |
4d3001fd | 9 | static void tui_progress__update(struct ui_progress *p) |
34cea7f7 | 10 | { |
ca59bcbc | 11 | int bar, y; |
34cea7f7 ACM |
12 | /* |
13 | * FIXME: We should have a per UI backend way of showing progress, | |
14 | * stdio will just show a percentage as NN%, etc. | |
15 | */ | |
16 | if (use_browser <= 0) | |
17 | return; | |
34cea7f7 | 18 | |
4d3001fd | 19 | if (p->total == 0) |
18b55235 ACM |
20 | return; |
21 | ||
d53e57d0 | 22 | ui__refresh_dimensions(false); |
ca59bcbc ACM |
23 | pthread_mutex_lock(&ui__lock); |
24 | y = SLtt_Screen_Rows / 2 - 2; | |
25 | SLsmg_set_color(0); | |
26 | SLsmg_draw_box(y, 0, 3, SLtt_Screen_Cols); | |
27 | SLsmg_gotorc(y++, 1); | |
4d3001fd | 28 | SLsmg_write_string((char *)p->title); |
d53e57d0 | 29 | SLsmg_fill_region(y, 1, 1, SLtt_Screen_Cols - 2, ' '); |
ca59bcbc | 30 | SLsmg_set_color(HE_COLORSET_SELECTED); |
4d3001fd | 31 | bar = ((SLtt_Screen_Cols - 2) * p->curr) / p->total; |
ca59bcbc ACM |
32 | SLsmg_fill_region(y, 1, 1, bar, ' '); |
33 | SLsmg_refresh(); | |
34 | pthread_mutex_unlock(&ui__lock); | |
34cea7f7 | 35 | } |
688f2f5b | 36 | |
1e259ad4 ACM |
37 | static void tui_progress__finish(void) |
38 | { | |
39 | int y; | |
40 | ||
41 | if (use_browser <= 0) | |
42 | return; | |
43 | ||
44 | ui__refresh_dimensions(false); | |
45 | pthread_mutex_lock(&ui__lock); | |
46 | y = SLtt_Screen_Rows / 2 - 2; | |
47 | SLsmg_set_color(0); | |
48 | SLsmg_fill_region(y, 0, 3, SLtt_Screen_Cols, ' '); | |
49 | SLsmg_refresh(); | |
50 | pthread_mutex_unlock(&ui__lock); | |
51 | } | |
52 | ||
4779a2e9 | 53 | static struct ui_progress_ops tui_progress__ops = |
688f2f5b | 54 | { |
1e259ad4 ACM |
55 | .update = tui_progress__update, |
56 | .finish = tui_progress__finish, | |
688f2f5b NK |
57 | }; |
58 | ||
4779a2e9 | 59 | void tui_progress__init(void) |
688f2f5b | 60 | { |
4779a2e9 | 61 | ui_progress__ops = &tui_progress__ops; |
688f2f5b | 62 | } |