#include <gdk/gdkkeysyms.h>
#include <vte/vte.h>

gboolean window_key_press(GtkWidget *window, GdkEventKey *event, GtkWidget *vte)
{
	if (((event->keyval==GDK_p) || (event->keyval==GDK_P)) && (event->state & GDK_CONTROL_MASK))
	{
		vte_terminal_search_find_previous(VTE_TERMINAL(vte));
		return TRUE;
	}
	if (((event->keyval==GDK_n) || (event->keyval==GDK_N)) && (event->state & GDK_CONTROL_MASK))
	{
		vte_terminal_search_find_next(VTE_TERMINAL(vte));
		return TRUE;
	}
	return FALSE;
}

int main( int   argc,
	  char *argv[])
{
	gtk_init (&argc, &argv);

	GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	g_signal_connect(G_OBJECT(window), "delete_event",
			  G_CALLBACK(gtk_main_quit), NULL);
	GtkWidget *vte = vte_terminal_new();
	vte_terminal_fork_command(VTE_TERMINAL(vte), NULL, NULL,
				  NULL, NULL, TRUE, TRUE, TRUE);
	g_signal_connect(G_OBJECT(vte), "child_exited",
			 G_CALLBACK(gtk_main_quit), NULL);
	vte_terminal_set_font_from_string(VTE_TERMINAL(vte),
					  "Monospace 12");
	gtk_container_add(GTK_CONTAINER(window), vte);

	GRegex *regex = g_regex_new(".", G_REGEX_OPTIMIZE, 0, NULL);
	vte_terminal_search_set_gregex(VTE_TERMINAL(vte), regex);
	vte_terminal_search_set_wrap_around(VTE_TERMINAL(vte), TRUE);
	g_regex_unref (regex);

	g_signal_connect(G_OBJECT(window), "key-press-event", 
			  G_CALLBACK(window_key_press), vte);
	gtk_widget_show_all(window);
	gtk_main();
	return 0;
}
