aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-02-13 18:13:46 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-02-13 18:13:46 +0000
commit4c1846f11b18193561c5449bed580c6542e9da3b (patch)
tree89b147db9bc619386b3c7cfcae65252f379bbadf
parentMerge branch 'releases/1.6' (diff)
parentreadme: mention that the key sequence alphabet can be configured (diff)
Merge branch 'url-hint-letters'
Closes #355
-rw-r--r--README.md4
-rw-r--r--config.c44
-rw-r--r--config.h1
-rw-r--r--doc/foot.1.scd4
-rw-r--r--doc/foot.ini.5.scd4
-rw-r--r--foot.ini1
-rw-r--r--input.c2
-rw-r--r--url-mode.c16
-rw-r--r--url-mode.h3
9 files changed, 57 insertions, 22 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
diff --git a/config.c b/config.c
index 56acb0cf..9ec6960f 100644
--- a/config.c
+++ b/config.c
@@ -398,6 +398,25 @@ str_to_double(const char *s, double *res)
}
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,
const char *section, const char *key)
@@ -712,18 +731,25 @@ 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, "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) {
@@ -2126,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,
@@ -2340,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 {
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
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_
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=<number of logical CPUs>
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 245f6273..df0f8fb8 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) {
@@ -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 <xkbcommon/xkbcommon.h>
#include <tllist.h>
+#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);