xref: /openbmc/linux/tools/perf/ui/tui/progress.c (revision 25cc4eb4)
1 #include "../cache.h"
2 #include "../progress.h"
3 #include "../libslang.h"
4 #include "../ui.h"
5 #include "tui.h"
6 #include "../browser.h"
7 
8 static void __tui_progress__init(struct ui_progress *p)
9 {
10 	p->next = p->step = p->total / (SLtt_Screen_Cols - 2) ?: 1;
11 }
12 
13 static void tui_progress__update(struct ui_progress *p)
14 {
15 	int bar, y;
16 	/*
17 	 * FIXME: We should have a per UI backend way of showing progress,
18 	 * stdio will just show a percentage as NN%, etc.
19 	 */
20 	if (use_browser <= 0)
21 		return;
22 
23 	if (p->total == 0)
24 		return;
25 
26 	ui__refresh_dimensions(false);
27 	pthread_mutex_lock(&ui__lock);
28 	y = SLtt_Screen_Rows / 2 - 2;
29 	SLsmg_set_color(0);
30 	SLsmg_draw_box(y, 0, 3, SLtt_Screen_Cols);
31 	SLsmg_gotorc(y++, 1);
32 	SLsmg_write_string((char *)p->title);
33 	SLsmg_fill_region(y, 1, 1, SLtt_Screen_Cols - 2, ' ');
34 	SLsmg_set_color(HE_COLORSET_SELECTED);
35 	bar = ((SLtt_Screen_Cols - 2) * p->curr) / p->total;
36 	SLsmg_fill_region(y, 1, 1, bar, ' ');
37 	SLsmg_refresh();
38 	pthread_mutex_unlock(&ui__lock);
39 }
40 
41 static void tui_progress__finish(void)
42 {
43 	int y;
44 
45 	if (use_browser <= 0)
46 		return;
47 
48 	ui__refresh_dimensions(false);
49 	pthread_mutex_lock(&ui__lock);
50 	y = SLtt_Screen_Rows / 2 - 2;
51 	SLsmg_set_color(0);
52 	SLsmg_fill_region(y, 0, 3, SLtt_Screen_Cols, ' ');
53 	SLsmg_refresh();
54 	pthread_mutex_unlock(&ui__lock);
55 }
56 
57 static struct ui_progress_ops tui_progress__ops = {
58 	.init   = __tui_progress__init,
59 	.update = tui_progress__update,
60 	.finish = tui_progress__finish,
61 };
62 
63 void tui_progress__init(void)
64 {
65 	ui_progress__ops = &tui_progress__ops;
66 }
67