about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-05-19 17:46:40 +0200
committerMichael Vetter <jubalh@iodoru.org>2020-05-20 10:47:46 +0200
commit22ca81e0b680cae9a3d00eea48a3a9013012af15 (patch)
tree90c4ae6ccacc300b6fcb979fce3fc6e7ffe8cd67 /src
parent03334664fb44ff268f6808a945d5d74d3ed34a70 (diff)
downloadprofani-tty-22ca81e0b680cae9a3d00eea48a3a9013012af15.tar.gz
Look for URLs via regex
Diffstat (limited to 'src')
-rw-r--r--src/command/cmd_ac.c15
-rw-r--r--src/ui/buffer.c28
-rw-r--r--src/ui/buffer.h2
3 files changed, 29 insertions, 16 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index 713653b4..a6f85a87 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -3919,19 +3919,14 @@ _software_autocomplete(ProfWin *window, const char *const input, gboolean previo
 static char*
 _urlopen_autocomplete(ProfWin *window, const char *const input, gboolean previous)
 {
-	if (window->type == WIN_CONSOLE){
-        return NULL;
-    }
+    char *result = NULL;
 
-    ProfBuffEntry *entry = buffer_get_url(window->layout->buffer, NULL);
-    if (entry && entry->message) {
-        GString *result_str = g_string_new("/urlopen ");
-        g_string_append(result_str, entry->message);
-        char *result = result_str->str;
-        g_string_free(result_str, FALSE);
+	if (window->type == WIN_CONSOLE){
         return result;
     }
 
-    return NULL;
+    result = autocomplete_param_no_with_func(input, "/urlopen", 2, buffer_get_url, previous, window->layout->buffer);
+
+    return result;
 }
 
diff --git a/src/ui/buffer.c b/src/ui/buffer.c
index 9b7d3f14..33b161f6 100644
--- a/src/ui/buffer.c
+++ b/src/ui/buffer.c
@@ -162,19 +162,37 @@ buffer_get_entry_by_id(ProfBuff buffer, const char *const id)
     return NULL;
 }
 
-ProfBuffEntry*
-buffer_get_url(ProfBuff buffer, const char *const id)
+char*
+buffer_get_url(const char *const search_str, gboolean previous, void *context)
 {
+    Autocomplete urls_ac = autocomplete_new();
+    ProfBuff buffer = (ProfBuff)context;
     GSList *entries = buffer->entries;
+
     while (entries) {
         ProfBuffEntry *entry = entries->data;
-        if (strstr(entry->message, "http://")) {
-            return entry;
+
+        GRegex *regex;
+        GMatchInfo *match_info;
+
+        regex = g_regex_new("https?://\\S+", 0, 0, NULL);
+        g_regex_match (regex, entry->message, 0, &match_info);
+        while (g_match_info_matches (match_info))
+        {
+            gchar *word = g_match_info_fetch (match_info, 0);
+
+            autocomplete_add(urls_ac, word);
+
+            g_free (word);
+            g_match_info_next (match_info, NULL);
         }
+        g_match_info_free (match_info);
+        g_regex_unref (regex);
+
         entries = g_slist_next(entries);
     }
 
-    return NULL;
+    return autocomplete_complete(urls_ac, "", FALSE, previous);
 }
 
 static void
diff --git a/src/ui/buffer.h b/src/ui/buffer.h
index f9b9030c..5853625e 100644
--- a/src/ui/buffer.h
+++ b/src/ui/buffer.h
@@ -73,6 +73,6 @@ int buffer_size(ProfBuff buffer);
 ProfBuffEntry* buffer_get_entry(ProfBuff buffer, int entry);
 ProfBuffEntry* buffer_get_entry_by_id(ProfBuff buffer, const char *const id);
 gboolean buffer_mark_received(ProfBuff buffer, const char *const id);
-ProfBuffEntry* buffer_get_url(ProfBuff buffer, const char *const id);
+char* buffer_get_url(const char *const search_str, gboolean previous, void *context);
 
 #endif