Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3) #include "../progress.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4) #include "../libslang.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) #include "../ui.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include "tui.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include "units.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include "../browser.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) static void __tui_progress__init(struct ui_progress *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) 	p->next = p->step = p->total / (SLtt_Screen_Cols - 2) ?: 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) static int get_title(struct ui_progress *p, char *buf, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 	char buf_cur[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 	char buf_tot[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 	ret  = unit_number__scnprintf(buf_cur, sizeof(buf_cur), p->curr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	ret += unit_number__scnprintf(buf_tot, sizeof(buf_tot), p->total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	return ret + scnprintf(buf, size, "%s [%s/%s]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 			       p->title, buf_cur, buf_tot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static void tui_progress__update(struct ui_progress *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	char buf[100], *title = (char *) p->title;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	int bar, y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	 * FIXME: We should have a per UI backend way of showing progress,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	 * stdio will just show a percentage as NN%, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	if (use_browser <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	if (p->total == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	if (p->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 		get_title(p, buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 		title = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	ui__refresh_dimensions(false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	pthread_mutex_lock(&ui__lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	y = SLtt_Screen_Rows / 2 - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	SLsmg_set_color(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	SLsmg_draw_box(y, 0, 3, SLtt_Screen_Cols);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	SLsmg_gotorc(y++, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 	SLsmg_write_string(title);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	SLsmg_fill_region(y, 1, 1, SLtt_Screen_Cols - 2, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	SLsmg_set_color(HE_COLORSET_SELECTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	bar = ((SLtt_Screen_Cols - 2) * p->curr) / p->total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	SLsmg_fill_region(y, 1, 1, bar, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 	SLsmg_refresh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	pthread_mutex_unlock(&ui__lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static void tui_progress__finish(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	int y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	if (use_browser <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	ui__refresh_dimensions(false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	pthread_mutex_lock(&ui__lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	y = SLtt_Screen_Rows / 2 - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	SLsmg_set_color(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 	SLsmg_fill_region(y, 0, 3, SLtt_Screen_Cols, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 	SLsmg_refresh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 	pthread_mutex_unlock(&ui__lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static struct ui_progress_ops tui_progress__ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 	.init   = __tui_progress__init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 	.update = tui_progress__update,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 	.finish = tui_progress__finish,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) void tui_progress__init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 	ui_progress__ops = &tui_progress__ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }