mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05:00
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.
This commit is contained in:
parent
b17a392b8c
commit
93181649b3
8 changed files with 52 additions and 20 deletions
1
config.c
1
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 */
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
1
foot.ini
1
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
|
||||
|
|
|
|||
10
input.c
10
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(
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
50
url-mode.c
50
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;
|
||||
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;
|
||||
|
||||
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);
|
||||
case URL_ACTION_LAUNCH: {
|
||||
size_t argc;
|
||||
char **argv;
|
||||
|
||||
for (size_t i = 0; i < argc; i++)
|
||||
free(argv[i]);
|
||||
free(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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue