mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-13 05:33:51 -04:00
urls: add key binding that toggles whether URLs are displayed on jump-label
By default, the URL isn’t shown on the jump-label. For auto-detect URLs, doing so is virtually always useless, as the URL is already visible in the grid. For OSC-8 URLs however, the URL is often _not_ visible in the grid. Many times, seeing the URL is still not needed (if you’re doing ‘ls --hyperlink’, you already know what the URIs are). But it is still useful to have a way to show the URLs. This patch adds a new key binding action that can be used in url-mode to toggle the URL on and off in the jump label. It is bound to ctrl+t by default.
This commit is contained in:
parent
cc43c1b704
commit
06a9ffa763
7 changed files with 44 additions and 2 deletions
2
config.c
2
config.c
|
|
@ -119,6 +119,7 @@ static_assert(ALEN(search_binding_action_map) == BIND_ACTION_SEARCH_COUNT,
|
||||||
static const char *const url_binding_action_map[] = {
|
static const char *const url_binding_action_map[] = {
|
||||||
[BIND_ACTION_URL_NONE] = NULL,
|
[BIND_ACTION_URL_NONE] = NULL,
|
||||||
[BIND_ACTION_URL_CANCEL] = "cancel",
|
[BIND_ACTION_URL_CANCEL] = "cancel",
|
||||||
|
[BIND_ACTION_URL_TOGGLE_URL_ON_JUMP_LABEL] = "toggle-url-visible",
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(ALEN(url_binding_action_map) == BIND_ACTION_URL_COUNT,
|
static_assert(ALEN(url_binding_action_map) == BIND_ACTION_URL_COUNT,
|
||||||
|
|
@ -2107,6 +2108,7 @@ add_default_url_bindings(struct config *conf)
|
||||||
add_binding(BIND_ACTION_URL_CANCEL, ctrl, XKB_KEY_g);
|
add_binding(BIND_ACTION_URL_CANCEL, ctrl, XKB_KEY_g);
|
||||||
add_binding(BIND_ACTION_URL_CANCEL, ctrl, XKB_KEY_d);
|
add_binding(BIND_ACTION_URL_CANCEL, ctrl, XKB_KEY_d);
|
||||||
add_binding(BIND_ACTION_URL_CANCEL, none, XKB_KEY_Escape);
|
add_binding(BIND_ACTION_URL_CANCEL, none, XKB_KEY_Escape);
|
||||||
|
add_binding(BIND_ACTION_URL_TOGGLE_URL_ON_JUMP_LABEL, ctrl, XKB_KEY_t);
|
||||||
|
|
||||||
#undef add_binding
|
#undef add_binding
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -610,6 +610,20 @@ mode. The syntax is exactly the same as the regular **key-bindings**.
|
||||||
Exits URL mode without opening an URL. Default: _Control+g
|
Exits URL mode without opening an URL. Default: _Control+g
|
||||||
Control+d Escape_.
|
Control+d Escape_.
|
||||||
|
|
||||||
|
*toggle-url-visible*
|
||||||
|
By default, the jump label only shows the key sequence required to
|
||||||
|
activate it. This is fine as long as the URL is visible in the
|
||||||
|
original text.
|
||||||
|
|
||||||
|
But with e.g. OSC-8 URLs (the terminal version of HTML anchors,
|
||||||
|
i.e. "links"), the text on the screen can be something completey
|
||||||
|
different than the URL.
|
||||||
|
|
||||||
|
This action toggles between showing and hiding the URL on the jump
|
||||||
|
label.
|
||||||
|
|
||||||
|
Default: _Control+t_
|
||||||
|
|
||||||
|
|
||||||
# SECTION: mouse-bindings
|
# SECTION: mouse-bindings
|
||||||
|
|
||||||
|
|
|
||||||
1
foot.ini
1
foot.ini
|
|
@ -125,6 +125,7 @@
|
||||||
|
|
||||||
[url-bindings]
|
[url-bindings]
|
||||||
# cancel=Control+g Control+d Escape
|
# cancel=Control+g Control+d Escape
|
||||||
|
# toggle-url-visible=Control+t
|
||||||
|
|
||||||
[mouse-bindings]
|
[mouse-bindings]
|
||||||
# primary-paste=BTN_MIDDLE
|
# primary-paste=BTN_MIDDLE
|
||||||
|
|
|
||||||
21
render.c
21
render.c
|
|
@ -2525,6 +2525,8 @@ render_urls(struct terminal *term)
|
||||||
+ term->grid->num_rows) & (term->grid->num_rows - 1);
|
+ term->grid->num_rows) & (term->grid->num_rows - 1);
|
||||||
const int view_end = view_start + term->rows - 1;
|
const int view_end = view_start + term->rows - 1;
|
||||||
|
|
||||||
|
const bool show_url = term->urls_show_uri_on_jump_label;
|
||||||
|
|
||||||
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 *key = url->key;
|
const wchar_t *key = url->key;
|
||||||
|
|
@ -2562,13 +2564,28 @@ render_urls(struct terminal *term)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t chars = wcslen(key);
|
const size_t key_len = wcslen(key);
|
||||||
|
|
||||||
|
size_t url_len = mbstowcs(NULL, url->url, 0);
|
||||||
|
if (url_len == (size_t)-1)
|
||||||
|
url_len = 0;
|
||||||
|
|
||||||
|
wchar_t url_wchars[url_len + 1];
|
||||||
|
mbstowcs(url_wchars, url->url, url_len + 1);
|
||||||
|
|
||||||
|
size_t chars = key_len + (show_url ? (2 + url_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];
|
||||||
wcscpy(label, key);
|
label[chars] = L'…';
|
||||||
|
label[chars + 1] = L'\0';
|
||||||
|
|
||||||
|
if (show_url)
|
||||||
|
swprintf(label, chars + 1, L"%ls: %ls", key, url_wchars);
|
||||||
|
else
|
||||||
|
wcsncpy(label, key, chars + 1);
|
||||||
|
|
||||||
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]);
|
||||||
|
|
|
||||||
|
|
@ -539,6 +539,7 @@ struct terminal {
|
||||||
|
|
||||||
url_list_t urls;
|
url_list_t urls;
|
||||||
wchar_t url_keys[5];
|
wchar_t url_keys[5];
|
||||||
|
bool urls_show_uri_on_jump_label;
|
||||||
|
|
||||||
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
||||||
struct {
|
struct {
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,11 @@ execute_binding(struct seat *seat, struct terminal *term,
|
||||||
urls_reset(term);
|
urls_reset(term);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
case BIND_ACTION_URL_TOGGLE_URL_ON_JUMP_LABEL:
|
||||||
|
term->urls_show_uri_on_jump_label = !term->urls_show_uri_on_jump_label;
|
||||||
|
render_refresh_urls(term);
|
||||||
|
return true;
|
||||||
|
|
||||||
case BIND_ACTION_URL_COUNT:
|
case BIND_ACTION_URL_COUNT:
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
@ -613,6 +618,7 @@ urls_reset(struct terminal *term)
|
||||||
tll_remove(term->urls, it);
|
tll_remove(term->urls, it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
term->urls_show_uri_on_jump_label = false;
|
||||||
memset(term->url_keys, 0, sizeof(term->url_keys));
|
memset(term->url_keys, 0, sizeof(term->url_keys));
|
||||||
render_refresh(term);
|
render_refresh(term);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@ enum bind_action_search {
|
||||||
enum bind_action_url {
|
enum bind_action_url {
|
||||||
BIND_ACTION_URL_NONE,
|
BIND_ACTION_URL_NONE,
|
||||||
BIND_ACTION_URL_CANCEL,
|
BIND_ACTION_URL_CANCEL,
|
||||||
|
BIND_ACTION_URL_TOGGLE_URL_ON_JUMP_LABEL,
|
||||||
BIND_ACTION_URL_COUNT,
|
BIND_ACTION_URL_COUNT,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue