mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Look for URLs via regex
This commit is contained in:
parent
03334664fb
commit
22ca81e0b6
@ -3919,19 +3919,14 @@ _software_autocomplete(ProfWin *window, const char *const input, gboolean previo
|
|||||||
static char*
|
static char*
|
||||||
_urlopen_autocomplete(ProfWin *window, const char *const input, gboolean previous)
|
_urlopen_autocomplete(ProfWin *window, const char *const input, gboolean previous)
|
||||||
{
|
{
|
||||||
if (window->type == WIN_CONSOLE){
|
char *result = NULL;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProfBuffEntry *entry = buffer_get_url(window->layout->buffer, NULL);
|
if (window->type == WIN_CONSOLE){
|
||||||
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);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
result = autocomplete_param_no_with_func(input, "/urlopen", 2, buffer_get_url, previous, window->layout->buffer);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,19 +162,37 @@ buffer_get_entry_by_id(ProfBuff buffer, const char *const id)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfBuffEntry*
|
char*
|
||||||
buffer_get_url(ProfBuff buffer, const char *const id)
|
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;
|
GSList *entries = buffer->entries;
|
||||||
|
|
||||||
while (entries) {
|
while (entries) {
|
||||||
ProfBuffEntry *entry = entries->data;
|
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);
|
entries = g_slist_next(entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return autocomplete_complete(urls_ac, "", FALSE, previous);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -73,6 +73,6 @@ int buffer_size(ProfBuff buffer);
|
|||||||
ProfBuffEntry* buffer_get_entry(ProfBuff buffer, int entry);
|
ProfBuffEntry* buffer_get_entry(ProfBuff buffer, int entry);
|
||||||
ProfBuffEntry* buffer_get_entry_by_id(ProfBuff buffer, const char *const id);
|
ProfBuffEntry* buffer_get_entry_by_id(ProfBuff buffer, const char *const id);
|
||||||
gboolean buffer_mark_received(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
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user