less/less-590-hyperlink-bleed.patch
2021-10-22 14:28:34 -04:00

78 lines
1.9 KiB
Diff

From a99bf3bf475057a2562bf89860c60b0c2a000d4a Mon Sep 17 00:00:00 2001
From: "FeRD (Frank Dana)" <ferdnyc@gmail.com>
Date: Fri, 22 Oct 2021 14:22:23 -0400
Subject: [PATCH] Backport of 089d6651 to less 590
---
line.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/line.c b/line.c
index b8f609e..a587f71 100644
--- a/line.c
+++ b/line.c
@@ -38,6 +38,7 @@ struct xbuffer last_ansi;
public int size_linebuf = 0; /* Size of line buffer (and attr buffer) */
static struct ansi_state *line_ansi = NULL;
+static int hlink_in_line;
static int cshift; /* Current left-shift of output line buffer */
public int hshift; /* Desired left-shift of output line buffer */
public int tabstops[TABSTOP_MAX] = { 0 }; /* Custom tabstops */
@@ -221,6 +222,7 @@ prewind(VOID_PARAM)
is_null_line = 0;
pendc = '\0';
in_hilite = 0;
+ hlink_in_line = 0;
xbuf_reset(&shifted_ansi);
xbuf_reset(&last_ansi);
}
@@ -251,6 +253,19 @@ add_linebuf(ch, attr, w)
inc_end_column(w);
}
+/*
+ * Append a string to the line buffer.
+ */
+ static void
+addstr_linebuf(s, attr, cw)
+ char *s;
+ int attr;
+ int cw;
+{
+ for ( ; *s != '\0'; s++)
+ add_linebuf(*s, attr, cw);
+}
+
/*
* Set a character in the line prefix buffer.
*/
@@ -958,6 +973,8 @@ store_ansi(ch, rep, pos)
case ANSI_MID:
if (!in_hilite)
STORE_CHAR(ch, AT_ANSI, rep, pos);
+ if (line_ansi->hlink)
+ hlink_in_line = 1;
break;
case ANSI_END:
if (!in_hilite)
@@ -1138,12 +1155,11 @@ pflushmbc(VOID_PARAM)
static void
add_attr_normal(VOID_PARAM)
{
- char *p = "\033[m";
-
if (ctldisp != OPT_ONPLUS || !is_ansi_end('m'))
return;
- for ( ; *p != '\0'; p++)
- add_linebuf(*p, AT_ANSI, 0);
+ addstr_linebuf("\033[m", AT_ANSI, 0);
+ if (hlink_in_line) /* Don't send hyperlink clear if we know we don't need to. */
+ addstr_linebuf("\033]8;;\033\\", AT_ANSI, 0);
}
/*
--
2.31.1