예제 #1
0
/* Start CPU-X in NCurses mode */
void start_tui_ncurses(Labels *data)
{
	int startx, starty, ch = 0;
	const SizeInfo info = { .height = LINE_COUNT, .width = 70, .start = 1, .tb = 2, .tm = 26, .te = 48 };
	NThrd refr = { .data = data, .info = info };
	WINDOW *win;

	MSG_VERBOSE(_("Starting NCurses TUI..."));
	setenv("TERMINFO", "/lib/terminfo", 0);
	freopen("/dev/null", "a", stderr);
	initscr();
	cbreak();
	noecho();
	curs_set(0);
	halfdelay(0);
	nodelay(stdscr, TRUE);
	keypad(stdscr, TRUE);
	if(opts->color)
	{
		start_color();
		opts->color &= has_colors();
	}

	if(PORTABLE_BINARY && new_version != NULL)
	{
		print_new_version();
		erase();
	}

	starty   = (LINES - info.height) / 2; /* Calculating for a center placement of the window */
	startx   = (COLS  - info.width)  / 2;
	win      = newwin(info.height, info.width, starty, startx);
	refr.win = win;

	refresh();
	main_win(win, info, data);
	ntab_cpu(win, info, data);
	timeout(opts->refr_time * 1000);
	printw(_("Press 'h' to see help.\n"));

	while(ch != 'q')
	{
		ch = getch();
		switch(ch)
		{
			case KEY_LEFT:
				/* Switch to left tab */
				if(page > NO_CPU)
				{
					page--;
					main_win(win, info, data);
					(*func_ptr[page])(win, info, data);
				}
				break;
			case KEY_RIGHT:
				/* Switch to right tab */
				if(page < NO_ABOUT)
				{
					page++;
					main_win(win, info, data);
					(*func_ptr[page])(win, info, data);
				}
				break;
			case KEY_DOWN:
				if(page == NO_CPU && opts->selected_core > 0)
				{
					opts->selected_core--;
					print_activecore(win);
				}
				else if(page == NO_CACHES && opts->bw_test > 0)
				{
					opts->bw_test--;
					print_activetest(win, data);
				}
				else if(page == NO_BENCH && data->b_data->duration > 1)
				{
					data->b_data->duration--;
					print_paramduration(win, info, data);
				}
				break;
			case KEY_NPAGE:
				if(page == NO_BENCH && data->b_data->threads > 1 && !data->b_data->run)
				{
					data->b_data->threads--;
					print_paramthreads(win, info, data);
				}
				break;
			case KEY_UP:
				if(page == NO_CPU && (int) opts->selected_core < data->cpu_count - 1)
				{
					opts->selected_core++;
					print_activecore(win);
				}
				else if(page == NO_CACHES && (int) opts->bw_test < data->w_data->test_count - 1)
				{
					opts->bw_test++;
					print_activetest(win, data);
				}
				else if(page == NO_BENCH && data->b_data->duration < 60 * 24)
				{
					data->b_data->duration++;
					print_paramduration(win, info, data);
				}
				break;
			case KEY_PPAGE:
				if(page == NO_BENCH && data->b_data->threads < data->cpu_count && !data->b_data->run)
				{
					data->b_data->threads++;
					print_paramthreads(win, info, data);
				}
				break;
			case 'f':
				if(page == NO_BENCH && !data->b_data->run)
				{
					data->b_data->fast_mode = true;
					start_benchmarks(data);
				}
				else if(page == NO_BENCH && data->b_data->run)
					data->b_data->run = false;
				break;
			case 's':
				if(page == NO_BENCH && !data->b_data->run)
				{
					data->b_data->fast_mode = false;
					start_benchmarks(data);
				}
				else if(page == NO_BENCH && data->b_data->run)
					data->b_data->run = false;
				break;
			case 'h':
				erase();
				print_help();
				erase();
				refresh();
				main_win(win, info, data);
				(*func_ptr[page])(win, info, data);
				break;
			case ERR:
				/* Refresh dynamic labels */
				if(page == NO_CPU || page == NO_CACHES || page == NO_SYSTEM || page == NO_GRAPHICS || page == NO_BENCH)
					nrefresh(&refr);
				break;
			case KEY_RESIZE:
				/* Resize window */
				erase();
				starty = (LINES - info.height) / 2;
				startx = (COLS - info.width) / 2;
				mvwin(win, starty, startx);
				refresh();
				main_win(win, info, data);
				(*func_ptr[page])(win, info, data);
				break;
			default:
				break;
		}
	}

	endwin();
	labels_free(data);
}


/************************* Private functions *************************/

/* Clean window */
static void wclrscr(WINDOW *pwin)
{
	int y, x, maxy, maxx;

	getmaxyx(pwin, maxy, maxx);
	for(y = 0; y < maxy; y++)
	{
		for(x = 0; x < maxx; x++)
			mvwaddch(pwin, y, x, ' ');
	}
}
예제 #2
0
파일: tui_ncurses.c 프로젝트: mrkidd/CPU-X
/* Start CPU-X in NCurses mode */
void start_tui_ncurses(Labels *data)
{
	int startx, starty, ch = 0;
	const SizeInfo info = { .height = LINE_COUNT, .width = 70, .start = 1, .tb = 2, .tm = 22, .te = 38 };
	NThrd refr = { .data = data, .info = info };
	WINDOW *win;

	MSG_VERBOSE(_("Starting NCurses TUI..."));
	setenv("TERMINFO", "/lib/terminfo", 0);
	freopen("/dev/null", "a", stderr);
	initscr();
	cbreak();
	noecho();
	curs_set(0);
	halfdelay(0);
	nodelay(stdscr, TRUE);
	keypad(stdscr, TRUE);
	if(opts->color)
	{
		start_color();
		opts->color &= has_colors();
	}

	starty   = (LINES - info.height) / 2; /* Calculating for a center placement of the window */
	startx   = (COLS  - info.width)  / 2;
	win      = newwin(info.height, info.width, starty, startx);
	refr.win = win;

	printw("Press 'q' to exit; use right/left key to change tab");
	refresh();
	main_win(win, info, data);
	ntab_cpu(win, info, data);
	timeout(opts->refr_time * 1000);

	while(ch != 'q')
	{
		ch = getch();
		switch(ch)
		{
			case KEY_LEFT:
				/* Switch to left tab */
				if(page > NO_CPU)
				{
					page--;
					main_win(win, info, data);
					(*func_ptr[page])(win, info, data);
				}
				break;
			case KEY_RIGHT:
				/* Switch to right tab */
				if(page < NO_ABOUT)
				{
					page++;
					main_win(win, info, data);
					(*func_ptr[page])(win, info, data);
				}
				break;

			case ERR:
				/* Refresh dynamic labels */
				if(page == NO_CPU || page == NO_CACHES || page == NO_SYSTEM || page == NO_GRAPHICS)
					nrefresh(&refr);
				break;
			case KEY_RESIZE:
				/* Resize window */
				erase();
				starty = (LINES - info.height) / 2;
				startx = (COLS - info.width) / 2;
				mvwin(win, starty, startx);
				printw("Press 'q' to exit; use right/left key to change tab");
				refresh();
				main_win(win, info, data);
				(*func_ptr[page])(win, info, data);
				break;
			default:
				break;
		}
	}

	endwin();
	labels_free(data);
}


/************************* Private functions *************************/

/* Clean window */
static void wclrscr(WINDOW *pwin)
{
	int y, x, maxy, maxx;

	getmaxyx(pwin, maxy, maxx);
	for(y = 0; y < maxy; y++)
	{
		for(x = 0; x < maxx; x++)
			mvwaddch(pwin, y, x, ' ');
	}
}