From b09606e3431f4a45ffb2d667c677e1c6704bee26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 13 Feb 2021 11:41:04 +0100 Subject: [PATCH 1/8] url-mode: do case insensitive comparison when matching key sequence --- url-mode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/url-mode.c b/url-mode.c index 245f6273..6aa7b4b8 100644 --- a/url-mode.c +++ b/url-mode.c @@ -125,8 +125,8 @@ urls_input(struct seat *seat, struct terminal *term, uint32_t key, const size_t key_len = wcslen(it->item.key); if (key_len >= seq_len + 1 && - wcsncmp(url->key, term->url_keys, seq_len) == 0 && - url->key[seq_len] == wc) + wcsncasecmp(url->key, term->url_keys, seq_len) == 0 && + towlower(url->key[seq_len]) == towlower(wc)) { is_valid = true; if (key_len == seq_len + 1) { From 94266b99d7a804008912f2354f8d8e7ed55d60a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 13 Feb 2021 11:42:21 +0100 Subject: [PATCH 2/8] config: refactor: add str_to_wchars(), use it when parsing word-delimiters --- config.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/config.c b/config.c index 56acb0cf..939a8c7e 100644 --- a/config.c +++ b/config.c @@ -397,6 +397,25 @@ str_to_double(const char *s, double *res) return errno == 0 && *end == '\0'; } +static bool +str_to_wchars(const char *s, wchar_t **res, struct config *conf, + const char *path, int lineno, + const char *section, const char *key) +{ + *res = NULL; + + size_t chars = mbstowcs(NULL, s, 0); + if (chars == (size_t)-1) { + LOG_AND_NOTIFY_ERR("%s:%d: [%s]: %s: invalid string: %s", + path, lineno, section, key, s); + return false; + } + + *res = xmalloc((chars + 1) * sizeof(wchar_t)); + mbstowcs(*res, s, chars + 1); + return true; +} + static bool str_to_color(const char *s, uint32_t *color, bool allow_alpha, struct config *conf, const char *path, int lineno, @@ -712,18 +731,15 @@ parse_section_main(const char *key, const char *value, struct config *conf, } else if (strcmp(key, "word-delimiters") == 0) { - size_t chars = mbstowcs(NULL, value, 0); - if (chars == (size_t)-1) { - LOG_AND_NOTIFY_ERR( - "%s:%d: [default]: word-delimiters: invalid string: %s", - path, lineno, value); + wchar_t *word_delimiters; + if (!str_to_wchars(value, &word_delimiters, conf, path, lineno, + "default", "word-delimiters")) + { return false; } - free(conf->word_delimiters); + conf->word_delimiters = word_delimiters; - conf->word_delimiters = xmalloc((chars + 1) * sizeof(wchar_t)); - mbstowcs(conf->word_delimiters, value, chars + 1); } else if (strcmp(key, "notify") == 0) { From 7bcab0106870b5c1d3de3990d31673b64ab3e9de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 13 Feb 2021 11:42:40 +0100 Subject: [PATCH 3/8] config: add jump-label-letters option --- config.c | 12 ++++++++++++ config.h | 1 + 2 files changed, 13 insertions(+) diff --git a/config.c b/config.c index 939a8c7e..9ec6960f 100644 --- a/config.c +++ b/config.c @@ -739,7 +739,17 @@ parse_section_main(const char *key, const char *value, struct config *conf, } free(conf->word_delimiters); conf->word_delimiters = word_delimiters; + } + else if (strcmp(key, "jump-label-letters") == 0) { + wchar_t *letters; + if (!str_to_wchars(value, &letters, conf, path, lineno, + "default", "jump-label-letters")) + { + return false; + } + free(conf->jump_label_letters); + conf->jump_label_letters = letters; } else if (strcmp(key, "notify") == 0) { @@ -2142,6 +2152,7 @@ config_load(struct config *conf, const char *conf_path, .title = xstrdup("foot"), .app_id = xstrdup("foot"), .word_delimiters = xwcsdup(L",│`|:\"'()[]{}<>"), + .jump_label_letters = xwcsdup(L"sadfjklewcmpgh"), .size = { .type = CONF_SIZE_PX, .width = 700, @@ -2356,6 +2367,7 @@ config_free(struct config conf) free(conf.title); free(conf.app_id); free(conf.word_delimiters); + free(conf.jump_label_letters); free(conf.scrollback.indicator.text); free_spawn_template(&conf.notify); free_spawn_template(&conf.url_launch); diff --git a/config.h b/config.h index 68a13434..69930ec0 100644 --- a/config.h +++ b/config.h @@ -64,6 +64,7 @@ struct config { char *title; char *app_id; wchar_t *word_delimiters; + wchar_t *jump_label_letters; bool login_shell; struct { From fe8e6f6cdba8e206af48de59ceba1083852f639e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 13 Feb 2021 11:42:51 +0100 Subject: [PATCH 4/8] foot.ini: add default value of jump-label-letters --- foot.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/foot.ini b/foot.ini index 062162f7..5a5256c4 100644 --- a/foot.ini +++ b/foot.ini @@ -26,6 +26,7 @@ # bold-text-in-bright=no # bell=none # word-delimiters=,│`|:"'()[]{}<> +# jump-label-letters=sadfjklewcmpgh # selection-target=primary # workers= From d29ec4fd18c629255b9c0a5c3aab5136ccfaec53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 13 Feb 2021 11:43:02 +0100 Subject: [PATCH 5/8] doc: foot.ini.5: document jump-label-letters --- doc/foot.ini.5.scd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index cb1f1c32..68b350aa 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -214,6 +214,10 @@ in this order: text. Note that whitespace characters are _always_ word delimiters, regardless of this setting. Default: _,│`|:"'()[]{}<>_ +*jump-label-letters* + String of characters that will be when generating key sequences + for URL jump labels. Default: _sadfjklewcmpgh_. + *notify* Command to execute to display a notification. _${title}_ and _${body}_ will be replaced with the notification's actual _title_ From c7006661f5edc55cf235a647da67e0e26e7fe594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 13 Feb 2021 11:43:28 +0100 Subject: [PATCH 6/8] =?UTF-8?q?url-mode:=20use=20=E2=80=98jump-label-lette?= =?UTF-8?q?rs=E2=80=99=20as=20the=20alphabet=20for=20key=20sequences?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of hard coding the alphabet to “sadfjklewcmpgh”, use the letters from ‘jump-label-letters’. Closes #355 --- input.c | 2 +- url-mode.c | 12 ++++++------ url-mode.h | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/input.c b/input.c index 64ab2065..b7b2d290 100644 --- a/input.c +++ b/input.c @@ -281,7 +281,7 @@ execute_binding(struct seat *seat, struct terminal *term, : URL_ACTION_LAUNCH; urls_collect(term, url_action, &term->urls); - urls_assign_key_combos(&term->urls); + urls_assign_key_combos(term->conf, &term->urls); urls_render(term); return true; } diff --git a/url-mode.c b/url-mode.c index 6aa7b4b8..df0f8fb8 100644 --- a/url-mode.c +++ b/url-mode.c @@ -353,11 +353,11 @@ wcscmp_qsort_wrapper(const void *_a, const void *_b) } static void -generate_key_combos(size_t count, wchar_t *combos[static count]) +generate_key_combos(const struct config *conf, + size_t count, wchar_t *combos[static count]) { - /* vimium default */ - static const wchar_t alphabet[] = L"sadfjklewcmpgh"; - static const size_t alphabet_len = ALEN(alphabet) - 1; + const wchar_t *alphabet = conf->jump_label_letters; + const size_t alphabet_len = wcslen(alphabet); size_t hints_count = 1; wchar_t **hints = xmalloc(hints_count * sizeof(hints[0])); @@ -410,14 +410,14 @@ generate_key_combos(size_t count, wchar_t *combos[static count]) } void -urls_assign_key_combos(url_list_t *urls) +urls_assign_key_combos(const struct config *conf, url_list_t *urls) { const size_t count = tll_length(*urls); if (count == 0) return; wchar_t *combos[count]; - generate_key_combos(count, combos); + generate_key_combos(conf, count, combos); size_t idx = 0; tll_foreach(*urls, it) diff --git a/url-mode.h b/url-mode.h index 12d20192..28abde18 100644 --- a/url-mode.h +++ b/url-mode.h @@ -4,6 +4,7 @@ #include #include +#include "config.h" #include "terminal.h" static inline bool urls_mode_is_active(const struct terminal *term) @@ -13,7 +14,7 @@ static inline bool urls_mode_is_active(const struct terminal *term) void urls_collect( const struct terminal *term, enum url_action action, url_list_t *urls); -void urls_assign_key_combos(url_list_t *urls); +void urls_assign_key_combos(const struct config *conf, url_list_t *urls); void urls_render(struct terminal *term); void urls_reset(struct terminal *term); From 4118d2326716244a96a669419718a9ca1e1379c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 13 Feb 2021 11:45:38 +0100 Subject: [PATCH 7/8] doc: foot.1: mention that the key sequence alphabet can be configured --- doc/foot.1.scd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/foot.1.scd b/doc/foot.1.scd index 71071dac..2893842c 100644 --- a/doc/foot.1.scd +++ b/doc/foot.1.scd @@ -262,8 +262,8 @@ be changed with the *url-launch* option. what activating an URL _does_; instead of opening it, it copies it to the clipboard. It is unbound by default. -Both the jump label colors, and the URL underline color can be -configured, independently. +Jump label colors, the URL underline color, and the letters used in +the jump label key sequences can be configured. # ALT/META CHARACTERS From 0b1af321d9ebde3ca9cde456e9d14607e558afb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 13 Feb 2021 11:45:54 +0100 Subject: [PATCH 8/8] readme: mention that the key sequence alphabet can be configured --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 428d4958..2c3281ad 100644 --- a/README.md +++ b/README.md @@ -275,8 +275,8 @@ be changed with the `url-launch` option. what activating an URL _does_; instead of opening it, it copies it to the clipboard. It is unbound by default. -Both the jump label colors, and the URL underline color can be -configured, independently. +Jump label colors, the URL underline color, and the letters used in +the jump label key sequences can be configured. ## Alt/meta