From 39c5057d4963b292651cb23adfd0e1127cf89188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 13 Feb 2021 12:42:35 +0100 Subject: [PATCH] url-mode: initial support for OSC-8 URLs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Things left to do: since OSC-8 URLs are stored as ranges in the per-row ‘extra’ data member, we currently do not handle line-wrapping URLs very well; they will be considered two separate URLs, and assigned two different key sequences. --- url-mode.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/url-mode.c b/url-mode.c index b6025b57..83421abf 100644 --- a/url-mode.c +++ b/url-mode.c @@ -355,11 +355,42 @@ auto_detected(const struct terminal *term, enum url_action action, url_list_t *u UNIGNORE_WARNINGS +static void +osc8_uris(const struct terminal *term, enum url_action action, url_list_t *urls) +{ + for (int r = 0; r < term->rows; r++) { + const struct row *row = grid_row_in_view(term->grid, r); + + if (row->extra == NULL) + continue; + + tll_foreach(row->extra->uri_ranges, it) { + struct coord start = { + .col = it->item.start, + .row = r + term->grid->view, + }; + struct coord end = { + .col = it->item.end, + .row = r + term->grid->view, + }; + tll_push_back( + *urls, + ((struct url){ + .url = xstrdup(it->item.uri), + .text = xwcsdup(L""), + .start = start, + .end = end, + .action = action})); + } + } +} + void urls_collect(const struct terminal *term, enum url_action action, url_list_t *urls) { xassert(tll_length(term->urls) == 0); auto_detected(term, action, urls); + osc8_uris(term, action, urls); } static void url_destroy(struct url *url);