summaryrefslogtreecommitdiffstats
path: root/format.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2022-07-06 10:01:10 +0100
committerThomas Adam <thomas@xteddy.org>2022-07-06 10:01:10 +0100
commitb130e951cc3157ef4deeadc25cc668b8e355f234 (patch)
treea0e44afc634668186123f03e891a37b531fa19a5 /format.c
parent9e19f132f2963d603a881d8e35411348638e5fc0 (diff)
parentd0d2c39decd1c342f2ffdb360e5d6b509b9bb34e (diff)
Merge branch 'obsd-master'
Diffstat (limited to 'format.c')
-rw-r--r--format.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/format.c b/format.c
index 830073e9..411d1bab 100644
--- a/format.c
+++ b/format.c
@@ -1145,6 +1145,25 @@ format_cb_mouse_word(struct format_tree *ft)
return (format_grid_word(gd, x, gd->hsize + y));
}
+/* Callback for mouse_hyperlink. */
+static void *
+format_cb_mouse_hyperlink(struct format_tree *ft)
+{
+ struct window_pane *wp;
+ struct grid *gd;
+ u_int x, y;
+
+ if (!ft->m.valid)
+ return (NULL);
+ wp = cmd_mouse_pane(&ft->m, NULL, NULL);
+ if (wp == NULL)
+ return (NULL);
+ if (cmd_mouse_at(wp, &ft->m, &x, &y, 0) != 0)
+ return (NULL);
+ gd = wp->base.grid;
+ return (format_grid_hyperlink(gd, x, gd->hsize + y, wp->screen));
+}
+
/* Callback for mouse_line. */
static void *
format_cb_mouse_line(struct format_tree *ft)
@@ -2789,6 +2808,9 @@ static const struct format_table_entry format_table[] = {
{ "mouse_button_flag", FORMAT_TABLE_STRING,
format_cb_mouse_button_flag
},
+ { "mouse_hyperlink", FORMAT_TABLE_STRING,
+ format_cb_mouse_hyperlink
+ },
{ "mouse_line", FORMAT_TABLE_STRING,
format_cb_mouse_line
},
@@ -5064,3 +5086,20 @@ format_grid_line(struct grid *gd, u_int y)
}
return (s);
}
+
+/* Return hyperlink at given coordinates. Caller frees. */
+char *
+format_grid_hyperlink(struct grid *gd, u_int x, u_int y, struct screen* s)
+{
+ const char *uri;
+ struct grid_cell gc;
+
+ grid_get_cell(gd, x, y, &gc);
+ if (gc.flags & GRID_FLAG_PADDING)
+ return (NULL);
+ if (s->hyperlinks == NULL || gc.link == 0)
+ return (NULL);
+ if (!hyperlinks_get(s->hyperlinks, gc.link, &uri, NULL, NULL))
+ return (NULL);
+ return (xstrdup(uri));
+}