aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-02-06 19:01:52 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-02-07 15:33:34 +0000
commita988138492ba39d507f644bbb0b6d452a864ca79 (patch)
tree6ef09b4e1260fe7cc6573a18a33b709e9147b1b2
parenturl-mode: underline URLs using the color from colors.urls (diff)
url-mode: urls_collect(): URL list pointer as an argument
-rw-r--r--input.c6
-rw-r--r--terminal.h3
-rw-r--r--url-mode.c98
-rw-r--r--url-mode.h7
4 files changed, 60 insertions, 54 deletions
diff --git a/input.c b/input.c
index 7ba8e8e0..69fce248 100644
--- a/input.c
+++ b/input.c
@@ -280,9 +280,9 @@ execute_binding(struct seat *seat, struct terminal *term,
? URL_ACTION_COPY
: URL_ACTION_LAUNCH;
- urls_collect(term, url_action);
- urls_tag_cells(term);
- render_refresh_urls(term);
+ urls_collect(term, url_action, &term->urls);
+ urls_assign_key_combos(&term->urls);
+ urls_render(term);
return true;
}
diff --git a/terminal.h b/terminal.h
index bb98efc2..b0084f63 100644
--- a/terminal.h
+++ b/terminal.h
@@ -234,6 +234,7 @@ struct url {
struct coord end;
enum url_action action;
};
+typedef tll(struct url) url_list_t;
struct terminal {
struct fdm *fdm;
@@ -513,7 +514,7 @@ struct terminal {
unsigned max_height; /* Maximum image height, in pixels */
} sixel;
- tll(struct url) urls;
+ url_list_t urls;
wchar_t url_keys[5];
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
diff --git a/url-mode.c b/url-mode.c
index e418eb7e..e770aa9b 100644
--- a/url-mode.c
+++ b/url-mode.c
@@ -141,7 +141,7 @@ urls_input(struct seat *seat, struct terminal *term, uint32_t key,
IGNORE_WARNING("-Wpedantic")
static void
-auto_detected(struct terminal *term, enum url_action action)
+auto_detected(const struct terminal *term, enum url_action action, url_list_t *urls)
{
static const wchar_t *const prots[] = {
L"http://",
@@ -299,7 +299,7 @@ auto_detected(struct terminal *term, enum url_action action)
end.row += term->grid->view;
tll_push_back(
- term->urls,
+ *urls,
((struct url){
.url = xwcsdup(url),
.text = xwcsdup(L""),
@@ -321,12 +321,16 @@ auto_detected(struct terminal *term, enum url_action action)
UNIGNORE_WARNINGS
void
-urls_collect(struct terminal *term, enum url_action action)
+urls_collect(const struct terminal *term, enum url_action action, url_list_t *urls)
{
xassert(tll_length(term->urls) == 0);
- auto_detected(term, action);
+ auto_detected(term, action, urls);
+}
- size_t count = tll_length(term->urls);
+void
+urls_assign_key_combos(url_list_t *urls)
+{
+ size_t count = tll_length(*urls);
/* Assign key combos */
@@ -337,7 +341,7 @@ urls_collect(struct terminal *term, enum url_action action)
if (count < ALEN(single)) {
size_t idx = 0;
- tll_foreach(term->urls, it) {
+ tll_foreach(*urls, it) {
xassert(wcslen(single[idx]) < ALEN(it->item.key) - 1);
wcscpy(it->item.key, single[idx++]);
}
@@ -347,7 +351,7 @@ urls_collect(struct terminal *term, enum url_action action)
}
#if defined(_DEBUG) && LOG_ENABLE_DBG
- tll_foreach(term->urls, it) {
+ tll_foreach(*urls, it) {
char url[1024];
wcstombs(url, it->item.url, sizeof(url) - 1);
@@ -358,6 +362,43 @@ urls_collect(struct terminal *term, enum url_action action)
}
#endif
+}
+
+static void
+tag_cells_for_url(struct terminal *term, const struct url *url, bool value)
+{
+ const struct coord *start = &url->start;
+ const struct coord *end = &url->end;
+
+ size_t end_r = end->row & (term->grid->num_rows - 1);
+
+ size_t r = start->row & (term->grid->num_rows - 1);
+ size_t c = start->col;
+
+ struct row *row = term->grid->rows[r];
+ row->dirty = true;
+
+ while (true) {
+ struct cell *cell = &row->cells[c];
+ cell->attrs.url = value;
+ cell->attrs.clean = 0;
+
+ if (r == end_r && c == end->col)
+ break;
+
+ if (++c >= term->cols) {
+ r = (r + 1) & (term->grid->num_rows - 1);
+ c = 0;
+
+ row = term->grid->rows[r];
+ row->dirty = true;
+ }
+ }
+}
+
+void
+urls_render(struct terminal *term)
+{
struct wl_window *win = term->window;
struct wayland *wayl = term->wl;
@@ -397,49 +438,10 @@ urls_collect(struct terminal *term, enum url_action action)
};
tll_push_back(win->urls, url);
+ tag_cells_for_url(term, &it->item, true);
}
-}
-
-static void
-tag_cells_for_url(struct terminal *term, const struct url *url, bool value)
-{
- const struct coord *start = &url->start;
- const struct coord *end = &url->end;
-
- size_t end_r = end->row & (term->grid->num_rows - 1);
-
- size_t r = start->row & (term->grid->num_rows - 1);
- size_t c = start->col;
-
- struct row *row = term->grid->rows[r];
- row->dirty = true;
-
- while (true) {
- struct cell *cell = &row->cells[c];
- cell->attrs.url = value;
- cell->attrs.clean = 0;
-
- if (r == end_r && c == end->col)
- break;
-
- if (++c >= term->cols) {
- r = (r + 1) & (term->grid->num_rows - 1);
- c = 0;
-
- row = term->grid->rows[r];
- row->dirty = true;
- }
- }
-}
-void
-urls_tag_cells(struct terminal *term)
-{
- if (unlikely(tll_length(term->urls)) == 0)
- return;
-
- tll_foreach(term->urls, it)
- tag_cells_for_url(term, &it->item, true);
+ render_refresh_urls(term);
render_refresh(term);
}
diff --git a/url-mode.h b/url-mode.h
index 6651e119..12d20192 100644
--- a/url-mode.h
+++ b/url-mode.h
@@ -11,8 +11,11 @@ static inline bool urls_mode_is_active(const struct terminal *term)
return tll_length(term->urls) > 0;
}
-void urls_collect(struct terminal *term, enum url_action action);
-void urls_tag_cells(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_render(struct terminal *term);
void urls_reset(struct terminal *term);
void urls_input(struct seat *seat, struct terminal *term, uint32_t key,