Example #1
0
void create_scrollback_windows(NEWWIN **mywin1, NEWWIN **mywin2, int nlines, int ncols, char fullscreen)
{
	/* Delete existing windows, if any. */
	if (*mywin1)
	{
		delete_popup(*mywin1);	
	}
	
	if (*mywin2)
	{
		delete_popup(*mywin2);	
	}

	/* Re-create windows, according to fullscreen flag */
	if (fullscreen)
	{
		*mywin1 = NULL;
		*mywin2 = create_popup(max_y, max_x);
		scrollok((*mywin2) -> win, FALSE); /* supposed to always return OK, according to the manpage */

	}
	else
	{
		*mywin1 = create_popup(max_y - 4, max_x - 4);
		*mywin2 = create_popup(nlines, ncols);
		scrollok((*mywin2) -> win, FALSE); /* supposed to always return OK, according to the manpage */
	}
}
Example #2
0
void scrollback_savefile(buffer *pbuf)
{
	char *file = NULL;
	NEWWIN *mywin = create_popup(8, 40);

	win_header(mywin, "Save buffer to file");

	mvwprintw(mywin -> win, 4, 2, "Select file");
	file = edit_string(mywin, 5, 2, 40, find_path_max(), 0, NULL, HELP_SCROLLBACK_SAVEFILE_ENTER_FILENAME, -1, &cmdfile_h, NULL);
	if (file)
	{
		FILE *fh = fopen(file, "w");
		if (fh)
		{
			int loop;

			for(loop=0; loop<pbuf -> curpos; loop++)
			{
				if ((pbuf -> be)[loop].Bline)
				{
					char display = 1;
					char *error;
					int dummy = -1;
					regmatch_t *pmatch = NULL;

					/* check filter */
					if (!IS_MARKERLINE((pbuf -> be)[loop].pi))
					{
						(void)check_filter((pbuf -> be)[loop].pi, (pbuf -> be)[loop].Bline, &pmatch, &error, &dummy, 0, &display);
						if (error)
						{
							fprintf(fh, "%s\n", error);
							myfree(error);
						}
					}
					if (display)
					{
						fprintf(fh, "%s\n", USE_IF_SET((pbuf -> be)[loop].Bline, ""));
					}

					if (pmatch) myfree(pmatch);
				}
			}

			fclose(fh);
		}
		else
		{
			error_popup("Save scrollback buffer", -1, "Cannot write to file, reason: %s", strerror(errno));
		}
	}

	delete_popup(mywin);
}
Example #3
0
void scrollback_find_popup(char **find_str, mybool_t *pcase_insensitive)
{
	char *dummy;
	NEWWIN *mywin = create_popup(5, 40);

	win_header(mywin, "Find");

	dummy = edit_string(mywin, 3, 2, 40, 80, 0, reuse_searchstring?*find_str:NULL, HELP_SCROLLBACK_EDIT_SEARCH_STRING, -1, &search_h, pcase_insensitive);
	myfree(*find_str);
	*find_str = dummy;

	delete_popup(mywin);
}
Example #4
0
void heartbeat(void)
{
	time_t now = time(NULL);
	struct tm *ptm = localtime(&now);
	static int x = 0, y = 0, dx = 1, dy = 1;
	static NEWWIN *hb_win = NULL;

	x += dx;
	y += dy;

	if (x >= (max_x - 8))
	{
		dx = -(myrand(1) + 1);
		x = max_x - (8 + 1);
	}
	else if (x < 0)
	{
		dx = (myrand(2) + 1);
		x = 0;
	}

	if (y >= max_y)
	{
		dy = -(myrand(2) + 1);
		y = max_y - 1;
	}
	else if (y < 0)
	{
		dy = (myrand(2) + 1);
		y = 0;
	}

	if (dx == 0 && dy == 0)
	{
		dy = 1;
		dy = -1;
	}

	if (!hb_win)
	{
		hb_win = create_popup(1, 8);
	}

	move_panel(hb_win -> pwin, y, x);
	ui_inverse_on(hb_win);
	mvwprintw(hb_win -> win, 0, 0, "%02d:%02d:%02d", ptm -> tm_hour, ptm -> tm_min, ptm -> tm_sec);
	ui_inverse_off(hb_win);
	mydoupdate();
}
Example #5
0
int selection_box(void **list, char *needs_mark, int nlines, selbox_type_t type, int what_help, char *heading)
{
	NEWWIN *mywin;
	int wlines = min(nlines, (max_y - 1) - 4);
	int total_win_size = wlines + 4;
	int win_width = max(32, max_x / 3);
	int wcols = win_width - 4;
	int pos = 0, ppos = -1, offs = 0, poffs = -1;
	int loop = 0, sel = -1;
	char first = 1;
	char *dummy = (char *)mymalloc(wcols + 1);
	int path_max = find_path_max();
	char *selstr = (char *)mymalloc(path_max + 1), selfound = 0;

	selstr[0] = 0x00;

	mywin = create_popup(total_win_size, win_width);

	for(;;)
	{
		int c;

		/* draw list */
		if (pos != ppos)
		{
			int entries_left = (nlines - pos);

			werase(mywin -> win);

			if (heading)
				win_header(mywin, heading);
			else if (type == SEL_WIN)
				win_header(mywin, "Select window");
			else if (type == SEL_SUBWIN)
				win_header(mywin, "Select subwindow");
			else if (type == SEL_FILES)
				win_header(mywin, "Select file");
			else if (type == SEL_CSCHEME)
				win_header(mywin, "Select color scheme");
			else if (type == SEL_HISTORY)
				win_header(mywin, "Select string from history");

			for(loop=0; loop<min(entries_left, wlines); loop++)
			{
				char invert = generate_string(dummy, list, type, wcols, loop + pos);
				if (loop == offs)
					ui_inverse_on(mywin);
				if (invert) color_on(mywin, find_colorpair(COLOR_YELLOW, -1, 0));
				if (needs_mark && needs_mark[loop + pos])
					mvwprintw(mywin -> win, loop + 2, 1, "*");
				mvwprintw(mywin -> win, loop + 2, 2, "%s", dummy);
				if (invert) color_off(mywin, find_colorpair(COLOR_YELLOW, -1, 0));
				if (loop == offs)
					ui_inverse_off(mywin);
			}

			draw_border(mywin);

			ppos = pos;
			poffs = offs;
		}
		else if (poffs != offs)
		{
			int yellow_cp = find_colorpair(COLOR_YELLOW, -1, 0);
			char invert = generate_string(dummy, list, type, wcols, poffs + pos);
			if (invert) color_on(mywin, yellow_cp);
			mvwprintw(mywin -> win, poffs + 2, 2, "%s", dummy);
			if (invert) color_off(mywin, yellow_cp);

			invert = generate_string(dummy, list, type, wcols, offs + pos);

			ui_inverse_on(mywin);
			if (invert) color_on(mywin, yellow_cp);
			if (needs_mark && needs_mark[offs + pos])
				mvwprintw(mywin -> win, loop + 2, 1, "*");
			mvwprintw(mywin -> win, offs + 2, 2, "%s", dummy);
			if (invert) color_off(mywin, yellow_cp);
			ui_inverse_off(mywin);

			poffs = offs;
		}

		if (first)
		{
			first = 0;
			color_on(mywin, find_colorpair(COLOR_GREEN, -1, 0));
			mvwprintw(mywin -> win, total_win_size - 2, 2, "Press ^G to abort");
			color_off(mywin, find_colorpair(COLOR_GREEN, -1, 0));
		}
		else
		{
			int loop, len = strlen(selstr);

			for(loop=0; loop<wcols; loop++)
				mvwprintw(mywin -> win, total_win_size - 2, 1 + loop, " ");

			if (!selfound) color_on(mywin, find_colorpair(COLOR_RED, -1, 0));
			mvwprintw(mywin -> win, total_win_size - 2, 1, "%s", &selstr[max(0, len - wcols)]);
			if (!selfound) color_off(mywin, find_colorpair(COLOR_RED, -1, 0));
		}

		mydoupdate();

		c = wait_for_keypress(what_help, 0, mywin, 1);

		if (c == KEY_UP)
		{
			if ((offs + pos) > 0)
			{
				if (offs)
					offs--;
				else
					pos--;
			}
			else
			{
				wrong_key();
			}
		}
		else if (c == KEY_DOWN)
		{
			if ((pos + offs) < (nlines-1))
			{
				if (offs < (wlines-1))
					offs++;
				else
					pos++;
			}
			else
			{
				wrong_key();
			}
		}
		else if (c == KEY_NPAGE)
		{
			if ((pos + offs) < (nlines - 1))
			{
				pos += min(wlines, (nlines - 1) - (pos + offs));
			}
			else
			{
				wrong_key();
			}
		}
		else if (c == KEY_PPAGE)
		{
			if ((pos + offs - wlines) >= 0)
			{
				if (pos > wlines)
				{
					pos -= wlines;
				}
				else
				{
					pos -= (wlines - offs);
					offs = 0;
				}
			}
			else if (offs > 0)
			{
				offs = 0;
			}
			else if (pos > 0)
			{
				pos = 0;
			}
			else
			{
				wrong_key();
			}
		}
		else if (c == KEY_ENTER || c == 13 || c == 10)
		{
			sel = pos + offs;
			break;
		}
		else if (c == abort_key || c == -1)
		{
			break;
		}
		else if ((c > 31 && c != 127) || (c == KEY_BACKSPACE))
		{
			int index, curlen;

			curlen = strlen(selstr);
			if (c == KEY_BACKSPACE)
			{
				if (curlen > 0)
					selstr[curlen - 1] = 0x00;
				else
					wrong_key();
			}
			else if (curlen < path_max)
			{
				selstr[curlen] = c;
				selstr[curlen + 1] = 0x00;
			}
			else
				wrong_key();


			curlen = strlen(selstr);
			if (curlen > 0)
			{
				index = find_sb_string(list, type, nlines, selstr);
				if (index != -1)
				{
					ppos = -1;
					sel = pos = index;
					selfound = 1;
				}
				else
				{
					selfound = 0;
				}
			}
		}
		else
		{
			wrong_key();
		}
	}

	delete_popup(mywin);

	myfree(dummy);
	myfree(selstr);

	return sel;
}
Example #6
0
void statistics_menu(void)
{
	NEWWIN *mywin = create_popup(23, 65);
	int offset = 0, cur_line = 0;

	for(;;)
	{
		int c;
		int vmsize = get_vmsize(getpid());
		time_t now = time(NULL);
		struct tm *tmnow = localtime(&now);
		proginfo **plist = NULL;
		char     *issub = NULL;
		int      *winnr = NULL;
		int loop, nwin = 0;

		/* create list of (sub-)windows */
		for(loop=0; loop<nfd; loop++)
		{
			proginfo *cur = &pi[loop];

			while(cur)
			{
				plist = (proginfo **)myrealloc(plist, (nwin + 1) * sizeof(proginfo *));
				issub = (char *)     myrealloc(issub, (nwin + 1) * sizeof(char)      );
				winnr = (int *)      myrealloc(winnr, (nwin + 1) * sizeof(int)       );

				plist[nwin] = cur;
				issub[nwin] = (cur != &pi[loop]);
				winnr[nwin] = loop;
				nwin++;

				cur = cur -> next;
			}
		}

		werase(mywin -> win);
		win_header(mywin, "Statistics");

		for(loop=0; loop<18; loop++)
		{
			int cur_index = loop + offset;
			int is_sub_indent;

			if (cur_index >= nwin) break;

			is_sub_indent = issub[cur_index];

			if (loop == cur_line) ui_inverse_on(mywin);
			if (is_sub_indent)
				mvwprintw(mywin -> win, 2 + loop, 7, "%s", shorten_filename(plist[cur_index] -> filename, 54));
			else
				mvwprintw(mywin -> win, 2 + loop, 2, "[%02d] %s", winnr[cur_index], shorten_filename(plist[cur_index] -> filename, 56));
			if (loop == cur_line) ui_inverse_off(mywin);
		}

		mvwprintw(mywin -> win, 20, 2, "Run-time: %.2f hours  %02d:%02d", (get_ts() - mt_started) / 3600.0, tmnow -> tm_hour, tmnow -> tm_min);
		if (vmsize != -1)
		{
			char *vmsize_str = amount_to_str(vmsize);
			mvwprintw(mywin -> win, 20, 35, "Memory usage: %s", vmsize_str);
			myfree(vmsize_str);
		}
		escape_print(mywin, 21, 2, "Press ^r^ to reset counters, ^q^ to exit");

		draw_border(mywin);
		mydoupdate();

		c = toupper(wait_for_keypress(HELP_STATISTICS, popup_refresh_interval, mywin, 1));

		if (c == 'R')
		{
			for(loop=0; loop<nfd; loop++)
			{
				proginfo *cur = &pi[loop];

				while(cur)
				{
					reset_counters(&cur -> statistics);

					cur = cur -> next;
				}
			}
		}
		else if (c == KEY_UP)
		{
			if (cur_line)
				cur_line--;
			else if (offset)
				offset--;
			else
				wrong_key();
		}
		else if (c == KEY_DOWN)
		{
			if ((cur_line + offset) < (nwin - 1))
			{
				if (cur_line < (18 - 1))
					cur_line++;
				else
					offset++;
			}
			else
				wrong_key();

		}
		else if (c == 13 || c == ' ')
		{
			statistics_popup(winnr[cur_line + offset], plist[cur_line + offset]);
		}
		else if (c == 'Q' || c == abort_key)
		{
			myfree(plist);
			myfree(issub);
			myfree(winnr);
			break;
		}
		else if (c != -1)
		{
			wrong_key();
		}

		myfree(plist);
		myfree(issub);
		myfree(winnr);
	}

	delete_popup(mywin);
}
Example #7
0
void info(void)
{
	NEWWIN *mywin = create_popup(19, 60);
	int line = 7;
	struct utsname uinfo;
	int proc_u_line;
	char *term = getenv("TERM");

	mvwprintw(mywin -> win, 1, 2, "-=* MultiTail " VERSION " *=-");
	mvwprintw(mywin -> win, 3, 2, "Written by [email protected]");
	mvwprintw(mywin -> win, 4, 2, "Website: http://www.vanheusden.com/multitail/");
	if (!use_colors)
		mvwprintw(mywin -> win, line++, 2, "Your terminal doesn't support colors");

	if (uname(&uinfo) == -1)
		error_popup("Retrieving system information", -1, "uname() failed\n");
	else
	{
		line++;
		mvwprintw(mywin -> win, line++, 2, "Running on:");
#ifdef _GNU_SOURCE
		mvwprintw(mywin -> win, line++, 2, "%s/%s %s %s", uinfo.nodename, uinfo.sysname, uinfo.machine, uinfo.domainname);
#else
		mvwprintw(mywin -> win, line++, 2, "%s/%s %s", uinfo.nodename, uinfo.sysname, uinfo.machine);
#endif
		mvwprintw(mywin -> win, line++, 2, "%s %s", uinfo.release, uinfo.version);
		line++;
	}

	if (has_colors())
		mvwprintw(mywin -> win, line++, 2, "colors: %d, colorpairs: %d (%d), change colors: %s", COLORS, COLOR_PAIRS, cp.n_def, can_change_color()?"yes":"no");
	else
		mvwprintw(mywin -> win, line++, 2, "Terminal does not support colors.");
	if (term)
		mvwprintw(mywin -> win, line++, 2, "Terminal size: %dx%d, terminal: %s", max_x, max_y, term);
	else
		mvwprintw(mywin -> win, line++, 2, "Terminal size: %dx%d", max_x, max_y);

	if (beep_interval > 0)
		mvwprintw(mywin -> win, line++, 2, "Did %d beeps.", did_n_beeps);

	proc_u_line = line++;

	escape_print(mywin, 16, 2, "_Press any key to exit this screen_");

#if defined(__FreeBSD__) || defined(linux) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(sun) || defined(__sun) || defined(__GNU__) || defined(__CYGWIN__)
	for(;;)
	{
		dtime_t run_time = get_ts() - mt_started;
#ifndef __CYGWIN__
		double v1, v2, v3;

		get_load_values(&v1, &v2, &v3);
		mvwprintw(mywin -> win, 6, 2, "Current load of system: %f %f %f", v1, v2, v3);
#endif

		if (run_time)
		{
			struct rusage usage;

			if (getrusage(RUSAGE_SELF, &usage) == -1)
				error_exit(TRUE, FALSE, "getrusage() failed\n");

			mvwprintw(mywin -> win, proc_u_line, 2, "Runtime: %02d:%02d:%02d, avg.proc.usage: %.2f%% ints/s: %.1f",
					(int)(run_time / 3600), ((int)run_time / 60) % 60, (int)run_time % 60,
					((double)usage.ru_utime.tv_sec + (double)usage.ru_utime.tv_usec / 1000000.0 + 
					 (double)usage.ru_stime.tv_sec + (double)usage.ru_stime.tv_usec / 1000000.0) * 100.0 / run_time,
					 (double)total_wakeups / run_time);
		}

		mydoupdate();

		if (wait_for_keypress(-1, popup_refresh_interval, mywin, 0) != -1)
			break;
	}
#else
	mydoupdate();
	wait_for_keypress(-1, 0, mywin, 0);
#endif

	delete_popup(mywin);
}
Example #8
0
void statistics_popup(int f_index, proginfo *cur)
{
	NEWWIN *popup = create_popup(16, 68);
	const char *title = "Statistics for ";
	char *abbr_fname = shorten_filename(cur -> filename, 54 - strlen(title));
	char buffer[54 + 1];

	snprintf(buffer, sizeof(buffer), "%s%s", title, abbr_fname);

	for(;;)
	{
		dtime_t time_running = get_ts() - cur -> statistics.start_ts;
		time_t start_ts = (time_t)cur -> statistics.start_ts;
		char *start_ts_str = mystrdup(ctime(&start_ts));
		time_t lastevent = (time_t)cur -> statistics.lastevent;
		char *last_ts_str  = mystrdup(ctime(&lastevent));
		char *dummy;
		char *vmsize_str = NULL;
		char *fsize_str = NULL;
		char *total_data_processed_str = amount_to_str(cur -> statistics.bytes_processed);
		char *buffer_kb;
		off64_t fsize = -1;
		int c;
		int total_re = 0;
		int loop;

		if (cur -> wt == WT_COMMAND)
		{
			vmsize_str = amount_to_str(get_vmsize(cur -> pid));
		}
		else if (cur -> wt == WT_FILE)
		{
			(void)file_info(cur -> filename, &fsize, 0, NULL, NULL);
			fsize_str = amount_to_str(fsize);
		}

		dummy = strchr(start_ts_str, '\n');
		if (dummy) *dummy = 0x00;
		dummy = strchr(last_ts_str, '\n');
		if (dummy) *dummy = 0x00;

		werase(popup -> win);
		win_header(popup, buffer);

		ui_inverse_on(popup);
		mvwprintw(popup -> win, 3, 2, "# lines       :");
		mvwprintw(popup -> win, 3, 27, "#l/s :");
		mvwprintw(popup -> win, 3, 44, "Avg len:");
		mvwprintw(popup -> win, 4, 2, "Data interval :");
		if (cur -> wt == WT_COMMAND)
			mvwprintw(popup -> win, 5, 2, "VM size       :");
		else if (cur -> wt == WT_FILE)
			mvwprintw(popup -> win, 5, 2, "File size     :");
		mvwprintw(popup -> win, 9, 2, "Data processed:");
		mvwprintw(popup -> win, 9, 27, "Bps  :");
		mvwprintw(popup -> win, 6, 2, "Started at    :");
		mvwprintw(popup -> win, 7, 2, "Last event    :");
		mvwprintw(popup -> win, 8, 2, "Next expected@:");
		mvwprintw(popup -> win, 10, 2, "# matched r.e.:");
		mvwprintw(popup -> win, 11, 2, "Buffered lines:");
		mvwprintw(popup -> win, 11, 27, "Bytes:");
		mvwprintw(popup -> win, 11, 44, "Limit  :");
		mvwprintw(popup -> win, 12, 2, "# of beeps:    ");
		if (cur -> wt == WT_COMMAND)
		{
			mvwprintw(popup -> win, 13, 2, "Number of runs:");
			mvwprintw(popup -> win, 13, 27, "Last rc:");
		}
		ui_inverse_off(popup);

		mvwprintw(popup -> win, 3, 18, "%d", cur -> statistics.n_events);
		mvwprintw(popup -> win, 6, 18, "%s", start_ts_str);
		if (cur -> statistics.lastevent != (dtime_t)0.0)
			mvwprintw(popup -> win, 7, 18, "%s", last_ts_str);
		else
			mvwprintw(popup -> win, 7, 18, "---");

		if (cur -> statistics.n_events == 0)
		{
			mvwprintw(popup -> win, 4, 18, "Not yet available");
		}
		else
		{
			double avg = cur -> statistics.med / (double)cur -> statistics.n_events;
			double dev = sqrt((cur -> statistics.dev / (double)cur -> statistics.n_events) - pow(avg, 2.0));

			/* serial correlation coefficient */
			double scct1 = cur -> statistics.scct1 + cur -> statistics.scclast * cur -> statistics.sccu0;
			double med = cur -> statistics.med * cur -> statistics.med;
			double scc = (double)cur -> statistics.n_events * cur -> statistics.dev - med;
			if (scc != 0.0)
			{
				scc = ((double)cur -> statistics.n_events * scct1 - med) / scc;
				mvwprintw(popup -> win, 4, 18, "average: %.2f, std.dev.: %.2f, SCC: %1.6f", avg, dev, scc);
			}
			else
				mvwprintw(popup -> win, 4, 18, "average: %.2f, std.dev.: %.2f, not correlated", avg, dev);

			if (avg)
			{
				double dummy_d = (double)(time(NULL) - cur -> statistics.lastevent) / avg;
				time_t next_event = cur -> statistics.lastevent + (ceil(dummy_d) * avg);
				char *ne_str = mystrdup(ctime(&next_event));
				char *dummy_str = strchr(ne_str, '\n');

				if (dummy_str) *dummy_str = 0x00;
				mvwprintw(popup -> win, 8, 18, "%s", ne_str); 
				myfree(ne_str);
			}

			mvwprintw(popup -> win, 3, 53, "%.1f", (double)cur -> statistics.bytes_processed / (double)cur -> statistics.n_events);
		}
		if (cur -> wt == WT_COMMAND)
			mvwprintw(popup -> win, 5, 18, "%s", vmsize_str);
		else if (cur -> wt == WT_STDIN || cur -> wt == WT_SOCKET)
			mvwprintw(popup -> win, 5, 18, "n.a.");
		else if (cur -> wt == WT_FILE)
			mvwprintw(popup -> win, 5, 18, "%s", fsize_str);
		myfree(vmsize_str);
		myfree(fsize_str);
		mvwprintw(popup -> win, 9, 18, "%s", total_data_processed_str);
		myfree(total_data_processed_str);
		if (time_running > 0)
		{
			char *bps_str = amount_to_str((double)cur -> statistics.bytes_processed / (double)time_running);
			mvwprintw(popup -> win, 9, 34, "%s", bps_str);
			myfree(bps_str);

			mvwprintw(popup -> win, 3, 34, "%.4f", (double)cur -> statistics.n_events / (double)time_running);
		}
		buffer_kb = amount_to_str(lb[f_index].curbytes);
		mvwprintw(popup -> win, 11, 18, "%d", lb[f_index].curpos);
		mvwprintw(popup -> win, 11, 34, "%s", buffer_kb);
		myfree(buffer_kb);
		mvwprintw(popup -> win, 12, 18, "%d", cur -> beep.did_n_beeps);
		escape_print(popup, 14, 2, "Press ^r^ to reset counters, ^q^ to exit");
		myfree(start_ts_str);
		myfree(last_ts_str);
		for(loop=0; loop<cur -> n_re; loop++)
			total_re += (cur -> pre)[loop].match_count;
		if (cur -> statistics.n_events)
			mvwprintw(popup -> win, 10, 18, "%d (%.2f%%)", total_re, (total_re * 100.0) / (double)cur -> statistics.n_events);
		else
			mvwprintw(popup -> win, 10, 18, "%d", total_re);
		if (cur -> wt == WT_COMMAND)
		{
			mvwprintw(popup -> win, 13, 18, "%d", cur -> n_runs);
			mvwprintw(popup -> win, 13, 36, "%d", cur -> last_exit_rc);
		}
		if (lb[f_index].maxnlines > 0)
		{
			mvwprintw(popup -> win, 11, 53, "%d lines", lb[f_index].maxnlines);
		}
		else if (lb[f_index].maxbytes > 0)
		{
			char *str = amount_to_str(lb[f_index].maxbytes);
			mvwprintw(popup -> win, 11, 53, "%s", str);
			myfree(str);
		}
		draw_border(popup);
		mydoupdate();

		c = toupper(wait_for_keypress(HELP_STATISTICS_POPUP, popup_refresh_interval, popup, 0));

		if (c == 'Q' || c == abort_key)
		{
			break;
		}
		else if (c == 'R')
		{
			reset_counters(&cur -> statistics);
		}
		else if (c !=  -1)
		{
			wrong_key();
		}
	}

	delete_popup(popup);
}
Example #9
0
static void
gtk_color_editor_init (GtkColorEditor *editor)
{
  GtkWidget *grid;
  GtkWidget *slider;
  GtkWidget *entry;
  GtkWidget *swatch;
  GtkAdjustment *h_adj, *s_adj, *v_adj, *a_adj;
  AtkObject *atk_obj;
  GdkRGBA transparent = { 0, 0, 0, 0 };

  editor->priv = G_TYPE_INSTANCE_GET_PRIVATE (editor,
                                              GTK_TYPE_COLOR_EDITOR,
                                              GtkColorEditorPrivate);
  editor->priv->use_alpha = TRUE;

  editor->priv->h_adj = h_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0);
  editor->priv->s_adj = s_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0);
  editor->priv->v_adj = v_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0);
  editor->priv->a_adj = a_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0);

  g_object_ref_sink (h_adj);
  g_object_ref_sink (s_adj);
  g_object_ref_sink (v_adj);
  g_object_ref_sink (a_adj);

  g_signal_connect_swapped (h_adj, "value-changed", G_CALLBACK (hsv_changed), editor);
  g_signal_connect_swapped (s_adj, "value-changed", G_CALLBACK (hsv_changed), editor);
  g_signal_connect_swapped (v_adj, "value-changed", G_CALLBACK (hsv_changed), editor);
  g_signal_connect_swapped (a_adj, "value-changed", G_CALLBACK (hsv_changed), editor);

  gtk_widget_push_composite_child ();

  /* Construct the main UI */
  editor->priv->swatch = swatch = gtk_color_swatch_new ();
  gtk_color_swatch_set_selectable (GTK_COLOR_SWATCH (editor->priv->swatch), FALSE);
  gtk_widget_set_events (swatch, gtk_widget_get_events (swatch)
                                 & ~(GDK_BUTTON_PRESS_MASK
                                     | GDK_BUTTON_RELEASE_MASK
                                     | GDK_KEY_PRESS_MASK
                                     | GDK_KEY_RELEASE_MASK));
  gtk_widget_set_can_focus (swatch, FALSE);

  editor->priv->entry = entry = gtk_entry_new ();
  atk_obj = gtk_widget_get_accessible (entry);
  atk_object_set_role (atk_obj, ATK_ROLE_ENTRY);
  atk_object_set_name (atk_obj, _("Color Name"));
  g_signal_connect (entry, "activate", G_CALLBACK (entry_apply), editor);
  g_signal_connect (entry, "notify::text", G_CALLBACK (entry_text_changed), editor);
  g_signal_connect (entry, "focus-out-event", G_CALLBACK (entry_focus_out), editor);

  editor->priv->h_slider = slider = gtk_color_scale_new (h_adj, GTK_COLOR_SCALE_HUE);
  gtk_orientable_set_orientation (GTK_ORIENTABLE (slider), GTK_ORIENTATION_VERTICAL);
  if (gtk_widget_get_direction (slider) == GTK_TEXT_DIR_RTL)
    gtk_style_context_add_class (gtk_widget_get_style_context (slider),
                                 GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
  else
    gtk_style_context_add_class (gtk_widget_get_style_context (slider),
                                 GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW);

  editor->priv->sv_plane = gtk_color_plane_new (h_adj, s_adj, v_adj);
  gtk_widget_set_size_request (editor->priv->sv_plane, 300, 300);

  editor->priv->a_slider = slider = gtk_color_scale_new (a_adj, GTK_COLOR_SCALE_ALPHA);
  gtk_orientable_set_orientation (GTK_ORIENTABLE (slider), GTK_ORIENTATION_HORIZONTAL);
  gtk_style_context_add_class (gtk_widget_get_style_context (slider),
                               GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);

  editor->priv->grid = grid = gtk_grid_new ();
  gtk_grid_set_row_spacing (GTK_GRID (grid), 12);
  gtk_grid_set_column_spacing (GTK_GRID (grid), 12);

  gtk_grid_attach (GTK_GRID (grid), editor->priv->swatch,   1, 0, 1, 1);
  gtk_grid_attach (GTK_GRID (grid), editor->priv->entry,    2, 0, 1, 1);
  gtk_grid_attach (GTK_GRID (grid), editor->priv->h_slider, 0, 1, 1, 1);
  gtk_grid_attach (GTK_GRID (grid), editor->priv->sv_plane, 1, 1, 2, 1);
  gtk_grid_attach (GTK_GRID (grid), editor->priv->a_slider, 1, 2, 2, 1);

  /* This extra margin is necessary so we have room to the sides
   * to place the popups as desired
   */
  gtk_widget_set_margin_left (grid, 30);
  gtk_widget_set_margin_right (grid, 30);

  editor->priv->overlay = gtk_overlay_new ();
  gtk_widget_override_background_color (editor->priv->overlay, 0, &transparent);
  gtk_container_add (GTK_CONTAINER (editor->priv->overlay), grid);

  /* Construct the sv popup */
  editor->priv->s_entry = entry = gtk_spin_button_new (scaled_adjustment (s_adj, 100), 1, 0);
  atk_obj = gtk_widget_get_accessible (entry);
  atk_object_set_name (atk_obj, C_("Color channel", "Saturation"));
  atk_object_set_role (atk_obj, ATK_ROLE_ENTRY);
  g_signal_connect (entry, "key-press-event", G_CALLBACK (popup_key_press), editor);

  editor->priv->v_entry = entry = gtk_spin_button_new (scaled_adjustment (v_adj, 100), 1, 0);
  atk_obj = gtk_widget_get_accessible (entry);
  atk_object_set_name (atk_obj, C_("Color channel", "Value"));
  atk_object_set_role (atk_obj, ATK_ROLE_ENTRY);
  g_signal_connect (entry, "key-press-event", G_CALLBACK (popup_key_press), editor);

  grid = gtk_grid_new ();
  gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
  gtk_grid_set_column_spacing (GTK_GRID (grid), 6);

  gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "S")), 0, 0, 1, 1);
  gtk_grid_attach (GTK_GRID (grid), editor->priv->s_entry, 1, 0, 1, 1);
  gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "V")), 0, 1, 1, 1);
  gtk_grid_attach (GTK_GRID (grid), editor->priv->v_entry, 1, 1, 1, 1);

  editor->priv->sv_popup = create_popup (editor, editor->priv->sv_plane, grid);

  /* Construct the h popup */
  editor->priv->h_entry = entry = gtk_spin_button_new (scaled_adjustment (h_adj, 100), 1, 0);
  atk_obj = gtk_widget_get_accessible (entry);
  atk_object_set_name (atk_obj, C_("Color channel", "Hue"));
  atk_object_set_role (atk_obj, ATK_ROLE_ENTRY);
  g_signal_connect (entry, "key-press-event", G_CALLBACK (popup_key_press), editor);

  grid = gtk_grid_new ();
  gtk_grid_set_column_spacing (GTK_GRID (grid), 6);

  gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "H")), 0, 0, 1, 1);
  gtk_grid_attach (GTK_GRID (grid), editor->priv->h_entry, 1, 0, 1, 1);

  editor->priv->h_popup = create_popup (editor, editor->priv->h_slider, grid);

  /* Construct the a popup */
  editor->priv->a_entry = entry = gtk_spin_button_new (scaled_adjustment (a_adj, 100), 1, 0);
  atk_obj = gtk_widget_get_accessible (entry);
  atk_object_set_name (atk_obj, C_("Color channel", "Alpha"));
  atk_object_set_role (atk_obj, ATK_ROLE_ENTRY);
  g_signal_connect (entry, "key-press-event", G_CALLBACK (popup_key_press), editor);

  grid = gtk_grid_new ();
  gtk_grid_set_column_spacing (GTK_GRID (grid), 6);

  gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "A")), 0, 0, 1, 1);
  gtk_grid_attach (GTK_GRID (grid), editor->priv->a_entry, 1, 0, 1, 1);

  editor->priv->a_popup = create_popup (editor, editor->priv->a_slider, grid);

  /* Hook up popup positioning */
  g_signal_connect (editor->priv->overlay, "get-child-position", G_CALLBACK (get_child_position), editor);
  g_signal_connect (editor, "notify::visible", G_CALLBACK (dismiss_current_popup), NULL);

  gtk_widget_show_all (editor->priv->overlay);
  gtk_container_add (GTK_CONTAINER (editor), editor->priv->overlay);

  gtk_widget_pop_composite_child ();
}
Example #10
0
int game() {
    static int selected_game = 0;

    drawgames(selected_game);
    xt_par0(XT_CH_NORMAL);
    SETPOS(2, COLS - 18);
    draw_users();
    fflush(stdout);
    int key;
    if ((key = getkey()) == KEY_NOTHING)
        return 0;

    xt_par0(XT_CH_NORMAL);
    SETPOS(2, COLS - 18);
    // printf("Who's Online");
    // for (i = 0; i < numusers - onlinelistoffset; i++) {
    //     SETPOS(4 + i, COLS - 18);
    //     if (5 + i > ROWS)
    //         break;
    //     printf("%s", users[i + onlinelistoffset].username);

    // }
    switch(key) {
        // case '<':
        //     xt_par0(XT_CLEAR_SCREEN);
        //     drawgames(selected_game);
        //     dispmultiframe();
        //     if (onlinelistoffset > 0)
        //         onlinelistoffset--;
        //     xt_par0(XT_CH_NORMAL);
        //     SETPOS(2, COLS - 18);
        //     printf("Who's Online");
        //     for (i = 0; i < numusers - onlinelistoffset; i++) {
        //         SETPOS(4 + i, COLS - 18);
        //         if (5 + i > ROWS)
        //             break;
        //         if (users[i + onlinelistoffset].status != CLIENT_FREE)
        //             printf("%s", users[i + onlinelistoffset].username);
        //     }
        //     break;
        // case '>':
        //     xt_par0(XT_CLEAR_SCREEN);
        //     drawgames(selected_game);
        //     dispmultiframe();
        //     if (ROWS - 5 + onlinelistoffset < 64)
        //         onlinelistoffset++;
        //     xt_par0(XT_CH_NORMAL);
        //     SETPOS(2, COLS - 18);
        //     printf("Who's Online");
        //     for (i = 0; i < numusers - onlinelistoffset; i++) {
        //         SETPOS(4 + i, COLS - 18);
        //         if (5 + i > ROWS)
        //             break;
        //         if (users[i + onlinelistoffset].status != CLIENT_FREE)
        //             printf("%s", users[i + onlinelistoffset].username);
        //     }
        //     break;
        case 'q':
        case 'Q':
            xt_par0(XT_CLEAR_SCREEN);
            SETPOS(0,0);
            return MENU_QUIT;
        case 'w':
        case KEY_UP: {
            int i;
            for (i = selected_game - 1; i > 0; i--) {
                if (games[i].status != GAME_FREE) {
                    selected_game = i;
                    drawgames(selected_game);
                    xt_par0(XT_CH_NORMAL);
                    SETPOS(2, COLS - 18);
                    draw_users();
                    fflush(stdout);
                }
            }
            break;
        }
        case 's':
        case KEY_DOWN: {
            int i;
            for (i = selected_game + 1; i < MAX_GAMES; i++) {
                if (games[i].status != GAME_FREE) {
                    selected_game = i;
                    drawgames(selected_game);
                    xt_par0(XT_CH_NORMAL);
                    SETPOS(2, COLS - 18);
                    draw_users();
                    fflush(stdout);
                }
            }
            break;
        }
        case 'j':
        case 'J':
            if (join_popup(&games[selected_game]))
                game_wait(selected_game);
            drawgames(selected_game);
            xt_par0(XT_CH_NORMAL);
            SETPOS(2, COLS - 18);
            draw_users();
            break;
        case 'c':
        case 'C':
            if (create_popup()) // create_popup also includes the error message handling
                game_wait(numgames - 1);
            drawgames(selected_game);
            xt_par0(XT_CH_NORMAL);
            SETPOS(2, COLS - 18);
            draw_users();
            break;
        case 'h':
        case 'H':
            help_popup();
            break;
    }
    return 0;
}