[vte/vte-next: 107/114] vteapp: Add option to add new dingus



commit 5510313c85319c4897d57c153fc625a7d038f4fd
Author: Christian Persch <chpe gnome org>
Date:   Sat May 28 13:07:13 2011 +0200

    vteapp: Add option to add new dingus
    
    For testing purposes, allow specifying extra dingu regexes
    on the command line.

 src/vteapp.c |   65 +++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 47 insertions(+), 18 deletions(-)
---
diff --git a/src/vteapp.c b/src/vteapp.c
index 94e93a6..7c6f0d7 100644
--- a/src/vteapp.c
+++ b/src/vteapp.c
@@ -36,7 +36,13 @@
 #include <glib/gi18n.h>
 
 #define DINGUS1 "(((gopher|news|telnet|nntp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+(:[0-9]*)?"
-#define DINGUS2 "(((gopher|news|telnet|nntp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+(:[0-9]*)?/[-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*[^]'\\.}>\\) ,\\\"]"
+#define DINGUS2 DINGUS1 "/[-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*[^]'\\.}>\\) ,\\\"]"
+
+static const char *builtin_dingus[] = {
+  DINGUS1,
+  DINGUS2,
+  NULL
+};
 
 static void
 window_title_changed(GtkWidget *widget, gpointer win)
@@ -527,6 +533,30 @@ parse_flags(GType type,
   return value;
 }
 
+static void
+add_dingus (VteTerminal *terminal,
+            char **dingus)
+{
+        const GdkCursorType cursors[] = { GDK_GUMBY, GDK_HAND1 };
+        GRegex *regex;
+        GError *error;
+        int id, i;
+
+        for (i = 0; dingus[i]; ++i) {
+                if (!(regex = g_regex_new(dingus[i], G_REGEX_OPTIMIZE, 0, &error))) {
+                        g_warning("Failed to compile regex '%s': %s\n",
+                                  dingus[i], error->message);
+                        g_error_free(error);
+                        continue;
+                }
+
+                id = vte_terminal_match_add_gregex(terminal, regex, 0);
+                g_regex_unref (regex);
+                vte_terminal_match_set_cursor_type(terminal, id,
+                                                   cursors[i % G_N_ELEMENTS(cursors)]);
+        }
+}
+
 int
 main(int argc, char **argv)
 {
@@ -541,7 +571,7 @@ main(int argc, char **argv)
 		NULL};
 	char *background = NULL;
 	gboolean audible = TRUE,
-		 debug = FALSE, dingus = FALSE, dbuffer = TRUE,
+		 debug = FALSE, use_builtin_dingus = FALSE, dbuffer = TRUE,
 		 console = FALSE, scroll = FALSE, keep = FALSE,
 		 icon_title = FALSE, shell = TRUE,
 		 reverse = FALSE, use_geometry_hints = TRUE,
@@ -564,6 +594,7 @@ main(int argc, char **argv)
         char *css = NULL;
         char *css_file = NULL;
         char *selection_background_color_string = NULL;
+        char **dingus = NULL;
 	const GOptionEntry options[]={
 		{
 			"background", 'B', 0,
@@ -575,10 +606,15 @@ main(int argc, char **argv)
 			G_OPTION_ARG_NONE, &console,
 			"Watch /dev/console", NULL
 		},
+                {
+                        "builtin-dingus", 'D', 0,
+                        G_OPTION_ARG_NONE, &use_builtin_dingus,
+                        "Highlight URLs inside the terminal", NULL
+                },
 		{
-			"dingus", 'D', 0,
-			G_OPTION_ARG_NONE, &dingus,
-			"Highlight URLs inside the terminal", NULL
+			"dingu", '\0', 0,
+			G_OPTION_ARG_STRING_ARRAY, &dingus,
+			"Add regex highlight", NULL
 		},
 		{
 			"shell", 'S', G_OPTION_FLAG_REVERSE,
@@ -959,20 +995,13 @@ main(int argc, char **argv)
 	}
 
 	/* Match "abcdefg". */
-	if (dingus) {
-		int id;
-		GRegex *regex;
-		regex = g_regex_new (DINGUS1, 0, 0, NULL);
-		id = vte_terminal_match_add_gregex(terminal, regex, 0);
-		g_regex_unref (regex);
-		vte_terminal_match_set_cursor_type(terminal,
-						   id, GDK_GUMBY);
-		regex = g_regex_new (DINGUS2, 0, 0, NULL);
-		id = vte_terminal_match_add_gregex(terminal, regex, 0);
-		g_regex_unref (regex);
-		vte_terminal_match_set_cursor_type(terminal,
-						   id, GDK_HAND1);
+	if (use_builtin_dingus) {
+                add_dingus (terminal, (char **) builtin_dingus);
 	}
+	if (dingus) {
+                add_dingus (terminal, dingus);
+                g_strfreev (dingus);
+        }
 
 	if (console) {
 		/* Open a "console" connection. */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]