=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/tty.c,v retrieving revision 1.420 retrieving revision 1.421 diff -c -r1.420 -r1.421 *** src/usr.bin/tmux/tty.c 2022/06/09 09:12:55 1.420 --- src/usr.bin/tmux/tty.c 2022/06/30 09:55:53 1.421 *************** *** 1,4 **** ! /* $OpenBSD: tty.c,v 1.420 2022/06/09 09:12:55 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: tty.c,v 1.421 2022/06/30 09:55:53 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 69,75 **** static void tty_repeat_space(struct tty *, u_int); static void tty_draw_pane(struct tty *, const struct tty_ctx *, u_int); static void tty_default_attributes(struct tty *, const struct grid_cell *, ! struct colour_palette *, u_int); static int tty_check_overlay(struct tty *, u_int, u_int); static void tty_check_overlay_range(struct tty *, u_int, u_int, u_int, struct overlay_ranges *); --- 69,75 ---- static void tty_repeat_space(struct tty *, u_int); static void tty_draw_pane(struct tty *, const struct tty_ctx *, u_int); static void tty_default_attributes(struct tty *, const struct grid_cell *, ! struct colour_palette *, u_int, struct hyperlinks *); static int tty_check_overlay(struct tty *, u_int, u_int); static void tty_check_overlay_range(struct tty *, u_int, u_int, u_int, struct overlay_ranges *); *************** *** 1455,1461 **** tty_term_has(tty->term, TTYC_EL1) && !tty_fake_bce(tty, defaults, 8) && c->overlay_check == NULL) { ! tty_default_attributes(tty, defaults, palette, 8); tty_cursor(tty, nx - 1, aty); tty_putcode(tty, TTYC_EL1); cleared = 1; --- 1455,1462 ---- tty_term_has(tty->term, TTYC_EL1) && !tty_fake_bce(tty, defaults, 8) && c->overlay_check == NULL) { ! tty_default_attributes(tty, defaults, palette, 8, ! s->hyperlinks); tty_cursor(tty, nx - 1, aty); tty_putcode(tty, TTYC_EL1); cleared = 1; *************** *** 1480,1488 **** gcp->fg != last.fg || gcp->bg != last.bg || gcp->us != last.us || ux + width + gcp->data.width > nx || (sizeof buf) - len < gcp->data.size)) { ! tty_attributes(tty, &last, defaults, palette); if (last.flags & GRID_FLAG_CLEARED) { log_debug("%s: %zu cleared", __func__, len); tty_clear_line(tty, defaults, aty, atx + ux, --- 1481,1491 ---- gcp->fg != last.fg || gcp->bg != last.bg || gcp->us != last.us || + gcp->link != last.link || ux + width + gcp->data.width > nx || (sizeof buf) - len < gcp->data.size)) { ! tty_attributes(tty, &last, defaults, palette, ! s->hyperlinks); if (last.flags & GRID_FLAG_CLEARED) { log_debug("%s: %zu cleared", __func__, len); tty_clear_line(tty, defaults, aty, atx + ux, *************** *** 1515,1521 **** ux += gcp->data.width; } else if (hidden != 0 || ux + gcp->data.width > nx) { if (~gcp->flags & GRID_FLAG_PADDING) { ! tty_attributes(tty, &last, defaults, palette); for (j = 0; j < OVERLAY_MAX_RANGES; j++) { if (r.nx[j] == 0) continue; --- 1518,1525 ---- ux += gcp->data.width; } else if (hidden != 0 || ux + gcp->data.width > nx) { if (~gcp->flags & GRID_FLAG_PADDING) { ! tty_attributes(tty, &last, defaults, palette, ! s->hyperlinks); for (j = 0; j < OVERLAY_MAX_RANGES; j++) { if (r.nx[j] == 0) continue; *************** *** 1532,1538 **** } } } else if (gcp->attr & GRID_ATTR_CHARSET) { ! tty_attributes(tty, &last, defaults, palette); tty_cursor(tty, atx + ux, aty); for (j = 0; j < gcp->data.size; j++) tty_putc(tty, gcp->data.data[j]); --- 1536,1543 ---- } } } else if (gcp->attr & GRID_ATTR_CHARSET) { ! tty_attributes(tty, &last, defaults, palette, ! s->hyperlinks); tty_cursor(tty, atx + ux, aty); for (j = 0; j < gcp->data.size; j++) tty_putc(tty, gcp->data.data[j]); *************** *** 1544,1550 **** } } if (len != 0 && ((~last.flags & GRID_FLAG_CLEARED) || last.bg != 8)) { ! tty_attributes(tty, &last, defaults, palette); if (last.flags & GRID_FLAG_CLEARED) { log_debug("%s: %zu cleared (end)", __func__, len); tty_clear_line(tty, defaults, aty, atx + ux, width, --- 1549,1555 ---- } } if (len != 0 && ((~last.flags & GRID_FLAG_CLEARED) || last.bg != 8)) { ! tty_attributes(tty, &last, defaults, palette, s->hyperlinks); if (last.flags & GRID_FLAG_CLEARED) { log_debug("%s: %zu cleared (end)", __func__, len); tty_clear_line(tty, defaults, aty, atx + ux, width, *************** *** 1560,1566 **** if (!cleared && ux < nx) { log_debug("%s: %u to end of line (%zu cleared)", __func__, nx - ux, len); ! tty_default_attributes(tty, defaults, palette, 8); tty_clear_line(tty, defaults, aty, atx + ux, nx - ux, 8); } --- 1565,1572 ---- if (!cleared && ux < nx) { log_debug("%s: %u to end of line (%zu cleared)", __func__, nx - ux, len); ! tty_default_attributes(tty, defaults, palette, 8, ! s->hyperlinks); tty_clear_line(tty, defaults, aty, atx + ux, nx - ux, 8); } *************** *** 1646,1652 **** return; } ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); --- 1652,1659 ---- return; } ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, ! ctx->s->hyperlinks); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); *************** *** 1668,1674 **** return; } ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); --- 1675,1682 ---- return; } ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, ! ctx->s->hyperlinks); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); *************** *** 1678,1684 **** void tty_cmd_clearcharacter(struct tty *tty, const struct tty_ctx *ctx) { ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg); tty_clear_pane_line(tty, ctx, ctx->ocy, ctx->ocx, ctx->num, ctx->bg); } --- 1686,1693 ---- void tty_cmd_clearcharacter(struct tty *tty, const struct tty_ctx *ctx) { ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, ! ctx->s->hyperlinks); tty_clear_pane_line(tty, ctx, ctx->ocy, ctx->ocx, ctx->num, ctx->bg); } *************** *** 1700,1706 **** return; } ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_margin_off(tty); --- 1709,1716 ---- return; } ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, ! ctx->s->hyperlinks); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_margin_off(tty); *************** *** 1727,1733 **** return; } ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_margin_off(tty); --- 1737,1744 ---- return; } ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, ! ctx->s->hyperlinks); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_margin_off(tty); *************** *** 1740,1746 **** void tty_cmd_clearline(struct tty *tty, const struct tty_ctx *ctx) { ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg); tty_clear_pane_line(tty, ctx, ctx->ocy, 0, ctx->sx, ctx->bg); } --- 1751,1758 ---- void tty_cmd_clearline(struct tty *tty, const struct tty_ctx *ctx) { ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, ! ctx->s->hyperlinks); tty_clear_pane_line(tty, ctx, ctx->ocy, 0, ctx->sx, ctx->bg); } *************** *** 1750,1756 **** { u_int nx = ctx->sx - ctx->ocx; ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg); tty_clear_pane_line(tty, ctx, ctx->ocy, ctx->ocx, nx, ctx->bg); } --- 1762,1769 ---- { u_int nx = ctx->sx - ctx->ocx; ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, ! ctx->s->hyperlinks); tty_clear_pane_line(tty, ctx, ctx->ocy, ctx->ocx, nx, ctx->bg); } *************** *** 1758,1764 **** void tty_cmd_clearstartofline(struct tty *tty, const struct tty_ctx *ctx) { ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg); tty_clear_pane_line(tty, ctx, ctx->ocy, 0, ctx->ocx + 1, ctx->bg); } --- 1771,1778 ---- void tty_cmd_clearstartofline(struct tty *tty, const struct tty_ctx *ctx) { ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, ! ctx->s->hyperlinks); tty_clear_pane_line(tty, ctx, ctx->ocy, 0, ctx->ocx + 1, ctx->bg); } *************** *** 1784,1790 **** return; } ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_margin_pane(tty, ctx); --- 1798,1805 ---- return; } ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, ! ctx->s->hyperlinks); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_margin_pane(tty, ctx); *************** *** 1815,1821 **** return; } ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_margin_pane(tty, ctx); --- 1830,1837 ---- return; } ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, ! ctx->s->hyperlinks); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_margin_pane(tty, ctx); *************** *** 1855,1861 **** return; } ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_margin_pane(tty, ctx); --- 1871,1878 ---- return; } ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, ! ctx->s->hyperlinks); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_margin_pane(tty, ctx); *************** *** 1895,1901 **** return; } ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_margin_pane(tty, ctx); --- 1912,1919 ---- return; } ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, ! ctx->s->hyperlinks); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_margin_pane(tty, ctx); *************** *** 1914,1920 **** { u_int px, py, nx, ny; ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg); tty_region_pane(tty, ctx, 0, ctx->sy - 1); tty_margin_off(tty); --- 1932,1939 ---- { u_int px, py, nx, ny; ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, ! ctx->s->hyperlinks); tty_region_pane(tty, ctx, 0, ctx->sy - 1); tty_margin_off(tty); *************** *** 1938,1944 **** { u_int px, py, nx, ny; ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg); tty_region_pane(tty, ctx, 0, ctx->sy - 1); tty_margin_off(tty); --- 1957,1964 ---- { u_int px, py, nx, ny; ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, ! ctx->s->hyperlinks); tty_region_pane(tty, ctx, 0, ctx->sy - 1); tty_margin_off(tty); *************** *** 1962,1968 **** { u_int px, py, nx, ny; ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg); tty_region_pane(tty, ctx, 0, ctx->sy - 1); tty_margin_off(tty); --- 1982,1989 ---- { u_int px, py, nx, ny; ! tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, ! ctx->s->hyperlinks); tty_region_pane(tty, ctx, 0, ctx->sy - 1); tty_margin_off(tty); *************** *** 1985,1991 **** return; } ! tty_attributes(tty, &grid_default_cell, &ctx->defaults, ctx->palette); tty_region_pane(tty, ctx, 0, ctx->sy - 1); tty_margin_off(tty); --- 2006,2013 ---- return; } ! tty_attributes(tty, &grid_default_cell, &ctx->defaults, ctx->palette, ! ctx->s->hyperlinks); tty_region_pane(tty, ctx, 0, ctx->sy - 1); tty_margin_off(tty); *************** *** 2031,2037 **** tty_margin_off(tty); tty_cursor_pane_unless_wrap(tty, ctx, ctx->ocx, ctx->ocy); ! tty_cell(tty, ctx->cell, &ctx->defaults, ctx->palette); } void --- 2053,2060 ---- tty_margin_off(tty); tty_cursor_pane_unless_wrap(tty, ctx, ctx->ocx, ctx->ocy); ! tty_cell(tty, ctx->cell, &ctx->defaults, ctx->palette, ! ctx->s->hyperlinks); } void *************** *** 2062,2068 **** tty_margin_off(tty); tty_cursor_pane_unless_wrap(tty, ctx, ctx->ocx, ctx->ocy); ! tty_attributes(tty, ctx->cell, &ctx->defaults, ctx->palette); /* Get tty position from pane position for overlay check. */ px = ctx->xoff + ctx->ocx - ctx->wox; --- 2085,2091 ---- tty_margin_off(tty); tty_cursor_pane_unless_wrap(tty, ctx, ctx->ocx, ctx->ocy); ! tty_attributes(tty, ctx->cell, &ctx->defaults, ctx->palette, ctx->s->hyperlinks); /* Get tty position from pane position for overlay check. */ px = ctx->xoff + ctx->ocx - ctx->wox; *************** *** 2136,2142 **** void tty_cell(struct tty *tty, const struct grid_cell *gc, ! const struct grid_cell *defaults, struct colour_palette *palette) { const struct grid_cell *gcp; --- 2159,2166 ---- void tty_cell(struct tty *tty, const struct grid_cell *gc, ! const struct grid_cell *defaults, struct colour_palette *palette, ! struct hyperlinks *hl) { const struct grid_cell *gcp; *************** *** 2152,2162 **** /* Check the output codeset and apply attributes. */ gcp = tty_check_codeset(tty, gc); ! tty_attributes(tty, gcp, defaults, palette); /* If it is a single character, write with putc to handle ACS. */ if (gcp->data.size == 1) { ! tty_attributes(tty, gcp, defaults, palette); if (*gcp->data.data < 0x20 || *gcp->data.data == 0x7f) return; tty_putc(tty, *gcp->data.data); --- 2176,2186 ---- /* Check the output codeset and apply attributes. */ gcp = tty_check_codeset(tty, gc); ! tty_attributes(tty, gcp, defaults, palette, hl); /* If it is a single character, write with putc to handle ACS. */ if (gcp->data.size == 1) { ! tty_attributes(tty, gcp, defaults, palette, hl); if (*gcp->data.data < 0x20 || *gcp->data.data == 0x7f) return; tty_putc(tty, *gcp->data.data); *************** *** 2173,2178 **** --- 2197,2204 ---- struct grid_cell *gc = &tty->cell; if (!grid_cells_equal(gc, &grid_default_cell)) { + if (gc->link != 0) + tty_putcode_ptr2(tty, TTYC_HLS, "", ""); if ((gc->attr & GRID_ATTR_CHARSET) && tty_acs_needed(tty)) tty_putcode(tty, TTYC_RMACS); tty_putcode(tty, TTYC_SGR0); *************** *** 2462,2470 **** tty->cy = cy; } void tty_attributes(struct tty *tty, const struct grid_cell *gc, ! const struct grid_cell *defaults, struct colour_palette *palette) { struct grid_cell *tc = &tty->cell, gc2; int changed; --- 2488,2516 ---- tty->cy = cy; } + static void + tty_hyperlink(struct tty *tty, const struct grid_cell *gc, + struct hyperlinks *hl) + { + const char *uri, *id; + + if (gc->link == tty->cell.link) + return; + tty->cell.link = gc->link; + + if (hl == NULL) + return; + + if (gc->link == 0 || !hyperlinks_get(hl, gc->link, &uri, &id)) + tty_putcode_ptr2(tty, TTYC_HLS, "", ""); + else + tty_putcode_ptr2(tty, TTYC_HLS, id, uri); + } + void tty_attributes(struct tty *tty, const struct grid_cell *gc, ! const struct grid_cell *defaults, struct colour_palette *palette, ! struct hyperlinks *hl) { struct grid_cell *tc = &tty->cell, gc2; int changed; *************** *** 2482,2488 **** if (gc2.attr == tty->last_cell.attr && gc2.fg == tty->last_cell.fg && gc2.bg == tty->last_cell.bg && ! gc2.us == tty->last_cell.us) return; /* --- 2528,2535 ---- if (gc2.attr == tty->last_cell.attr && gc2.fg == tty->last_cell.fg && gc2.bg == tty->last_cell.bg && ! gc2.us == tty->last_cell.us && ! gc2.link == tty->last_cell.link) return; /* *************** *** 2559,2564 **** --- 2606,2614 ---- if ((changed & GRID_ATTR_CHARSET) && tty_acs_needed(tty)) tty_putcode(tty, TTYC_SMACS); + /* Set hyperlink if any. */ + tty_hyperlink(tty, gc, hl); + memcpy(&tty->last_cell, &gc2, sizeof tty->last_cell); } *************** *** 2924,2936 **** static void tty_default_attributes(struct tty *tty, const struct grid_cell *defaults, ! struct colour_palette *palette, u_int bg) { struct grid_cell gc; memcpy(&gc, &grid_default_cell, sizeof gc); gc.bg = bg; ! tty_attributes(tty, &gc, defaults, palette); } static void --- 2974,2986 ---- static void tty_default_attributes(struct tty *tty, const struct grid_cell *defaults, ! struct colour_palette *palette, u_int bg, struct hyperlinks *hl) { struct grid_cell gc; memcpy(&gc, &grid_default_cell, sizeof gc); gc.bg = bg; ! tty_attributes(tty, &gc, defaults, palette, hl); } static void