mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-02 07:15:31 -04: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);
|
auto_detected(term, action, urls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void url_destroy(struct url *url);
|
||||||
|
|
||||||
void
|
void
|
||||||
urls_assign_key_combos(url_list_t *urls)
|
urls_assign_key_combos(url_list_t *urls)
|
||||||
{
|
{
|
||||||
size_t count = tll_length(*urls);
|
static const wchar_t *const combos[] = {
|
||||||
|
|
||||||
/* Assign key combos */
|
|
||||||
|
|
||||||
static const wchar_t *const single[] = {
|
|
||||||
L"f", L"j", L"d", L"k", L"e", L"i", L"c", L"m", L"r",
|
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",
|
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;
|
||||||
size_t idx = 0;
|
tll_foreach(*urls, it) {
|
||||||
tll_foreach(*urls, it) {
|
if (idx < ALEN(combos)) {
|
||||||
xassert(wcslen(single[idx]) < ALEN(it->item.key) - 1);
|
xassert(wcslen(combos[idx]) < ALEN(it->item.key) - 1);
|
||||||
wcscpy(it->item.key, single[idx++]);
|
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
|
#if defined(_DEBUG) && LOG_ENABLE_DBG
|
||||||
|
|
@ -450,6 +453,13 @@ urls_render(struct terminal *term)
|
||||||
render_refresh(term);
|
render_refresh(term);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
url_destroy(struct url *url)
|
||||||
|
{
|
||||||
|
free(url->url);
|
||||||
|
free(url->text);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
urls_reset(struct terminal *term)
|
urls_reset(struct terminal *term)
|
||||||
{
|
{
|
||||||
|
|
@ -468,8 +478,7 @@ urls_reset(struct terminal *term)
|
||||||
|
|
||||||
tll_foreach(term->urls, it) {
|
tll_foreach(term->urls, it) {
|
||||||
tag_cells_for_url(term, &it->item, false);
|
tag_cells_for_url(term, &it->item, false);
|
||||||
free(it->item.url);
|
url_destroy(&it->item);
|
||||||
free(it->item.text);
|
|
||||||
}
|
}
|
||||||
tll_free(term->urls);
|
tll_free(term->urls);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue