0001
0002 #include <linux/kernel.h>
0003 #include "../progress.h"
0004 #include "../libslang.h"
0005 #include "../ui.h"
0006 #include "tui.h"
0007 #include "units.h"
0008 #include "../browser.h"
0009
0010 static void __tui_progress__init(struct ui_progress *p)
0011 {
0012 p->next = p->step = p->total / (SLtt_Screen_Cols - 2) ?: 1;
0013 }
0014
0015 static int get_title(struct ui_progress *p, char *buf, size_t size)
0016 {
0017 char buf_cur[20];
0018 char buf_tot[20];
0019 int ret;
0020
0021 ret = unit_number__scnprintf(buf_cur, sizeof(buf_cur), p->curr);
0022 ret += unit_number__scnprintf(buf_tot, sizeof(buf_tot), p->total);
0023
0024 return ret + scnprintf(buf, size, "%s [%s/%s]",
0025 p->title, buf_cur, buf_tot);
0026 }
0027
0028 static void tui_progress__update(struct ui_progress *p)
0029 {
0030 char buf[100], *title = (char *) p->title;
0031 int bar, y;
0032
0033
0034
0035
0036 if (use_browser <= 0)
0037 return;
0038
0039 if (p->total == 0)
0040 return;
0041
0042 if (p->size) {
0043 get_title(p, buf, sizeof(buf));
0044 title = buf;
0045 }
0046
0047 ui__refresh_dimensions(false);
0048 pthread_mutex_lock(&ui__lock);
0049 y = SLtt_Screen_Rows / 2 - 2;
0050 SLsmg_set_color(0);
0051 SLsmg_draw_box(y, 0, 3, SLtt_Screen_Cols);
0052 SLsmg_gotorc(y++, 1);
0053 SLsmg_write_string(title);
0054 SLsmg_fill_region(y, 1, 1, SLtt_Screen_Cols - 2, ' ');
0055 SLsmg_set_color(HE_COLORSET_SELECTED);
0056 bar = ((SLtt_Screen_Cols - 2) * p->curr) / p->total;
0057 SLsmg_fill_region(y, 1, 1, bar, ' ');
0058 SLsmg_refresh();
0059 pthread_mutex_unlock(&ui__lock);
0060 }
0061
0062 static void tui_progress__finish(void)
0063 {
0064 int y;
0065
0066 if (use_browser <= 0)
0067 return;
0068
0069 ui__refresh_dimensions(false);
0070 pthread_mutex_lock(&ui__lock);
0071 y = SLtt_Screen_Rows / 2 - 2;
0072 SLsmg_set_color(0);
0073 SLsmg_fill_region(y, 0, 3, SLtt_Screen_Cols, ' ');
0074 SLsmg_refresh();
0075 pthread_mutex_unlock(&ui__lock);
0076 }
0077
0078 static struct ui_progress_ops tui_progress__ops = {
0079 .init = __tui_progress__init,
0080 .update = tui_progress__update,
0081 .finish = tui_progress__finish,
0082 };
0083
0084 void tui_progress__init(void)
0085 {
0086 ui_progress__ops = &tui_progress__ops;
0087 }