mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
url-mode: urls_assign_key_combos(): remove URLs when all key combos have been used up
This commit is contained in:
parent
e6612927be
commit
ab1224ba91
1 changed files with 24 additions and 15 deletions
39
url-mode.c
39
url-mode.c
|
|
@ -332,27 +332,30 @@ urls_collect(const struct terminal *term, enum url_action action, url_list_t *ur
|
|||
auto_detected(term, action, urls);
|
||||
}
|
||||
|
||||
static void url_destroy(struct url *url);
|
||||
|
||||
void
|
||||
urls_assign_key_combos(url_list_t *urls)
|
||||
{
|
||||
size_t count = tll_length(*urls);
|
||||
|
||||
/* Assign key combos */
|
||||
|
||||
static const wchar_t *const single[] = {
|
||||
static const wchar_t *const combos[] = {
|
||||
L"f", L"j", L"d", L"k", L"e", L"i", L"c", L"m", L"r",
|
||||
L"u", L"s", L"l", L"w", L"o", L"x", L"a", L"q", L"p",
|
||||
};
|
||||
|
||||
if (count < ALEN(single)) {
|
||||
size_t idx = 0;
|
||||
tll_foreach(*urls, it) {
|
||||
xassert(wcslen(single[idx]) < ALEN(it->item.key) - 1);
|
||||
wcscpy(it->item.key, single[idx++]);
|
||||
size_t idx = 0;
|
||||
tll_foreach(*urls, it) {
|
||||
if (idx < ALEN(combos)) {
|
||||
xassert(wcslen(combos[idx]) < ALEN(it->item.key) - 1);
|
||||
wcscpy(it->item.key, combos[idx]);
|
||||
} else {
|
||||
url_destroy(&it->item);
|
||||
tll_remove(*urls, it);
|
||||
}
|
||||
|
||||
if (++idx == ALEN(combos)) {
|
||||
LOG_WARN("not enough key combos (%zu) for %zu URLs",
|
||||
ALEN(combos), tll_length(*urls));
|
||||
}
|
||||
} else {
|
||||
LOG_ERR("unimplemented: more URLs than %zu", ALEN(single));
|
||||
assert(false);
|
||||
}
|
||||
|
||||
#if defined(_DEBUG) && LOG_ENABLE_DBG
|
||||
|
|
@ -450,6 +453,13 @@ urls_render(struct terminal *term)
|
|||
render_refresh(term);
|
||||
}
|
||||
|
||||
static void
|
||||
url_destroy(struct url *url)
|
||||
{
|
||||
free(url->url);
|
||||
free(url->text);
|
||||
}
|
||||
|
||||
void
|
||||
urls_reset(struct terminal *term)
|
||||
{
|
||||
|
|
@ -468,8 +478,7 @@ urls_reset(struct terminal *term)
|
|||
|
||||
tll_foreach(term->urls, it) {
|
||||
tag_cells_for_url(term, &it->item, false);
|
||||
free(it->item.url);
|
||||
free(it->item.text);
|
||||
url_destroy(&it->item);
|
||||
}
|
||||
tll_free(term->urls);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue