From 84b0743e9f49947d95a9cd226fcdf0226e303746 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Fri, 9 Feb 2024 14:28:49 +0100 Subject: [PATCH] support hyperlinks separated by BEL characters --- src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 1ee70d8..cf47f5e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,7 @@ pub fn ansi_width(s: &str) -> usize { ']' => { let mut last = c; while let Some(new) = chars.next() { - if new == '\\' && last == ESC { + if new == '\x07' || (new == '\\' && last == ESC) { break; } last = new; @@ -93,4 +93,13 @@ mod tests { 14 ) } + + #[test] + fn nonstandard_hyperlink() { + // This hyperlink has a BEL character in the middle instead of `\x1b\\` + assert_eq!( + ansi_width("\x1b]8;;file://coreutils.md\x07coreutils.md\x1b]8;;\x07"), + 12 + ) + } }