diff options
author | Thomas Adam <thomas@xteddy.org> | 2022-07-06 10:01:10 +0100 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2022-07-06 10:01:10 +0100 |
commit | b130e951cc3157ef4deeadc25cc668b8e355f234 (patch) | |
tree | a0e44afc634668186123f03e891a37b531fa19a5 /format.c | |
parent | 9e19f132f2963d603a881d8e35411348638e5fc0 (diff) | |
parent | d0d2c39decd1c342f2ffdb360e5d6b509b9bb34e (diff) | |
download | rtmux-b130e951cc3157ef4deeadc25cc668b8e355f234.tar.gz rtmux-b130e951cc3157ef4deeadc25cc668b8e355f234.tar.bz2 rtmux-b130e951cc3157ef4deeadc25cc668b8e355f234.zip |
Merge branch 'obsd-master'
Diffstat (limited to 'format.c')
-rw-r--r-- | format.c | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -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)); +} |