=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/format.c,v retrieving revision 1.307 retrieving revision 1.308 diff -c -r1.307 -r1.308 *** src/usr.bin/tmux/format.c 2022/06/27 09:16:54 1.307 --- src/usr.bin/tmux/format.c 2022/07/06 07:36:36 1.308 *************** *** 1,4 **** ! /* $OpenBSD: format.c,v 1.307 2022/06/27 09:16:54 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: format.c,v 1.308 2022/07/06 07:36:36 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott *************** *** 1145,1150 **** --- 1145,1169 ---- 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,2794 **** --- 2808,2816 ---- { "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 }, *************** *** 5063,5066 **** --- 5085,5105 ---- free(ud); } 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)); }