[vte/vte-next] vteapp: Add option to add new dingus
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte/vte-next] vteapp: Add option to add new dingus
- Date: Sat, 28 May 2011 12:18:42 +0000 (UTC)
commit 16538b9ac8a36413e95aec21fa9e1accf3c960c9
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 e9aff12..0cc81d4 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)
@@ -523,6 +529,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)
{
@@ -537,7 +567,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,
@@ -560,6 +590,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,
@@ -571,10 +602,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,
@@ -955,20 +991,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]