less/SOURCES/less-590-fixhyperlink.patch

65 lines
1.7 KiB
Diff

diff -up less-590-build/less-590/line.c.fixhyperlink less-590-build/less-590/line.c
--- less-590-build/less-590/line.c.fixhyperlink 2025-03-20 00:18:52.931007552 +0100
+++ less-590-build/less-590/line.c 2025-03-20 00:22:29.299071888 +0100
@@ -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);
}
@@ -252,6 +254,19 @@ add_linebuf(ch, attr, 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.
*/
static void
@@ -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);
}
/*