[gnome-terminal/wip/regex-builtins] regex: Use vte builtin regexes instead of our own
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-terminal/wip/regex-builtins] regex: Use vte builtin regexes instead of our own
- Date: Wed, 8 May 2019 16:00:59 +0000 (UTC)
commit 7457b47d64ecd079d59cb69bf5d1039eea0328d6
Author: Christian Persch <chpe src gnome org>
Date: Wed May 8 18:00:01 2019 +0200
regex: Use vte builtin regexes instead of our own
https://gitlab.gnome.org/GNOME/vte/issues/114
src/Makefile.am | 20 +--
src/terminal-regex.c | 374 --------------------------------------------------
src/terminal-regex.h | 154 ---------------------
src/terminal-screen.c | 23 +---
src/terminal-screen.h | 3 -
src/terminal-util.c | 26 +---
src/terminal-util.h | 3 +-
src/terminal-window.c | 25 ++--
8 files changed, 20 insertions(+), 608 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index b36cc8e3..f7a6ff9b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -6,8 +6,6 @@ bin_PROGRAMS = gnome-terminal
libexec_PROGRAMS = gnome-terminal-server
noinst_PROGRAMS =
-check_PROGRAMS = terminal-regex
-
if WITH_NAUTILUS_EXTENSION
nautilusextension_LTLIBRARIES = libterminal-nautilus.la
endif # WITH_NAUTILUS_EXTENSION
@@ -74,7 +72,6 @@ gnome_terminal_server_SOURCES = \
terminal-prefs.h \
terminal-profiles-list.c \
terminal-profiles-list.h \
- terminal-regex.h \
terminal-schemas.h \
terminal-settings-list.c \
terminal-settings-list.h \
@@ -183,26 +180,11 @@ terminal-resources.h terminal-resources.c: terminal.gresource.xml Makefile $(she
# Checks
TESTS = \
- terminal-regex \
$(NULL)
# Check programmes
-terminal_regex_CPPFLAGS = \
- $(AM_CPPFLAGS)
-terminal_regex_SOURCES = \
- terminal-regex.c \
- terminal-regex.h \
- $(NULL)
-terminal_regex_CFLAGS = \
- -DTERMINAL_REGEX_MAIN \
- $(TERM_CFLAGS) \
- $(WARN_CFLAGS) \
- $(AM_CFLAGS)
-terminal_regex_LDFLAGS = \
- $(AM_LDFLAGS)
-terminal_regex_LDADD = \
- $(TERM_LIBS)
+# none so far
# Legacy terminal client
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index 23134e80..3087d7e1 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -19,7 +19,6 @@
#include "config.h"
#include "terminal-pcre2.h"
-#include "terminal-regex.h"
#include "terminal-screen.h"
#include <errno.h>
@@ -170,24 +169,12 @@ typedef struct {
TerminalURLFlavor flavor;
} TerminalRegexPattern;
-static const TerminalRegexPattern url_regex_patterns[] = {
- { REGEX_URL_AS_IS, FLAVOR_AS_IS },
- { REGEX_URL_HTTP, FLAVOR_DEFAULT_TO_HTTP },
- { REGEX_URL_FILE, FLAVOR_AS_IS },
- { REGEX_URL_VOIP, FLAVOR_VOIP_CALL },
- { REGEX_EMAIL, FLAVOR_EMAIL },
- { REGEX_NEWS_MAN, FLAVOR_AS_IS },
-};
-
static const TerminalRegexPattern extra_regex_patterns[] = {
{ "(0[Xx][[:xdigit:]]+|[[:digit:]]+)", FLAVOR_NUMBER },
};
-static VteRegex **url_regexes;
static VteRegex **extra_regexes;
-static TerminalURLFlavor *url_regex_flavors;
static TerminalURLFlavor *extra_regex_flavors;
-static guint n_url_regexes;
static guint n_extra_regexes;
/* See bug #697024 */
@@ -344,7 +331,6 @@ terminal_screen_init (TerminalScreen *screen)
GtkTargetList *target_list;
GtkTargetEntry *targets;
int n_targets;
- guint i;
uuid_t u;
char uuidstr[37];
@@ -360,14 +346,13 @@ terminal_screen_init (TerminalScreen *screen)
vte_terminal_set_allow_hyperlink (terminal, TRUE);
- for (i = 0; i < n_url_regexes; ++i)
+ vte_terminal_match_add_builtins (terminal);
{
TagData *tag_data;
tag_data = g_slice_new (TagData);
- tag_data->flavor = url_regex_flavors[i];
- tag_data->tag = vte_terminal_match_add_regex (terminal, url_regexes[i], 0);
- vte_terminal_match_set_cursor_type (terminal, tag_data->tag, URL_MATCH_CURSOR);
+ tag_data->flavor = FLAVOR_AS_IS;
+ tag_data->tag = VTE_BUILTIN_MATCH_TAG_URI;
priv->match_tags = g_slist_prepend (priv->match_tags, tag_data);
}
@@ -542,8 +527,6 @@ terminal_screen_class_init (TerminalScreenClass *klass)
g_type_class_add_private (object_class, sizeof (TerminalScreenPrivate));
- n_url_regexes = G_N_ELEMENTS (url_regex_patterns);
- precompile_regexes (url_regex_patterns, n_url_regexes, &url_regexes, &url_regex_flavors);
n_extra_regexes = G_N_ELEMENTS (extra_regex_patterns);
precompile_regexes (extra_regex_patterns, n_extra_regexes, &extra_regexes, &extra_regex_flavors);
diff --git a/src/terminal-screen.h b/src/terminal-screen.h
index ff77fcf7..44a4e755 100644
--- a/src/terminal-screen.h
+++ b/src/terminal-screen.h
@@ -28,9 +28,6 @@ G_BEGIN_DECLS
typedef enum {
FLAVOR_AS_IS,
- FLAVOR_DEFAULT_TO_HTTP,
- FLAVOR_VOIP_CALL,
- FLAVOR_EMAIL,
FLAVOR_NUMBER,
} TerminalURLFlavor;
diff --git a/src/terminal-util.c b/src/terminal-util.c
index 72a0d401..317f2d02 100644
--- a/src/terminal-util.c
+++ b/src/terminal-util.c
@@ -286,34 +286,12 @@ terminal_util_set_atk_name_description (GtkWidget *widget,
void
terminal_util_open_url (GtkWidget *parent,
- const char *orig_url,
- TerminalURLFlavor flavor,
+ const char *uri,
guint32 user_time)
{
gs_free_error GError *error = NULL;
- gs_free char *uri = NULL;
- g_return_if_fail (orig_url != NULL);
-
- switch (flavor)
- {
- case FLAVOR_DEFAULT_TO_HTTP:
- uri = g_strdup_printf ("http://%s", orig_url);
- break;
- case FLAVOR_EMAIL:
- if (g_ascii_strncasecmp ("mailto:", orig_url, 7) != 0)
- uri = g_strdup_printf ("mailto:%s", orig_url);
- else
- uri = g_strdup (orig_url);
- break;
- case FLAVOR_VOIP_CALL:
- case FLAVOR_AS_IS:
- uri = g_strdup (orig_url);
- break;
- default:
- uri = NULL;
- g_assert_not_reached ();
- }
+ g_return_if_fail (uri != NULL);
if (!open_url (GTK_WINDOW (parent), uri, user_time, &error))
{
diff --git a/src/terminal-util.h b/src/terminal-util.h
index abd34fd7..591e43eb 100644
--- a/src/terminal-util.h
+++ b/src/terminal-util.h
@@ -40,8 +40,7 @@ void terminal_util_set_atk_name_description (GtkWidget *widget,
const char *desc);
void terminal_util_open_url (GtkWidget *parent,
- const char *orig_url,
- TerminalURLFlavor flavor,
+ const char *uri,
guint32 user_time);
void terminal_util_transform_uris_to_quoted_fuse_paths (char **uris);
diff --git a/src/terminal-window.c b/src/terminal-window.c
index 19198f49..5ed97859 100644
--- a/src/terminal-window.c
+++ b/src/terminal-window.c
@@ -999,7 +999,7 @@ action_open_match_cb (GSimpleAction *action,
if (info->url == NULL)
return;
- terminal_util_open_url (GTK_WIDGET (window), info->url, info->url_flavor,
+ terminal_util_open_url (GTK_WIDGET (window), info->url,
gtk_get_current_event_time ());
}
@@ -1034,7 +1034,7 @@ action_open_hyperlink_cb (GSimpleAction *action,
if (info->hyperlink == NULL)
return;
- terminal_util_open_url (GTK_WIDGET (window), info->hyperlink, FLAVOR_AS_IS,
+ terminal_util_open_url (GTK_WIDGET (window), info->hyperlink,
gtk_get_current_event_time ());
}
@@ -1728,23 +1728,21 @@ screen_show_popup_menu_cb (TerminalScreen *screen,
/* Matched link section */
else if (info->url != NULL) {
gs_unref_object GMenu *section2 = g_menu_new ();
+ gs_free char* scheme = g_uri_parse_scheme (info->url);
const char *open_label = NULL, *copy_label = NULL;
- switch (info->url_flavor) {
- case FLAVOR_EMAIL:
+ if (scheme == NULL) {
+ /* Not a valid URI; do nothing. */
+ } else if (g_ascii_strcasecmp (scheme, "mailto") == 0) {
open_label = _("Send Mail _To…");
copy_label = _("Copy Mail _Address");
- break;
- case FLAVOR_VOIP_CALL:
+ } else if (g_ascii_strcasecmp (scheme, "sip") == 0 ||
+ g_ascii_strcasecmp (scheme, "sips") == 0) {
open_label = _("Call _To…");
copy_label = _("Copy Call _Address ");
- break;
- case FLAVOR_AS_IS:
- case FLAVOR_DEFAULT_TO_HTTP:
- default:
+ } else {
open_label = _("_Open Link");
copy_label = _("Copy _Link");
- break;
}
g_menu_append (section2, open_label, "win.open-match");
@@ -1848,8 +1846,11 @@ screen_match_clicked_cb (TerminalScreen *screen,
if (screen != priv->active_screen)
return FALSE;
+ if (url_flavor != FLAVOR_AS_IS)
+ return FALSE;
+
gtk_widget_grab_focus (GTK_WIDGET (screen));
- terminal_util_open_url (GTK_WIDGET (window), url, url_flavor,
+ terminal_util_open_url (GTK_WIDGET (window), url,
gtk_get_current_event_time ());
return TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]