1 // SPDX-License-Identifier: GPL-2.0 2 #include "../cache.h" 3 #include "../progress.h" 4 #include "../libslang.h" 5 #include "../ui.h" 6 #include "tui.h" 7 #include "../browser.h" 8 9 static void tui_progress__update(struct ui_progress *p) 10 { 11 int bar, y; 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; 18 19 if (p->total == 0) 20 return; 21 22 ui__refresh_dimensions(false); 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); 28 SLsmg_write_string((char *)p->title); 29 SLsmg_fill_region(y, 1, 1, SLtt_Screen_Cols - 2, ' '); 30 SLsmg_set_color(HE_COLORSET_SELECTED); 31 bar = ((SLtt_Screen_Cols - 2) * p->curr) / p->total; 32 SLsmg_fill_region(y, 1, 1, bar, ' '); 33 SLsmg_refresh(); 34 pthread_mutex_unlock(&ui__lock); 35 } 36 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 53 static struct ui_progress_ops tui_progress__ops = 54 { 55 .update = tui_progress__update, 56 .finish = tui_progress__finish, 57 }; 58 59 void tui_progress__init(void) 60 { 61 ui_progress__ops = &tui_progress__ops; 62 } 63