From ee39966dedf9e8fbee5528c324c807b92b9a6c23 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 30 Jan 2021 12:43:59 +0100 Subject: config: add infrastructure to handle URL mode specific key bindings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add “show-urls” action to regular key bindings * Add url-bindings section to foot.ini * Add “cancel” action to URL mode key bindings --- doc/foot.ini.5.scd | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'doc') diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 8684850b..9982acb8 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -491,6 +491,11 @@ e.g. *search-start=none*. Default: _not bound_ +*show-urls* + Enters URL mode, where all currently visible URLs are tagged with + a jump label with a key sequence that will open the URL. Default: + _Control+Shift+F_. + # SECTION: search-bindings @@ -569,6 +574,17 @@ scrollback search mode. The syntax is exactly the same as the regular Paste from the _primary selection_ into the search buffer. Default: _Shift+Insert_. + +# SECTION: url-bindings + +This section lets you override the default key bindings used in URL +mode. The syntax is exactly the same as the regular **key-bindings**. + +*cancel* + Exits URL mode without opening an URL. Default: _Control+g + Escape_. + + # SECTION: mouse-bindings This section lets you override the default mouse bindings. -- cgit v1.3 From 4233c806c32fef8f92e51361b2f00fd50799f9be Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 31 Jan 2021 14:27:13 +0100 Subject: config: add ‘url-launch’ option, defaulting to “xdg-open ${url}” MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.c | 66 ++++++++++++++++++++++++++++++++++++++++-------------- config.h | 11 +++++---- doc/foot.ini.5.scd | 4 ++++ foot.ini | 4 +++- 4 files changed, 63 insertions(+), 22 deletions(-) (limited to 'doc') diff --git a/config.c b/config.c index 5fccbea4..18503541 100644 --- a/config.c +++ b/config.c @@ -453,6 +453,33 @@ str_to_pt_or_px(const char *s, struct pt_or_px *res, struct config *conf, return true; } +static bool +str_to_spawn_template(struct config *conf, + const char *s, struct config_spawn_template *template, + const char *path, int lineno, const char *section, + const char *key) +{ + free(template->raw_cmd); + free(template->argv); + + template->raw_cmd = NULL; + template->argv = NULL; + + char *raw_cmd = xstrdup(s); + char **argv = NULL; + + if (!tokenize_cmdline(raw_cmd, &argv)) { + LOG_AND_NOTIFY_ERR( + "%s:%d: [%s]: %s: syntax error in command line", + path, lineno, section, key); + return false; + } + + template->raw_cmd = raw_cmd; + template->argv = argv; + return true; +} + static bool parse_section_main(const char *key, const char *value, struct config *conf, const char *path, unsigned lineno) @@ -675,24 +702,19 @@ parse_section_main(const char *key, const char *value, struct config *conf, } else if (strcmp(key, "notify") == 0) { - free(conf->notify.raw_cmd); - free(conf->notify.argv); - - conf->notify.raw_cmd = NULL; - conf->notify.argv = NULL; - - char *raw_cmd = xstrdup(value); - char **argv = NULL; - - if (!tokenize_cmdline(raw_cmd, &argv)) { - LOG_AND_NOTIFY_ERR( - "%s:%d: [default]: notify: syntax error in command line", - path, lineno); + if (!str_to_spawn_template(conf, value, &conf->notify, path, lineno, + "default", "notify")) + { return false; } + } - conf->notify.raw_cmd = raw_cmd; - conf->notify.argv = argv; + else if (strcmp(key, "url-launch") == 0) { + if (!str_to_spawn_template(conf, value, &conf->url_launch, path, lineno, + "default", "url-launch")) + { + return false; + } } else if (strcmp(key, "selection-target") == 0) { @@ -2308,6 +2330,9 @@ config_load(struct config *conf, const char *conf_path, "notify-send -a foot -i foot ${title} ${body}"); tokenize_cmdline(conf->notify.raw_cmd, &conf->notify.argv); + conf->url_launch.raw_cmd = xstrdup("xdg-open ${url}"); + tokenize_cmdline(conf->url_launch.raw_cmd, &conf->url_launch.argv); + tll_foreach(*initial_user_notifications, it) tll_push_back(conf->notifications, it->item); tll_free(*initial_user_notifications); @@ -2372,6 +2397,13 @@ out: return ret; } +static void +free_spawn_template(struct config_spawn_template *template) +{ + free(template->raw_cmd); + free(template->argv); +} + void config_free(struct config conf) { @@ -2381,8 +2413,8 @@ config_free(struct config conf) free(conf.app_id); free(conf.word_delimiters); free(conf.scrollback.indicator.text); - free(conf.notify.raw_cmd); - free(conf.notify.argv); + free_spawn_template(&conf.notify); + free_spawn_template(&conf.url_launch); for (size_t i = 0; i < ALEN(conf.fonts); i++) { tll_foreach(conf.fonts[i], it) config_font_destroy(&it->item); diff --git a/config.h b/config.h index f46fa35f..d6ad2b24 100644 --- a/config.h +++ b/config.h @@ -66,6 +66,11 @@ struct pt_or_px { float pt; }; +struct config_spawn_template { + char *raw_cmd; + char **argv; +}; + struct config { char *term; char *shell; @@ -198,10 +203,8 @@ struct config { SELECTION_TARGET_BOTH } selection_target; - struct { - char *raw_cmd; - char **argv; - } notify; + struct config_spawn_template notify; + struct config_spawn_template url_launch; struct { enum fcft_scaling_filter fcft_filter; diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 9982acb8..71fbc313 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -225,6 +225,10 @@ in this order: Default: _notify-send -a foot -i foot ${title} ${body}_. +*url-launch* + Command to execute when opening URLs. _${url}_ will be replaced + with the actual URL. Default: _xdg-open ${url}_. + *selection-target* Clipboard target to automatically copy selected text to. One of *none*, *primary*, *clipboard* or *both*. Default: _primary_. diff --git a/foot.ini b/foot.ini index 2ea574a2..c69f9716 100644 --- a/foot.ini +++ b/foot.ini @@ -20,10 +20,12 @@ # pad=2x2 # optionally append 'center' # resize-delay-ms=100 +# notify=notify-send -a foot -i foot ${title} ${body} +# url-launch=xdg-open ${url} + # bold-text-in-bright=no # bell=none # word-delimiters=,│`|:"'()[]{}<> -# notify=notify-send -a foot -i foot ${title} ${body} # selection-target=primary # workers= -- cgit v1.3 From 82e2541760e05e989a6fadf834e088b8128ac74a Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 4 Feb 2021 19:40:24 +0100 Subject: config: add ctrl+d as (yet another) default binding url-bindings.cancel --- config.c | 1 + doc/foot.ini.5.scd | 2 +- foot.ini | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/config.c b/config.c index 18503541..2cf62f45 100644 --- a/config.c +++ b/config.c @@ -2181,6 +2181,7 @@ add_default_url_bindings(struct config *conf) const struct config_key_modifiers ctrl = {.ctrl = true}; 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, none, XKB_KEY_Escape); #undef add_binding diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 71fbc313..0eb4cc11 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -586,7 +586,7 @@ mode. The syntax is exactly the same as the regular **key-bindings**. *cancel* Exits URL mode without opening an URL. Default: _Control+g - Escape_. + Control+d Escape_. # SECTION: mouse-bindings diff --git a/foot.ini b/foot.ini index c69f9716..b8998c18 100644 --- a/foot.ini +++ b/foot.ini @@ -119,7 +119,7 @@ # primary-paste=Shift+Insert [url-bindings] -# cancel=Control+g Escape +# cancel=Control+g Control+d Escape [mouse-bindings] # primary-paste=BTN_MIDDLE -- cgit v1.3 From 0a1c5e44c4459390e927440a59acafafc8372da5 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 4 Feb 2021 20:39:13 +0100 Subject: config: rename ‘show-urls’ to ‘show-urls-launch’ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.c | 4 ++-- doc/foot.ini.5.scd | 2 +- foot.ini | 1 + input.c | 2 +- wayland.h | 4 ++-- 5 files changed, 7 insertions(+), 6 deletions(-) (limited to 'doc') diff --git a/config.c b/config.c index 2cf62f45..1c320da8 100644 --- a/config.c +++ b/config.c @@ -75,7 +75,7 @@ static const char *const binding_action_map[] = { [BIND_ACTION_PIPE_SCROLLBACK] = "pipe-scrollback", [BIND_ACTION_PIPE_VIEW] = "pipe-visible", [BIND_ACTION_PIPE_SELECTED] = "pipe-selected", - [BIND_ACTION_SHOW_URLS] = "show-urls", + [BIND_ACTION_SHOW_URLS_LAUNCH] = "show-urls-launch", /* Mouse-specific actions */ [BIND_ACTION_SELECT_BEGIN] = "select-begin", @@ -2114,7 +2114,7 @@ add_default_key_bindings(struct config *conf) add_binding(BIND_ACTION_FONT_SIZE_RESET, ctrl, XKB_KEY_0); add_binding(BIND_ACTION_FONT_SIZE_RESET, ctrl, XKB_KEY_KP_0); add_binding(BIND_ACTION_SPAWN_TERMINAL, ctrl_shift, XKB_KEY_N); - add_binding(BIND_ACTION_SHOW_URLS, ctrl_shift, XKB_KEY_F); + add_binding(BIND_ACTION_SHOW_URLS_LAUNCH, ctrl_shift, XKB_KEY_F); #undef add_binding } diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 0eb4cc11..4d552a67 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -495,7 +495,7 @@ e.g. *search-start=none*. Default: _not bound_ -*show-urls* +*show-urls-launch* Enters URL mode, where all currently visible URLs are tagged with a jump label with a key sequence that will open the URL. Default: _Control+Shift+F_. diff --git a/foot.ini b/foot.ini index b8998c18..41dec6c6 100644 --- a/foot.ini +++ b/foot.ini @@ -97,6 +97,7 @@ # pipe-visible=[sh -c "xurls | bemenu | xargs -r firefox"] none # pipe-scrollback=[sh -c "xurls | bemenu | xargs -r firefox"] none # pipe-selected=[xargs -r firefox] none +# show-urls=Control+Shift+F [search-bindings] # cancel=Control+g Escape diff --git a/input.c b/input.c index 9dbdaad1..dfbf4fa3 100644 --- a/input.c +++ b/input.c @@ -272,7 +272,7 @@ execute_binding(struct seat *seat, struct terminal *term, return true; } - case BIND_ACTION_SHOW_URLS: + case BIND_ACTION_SHOW_URLS_LAUNCH: xassert(!urls_mode_is_active(term)); urls_collect(term); diff --git a/wayland.h b/wayland.h index 2e5997e4..3ad7b862 100644 --- a/wayland.h +++ b/wayland.h @@ -49,7 +49,7 @@ enum bind_action_normal { BIND_ACTION_PIPE_SCROLLBACK, BIND_ACTION_PIPE_VIEW, BIND_ACTION_PIPE_SELECTED, - BIND_ACTION_SHOW_URLS, + BIND_ACTION_SHOW_URLS_LAUNCH, /* Mouse specific actions - i.e. they require a mouse coordinate */ BIND_ACTION_SELECT_BEGIN, @@ -60,7 +60,7 @@ enum bind_action_normal { BIND_ACTION_SELECT_WORD_WS, BIND_ACTION_SELECT_ROW, - BIND_ACTION_KEY_COUNT = BIND_ACTION_SHOW_URLS + 1, + BIND_ACTION_KEY_COUNT = BIND_ACTION_SHOW_URLS_LAUNCH + 1, BIND_ACTION_COUNT = BIND_ACTION_SELECT_ROW + 1, }; -- cgit v1.3 From b17a392b8cd1a16a74c4190d4d95cdb32c168445 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 4 Feb 2021 20:54:17 +0100 Subject: config: show-urls-launch: change default key binding to ctrl+shift+u --- config.c | 2 +- doc/foot.ini.5.scd | 2 +- foot.ini | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'doc') diff --git a/config.c b/config.c index 1c320da8..0ea45b02 100644 --- a/config.c +++ b/config.c @@ -2114,7 +2114,7 @@ add_default_key_bindings(struct config *conf) add_binding(BIND_ACTION_FONT_SIZE_RESET, ctrl, XKB_KEY_0); add_binding(BIND_ACTION_FONT_SIZE_RESET, ctrl, XKB_KEY_KP_0); add_binding(BIND_ACTION_SPAWN_TERMINAL, ctrl_shift, XKB_KEY_N); - add_binding(BIND_ACTION_SHOW_URLS_LAUNCH, ctrl_shift, XKB_KEY_F); + add_binding(BIND_ACTION_SHOW_URLS_LAUNCH, ctrl_shift, XKB_KEY_U); #undef add_binding } diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 4d552a67..fe158279 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -498,7 +498,7 @@ e.g. *search-start=none*. *show-urls-launch* Enters URL mode, where all currently visible URLs are tagged with a jump label with a key sequence that will open the URL. Default: - _Control+Shift+F_. + _Control+Shift+U_. # SECTION: search-bindings diff --git a/foot.ini b/foot.ini index 41dec6c6..692eac4f 100644 --- a/foot.ini +++ b/foot.ini @@ -97,7 +97,7 @@ # pipe-visible=[sh -c "xurls | bemenu | xargs -r firefox"] none # pipe-scrollback=[sh -c "xurls | bemenu | xargs -r firefox"] none # pipe-selected=[xargs -r firefox] none -# show-urls=Control+Shift+F +# show-urls-launch=Control+Shift+U [search-bindings] # cancel=Control+g Escape -- cgit v1.3 From 93181649b32249f572bc4c6892c99155186fc714 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 4 Feb 2021 20:55:08 +0100 Subject: config: add show-urls-copy action This works just like show-urls-launch, except that instead of opening the URL (typically using xdg-open), it is placed in the clipboard when activated. --- config.c | 1 + doc/foot.ini.5.scd | 5 +++++ foot.ini | 1 + input.c | 10 ++++++++-- terminal.h | 2 ++ url-mode.c | 52 ++++++++++++++++++++++++++++++++++------------------ url-mode.h | 2 +- wayland.h | 1 + 8 files changed, 53 insertions(+), 21 deletions(-) (limited to 'doc') diff --git a/config.c b/config.c index 0ea45b02..74cff1f3 100644 --- a/config.c +++ b/config.c @@ -75,6 +75,7 @@ static const char *const binding_action_map[] = { [BIND_ACTION_PIPE_SCROLLBACK] = "pipe-scrollback", [BIND_ACTION_PIPE_VIEW] = "pipe-visible", [BIND_ACTION_PIPE_SELECTED] = "pipe-selected", + [BIND_ACTION_SHOW_URLS_COPY] = "show-urls-copy", [BIND_ACTION_SHOW_URLS_LAUNCH] = "show-urls-launch", /* Mouse-specific actions */ diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index fe158279..727b81f1 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -500,6 +500,11 @@ e.g. *search-start=none*. a jump label with a key sequence that will open the URL. Default: _Control+Shift+U_. +*show-urls-copy* + Enters URL mode, where all currently visible URLs are tagged with + a jump label with a key sequence that will place the URL in the + clipboard. Default: _none_. + # SECTION: search-bindings diff --git a/foot.ini b/foot.ini index 692eac4f..4ed3d64b 100644 --- a/foot.ini +++ b/foot.ini @@ -98,6 +98,7 @@ # pipe-scrollback=[sh -c "xurls | bemenu | xargs -r firefox"] none # pipe-selected=[xargs -r firefox] none # show-urls-launch=Control+Shift+U +# show-urls-copy=none [search-bindings] # cancel=Control+g Escape diff --git a/input.c b/input.c index dfbf4fa3..65670aa3 100644 --- a/input.c +++ b/input.c @@ -272,12 +272,18 @@ execute_binding(struct seat *seat, struct terminal *term, return true; } - case BIND_ACTION_SHOW_URLS_LAUNCH: + case BIND_ACTION_SHOW_URLS_COPY: + case BIND_ACTION_SHOW_URLS_LAUNCH: { xassert(!urls_mode_is_active(term)); - urls_collect(term); + enum url_action url_action = action == BIND_ACTION_SHOW_URLS_COPY + ? URL_ACTION_COPY + : URL_ACTION_LAUNCH; + + urls_collect(term, url_action); render_refresh_urls(term); return true; + } case BIND_ACTION_SELECT_BEGIN: selection_start( diff --git a/terminal.h b/terminal.h index 24183c7b..b58cd137 100644 --- a/terminal.h +++ b/terminal.h @@ -223,12 +223,14 @@ enum term_surface { typedef tll(struct ptmx_buffer) ptmx_buffer_list_t; +enum url_action { URL_ACTION_COPY, URL_ACTION_LAUNCH }; struct url { wchar_t *url; wchar_t *text; wchar_t key[4]; struct coord start; struct coord end; + enum url_action action; }; struct terminal { diff --git a/url-mode.c b/url-mode.c index 78291685..79c6c17c 100644 --- a/url-mode.c +++ b/url-mode.c @@ -7,6 +7,7 @@ #define LOG_ENABLE_DBG 1 #include "log.h" #include "grid.h" +#include "selection.h" #include "spawn.h" #include "terminal.h" #include "util.h" @@ -88,24 +89,38 @@ urls_input(struct seat *seat, struct terminal *term, uint32_t key, size_t chars = wcstombs(NULL, match->url, 0); if (chars != (size_t)-1) { - char url_utf8[chars + 1]; + char *url_utf8 = malloc(chars + 1); wcstombs(url_utf8, match->url, chars + 1); - size_t argc; - char **argv; - - if (spawn_expand_template( - &term->conf->url_launch, 1, - (const char *[]){"url"}, - (const char *[]){url_utf8}, - &argc, &argv)) - { - spawn(term->reaper, term->cwd, argv, -1, -1, -1); + switch (match->action) { + case URL_ACTION_COPY: + if (text_to_clipboard(seat, term, url_utf8, seat->kbd.serial)) { + /* Now owned by our clipboard “manager” */ + url_utf8 = NULL; + } + break; - for (size_t i = 0; i < argc; i++) - free(argv[i]); - free(argv); + case URL_ACTION_LAUNCH: { + size_t argc; + char **argv; + + if (spawn_expand_template( + &term->conf->url_launch, 1, + (const char *[]){"url"}, + (const char *[]){url_utf8}, + &argc, &argv)) + { + spawn(term->reaper, term->cwd, argv, -1, -1, -1); + + for (size_t i = 0; i < argc; i++) + free(argv[i]); + free(argv); + } + break; + } } + + free(url_utf8); } urls_reset(term); @@ -120,7 +135,7 @@ urls_input(struct seat *seat, struct terminal *term, uint32_t key, IGNORE_WARNING("-Wpedantic") static void -auto_detected(struct terminal *term) +auto_detected(struct terminal *term, enum url_action action) { static const wchar_t *const prots[] = { L"http://", @@ -274,7 +289,8 @@ auto_detected(struct terminal *term) .url = xwcsdup(url), .text = xwcsdup(L""), .start = start, - .end = end})); + .end = end, + .action = action})); state = STATE_PROTOCOL; len = 0; @@ -290,10 +306,10 @@ auto_detected(struct terminal *term) UNIGNORE_WARNINGS void -urls_collect(struct terminal *term) +urls_collect(struct terminal *term, enum url_action action) { xassert(tll_length(term->urls) == 0); - auto_detected(term); + auto_detected(term, action); size_t count = tll_length(term->urls); diff --git a/url-mode.h b/url-mode.h index 150a0222..94c1e675 100644 --- a/url-mode.h +++ b/url-mode.h @@ -11,7 +11,7 @@ static inline bool urls_mode_is_active(const struct terminal *term) return tll_length(term->urls) > 0; } -void urls_collect(struct terminal *term); +void urls_collect(struct terminal *term, enum url_action action); void urls_reset(struct terminal *term); void urls_input(struct seat *seat, struct terminal *term, uint32_t key, diff --git a/wayland.h b/wayland.h index 3ad7b862..3c160b7c 100644 --- a/wayland.h +++ b/wayland.h @@ -49,6 +49,7 @@ enum bind_action_normal { BIND_ACTION_PIPE_SCROLLBACK, BIND_ACTION_PIPE_VIEW, BIND_ACTION_PIPE_SELECTED, + BIND_ACTION_SHOW_URLS_COPY, BIND_ACTION_SHOW_URLS_LAUNCH, /* Mouse specific actions - i.e. they require a mouse coordinate */ -- cgit v1.3 From e9c3d03837bb50ec39b85ee92f2906e2bb40971f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 6 Feb 2021 11:10:40 +0100 Subject: config: add colors.jump_labels and colors.urls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * colors.jump_labels configures the foreground and background colors used when rendering URL jump labels. Defaults to “regular0 regular3” (i.e. black on yellow). * colors.urls configures the color to use when highlighting URLs in URL mode. Note that we aren’t currently doing any highlighting... Defaults to regular3 (i.e. yellow). --- config.c | 68 +++++++++++++++++++++++++++++++++++++++++++----------- config.h | 8 +++++++ doc/foot.ini.5.scd | 9 ++++++++ foot.ini | 2 ++ render.c | 12 ++++++++-- 5 files changed, 84 insertions(+), 15 deletions(-) (limited to 'doc') diff --git a/config.c b/config.c index 285bc889..f7452994 100644 --- a/config.c +++ b/config.c @@ -420,6 +420,30 @@ str_to_color(const char *s, uint32_t *color, bool allow_alpha, return true; } +static bool +str_to_two_colors(const char *s, uint32_t *first, uint32_t *second, + bool allow_alpha, struct config *conf, const char *path, + int lineno, const char *section, const char *key) +{ + /* TODO: do this without strdup() */ + char *value_copy = xstrdup(s); + const char *first_as_str = strtok(value_copy, " "); + const char *second_as_str = strtok(NULL, " "); + + if (first_as_str == NULL || second_as_str == NULL || + !str_to_color(first_as_str, first, allow_alpha, conf, path, lineno, section, key) || + !str_to_color(second_as_str, second, allow_alpha, conf, path, lineno, section, key)) + { + LOG_AND_NOTIFY_ERR("%s:%d: [%s]: %s: invalid colors: %s", + path, lineno, section, key, s); + free(value_copy); + return false; + } + + free(value_copy); + return true; +} + static bool str_to_pt_or_px(const char *s, struct pt_or_px *res, struct config *conf, const char *path, int lineno, const char *section, const char *key) @@ -845,6 +869,30 @@ parse_section_colors(const char *key, const char *value, struct config *conf, else if (strcmp(key, "bright7") == 0) color = &conf->colors.bright[7]; else if (strcmp(key, "selection-foreground") == 0) color = &conf->colors.selection_fg; else if (strcmp(key, "selection-background") == 0) color = &conf->colors.selection_bg; + + else if (strcmp(key, "jump-labels") == 0) { + if (!str_to_two_colors( + value, &conf->colors.jump_label.fg, &conf->colors.jump_label.bg, + false, conf, path, lineno, "colors", "jump-labels")) + { + return false; + } + + conf->colors.use_custom.jump_label = true; + return true; + } + + else if (strcmp(key, "urls") == 0) { + if (!str_to_color(value, &conf->colors.url, false, + conf, path, lineno, "colors", "urls")) + { + return false; + } + + conf->colors.use_custom.url = true; + return true; + } + else if (strcmp(key, "alpha") == 0) { double alpha; if (!str_to_double(value, &alpha) || alpha < 0. || alpha > 1.) { @@ -892,23 +940,15 @@ parse_section_cursor(const char *key, const char *value, struct config *conf, conf->cursor.blink = str_to_bool(value); else if (strcmp(key, "color") == 0) { - char *value_copy = xstrdup(value); - const char *text = strtok(value_copy, " "); - const char *cursor = strtok(NULL, " "); - - uint32_t text_color, cursor_color; - if (text == NULL || cursor == NULL || - !str_to_color(text, &text_color, false, conf, path, lineno, "cursor", "color") || - !str_to_color(cursor, &cursor_color, false, conf, path, lineno, "cursor", "color")) + if (!str_to_two_colors( + value, &conf->cursor.color.text, &conf->cursor.color.cursor, + false, conf, path, lineno, "cursor", "color")) { - LOG_AND_NOTIFY_ERR("%s:%d: invalid cursor colors: %s", path, lineno, value); - free(value_copy); return false; } - conf->cursor.color.text = 1u << 31 | text_color; - conf->cursor.color.cursor = 1u << 31 | cursor_color; - free(value_copy); + conf->cursor.color.text |= 1u << 31; + conf->cursor.color.cursor |= 1u << 31; } else { @@ -2283,6 +2323,8 @@ config_load(struct config *conf, const char *conf_path, .selection_bg = 0x80000000, /* Use default fg */ .use_custom = { .selection = false, + .jump_label = false, + .url = false, }, }, diff --git a/config.h b/config.h index f8ebb572..94998f28 100644 --- a/config.h +++ b/config.h @@ -139,9 +139,17 @@ struct config { uint16_t alpha; uint32_t selection_fg; uint32_t selection_bg; + uint32_t url; + + struct { + uint32_t fg; + uint32_t bg; + } jump_label; struct { bool selection:1; + bool jump_label:1; + bool url:1; } use_custom; } colors; diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 727b81f1..3b913eda 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -351,6 +351,15 @@ _alpha_ option. text. Note that *both* options must be set, or the default will be used. Default: _inverse foreground/background_. +*jump-labels* + To RRGGBB values specifying the foreground (text) and background + colors to use when rendering jump labels in URL mode. Default: + _regular0 regular3_. + +*urls* + Color to use for the underline used to highlight URLs in URL + mode. Default: _regular3_. + # SECTION: csd diff --git a/foot.ini b/foot.ini index d90c0a06..8896eef0 100644 --- a/foot.ini +++ b/foot.ini @@ -66,6 +66,8 @@ # bright7=ffffff # bright white # selection-foreground= # selection-background= +# jump-labels= +# urls= [csd] # preferred=server diff --git a/render.c b/render.c index 8415ac81..040fa34a 100644 --- a/render.c +++ b/render.c @@ -2578,9 +2578,17 @@ render_urls(struct terminal *term) (term->margins.left + x) / term->scale, (term->margins.top + y) / term->scale); + uint32_t fg = term->conf->colors.use_custom.jump_label + ? term->conf->colors.jump_label.fg + : term->colors.table[0]; + uint32_t bg = term->conf->colors.use_custom.jump_label + ? term->conf->colors.jump_label.bg + : term->colors.table[3]; + + uint16_t alpha = 0xffff; + render_osd(term, surf, sub_surf, buf, label, - term->colors.table[0], term->colors.table[3], 0xf000, - width, height, margin, margin); + fg, bg, alpha, width, height, margin, margin); } } -- cgit v1.3 From d63bc1a88026b5481fec9559681cdf8244a9f905 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 6 Feb 2021 11:18:35 +0100 Subject: readme: add ctrl+shift+u, with description, to the list of default key bindings --- README.md | 4 ++++ doc/foot.ini.5.scd | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'doc') diff --git a/README.md b/README.md index e55d3e82..07d82b1e 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,10 @@ These are the default shortcuts. See `man foot.ini` and the example sequence](https://codeberg.org/dnkl/foot/wiki#user-content-how-to-configure-my-shell-to-emit-the-osc-7-escape-sequence), the new terminal will start in the current working directory. +ctrl+shift+u +: Enter URL mode, where all currently visible URLs are tagged with a + jump label with a key sequence that will open the URL. + #### Scrollback search diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 3b913eda..5bf9bbf5 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -505,13 +505,13 @@ e.g. *search-start=none*. Default: _not bound_ *show-urls-launch* - Enters URL mode, where all currently visible URLs are tagged with - a jump label with a key sequence that will open the URL. Default: + Enter URL mode, where all currently visible URLs are tagged with a + jump label with a key sequence that will open the URL. Default: _Control+Shift+U_. *show-urls-copy* - Enters URL mode, where all currently visible URLs are tagged with - a jump label with a key sequence that will place the URL in the + Enter URL mode, where all currently visible URLs are tagged with a + jump label with a key sequence that will place the URL in the clipboard. Default: _none_. -- cgit v1.3 From 0c847cfe7b5b18fa99078554123a2b2c9e9b0fa3 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 7 Feb 2021 11:39:07 +0100 Subject: doc: foot.1: document the new URL mode --- doc/foot.1.scd | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'doc') diff --git a/doc/foot.1.scd b/doc/foot.1.scd index 9099adc2..4965ca56 100644 --- a/doc/foot.1.scd +++ b/doc/foot.1.scd @@ -236,6 +236,31 @@ _Examples_: - Dina:weight=bold:slant=italic - Courier New:size=12 +# URLs + +Foot supports URL detection. But, unlike many other terminal +emulators, where URLs are highlighted when they are hovered and opened +by clicking on them, foot uses a keyboard driven approach. + +Pressing *ctrl*+*shift*+*u* enters _“URL mode”_, where all currently +visible URLs are underlined, and is associated with a +_“jump-label”_. The jump-label indicates the _key sequence_ +(e.g. *”AF”*) to use to activate the URL. + +The key binding can, of course, be customized, like all other key +bindings in foot. See *show-urls-launch* and *show-urls-copy* in +*foot.ini*(5). + +*show-urls-launch* by default opens the URL with *xdg-open*. This can +be changed with the *url-launch* option. + +*show-urls-copy* is an alternative to *show-urls-launch*, that changes +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. + # ALT/META CHARACTERS By default, foot prefixes meta characters with *ESC*. This corresponds -- cgit v1.3