urls: remove free-form ‘text’ member from URL struct

This commit is contained in:
Daniel Eklöf 2021-02-14 13:42:37 +01:00
parent cf651d361f
commit cc43c1b704
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 5 additions and 21 deletions

View file

@ -2527,7 +2527,6 @@ render_urls(struct terminal *term)
tll_foreach(win->urls, it) { tll_foreach(win->urls, it) {
const struct url *url = it->item.url; const struct url *url = it->item.url;
const wchar_t *text = url->text;
const wchar_t *key = url->key; const wchar_t *key = url->key;
const size_t entered_key_len = wcslen(term->url_keys); const size_t entered_key_len = wcslen(term->url_keys);
@ -2563,22 +2562,13 @@ render_urls(struct terminal *term)
continue; continue;
} }
size_t text_len = wcslen(text); size_t chars = wcslen(key);
size_t chars = wcslen(key) + (text_len > 0 ? 3 + text_len : 0);
const size_t max_chars = 50; const size_t max_chars = 50;
chars = min(chars, max_chars); chars = min(chars, max_chars);
wchar_t label[chars + 2]; wchar_t label[chars + 2];
if (text_len == 0) wcscpy(label, key);
wcscpy(label, key);
else {
int count = swprintf(label, chars + 1, L"%ls - %ls", key, text);
if (count >= max_chars) {
label[max_chars] = L'';
label[max_chars + 1] = L'\0';
}
}
for (size_t i = 0; i < wcslen(key); i++) for (size_t i = 0; i < wcslen(key); i++)
label[i] = towupper(label[i]); label[i] = towupper(label[i]);

View file

@ -252,7 +252,6 @@ enum url_action { URL_ACTION_COPY, URL_ACTION_LAUNCH };
struct url { struct url {
uint64_t id; uint64_t id;
char *url; char *url;
wchar_t *text;
wchar_t *key; wchar_t *key;
struct coord start; struct coord start;
struct coord end; struct coord end;

View file

@ -16,6 +16,8 @@
#include "util.h" #include "util.h"
#include "xmalloc.h" #include "xmalloc.h"
static void url_destroy(struct url *url);
static bool static bool
execute_binding(struct seat *seat, struct terminal *term, execute_binding(struct seat *seat, struct terminal *term,
enum bind_action_url action, uint32_t serial) enum bind_action_url action, uint32_t serial)
@ -346,7 +348,6 @@ auto_detected(const struct terminal *term, enum url_action action,
((struct url){ ((struct url){
.id = (uint64_t)rand() << 32 | rand(), .id = (uint64_t)rand() << 32 | rand(),
.url = url_utf8, .url = url_utf8,
.text = xwcsdup(L""),
.start = start, .start = start,
.end = end, .end = end,
.action = action})); .action = action}));
@ -388,7 +389,6 @@ osc8_uris(const struct terminal *term, enum url_action action, url_list_t *urls)
((struct url){ ((struct url){
.id = it->item.id, .id = it->item.id,
.url = xstrdup(it->item.uri), .url = xstrdup(it->item.uri),
.text = xwcsdup(L""),
.start = start, .start = start,
.end = end, .end = end,
.action = action})); .action = action}));
@ -409,9 +409,7 @@ remove_duplicates(url_list_t *urls)
outer->item.end.row == inner->item.end.row && outer->item.end.row == inner->item.end.row &&
outer->item.end.col == inner->item.end.col) outer->item.end.col == inner->item.end.col)
{ {
free(inner->item.url); url_destroy(&inner->item);
free(inner->item.text);
free(inner->item.key);
tll_remove(*urls, inner); tll_remove(*urls, inner);
} }
} }
@ -427,8 +425,6 @@ urls_collect(const struct terminal *term, enum url_action action, url_list_t *ur
remove_duplicates(urls); remove_duplicates(urls);
} }
static void url_destroy(struct url *url);
static int static int
wcscmp_qsort_wrapper(const void *_a, const void *_b) wcscmp_qsort_wrapper(const void *_a, const void *_b)
{ {
@ -595,7 +591,6 @@ static void
url_destroy(struct url *url) url_destroy(struct url *url)
{ {
free(url->url); free(url->url);
free(url->text);
free(url->key); free(url->key);
} }