Skip to content

Commit

Permalink
Merge pull request #150 from db7/term-link-close-order
Browse files Browse the repository at this point in the history
Close link after closing style and fix case where an existing style would cause the override style not to be closed.
  • Loading branch information
kristapsdz authored Jan 25, 2025
2 parents e8a17ae + 75f3577 commit 9f83c3f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
2 changes: 1 addition & 1 deletion regress/link-with-links.term
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
a

 · b ]8;;https://foo.com\https://foo.com]8;;\ c
 · b ]8;;https://foo.com\https://foo.com]8;;\ c
 · d e
32 changes: 16 additions & 16 deletions regress/links.term
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
a ]8;;https://bar.com\https://bar.com]8;;\ b c

a b]8;;https://bar.com\https://bar.com]8;;\c d

a ]8;;https://bar.com\b]8;;\ ]8;;https://bar.com\https://bar.com]8;;\ c

a b]8;;https://bar.com\c]8;;\ ]8;;https://bar.com\https://bar.com]8;;\d e

a ]8;;https://bar.com\b]8;;\ ]8;;https://bar.com\https://bar.com]8;;\ c

a ]8;;https://bar.com\https://bar.com]8;;\ b c
a b]8;;https://bar.com\https://bar.com]8;;\c d
a ]8;;https://bar.com\b]8;;\ ]8;;https://bar.com\https://bar.com]8;;\ c
a b]8;;https://bar.com\c]8;;\ ]8;;https://bar.com\https://bar.com]8;;\d e
a ]8;;https://bar.com\b]8;;\ ]8;;https://bar.com\https://bar.com]8;;\ c
asd

a]8;;https://bar.com\b]8;;\ ]8;;https://bar.com\https://bar.com]8;;\c

a ]8;;https://foo.com\b]8;;\ ]8;;https://foo.com\c]8;;\ ]8;;https://foo.com\https://foo.com]8;;\ d

a ]8;;https://foo.com\b]8;;\ ]8;;https://foo.com\https://foo.com]8;;\ c d
a]8;;https://bar.com\b]8;;\ ]8;;https://bar.com\https://bar.com]8;;\c
a ]8;;https://foo.com\b]8;;\ ]8;;https://foo.com\c]8;;\ ]8;;https://foo.com\https://foo.com]8;;\ d
a ]8;;https://foo.com\b]8;;\ ]8;;https://foo.com\https://foo.com]8;;\ c d
2 changes: 1 addition & 1 deletion regress/newline-before-link.term
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a bwww wcdef ]8;;https://foo.com\g]8;;\ ]8;;https://foo.com\https://foo.com]8;;\
a bwww wcdef ]8;;https://foo.com\g]8;;\ ]8;;https://foo.com\https://foo.com]8;;\
23 changes: 13 additions & 10 deletions term.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ rndr_buf_unstyle(const struct term *term,
}

/*
* Start sequence for a terminal link (only in ANSI mode).
* Start sequence for a terminal link (only in ANSI mode).
*/
static int
rndr_buf_osc8_open(const struct term *term, struct lowdown_buf *out,
Expand All @@ -282,7 +282,7 @@ rndr_buf_osc8_open(const struct term *term, struct lowdown_buf *out,

if (term->opts & LOWDOWN_TERM_NOANSI)
return 1;

if (n->type == LOWDOWN_LINK_AUTO)
uri = &n->rndr_autolink.link;
else if (n->type == LOWDOWN_LINK)
Expand Down Expand Up @@ -493,12 +493,15 @@ rndr_buf_endwords(struct term *term, struct lowdown_buf *out,
* matter where this appears in relation to other styling).
*/

if (rndr_buf_endstyle(n) && !rndr_buf_unstyle(term, out, NULL))
return 0;

if (osty != NULL && !rndr_buf_unstyle(term, out, osty))
return 0;

if (term->in_link && !rndr_buf_osc8_close(term, out))
return 0;
if (rndr_buf_endstyle(n))
return rndr_buf_unstyle(term, out, NULL);
if (osty != NULL)
return rndr_buf_unstyle(term, out, osty);
return 0;

return 1;
}

Expand Down Expand Up @@ -1578,7 +1581,7 @@ rndr(struct lowdown_buf *ob, struct term *st,
if (!rndr_buf(st, ob, n, st->tmp, NULL))
return 0;
} else {
if (!rndr_buf(st, ob, n,
if (!rndr_buf(st, ob, n,
&n->rndr_entity.text, &sty_bad_ent))
return 0;
}
Expand Down Expand Up @@ -1735,7 +1738,7 @@ rndr(struct lowdown_buf *ob, struct term *st,
return 0;
if (!rndr_buf_vspace(st, ob, n, 1))
return 0;

/* Strip trailing newlines but for the vmargin. */

while (ob->size && ob->data[ob->size - 1] == '\n')
Expand Down Expand Up @@ -1826,7 +1829,7 @@ void
lowdown_term_free(void *arg)
{
struct term *st = arg;

if (st == NULL)
return;

Expand Down

0 comments on commit 9f83c3f

Please sign in to comment.