Merge branch 'url-hint-letters'

Closes #355
This commit is contained in:
Daniel Eklöf 2021-02-13 19:13:46 +01:00
commit 4c1846f11b
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
9 changed files with 57 additions and 22 deletions

View file

@ -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

View file

@ -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,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);

View file

@ -64,6 +64,7 @@ struct config {
char *title;
char *app_id;
wchar_t *word_delimiters;
wchar_t *jump_label_letters;
bool login_shell;
struct {

View file

@ -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

View file

@ -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_

View file

@ -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>

View file

@ -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;
}

View file

@ -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)

View file

@ -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);