terminal_hyperlinks.rs

   1use alacritty_terminal::{
   2    Term,
   3    event::EventListener,
   4    grid::Dimensions,
   5    index::{Boundary, Column, Direction as AlacDirection, Point as AlacPoint},
   6    term::{
   7        cell::Flags,
   8        search::{Match, RegexIter, RegexSearch},
   9    },
  10};
  11use log::{info, warn};
  12use regex::Regex;
  13use std::{
  14    ops::{Index, Range},
  15    time::{Duration, Instant},
  16};
  17use url::Url;
  18use util::paths::{PathStyle, UrlExt};
  19
  20const URL_REGEX: &str = r#"(ipfs:|ipns:|magnet:|mailto:|gemini://|gopher://|https://|http://|news:|file://|git://|ssh:|ftp://)[^\u{0000}-\u{001F}\u{007F}-\u{009F}<>"\s{-}\^โŸจโŸฉ`']+"#;
  21const WIDE_CHAR_SPACERS: Flags =
  22    Flags::from_bits(Flags::LEADING_WIDE_CHAR_SPACER.bits() | Flags::WIDE_CHAR_SPACER.bits())
  23        .unwrap();
  24
  25pub(super) struct RegexSearches {
  26    url_regex: RegexSearch,
  27    path_hyperlink_regexes: Vec<Regex>,
  28    path_hyperlink_timeout: Duration,
  29}
  30
  31impl Default for RegexSearches {
  32    fn default() -> Self {
  33        Self {
  34            url_regex: RegexSearch::new(URL_REGEX).unwrap(),
  35            path_hyperlink_regexes: Vec::default(),
  36            path_hyperlink_timeout: Duration::default(),
  37        }
  38    }
  39}
  40impl RegexSearches {
  41    pub(super) fn new(
  42        path_hyperlink_regexes: impl IntoIterator<Item: AsRef<str>>,
  43        path_hyperlink_timeout_ms: u64,
  44    ) -> Self {
  45        Self {
  46            url_regex: RegexSearch::new(URL_REGEX).unwrap(),
  47            path_hyperlink_regexes: path_hyperlink_regexes
  48                .into_iter()
  49                .filter_map(|regex| {
  50                    Regex::new(regex.as_ref())
  51                        .inspect_err(|error| {
  52                            warn!(
  53                                concat!(
  54                                    "Ignoring path hyperlink regex specified in ",
  55                                    "`terminal.path_hyperlink_regexes`:\n\n\t{}\n\nError: {}",
  56                                ),
  57                                regex.as_ref(),
  58                                error
  59                            );
  60                        })
  61                        .ok()
  62                })
  63                .collect(),
  64            path_hyperlink_timeout: Duration::from_millis(path_hyperlink_timeout_ms),
  65        }
  66    }
  67}
  68
  69pub(super) fn find_from_grid_point<T: EventListener>(
  70    term: &Term<T>,
  71    point: AlacPoint,
  72    regex_searches: &mut RegexSearches,
  73    path_style: PathStyle,
  74) -> Option<(String, bool, Match)> {
  75    let grid = term.grid();
  76    let link = grid.index(point).hyperlink();
  77    let found_word = if let Some(ref url) = link {
  78        let mut min_index = point;
  79        loop {
  80            let new_min_index = min_index.sub(term, Boundary::Cursor, 1);
  81            if new_min_index == min_index || grid.index(new_min_index).hyperlink() != link {
  82                break;
  83            } else {
  84                min_index = new_min_index
  85            }
  86        }
  87
  88        let mut max_index = point;
  89        loop {
  90            let new_max_index = max_index.add(term, Boundary::Cursor, 1);
  91            if new_max_index == max_index || grid.index(new_max_index).hyperlink() != link {
  92                break;
  93            } else {
  94                max_index = new_max_index
  95            }
  96        }
  97
  98        let url = url.uri().to_owned();
  99        let url_match = min_index..=max_index;
 100
 101        Some((url, true, url_match))
 102    } else {
 103        let (line_start, line_end) = (term.line_search_left(point), term.line_search_right(point));
 104        if let Some((url, url_match)) = RegexIter::new(
 105            line_start,
 106            line_end,
 107            AlacDirection::Right,
 108            term,
 109            &mut regex_searches.url_regex,
 110        )
 111        .find(|rm| rm.contains(&point))
 112        .map(|url_match| {
 113            let url = term.bounds_to_string(*url_match.start(), *url_match.end());
 114            sanitize_url_punctuation(url, url_match, term)
 115        }) {
 116            Some((url, true, url_match))
 117        } else {
 118            path_match(
 119                &term,
 120                line_start,
 121                line_end,
 122                point,
 123                &mut regex_searches.path_hyperlink_regexes,
 124                regex_searches.path_hyperlink_timeout,
 125            )
 126            .map(|(path, path_match)| (path, false, path_match))
 127        }
 128    };
 129
 130    found_word.map(|(maybe_url_or_path, is_url, word_match)| {
 131        if is_url {
 132            // Treat "file://" IRIs like file paths to ensure
 133            // that line numbers at the end of the path are
 134            // handled correctly.
 135            // Use Url::to_file_path() to properly handle Windows drive letters
 136            // (e.g., file:///C:/path -> C:\path)
 137            if maybe_url_or_path.starts_with("file://") {
 138                if let Ok(url) = Url::parse(&maybe_url_or_path) {
 139                    if let Ok(path) = url.to_file_path_ext(path_style) {
 140                        return (path.to_string_lossy().into_owned(), false, word_match);
 141                    }
 142                }
 143                // Fallback: strip file:// prefix if URL parsing fails
 144                let path = maybe_url_or_path
 145                    .strip_prefix("file://")
 146                    .unwrap_or(&maybe_url_or_path);
 147                (path.to_string(), false, word_match)
 148            } else {
 149                (maybe_url_or_path, true, word_match)
 150            }
 151        } else {
 152            (maybe_url_or_path, false, word_match)
 153        }
 154    })
 155}
 156
 157fn sanitize_url_punctuation<T: EventListener>(
 158    url: String,
 159    url_match: Match,
 160    term: &Term<T>,
 161) -> (String, Match) {
 162    let mut sanitized_url = url;
 163    let mut chars_trimmed = 0;
 164
 165    // Count parentheses in the URL
 166    let (open_parens, mut close_parens) =
 167        sanitized_url
 168            .chars()
 169            .fold((0, 0), |(opens, closes), c| match c {
 170                '(' => (opens + 1, closes),
 171                ')' => (opens, closes + 1),
 172                _ => (opens, closes),
 173            });
 174
 175    // Remove trailing characters that shouldn't be at the end of URLs
 176    while let Some(last_char) = sanitized_url.chars().last() {
 177        let should_remove = match last_char {
 178            // These may be part of a URL but not at the end. It's not that the spec
 179            // doesn't allow them, but they are frequently used in plain text as delimiters
 180            // where they're not meant to be part of the URL.
 181            '.' | ',' | ':' | ';' => true,
 182            '(' => true,
 183            ')' if close_parens > open_parens => {
 184                close_parens -= 1;
 185
 186                true
 187            }
 188            _ => false,
 189        };
 190
 191        if should_remove {
 192            sanitized_url.pop();
 193            chars_trimmed += 1;
 194        } else {
 195            break;
 196        }
 197    }
 198
 199    if chars_trimmed > 0 {
 200        let new_end = url_match.end().sub(term, Boundary::Grid, chars_trimmed);
 201        let sanitized_match = Match::new(*url_match.start(), new_end);
 202        (sanitized_url, sanitized_match)
 203    } else {
 204        (sanitized_url, url_match)
 205    }
 206}
 207
 208/// Returns the byte offset just past the first unbalanced `(` in `s`, or `None`
 209/// if all parentheses are balanced. Used to strip prefixes like `Update(` from
 210/// path matches while preserving balanced parens in filenames like `file(copy).txt`.
 211fn first_unbalanced_open_paren(s: &str) -> Option<usize> {
 212    let mut balance: i32 = 0;
 213    let mut first_unmatched = None;
 214    for (i, c) in s.char_indices() {
 215        match c {
 216            '(' => {
 217                if balance == 0 {
 218                    first_unmatched = Some(i + c.len_utf8());
 219                }
 220                balance += 1;
 221            }
 222            ')' => {
 223                balance -= 1;
 224                if balance <= 0 {
 225                    balance = 0;
 226                    first_unmatched = None;
 227                }
 228            }
 229            _ => {}
 230        }
 231    }
 232    first_unmatched.filter(|_| balance > 0)
 233}
 234
 235fn path_match<T>(
 236    term: &Term<T>,
 237    line_start: AlacPoint,
 238    line_end: AlacPoint,
 239    hovered: AlacPoint,
 240    path_hyperlink_regexes: &mut Vec<Regex>,
 241    path_hyperlink_timeout: Duration,
 242) -> Option<(String, Match)> {
 243    if path_hyperlink_regexes.is_empty() || path_hyperlink_timeout.as_millis() == 0 {
 244        return None;
 245    }
 246    debug_assert!(line_start <= hovered);
 247    debug_assert!(line_end >= hovered);
 248    let search_start_time = Instant::now();
 249
 250    let timed_out = || {
 251        let elapsed_time = Instant::now().saturating_duration_since(search_start_time);
 252        (elapsed_time > path_hyperlink_timeout)
 253            .then_some((elapsed_time.as_millis(), path_hyperlink_timeout.as_millis()))
 254    };
 255
 256    // This used to be: `let line = term.bounds_to_string(line_start, line_end)`, however, that
 257    // api compresses tab characters into a single space, whereas we require a cell accurate
 258    // string representation of the line. The below algorithm does this, but seems a bit odd.
 259    // Maybe there is a clean api for doing this, but I couldn't find it.
 260    let mut line = String::with_capacity(
 261        (line_end.line.0 - line_start.line.0 + 1) as usize * term.grid().columns(),
 262    );
 263    let first_cell = &term.grid()[line_start];
 264    let mut prev_len = 0;
 265    line.push(first_cell.c);
 266    let mut hovered_point_byte_offset = None;
 267
 268    if line_start == hovered {
 269        hovered_point_byte_offset = Some(0);
 270    }
 271
 272    for cell in term.grid().iter_from(line_start) {
 273        if cell.point > line_end {
 274            break;
 275        }
 276
 277        if !cell.flags.intersects(WIDE_CHAR_SPACERS) {
 278            prev_len = line.len();
 279            match cell.c {
 280                ' ' | '\t' => line.push(' '),
 281                c => line.push(c),
 282            }
 283        }
 284
 285        if cell.point == hovered {
 286            debug_assert!(hovered_point_byte_offset.is_none());
 287            hovered_point_byte_offset = Some(prev_len);
 288        }
 289    }
 290    let line = line.trim_ascii_end();
 291    let hovered_point_byte_offset = hovered_point_byte_offset?;
 292    if line.len() <= hovered_point_byte_offset {
 293        return None;
 294    }
 295    let found_from_range = |path_range: Range<usize>,
 296                            link_range: Range<usize>,
 297                            position: Option<(u32, Option<u32>)>| {
 298        let advance_point_by_str = |mut point: AlacPoint, s: &str| {
 299            for _ in s.chars() {
 300                point = term
 301                    .expand_wide(point, AlacDirection::Right)
 302                    .add(term, Boundary::Grid, 1);
 303            }
 304
 305            // There does not appear to be an alacritty api that is
 306            // "move to start of current wide char", so we have to do it ourselves.
 307            let flags = term.grid().index(point).flags;
 308            if flags.contains(Flags::LEADING_WIDE_CHAR_SPACER) {
 309                AlacPoint::new(point.line + 1, Column(0))
 310            } else if flags.contains(Flags::WIDE_CHAR_SPACER) {
 311                AlacPoint::new(point.line, point.column - 1)
 312            } else {
 313                point
 314            }
 315        };
 316
 317        let link_start = advance_point_by_str(line_start, &line[..link_range.start]);
 318        let link_end = advance_point_by_str(link_start, &line[link_range]);
 319        let link_match = link_start
 320            ..=term
 321                .expand_wide(link_end, AlacDirection::Left)
 322                .sub(term, Boundary::Grid, 1);
 323
 324        (
 325            {
 326                let mut path = line[path_range].to_string();
 327                position.inspect(|(line, column)| {
 328                    path += &format!(":{line}");
 329                    column.inspect(|column| path += &format!(":{column}"));
 330                });
 331                path
 332            },
 333            link_match,
 334        )
 335    };
 336
 337    for regex in path_hyperlink_regexes {
 338        let mut path_found = false;
 339
 340        for (line_start_offset, captures) in regex
 341            .captures_iter(&line)
 342            .map(|captures| (0usize, captures))
 343        {
 344            path_found = true;
 345            let match_range = captures.get(0).unwrap().range();
 346            let (mut path_range, line_column) = if let Some(path) = captures.name("path") {
 347                let parse = |name: &str| {
 348                    captures
 349                        .name(name)
 350                        .and_then(|capture| capture.as_str().parse().ok())
 351                };
 352
 353                (
 354                    path.range(),
 355                    parse("line").map(|line| (line, parse("column"))),
 356                )
 357            } else {
 358                (match_range.clone(), None)
 359            };
 360            let mut link_range = captures
 361                .name("link")
 362                .map_or_else(|| match_range.clone(), |link| link.range());
 363
 364            path_range.start += line_start_offset;
 365            path_range.end += line_start_offset;
 366            link_range.start += line_start_offset;
 367            link_range.end += line_start_offset;
 368
 369            // Strip prefix up to the first unbalanced `(` in the matched path.
 370            // This handles delimiter parens like `Update(.claude/SKILL.md)` while
 371            // preserving balanced parens in filenames like `file(copy).txt`.
 372            // Analogous to `sanitize_url_punctuation` which strips unbalanced
 373            // trailing `)` from URLs.
 374            if let Some(trim) = first_unbalanced_open_paren(&line[path_range.clone()]) {
 375                path_range.start += trim;
 376                link_range.start = link_range.start.max(path_range.start);
 377            }
 378
 379            if !link_range.contains(&hovered_point_byte_offset) {
 380                // No match, just skip.
 381                continue;
 382            }
 383            let found = found_from_range(path_range, link_range, line_column);
 384
 385            if found.1.contains(&hovered) {
 386                return Some(found);
 387            }
 388        }
 389
 390        if path_found {
 391            return None;
 392        }
 393
 394        if let Some((timed_out_ms, timeout_ms)) = timed_out() {
 395            warn!("Timed out processing path hyperlink regexes after {timed_out_ms}ms");
 396            info!("{timeout_ms}ms time out specified in `terminal.path_hyperlink_timeout_ms`");
 397            return None;
 398        }
 399    }
 400
 401    None
 402}
 403
 404#[cfg(test)]
 405mod tests {
 406    use crate::terminal_settings::TerminalSettings;
 407
 408    use super::*;
 409    use alacritty_terminal::{
 410        event::VoidListener,
 411        grid::Dimensions,
 412        index::{Boundary, Column, Line, Point as AlacPoint},
 413        term::{Config, cell::Flags, test::TermSize},
 414        vte::ansi::Handler,
 415    };
 416    use regex::Regex;
 417    use settings::{self, Settings, SettingsContent};
 418    use std::{cell::RefCell, ops::RangeInclusive, path::PathBuf, rc::Rc};
 419    use url::Url;
 420    use util::paths::PathWithPosition;
 421
 422    fn re_test(re: &str, hay: &str, expected: Vec<&str>) {
 423        let results: Vec<_> = Regex::new(re)
 424            .unwrap()
 425            .find_iter(hay)
 426            .map(|m| m.as_str())
 427            .collect();
 428        assert_eq!(results, expected);
 429    }
 430
 431    #[test]
 432    fn test_url_regex() {
 433        re_test(
 434            URL_REGEX,
 435            "test http://example.com test 'https://website1.com' test mailto:bob@example.com train",
 436            vec![
 437                "http://example.com",
 438                "https://website1.com",
 439                "mailto:bob@example.com",
 440            ],
 441        );
 442    }
 443
 444    #[test]
 445    fn test_url_parentheses_sanitization() {
 446        // Test our sanitize_url_parentheses function directly
 447        let test_cases = vec![
 448            // Cases that should be sanitized (unbalanced parentheses)
 449            ("https://www.google.com/)", "https://www.google.com/"),
 450            ("https://example.com/path)", "https://example.com/path"),
 451            ("https://test.com/))", "https://test.com/"),
 452            ("https://test.com/(((", "https://test.com/"),
 453            ("https://test.com/(test)(", "https://test.com/(test)"),
 454            // Cases that should NOT be sanitized (balanced parentheses)
 455            (
 456                "https://en.wikipedia.org/wiki/Example_(disambiguation)",
 457                "https://en.wikipedia.org/wiki/Example_(disambiguation)",
 458            ),
 459            ("https://test.com/(hello)", "https://test.com/(hello)"),
 460            (
 461                "https://example.com/path(1)(2)",
 462                "https://example.com/path(1)(2)",
 463            ),
 464            // Edge cases
 465            ("https://test.com/", "https://test.com/"),
 466            ("https://example.com", "https://example.com"),
 467        ];
 468
 469        for (input, expected) in test_cases {
 470            // Create a minimal terminal for testing
 471            let term = Term::new(Config::default(), &TermSize::new(80, 24), VoidListener);
 472
 473            // Create a dummy match that spans the entire input
 474            let start_point = AlacPoint::new(Line(0), Column(0));
 475            let end_point = AlacPoint::new(Line(0), Column(input.len()));
 476            let dummy_match = Match::new(start_point, end_point);
 477
 478            let (result, _) = sanitize_url_punctuation(input.to_string(), dummy_match, &term);
 479            assert_eq!(result, expected, "Failed for input: {}", input);
 480        }
 481    }
 482
 483    #[test]
 484    fn test_url_punctuation_sanitization() {
 485        // Test URLs with trailing punctuation (sentence/text punctuation)
 486        // The sanitize_url_punctuation function removes ., ,, :, ;, from the end
 487        let test_cases = vec![
 488            ("https://example.com.", "https://example.com"),
 489            (
 490                "https://github.com/zed-industries/zed.",
 491                "https://github.com/zed-industries/zed",
 492            ),
 493            (
 494                "https://example.com/path/file.html.",
 495                "https://example.com/path/file.html",
 496            ),
 497            (
 498                "https://example.com/file.pdf.",
 499                "https://example.com/file.pdf",
 500            ),
 501            ("https://example.com:8080.", "https://example.com:8080"),
 502            ("https://example.com..", "https://example.com"),
 503            (
 504                "https://en.wikipedia.org/wiki/C.E.O.",
 505                "https://en.wikipedia.org/wiki/C.E.O",
 506            ),
 507            ("https://example.com,", "https://example.com"),
 508            ("https://example.com/path,", "https://example.com/path"),
 509            ("https://example.com,,", "https://example.com"),
 510            ("https://example.com:", "https://example.com"),
 511            ("https://example.com/path:", "https://example.com/path"),
 512            ("https://example.com::", "https://example.com"),
 513            ("https://example.com;", "https://example.com"),
 514            ("https://example.com/path;", "https://example.com/path"),
 515            ("https://example.com;;", "https://example.com"),
 516            ("https://example.com.,", "https://example.com"),
 517            ("https://example.com.:;", "https://example.com"),
 518            ("https://example.com!.", "https://example.com!"),
 519            ("https://example.com/).", "https://example.com/"),
 520            ("https://example.com/);", "https://example.com/"),
 521            ("https://example.com/;)", "https://example.com/"),
 522            (
 523                "https://example.com/v1.0/api",
 524                "https://example.com/v1.0/api",
 525            ),
 526            ("https://192.168.1.1", "https://192.168.1.1"),
 527            ("https://sub.domain.com", "https://sub.domain.com"),
 528            (
 529                "https://example.com?query=value",
 530                "https://example.com?query=value",
 531            ),
 532            ("https://example.com?a=1&b=2", "https://example.com?a=1&b=2"),
 533            (
 534                "https://example.com/path:8080",
 535                "https://example.com/path:8080",
 536            ),
 537        ];
 538
 539        for (input, expected) in test_cases {
 540            // Create a minimal terminal for testing
 541            let term = Term::new(Config::default(), &TermSize::new(80, 24), VoidListener);
 542
 543            // Create a dummy match that spans the entire input
 544            let start_point = AlacPoint::new(Line(0), Column(0));
 545            let end_point = AlacPoint::new(Line(0), Column(input.len()));
 546            let dummy_match = Match::new(start_point, end_point);
 547
 548            let (result, _) = sanitize_url_punctuation(input.to_string(), dummy_match, &term);
 549            assert_eq!(result, expected, "Failed for input: {}", input);
 550        }
 551    }
 552
 553    macro_rules! test_hyperlink {
 554        ($($lines:expr),+; $hyperlink_kind:ident) => { {
 555            use crate::terminal_hyperlinks::tests::line_cells_count;
 556            use std::cmp;
 557
 558            let test_lines = vec![$($lines),+];
 559            let (total_cells, longest_line_cells) =
 560                test_lines.iter().copied()
 561                    .map(line_cells_count)
 562                    .fold((0, 0), |state, cells| (state.0 + cells, cmp::max(state.1, cells)));
 563            let contains_tab_char = test_lines.iter().copied()
 564                .map(str::chars).flatten().find(|&c| c == '\t');
 565            let columns = if contains_tab_char.is_some() {
 566                // This avoids tabs at end of lines causing whitespace-eating line wraps...
 567                vec![longest_line_cells + 1]
 568            } else {
 569                // Alacritty has issues with 2 columns, use 3 as the minimum for now.
 570                vec![3, longest_line_cells / 2, longest_line_cells + 1]
 571            };
 572            test_hyperlink!(
 573                columns;
 574                total_cells;
 575                test_lines.iter().copied();
 576                $hyperlink_kind
 577            )
 578        } };
 579
 580        ($columns:expr; $total_cells:expr; $lines:expr; $hyperlink_kind:ident) => { {
 581            use crate::terminal_hyperlinks::tests::{ test_hyperlink, HyperlinkKind };
 582
 583            let source_location = format!("{}:{}", std::file!(), std::line!());
 584            for columns in $columns {
 585                test_hyperlink(columns, $total_cells, $lines, HyperlinkKind::$hyperlink_kind,
 586                    &source_location);
 587            }
 588        } };
 589    }
 590
 591    mod path {
 592        /// ๐Ÿ‘‰ := **hovered** on following char
 593        ///
 594        /// ๐Ÿ‘ˆ := **hovered** on wide char spacer of previous full width char
 595        ///
 596        /// **`โ€นโ€บ`** := expected **hyperlink** match
 597        ///
 598        /// **`ยซยป`** := expected **path**, **row**, and **column** capture groups
 599        ///
 600        /// [**`cโ‚€, cโ‚, โ€ฆ, cโ‚™;`**]โ‚’โ‚šโ‚œ := use specified terminal widths of `cโ‚€, cโ‚, โ€ฆ, cโ‚™` **columns**
 601        /// (defaults to `3, longest_line_cells / 2, longest_line_cells + 1;`)
 602        ///
 603        macro_rules! test_path {
 604            ($($lines:literal),+) => { test_hyperlink!($($lines),+; Path) };
 605        }
 606
 607        #[test]
 608        fn simple() {
 609            // Rust paths
 610            // Just the path
 611            test_path!("โ€นยซ/๐Ÿ‘‰test/cool.rsยปโ€บ");
 612            test_path!("โ€นยซ/test/cool๐Ÿ‘‰.rsยปโ€บ");
 613
 614            // path and line
 615            test_path!("โ€นยซ/๐Ÿ‘‰test/cool.rsยป:ยซ4ยปโ€บ");
 616            test_path!("โ€นยซ/test/cool.rsยป๐Ÿ‘‰:ยซ4ยปโ€บ");
 617            test_path!("โ€นยซ/test/cool.rsยป:ยซ๐Ÿ‘‰4ยปโ€บ");
 618            test_path!("โ€นยซ/๐Ÿ‘‰test/cool.rsยป(ยซ4ยป)โ€บ");
 619            test_path!("โ€นยซ/test/cool.rsยป๐Ÿ‘‰(ยซ4ยป)โ€บ");
 620            test_path!("โ€นยซ/test/cool.rsยป(ยซ๐Ÿ‘‰4ยป)โ€บ");
 621            test_path!("โ€นยซ/test/cool.rsยป(ยซ4ยป๐Ÿ‘‰)โ€บ");
 622
 623            // path, line, and column
 624            test_path!("โ€นยซ/๐Ÿ‘‰test/cool.rsยป:ยซ4ยป:ยซ2ยปโ€บ");
 625            test_path!("โ€นยซ/test/cool.rsยป:ยซ4ยป:ยซ๐Ÿ‘‰2ยปโ€บ");
 626            test_path!("โ€นยซ/๐Ÿ‘‰test/cool.rsยป(ยซ4ยป,ยซ2ยป)โ€บ");
 627            test_path!("โ€นยซ/test/cool.rsยป(ยซ4ยป๐Ÿ‘‰,ยซ2ยป)โ€บ");
 628
 629            // path, line, column, and ':' suffix
 630            test_path!("โ€นยซ/๐Ÿ‘‰test/cool.rsยป:ยซ4ยป:ยซ2ยปโ€บ:");
 631            test_path!("โ€นยซ/test/cool.rsยป:ยซ4ยป:ยซ๐Ÿ‘‰2ยปโ€บ:");
 632            test_path!("โ€นยซ/๐Ÿ‘‰test/cool.rsยป(ยซ4ยป,ยซ2ยป)โ€บ:");
 633            test_path!("โ€นยซ/test/cool.rsยป(ยซ4ยป,ยซ2ยป๐Ÿ‘‰)โ€บ:");
 634            test_path!("โ€นยซ/๐Ÿ‘‰test/cool.rsยป:(ยซ4ยป,ยซ2ยป)โ€บ:");
 635            test_path!("โ€นยซ/test/cool.rsยป:(ยซ4ยป,ยซ2ยป๐Ÿ‘‰)โ€บ:");
 636            test_path!("โ€นยซ/๐Ÿ‘‰test/cool.rsยป:(ยซ4ยป:ยซ2ยป)โ€บ:");
 637            test_path!("โ€นยซ/test/cool.rsยป:(ยซ4ยป:ยซ2ยป๐Ÿ‘‰)โ€บ:");
 638            test_path!("/test/cool.rs:4:2๐Ÿ‘‰:", "What is this?");
 639            test_path!("/test/cool.rs(4,2)๐Ÿ‘‰:", "What is this?");
 640
 641            // path, line, column, and description
 642            test_path!("โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยป:ยซ2ยปโ€บ:Error!");
 643            test_path!("โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ4ยป,ยซ2ยป)โ€บ:Error!");
 644
 645            // Cargo output
 646            test_path!("    Compiling Cool ๐Ÿ‘‰(/test/Cool)");
 647            test_path!("    Compiling Cool (โ€นยซ/๐Ÿ‘‰test/Coolยปโ€บ)");
 648            test_path!("    Compiling Cool (/test/Cool๐Ÿ‘‰)");
 649
 650            // Tool output with path inside parens (e.g. Claude Code)
 651            test_path!("Update๐Ÿ‘‰(src/cool.rs)");
 652            test_path!("Update(โ€นยซsrc/๐Ÿ‘‰cool.rsยปโ€บ)");
 653            test_path!("Update(src/cool.rs๐Ÿ‘‰)");
 654            test_path!("Write(โ€นยซ/๐Ÿ‘‰test/Coolยปโ€บ)");
 655
 656            // Python
 657            test_path!("โ€นยซawe๐Ÿ‘‰some.pyยปโ€บ");
 658            test_path!("โ€นยซ๐Ÿ‘‰aยปโ€บ ");
 659
 660            test_path!("    โ€นF๐Ÿ‘‰ile \"ยซ/awesome.pyยป\", line ยซ42ยปโ€บ: Wat?");
 661            test_path!("    โ€นFile \"ยซ/awe๐Ÿ‘‰some.pyยป\", line ยซ42ยปโ€บ");
 662            test_path!("    โ€นFile \"ยซ/awesome.pyยป๐Ÿ‘‰\", line ยซ42ยปโ€บ: Wat?");
 663            test_path!("    โ€นFile \"ยซ/awesome.pyยป\", line ยซ4๐Ÿ‘‰2ยปโ€บ");
 664        }
 665
 666        #[test]
 667        fn simple_with_descriptions() {
 668            // path, line, column and description
 669            test_path!("โ€นยซ/๐Ÿ‘‰test/cool.rsยป:ยซ4ยป:ยซ2ยปโ€บ:ไพ‹Descไพ‹ไพ‹ไพ‹");
 670            test_path!("โ€นยซ/test/cool.rsยป:ยซ4ยป:ยซ๐Ÿ‘‰2ยปโ€บ:ไพ‹Descไพ‹ไพ‹ไพ‹");
 671            test_path!("โ€นยซ/๐Ÿ‘‰test/cool.rsยป(ยซ4ยป,ยซ2ยป)โ€บ:ไพ‹Descไพ‹ไพ‹ไพ‹");
 672            test_path!("โ€นยซ/test/cool.rsยป(ยซ4ยป๐Ÿ‘‰,ยซ2ยป)โ€บ:ไพ‹Descไพ‹ไพ‹ไพ‹");
 673
 674            // path, line, column and description w/extra colons
 675            test_path!("โ€นยซ/๐Ÿ‘‰test/cool.rsยป:ยซ4ยป:ยซ2ยปโ€บ::ไพ‹Descไพ‹ไพ‹ไพ‹");
 676            test_path!("โ€นยซ/test/cool.rsยป:ยซ4ยป:ยซ๐Ÿ‘‰2ยปโ€บ::ไพ‹Descไพ‹ไพ‹ไพ‹");
 677            test_path!("โ€นยซ/๐Ÿ‘‰test/cool.rsยป(ยซ4ยป,ยซ2ยป)โ€บ::ไพ‹Descไพ‹ไพ‹ไพ‹");
 678            test_path!("โ€นยซ/test/cool.rsยป(ยซ4ยป,ยซ2ยป๐Ÿ‘‰)โ€บ::ไพ‹Descไพ‹ไพ‹ไพ‹");
 679        }
 680
 681        #[test]
 682        fn multiple_same_line() {
 683            test_path!("โ€นยซ/๐Ÿ‘‰test/cool.rsยปโ€บ /test/cool.rs");
 684            test_path!("/test/cool.rs โ€นยซ/๐Ÿ‘‰test/cool.rsยปโ€บ");
 685
 686            test_path!(
 687                "โ€นยซ๐Ÿฆ€ multiple_๐Ÿ‘‰same_line ๐Ÿฆ€ยป ๐Ÿšฃยซ4ยป ๐Ÿ›๏ธยซ2ยปโ€บ: ๐Ÿฆ€ multiple_same_line ๐Ÿฆ€ ๐Ÿšฃ4 ๐Ÿ›๏ธ2:"
 688            );
 689
 690            // ls output (tab separated)
 691            test_path!(
 692                "โ€นยซCarg๐Ÿ‘‰o.tomlยปโ€บ\t\texperiments\t\tnotebooks\t\trust-toolchain.toml\ttooling"
 693            );
 694            test_path!(
 695                "Cargo.toml\t\tโ€นยซexper๐Ÿ‘‰imentsยปโ€บ\t\tnotebooks\t\trust-toolchain.toml\ttooling"
 696            );
 697            test_path!(
 698                "Cargo.toml\t\texperiments\t\tโ€นยซnote๐Ÿ‘‰booksยปโ€บ\t\trust-toolchain.toml\ttooling"
 699            );
 700            test_path!(
 701                "Cargo.toml\t\texperiments\t\tnotebooks\t\tโ€นยซrust-t๐Ÿ‘‰oolchain.tomlยปโ€บ\ttooling"
 702            );
 703            test_path!(
 704                "Cargo.toml\t\texperiments\t\tnotebooks\t\trust-toolchain.toml\tโ€นยซtoo๐Ÿ‘‰lingยปโ€บ"
 705            );
 706        }
 707
 708        #[test]
 709        fn colons_galore() {
 710            test_path!("โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ");
 711            test_path!("โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ:");
 712            test_path!("โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยป:ยซ2ยปโ€บ");
 713            test_path!("โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยป:ยซ2ยปโ€บ:");
 714            test_path!("โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ1ยป)โ€บ");
 715            test_path!("โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ1ยป)โ€บ:");
 716            test_path!("โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ1ยป,ยซ618ยป)โ€บ");
 717            test_path!("โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ1ยป,ยซ618ยป)โ€บ:");
 718            test_path!("โ€นยซ/test/co๐Ÿ‘‰ol.rsยป::ยซ42ยปโ€บ");
 719            test_path!("โ€นยซ/test/co๐Ÿ‘‰ol.rsยป::ยซ42ยปโ€บ:");
 720            test_path!("โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ1ยป,ยซ618ยป)โ€บ::");
 721        }
 722
 723        #[test]
 724        fn quotes_and_brackets() {
 725            test_path!("\"โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ\"");
 726            test_path!("'โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ'");
 727            test_path!("`โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ`");
 728
 729            test_path!("[โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ]");
 730            test_path!("(โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ)");
 731            test_path!("{โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ}");
 732            test_path!("<โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ>");
 733
 734            test_path!("[\"โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ\"]");
 735            test_path!("'(โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ)'");
 736
 737            test_path!("\"โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยป:ยซ2ยปโ€บ\"");
 738            test_path!("'โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยป:ยซ2ยปโ€บ'");
 739            test_path!("`โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยป:ยซ2ยปโ€บ`");
 740
 741            test_path!("[โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยป:ยซ2ยปโ€บ]");
 742            test_path!("(โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยป:ยซ2ยปโ€บ)");
 743            test_path!("{โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยป:ยซ2ยปโ€บ}");
 744            test_path!("<โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยป:ยซ2ยปโ€บ>");
 745
 746            test_path!("[\"โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยป:ยซ2ยปโ€บ\"]");
 747
 748            test_path!("\"โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ4ยป)โ€บ\"");
 749            test_path!("'โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ4ยป)โ€บ'");
 750            test_path!("`โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ4ยป)โ€บ`");
 751
 752            test_path!("[โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ4ยป)โ€บ]");
 753            test_path!("(โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ4ยป)โ€บ)");
 754            test_path!("{โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ4ยป)โ€บ}");
 755            test_path!("<โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ4ยป)โ€บ>");
 756
 757            test_path!("[\"โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ4ยป)โ€บ\"]");
 758
 759            test_path!("\"โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ4ยป,ยซ2ยป)โ€บ\"");
 760            test_path!("'โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ4ยป,ยซ2ยป)โ€บ'");
 761            test_path!("`โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ4ยป,ยซ2ยป)โ€บ`");
 762
 763            test_path!("[โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ4ยป,ยซ2ยป)โ€บ]");
 764            test_path!("(โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ4ยป,ยซ2ยป)โ€บ)");
 765            test_path!("{โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ4ยป,ยซ2ยป)โ€บ}");
 766            test_path!("<โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ4ยป,ยซ2ยป)โ€บ>");
 767
 768            test_path!("[\"โ€นยซ/test/co๐Ÿ‘‰ol.rsยป(ยซ4ยป,ยซ2ยป)โ€บ\"]");
 769
 770            // Imbalanced
 771            test_path!("([โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ] was here...)");
 772            test_path!("[Here's <โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ>]");
 773            test_path!("('โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ' was here...)");
 774            test_path!("[Here's `โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ`]");
 775        }
 776
 777        #[test]
 778        fn trailing_punctuation() {
 779            test_path!("โ€นยซ/test/co๐Ÿ‘‰ol.rsยปโ€บ:,..");
 780            test_path!("/test/cool.rs:,๐Ÿ‘‰..");
 781            test_path!("โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ:,");
 782            test_path!("/test/cool.rs:4:๐Ÿ‘‰,");
 783            test_path!("[\"โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ\"]:,");
 784            test_path!("'(โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ),,'...");
 785            test_path!("('โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ'::: was here...)");
 786            test_path!("[Here's <โ€นยซ/test/co๐Ÿ‘‰ol.rsยป:ยซ4ยปโ€บ>]::: ");
 787        }
 788
 789        #[test]
 790        fn word_wide_chars() {
 791            // Rust paths
 792            test_path!("โ€นยซ/๐Ÿ‘‰ไพ‹/cool.rsยปโ€บ");
 793            test_path!("โ€นยซ/ไพ‹๐Ÿ‘ˆ/cool.rsยปโ€บ");
 794            test_path!("โ€นยซ/ไพ‹/cool.rsยป:ยซ๐Ÿ‘‰4ยปโ€บ");
 795            test_path!("โ€นยซ/ไพ‹/cool.rsยป:ยซ4ยป:ยซ๐Ÿ‘‰2ยปโ€บ");
 796
 797            // Cargo output
 798            test_path!("    Compiling Cool (โ€นยซ/๐Ÿ‘‰ไพ‹/Coolยปโ€บ)");
 799            test_path!("    Compiling Cool (โ€นยซ/ไพ‹๐Ÿ‘ˆ/Coolยปโ€บ)");
 800
 801            test_path!("    Compiling Cool (โ€นยซ/๐Ÿ‘‰ไพ‹/Cool Spacesยปโ€บ)");
 802            test_path!("    Compiling Cool (โ€นยซ/ไพ‹๐Ÿ‘ˆ/Cool Spacesยปโ€บ)");
 803            test_path!("    Compiling Cool (โ€นยซ/๐Ÿ‘‰ไพ‹/Cool Spacesยป:ยซ4ยป:ยซ2ยปโ€บ)");
 804            test_path!("    Compiling Cool (โ€นยซ/ไพ‹๐Ÿ‘ˆ/Cool Spacesยป(ยซ4ยป,ยซ2ยป)โ€บ)");
 805
 806            test_path!("    --> โ€นยซ/๐Ÿ‘‰ไพ‹/Cool Spacesยปโ€บ");
 807            test_path!("    ::: โ€นยซ/ไพ‹๐Ÿ‘ˆ/Cool Spacesยปโ€บ");
 808            test_path!("    --> โ€นยซ/๐Ÿ‘‰ไพ‹/Cool Spacesยป:ยซ4ยป:ยซ2ยปโ€บ");
 809            test_path!("    ::: โ€นยซ/ไพ‹๐Ÿ‘ˆ/Cool Spacesยป(ยซ4ยป,ยซ2ยป)โ€บ");
 810            test_path!("    panicked at โ€นยซ/๐Ÿ‘‰ไพ‹/Cool Spacesยป:ยซ4ยป:ยซ2ยปโ€บ:");
 811            test_path!("    panicked at โ€นยซ/ไพ‹๐Ÿ‘ˆ/Cool Spacesยป(ยซ4ยป,ยซ2ยป)โ€บ:");
 812            test_path!("    at โ€นยซ/๐Ÿ‘‰ไพ‹/Cool Spacesยป:ยซ4ยป:ยซ2ยปโ€บ");
 813            test_path!("    at โ€นยซ/ไพ‹๐Ÿ‘ˆ/Cool Spacesยป(ยซ4ยป,ยซ2ยป)โ€บ");
 814
 815            // Python
 816            test_path!("โ€นยซ๐Ÿ‘‰ไพ‹wesome.pyยปโ€บ");
 817            test_path!("โ€นยซไพ‹๐Ÿ‘ˆwesome.pyยปโ€บ");
 818            test_path!("    โ€นFile \"ยซ/๐Ÿ‘‰ไพ‹wesome.pyยป\", line ยซ42ยปโ€บ: Wat?");
 819            test_path!("    โ€นFile \"ยซ/ไพ‹๐Ÿ‘ˆwesome.pyยป\", line ยซ42ยปโ€บ: Wat?");
 820        }
 821
 822        #[test]
 823        fn non_word_wide_chars() {
 824            // Mojo diagnostic message
 825            test_path!("    โ€นFile \"ยซ/awe๐Ÿ‘‰some.๐Ÿ”ฅยป\", line ยซ42ยปโ€บ: Wat?");
 826            test_path!("    โ€นFile \"ยซ/awesome๐Ÿ‘‰.๐Ÿ”ฅยป\", line ยซ42ยปโ€บ: Wat?");
 827            test_path!("    โ€นFile \"ยซ/awesome.๐Ÿ‘‰๐Ÿ”ฅยป\", line ยซ42ยปโ€บ: Wat?");
 828            test_path!("    โ€นFile \"ยซ/awesome.๐Ÿ”ฅ๐Ÿ‘ˆยป\", line ยซ42ยปโ€บ: Wat?");
 829        }
 830
 831        /// These likely rise to the level of being worth fixing.
 832        mod issues {
 833            #[test]
 834            // <https://github.com/alacritty/alacritty/issues/8586>
 835            fn issue_alacritty_8586() {
 836                // Rust paths
 837                test_path!("โ€นยซ/๐Ÿ‘‰ไพ‹/cool.rsยปโ€บ");
 838                test_path!("โ€นยซ/ไพ‹๐Ÿ‘ˆ/cool.rsยปโ€บ");
 839                test_path!("โ€นยซ/ไพ‹/cool.rsยป:ยซ๐Ÿ‘‰4ยปโ€บ");
 840                test_path!("โ€นยซ/ไพ‹/cool.rsยป:ยซ4ยป:ยซ๐Ÿ‘‰2ยปโ€บ");
 841
 842                // Cargo output
 843                test_path!("    Compiling Cool (โ€นยซ/๐Ÿ‘‰ไพ‹/Coolยปโ€บ)");
 844                test_path!("    Compiling Cool (โ€นยซ/ไพ‹๐Ÿ‘ˆ/Coolยปโ€บ)");
 845
 846                // Python
 847                test_path!("โ€นยซ๐Ÿ‘‰ไพ‹wesome.pyยปโ€บ");
 848                test_path!("โ€นยซไพ‹๐Ÿ‘ˆwesome.pyยปโ€บ");
 849                test_path!("    โ€นFile \"ยซ/๐Ÿ‘‰ไพ‹wesome.pyยป\", line ยซ42ยปโ€บ: Wat?");
 850                test_path!("    โ€นFile \"ยซ/ไพ‹๐Ÿ‘ˆwesome.pyยป\", line ยซ42ยปโ€บ: Wat?");
 851            }
 852
 853            #[test]
 854            // <https://github.com/zed-industries/zed/issues/12338>
 855            fn issue_12338_regex() {
 856                // Issue #12338
 857                test_path!(".rw-r--r--     0     staff 05-27 14:03 โ€นยซ'test file ๐Ÿ‘‰1.txt'ยปโ€บ");
 858                test_path!(".rw-r--r--     0     staff 05-27 14:03 โ€นยซ๐Ÿ‘‰'test file 1.txt'ยปโ€บ");
 859            }
 860
 861            #[test]
 862            // <https://github.com/zed-industries/zed/issues/12338>
 863            fn issue_12338() {
 864                // Issue #12338
 865                test_path!(".rw-r--r--     0     staff 05-27 14:03 โ€นยซtest๐Ÿ‘‰ใ€2.txtยปโ€บ");
 866                test_path!(".rw-r--r--     0     staff 05-27 14:03 โ€นยซtestใ€๐Ÿ‘ˆ2.txtยปโ€บ");
 867                test_path!(".rw-r--r--     0     staff 05-27 14:03 โ€นยซtest๐Ÿ‘‰ใ€‚3.txtยปโ€บ");
 868                test_path!(".rw-r--r--     0     staff 05-27 14:03 โ€นยซtestใ€‚๐Ÿ‘ˆ3.txtยปโ€บ");
 869
 870                // Rust paths
 871                test_path!("โ€นยซ/๐Ÿ‘‰๐Ÿƒ/๐Ÿฆ€.rsยปโ€บ");
 872                test_path!("โ€นยซ/๐Ÿƒ๐Ÿ‘ˆ/๐Ÿฆ€.rsยปโ€บ");
 873                test_path!("โ€นยซ/๐Ÿƒ/๐Ÿ‘‰๐Ÿฆ€.rsยป:ยซ4ยปโ€บ");
 874                test_path!("โ€นยซ/๐Ÿƒ/๐Ÿฆ€๐Ÿ‘ˆ.rsยป:ยซ4ยป:ยซ2ยปโ€บ");
 875
 876                // Cargo output
 877                test_path!("    Compiling Cool (โ€นยซ/๐Ÿ‘‰๐Ÿƒ/Coolยปโ€บ)");
 878                test_path!("    Compiling Cool (โ€นยซ/๐Ÿƒ๐Ÿ‘ˆ/Coolยปโ€บ)");
 879
 880                // Python
 881                test_path!("โ€นยซ๐Ÿ‘‰๐Ÿƒwesome.pyยปโ€บ");
 882                test_path!("โ€นยซ๐Ÿƒ๐Ÿ‘ˆwesome.pyยปโ€บ");
 883                test_path!("    โ€นFile \"ยซ/๐Ÿ‘‰๐Ÿƒwesome.pyยป\", line ยซ42ยปโ€บ: Wat?");
 884                test_path!("    โ€นFile \"ยซ/๐Ÿƒ๐Ÿ‘ˆwesome.pyยป\", line ยซ42ยปโ€บ: Wat?");
 885
 886                // Mojo
 887                test_path!("โ€นยซ/awe๐Ÿ‘‰some.๐Ÿ”ฅยปโ€บ is some good Mojo!");
 888                test_path!("โ€นยซ/awesome๐Ÿ‘‰.๐Ÿ”ฅยปโ€บ is some good Mojo!");
 889                test_path!("โ€นยซ/awesome.๐Ÿ‘‰๐Ÿ”ฅยปโ€บ is some good Mojo!");
 890                test_path!("โ€นยซ/awesome.๐Ÿ”ฅ๐Ÿ‘ˆยปโ€บ is some good Mojo!");
 891                test_path!("    โ€นFile \"ยซ/๐Ÿ‘‰๐Ÿƒwesome.๐Ÿ”ฅยป\", line ยซ42ยปโ€บ: Wat?");
 892                test_path!("    โ€นFile \"ยซ/๐Ÿƒ๐Ÿ‘ˆwesome.๐Ÿ”ฅยป\", line ยซ42ยปโ€บ: Wat?");
 893            }
 894
 895            #[test]
 896            // <https://github.com/zed-industries/zed/issues/40202>
 897            fn issue_40202() {
 898                // Elixir
 899                test_path!("[โ€นยซlib/blitz_apex_๐Ÿ‘‰server/stats/aggregate_rank_stats.exยป:ยซ35ยปโ€บ: BlitzApexServer.Stats.AggregateRankStats.update/2]
 900                1 #=> 1");
 901            }
 902
 903            #[test]
 904            // <https://github.com/zed-industries/zed/issues/28194>
 905            fn issue_28194() {
 906                test_path!(
 907                    "โ€นยซtest/c๐Ÿ‘‰ontrollers/template_items_controller_test.rbยป:ยซ20ยปโ€บ:in 'block (2 levels) in <class:TemplateItemsControllerTest>'"
 908                );
 909            }
 910
 911            #[test]
 912            // <https://github.com/zed-industries/zed/issues/50531>
 913            fn issue_50531() {
 914                // Paths preceded by "N:" prefix (e.g. grep output line numbers)
 915                // should still be clickable
 916                test_path!("0: โ€นยซfoo/๐Ÿ‘‰bar.txtยปโ€บ");
 917                test_path!("0: โ€นยซ๐Ÿ‘‰foo/bar.txtยปโ€บ");
 918                test_path!("42: โ€นยซ๐Ÿ‘‰foo/bar.txtยปโ€บ");
 919                test_path!("1: โ€นยซ/๐Ÿ‘‰test/cool.rsยปโ€บ");
 920                test_path!("1: โ€นยซ/๐Ÿ‘‰test/cool.rsยป:ยซ4ยป:ยซ2ยปโ€บ");
 921            }
 922
 923            #[test]
 924            // <https://github.com/zed-industries/zed/issues/46795>
 925            fn issue_46795() {
 926                // Box drawing characters are commonly used as UI elements and
 927                // should not interfere with path detection; they appear rarely
 928                // enough in actual paths that false positives should be minimal
 929
 930                test_path!("โ”€โ€นยซ/๐Ÿ‘‰test/cool.rsยป:ยซ4ยป:ยซ2ยปโ€บ");
 931                test_path!("โ”คโ€นยซ/๐Ÿ‘‰test/cool.rsยป:ยซ4ยป:ยซ2ยปโ€บ");
 932                test_path!("โ•ฟโ€นยซ/๐Ÿ‘‰test/cool.rsยป:ยซ4ยป:ยซ2ยปโ€บ");
 933
 934                test_path!("โ””โ”€โ”€โ€นยซ/๐Ÿ‘‰test/cool.rsยป:ยซ4ยป:ยซ2ยปโ€บ");
 935                test_path!("โ”œโ”€[โ€นยซ/๐Ÿ‘‰test/cool.rsยป:ยซ4ยป:ยซ2ยปโ€บ]");
 936                test_path!("โ”€[โ€นยซ/๐Ÿ‘‰test/cool.rsยป:ยซ4ยป:ยซ2ยปโ€บ]");
 937                test_path!("โ”ฌโ€นยซ/๐Ÿ‘‰test/cool.rsยป:ยซ4ยป:ยซ2ยปโ€บโ”ฌ");
 938            }
 939
 940            #[test]
 941            #[cfg_attr(
 942                not(target_os = "windows"),
 943                should_panic(
 944                    expected = "Path = ยซ/test/cool.rs:4:NotDescยป, at grid cells (0, 1)..=(7, 2)"
 945                )
 946            )]
 947            #[cfg_attr(
 948                target_os = "windows",
 949                should_panic(
 950                    expected = r#"Path = ยซC:\\test\\cool.rs:4:NotDescยป, at grid cells (0, 1)..=(8, 1)"#
 951                )
 952            )]
 953            // PathWithPosition::parse_str considers "/test/co๐Ÿ‘‰ol.rs:4:NotDesc" invalid input, but
 954            // still succeeds and truncates the part after the position. Ideally this would be
 955            // parsed as the path "/test/co๐Ÿ‘‰ol.rs:4:NotDesc" with no position.
 956            fn path_with_position_parse_str() {
 957                test_path!("`โ€นยซ/test/co๐Ÿ‘‰ol.rs:4:NotDescยปโ€บ`");
 958                test_path!("<โ€นยซ/test/co๐Ÿ‘‰ol.rs:4:NotDescยปโ€บ>");
 959
 960                test_path!("'โ€นยซ(/test/co๐Ÿ‘‰ol.rs:4:2)ยปโ€บ'");
 961                test_path!("'โ€นยซ(/test/co๐Ÿ‘‰ol.rs(4))ยปโ€บ'");
 962                test_path!("'โ€นยซ(/test/co๐Ÿ‘‰ol.rs(4,2))ยปโ€บ'");
 963            }
 964        }
 965
 966        /// Minor issues arguably not important enough to fix/workaround...
 967        mod nits {
 968            #[test]
 969            fn alacritty_bugs_with_two_columns() {
 970                test_path!("โ€นยซ/๐Ÿ‘‰test/cool.rsยป(ยซ4ยป)โ€บ");
 971                test_path!("โ€นยซ/test/cool.rsยป(ยซ๐Ÿ‘‰4ยป)โ€บ");
 972                test_path!("โ€นยซ/test/cool.rsยป(ยซ4ยป,ยซ๐Ÿ‘‰2ยป)โ€บ");
 973
 974                // Python
 975                test_path!("โ€นยซawe๐Ÿ‘‰some.pyยปโ€บ");
 976            }
 977
 978            #[test]
 979            #[cfg_attr(
 980                not(target_os = "windows"),
 981                should_panic(
 982                    expected = "Path = ยซ/test/cool.rsยป, line = 1, at grid cells (0, 0)..=(9, 0)"
 983                )
 984            )]
 985            #[cfg_attr(
 986                target_os = "windows",
 987                should_panic(
 988                    expected = r#"Path = ยซC:\\test\\cool.rsยป, line = 1, at grid cells (0, 0)..=(9, 2)"#
 989                )
 990            )]
 991            fn invalid_row_column_should_be_part_of_path() {
 992                test_path!("โ€นยซ/๐Ÿ‘‰test/cool.rs:1:618033988749ยปโ€บ");
 993                test_path!("โ€นยซ/๐Ÿ‘‰test/cool.rs(1,618033988749)ยปโ€บ");
 994            }
 995
 996            #[test]
 997            #[cfg_attr(
 998                not(target_os = "windows"),
 999                should_panic(expected = "Path = ยซ/te:st/co:ol.r:s:4:2::::::ยป")
1000            )]
1001            #[cfg_attr(
1002                target_os = "windows",
1003                should_panic(expected = r#"Path = ยซC:\\te:st\\co:ol.r:s:4:2::::::ยป"#)
1004            )]
1005            fn many_trailing_colons_should_be_parsed_as_part_of_the_path() {
1006                test_path!("โ€นยซ/te:st/๐Ÿ‘‰co:ol.r:s:4:2::::::ยปโ€บ");
1007                test_path!("/test/cool.rs:::๐Ÿ‘‰:");
1008            }
1009
1010            #[test]
1011            // Filenames with balanced parentheses are preserved as a single path.
1012            // Unbalanced leading `(` (e.g. `Update(.claude/SKILL.md)`) is stripped.
1013            fn parens_in_filename() {
1014                test_path!("โ€นยซdocker-compose.prod(๐Ÿ‘‰copy).ymlยปโ€บ");
1015            }
1016        }
1017
1018        mod windows {
1019            // Lots of fun to be had with long file paths (verbatim) and UNC paths on Windows.
1020            // See <https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation>
1021            // See <https://users.rust-lang.org/t/understanding-windows-paths/58583>
1022            // See <https://github.com/rust-lang/cargo/issues/13919>
1023
1024            #[test]
1025            fn default_prompts() {
1026                // Windows command prompt
1027                test_path!(r#"โ€นยซC:\Users\someone\๐Ÿ‘‰testยปโ€บ>"#);
1028                test_path!(r#"C:\Users\someone\test๐Ÿ‘‰>"#);
1029
1030                // Windows PowerShell
1031                test_path!(r#"PS โ€นยซC:\Users\someone\๐Ÿ‘‰test\cool.rsยปโ€บ>"#);
1032                test_path!(r#"PS C:\Users\someone\test\cool.rs๐Ÿ‘‰>"#);
1033            }
1034
1035            #[test]
1036            fn unc() {
1037                test_path!(r#"โ€นยซ\\server\share\๐Ÿ‘‰test\cool.rsยปโ€บ"#);
1038                test_path!(r#"โ€นยซ\\server\share\test\cool๐Ÿ‘‰.rsยปโ€บ"#);
1039            }
1040
1041            mod issues {
1042                #[test]
1043                fn issue_verbatim() {
1044                    test_path!(r#"โ€นยซ\\?\C:\๐Ÿ‘‰test\cool.rsยปโ€บ"#);
1045                    test_path!(r#"โ€นยซ\\?\C:\test\cool๐Ÿ‘‰.rsยปโ€บ"#);
1046                }
1047
1048                #[test]
1049                fn issue_verbatim_unc() {
1050                    test_path!(r#"โ€นยซ\\?\UNC\server\share\๐Ÿ‘‰test\cool.rsยปโ€บ"#);
1051                    test_path!(r#"โ€นยซ\\?\UNC\server\share\test\cool๐Ÿ‘‰.rsยปโ€บ"#);
1052                }
1053            }
1054        }
1055
1056        mod perf {
1057            use super::super::*;
1058            use crate::TerminalSettings;
1059            use alacritty_terminal::{
1060                event::VoidListener,
1061                grid::Scroll,
1062                index::{Column, Point as AlacPoint},
1063                term::test::mock_term,
1064                term::{Term, search::Match},
1065            };
1066            use settings::{self, Settings, SettingsContent};
1067            use std::{cell::RefCell, rc::Rc};
1068            use util_macros::perf;
1069
1070            fn build_test_term(
1071                line: &str,
1072                repeat: usize,
1073                hover_offset_column: usize,
1074            ) -> (Term<VoidListener>, AlacPoint) {
1075                let content = line.repeat(repeat);
1076                let mut term = mock_term(&content);
1077                term.resize(TermSize {
1078                    columns: 1024,
1079                    screen_lines: 10,
1080                });
1081                term.scroll_display(Scroll::Top);
1082                let point =
1083                    AlacPoint::new(Line(term.topmost_line().0 + 3), Column(hover_offset_column));
1084                (term, point)
1085            }
1086
1087            #[perf]
1088            pub fn cargo_hyperlink_benchmark() {
1089                const LINE: &str = "    Compiling terminal v0.1.0 (/Hyperlinks/Bench/Source/zed-hyperlinks/crates/terminal)\r\n";
1090                thread_local! {
1091                    static TEST_TERM_AND_POINT: (Term<VoidListener>, AlacPoint) =
1092                        build_test_term(LINE, 500, 50);
1093                }
1094                TEST_TERM_AND_POINT.with(|(term, point)| {
1095                    assert_eq!(
1096                        find_from_grid_point_bench(term, *point)
1097                            .map(|(path, ..)| path)
1098                            .unwrap_or_default(),
1099                        "/Hyperlinks/Bench/Source/zed-hyperlinks/crates/terminal",
1100                        "Hyperlink should have been found"
1101                    );
1102                });
1103            }
1104
1105            #[perf]
1106            pub fn rust_hyperlink_benchmark() {
1107                const LINE: &str = "    --> /Hyperlinks/Bench/Source/zed-hyperlinks/crates/terminal/terminal.rs:1000:42\r\n";
1108                thread_local! {
1109                    static TEST_TERM_AND_POINT: (Term<VoidListener>, AlacPoint) =
1110                        build_test_term(LINE, 500, 50);
1111                }
1112                TEST_TERM_AND_POINT.with(|(term, point)| {
1113                    assert_eq!(
1114                        find_from_grid_point_bench(term, *point)
1115                            .map(|(path, ..)| path)
1116                            .unwrap_or_default(),
1117                        "/Hyperlinks/Bench/Source/zed-hyperlinks/crates/terminal/terminal.rs:1000:42",
1118                        "Hyperlink should have been found"
1119                    );
1120                });
1121            }
1122
1123            #[perf]
1124            pub fn ls_hyperlink_benchmark() {
1125                const LINE: &str = "Cargo.toml        experiments        notebooks        rust-toolchain.toml    tooling\r\n";
1126                thread_local! {
1127                    static TEST_TERM_AND_POINT: (Term<VoidListener>, AlacPoint) =
1128                        build_test_term(LINE, 500, 60);
1129                }
1130                TEST_TERM_AND_POINT.with(|(term, point)| {
1131                    assert_eq!(
1132                        find_from_grid_point_bench(term, *point)
1133                            .map(|(path, ..)| path)
1134                            .unwrap_or_default(),
1135                        "rust-toolchain.toml",
1136                        "Hyperlink should have been found"
1137                    );
1138                });
1139            }
1140
1141            #[perf]
1142            // https://github.com/zed-industries/zed/pull/44407
1143            pub fn pr_44407_hyperlink_benchmark() {
1144                const LINE: &str = "-748, 706, 163, 222, -980, 949, 381, -568, 199, 501, 760, -821, 90, -451, 183, 867, -351, -810, -762, -109, 423, 84, 14, -77, -820, -345, 74, -791, 930, -618, -900, 862, -959, 289, -19, 471, -757, 793, 155, -554, 249, 830, 402, 732, -731, -866, -720, -703, -257, -439, 731, 872, -489, 676, -167, 613, -698, 415, -80, -453, -896, 333, -511, 621, -450, 624, -309, -575, 177, 141, 891, -104, -97, -367, -599, -675, 607, -225, -760, 552, -465, 804, 55, 282, 104, -929, -252,\
1145-311, 900, 550, 599, -80, 774, 553, 837, -395, 541, 953, 154, -396, -596, -111, -802, -221, -337, -633, -73, -527, -82, -658, -264, 222, 375, 434, 204, -756, -703, 303, 239, -257, -365, -351, 904, 364, -743, -484, 655, -542, 446, 888, 632, -167, -260, 716, 150, 806, 723, 513, -118, -323, -683, 983, -564, 358, -16, -287, 277, -607, 87, 365, -1, 164, 401, 257, 369, -893, 145, -969, 375, -53, 541, -408, -865, 753, 258, 337, -886, 593, -378, -528, 191, 204, 566, -61, -621, 769, 524, -628, 6,\
1146249, 896, -785, -776, 321, -681, 604, -740, 886, 426, -480, -983, 23, -247, 125, -666, 913, 842, -460, -797, -483, -58, -565, -587, -206, 197, 715, 764, -97, 457, -149, -226, 261, 194, -390, 431, 180, -778, 829, -657, -668, 397, 859, 152, -178, 677, -18, 687, -247, 96, 466, -572, 478, 622, -143, -25, -471, 265, 335, 957, 152, -951, -647, 670, 57, 152, -115, 206, 87, 629, -798, -125, -725, -31, 844, 398, -876, 44, 963, -211, 518, -8, -103, -999, 948, 823, 149, -803, 769, -236, -683, 527,\
1147-108, -36, 18, -437, 687, -305, -526, 972, -965, 276, 420, -259, -379, -142, -747, 600, -578, 197, 673, 890, 324, -931, 755, -765, -422, 785, -369, -110, -505, 532, -208, -438, 713, 110, 853, 996, -360, 823, 289, -699, 629, -661, 560, -329, -323, 439, 571, -537, 644, -84, 25, -536, -161, 112, 169, -922, -537, -734, -423, 37, 451, -149, 408, 18, -672, 206, -784, 444, 593, -241, 502, -259, -798, -352, -658, 712, -675, -734, 627, -620, 64, -554, 999, -537, -160, -641, 464, 894, 29, 322, 566,\
1148-510, -749, 982, 204, 967, -261, -986, -136, 251, -598, 995, -831, 891, 22, 761, -783, -415, 125, 470, -919, -97, -668, 85, 205, -175, -550, 502, 652, -468, 798, 775, -216, 89, -433, -24, -621, 877, -126, 951, 809, 782, 156, -618, -841, -463, 19, -723, -904, 550, 263, 991, -758, -114, 446, -731, -623, -634, 462, 48, 851, 333, -846, 480, 892, -966, -910, -436, 317, -711, -341, -294, 124, 238, -214, -281, 467, -950, -342, 913, -90, -388, -573, 740, -883, -451, 493, -500, 863, 930, 127, 530,\
1149-810, 540, 541, -664, -951, -227, -420, -476, -581, -534, 549, 253, 984, -985, -84, -521, 538, 484, -440, 371, 784, -306, -850, 530, -133, 251, -799, 446, -170, -243, -674, 769, 646, 778, -680, -714, -442, 804, 901, -774, 69, 307, -293, 755, 443, 224, -918, -771, 723, 40, 132, 568, -847, -47, 844, 69, 986, -293, -459, 313, 155, 331, 69, 280, -637, 569, 104, -119, -988, 252, 857, -590, 810, -891, 484, 566, -934, -587, -290, 566, 587, 489, 870, 280, 454, -252, 613, -701, -278, 195, -198,\
1150683, 533, -372, 707, -152, 371, 866, 609, -5, -372, -30, -694, 552, 192, 452, -663, 350, -985, 10, 884, 813, -592, -331, -470, 711, -941, 928, 379, -339, 220, 999, 376, 507, 179, 916, 84, 104, 392, 192, 299, -860, 218, -698, -919, -452, 37, 850, 5, -874, 287, 123, -746, -575, 776, -909, 118, 903, -275, 450, -996, -591, -920, -850, 453, -896, 73, 83, -535, -20, 287, -765, 442, 808, 45, 445, 202, 917, -208, 783, 790, -534, 373, -129, 556, -757, -69, 459, -163, -59, 265, -563, -889, 635,\
1151-583, -261, -790, 799, 826, 953, 85, 619, 334, 842, 672, -869, -4, -833, 315, 942, -524, 579, 926, 628, -404, 128, -629, 161, 568, -117, -526, 223, -876, 906, 176, -549, -317, 381, 375, -801, -416, 647, 335, 253, -386, -375, -254, 635, 352, 317, 398, -422, 111, 201, 220, 554, -972, 853, 378, 956, 942, -857, -289, -333, -180, 488, -814, -42, -595, 721, 39, 644, 721, -242, -44, 643, -457, -419, 560, -863, 974, 458, 222, -882, 526, -243, -318, -343, -707, -401, 117, 677, -489, 546, -903,\
1152-960, -881, -684, 125, -928, -995, -692, -773, 647, -718, -862, -814, 671, 664, -130, -856, -674, 653, 711, 194, -685, -160, 138, -27, -128, -671, -242, 526, 494, -674, 424, -921, -778, 313, -237, 332, 913, 252, 808, -936, 289, 755, 52, -139, 57, -19, -827, -775, -561, -14, 107, -84, 622, -303, -747, 258, -942, 290, 211, -919, -207, 797, 95, 794, -830, -181, -788, 757, 75, -946, -949, -988, 152, 340, 732, 886, -891, -642, -666, 321, -910, 841, 632, 298, 55, -349, 498, 287, -711, 97, 305,\
1153-974, -987, 790, -64, 605, -583, -821, 345, 887, -861, 548, 894, 288, 452, 556, -448, 813, 420, 545, 967, 127, -947, 19, -314, -607, -513, -851, 254, -290, -938, -783, -93, 474, 368, -485, -935, -539, 81, 404, -283, 779, 345, -164, 53, 563, -771, 911, -323, 522, -998, 315, 415, 460, 58, -541, -878, -152, -886, 201, -446, -810, 549, -142, -575, -632, 521, 549, 209, -681, 998, 798, -611, -919, -708, -4, 677, -172, 588, 750, -435, 508, 609, 498, -535, -691, -738, 85, 615, 705, 169, 425,\
1154-669, -491, -783, 73, -847, 228, -981, -812, -229, 950, -904, 175, -438, 632, -556, 910, 173, 576, -751, -53, -169, 635, 607, -944, -13, -84, 105, -644, 984, 935, 259, -445, 620, -405, 832, 167, 114, 209, -181, -944, -496, 693, -473, 137, 38, -873, -334, -353, -57, 397, 944, 698, 811, -401, 712, -667, 905, 276, -653, 368, -543, -349, 414, 287, 894, 935, 461, 55, 741, -623, -660, -773, 617, 834, 278, -121, 52, 495, -855, -440, -210, -99, 279, -661, 540, 934, 540, 784, 895, 268, -503, 513,\
1155-484, -352, 528, 341, -451, 885, -71, 799, -195, -885, -585, -233, 92, 453, 994, 464, 694, 190, -561, -116, 675, -775, -236, 556, -110, -465, 77, -781, 507, -960, -410, 229, -632, 717, 597, 429, 358, -430, -692, -825, 576, 571, 758, -891, 528, -267, 190, -869, 132, -811, 796, 750, -596, -681, 870, 360, 969, 860, -412, -567, 694, -86, -498, 38, -178, -583, -778, 412, 842, -586, 722, -192, 350, 363, 81, -677, -163, 564, 543, 671, 110, 314, 739, -552, -224, -644, 922, 685, 134, 613, 793,\
1156-363, -244, -284, -257, -561, 418, 988, 333, 110, -966, 790, 927, 536, -620, -309, -358, 895, -867, -796, -357, 308, -740, 287, -732, -363, -969, 658, 711, 511, 256, 590, -574, 815, -845, -84, 546, -581, -71, -334, -890, 652, -959, 320, -236, 445, -851, 825, -756, -4, 877, 308, 573, -117, 293, 686, -483, 391, 342, -550, -982, 713, 886, 552, 474, -673, 283, -591, -383, 988, 435, -131, 708, -326, -884, 87, 680, -818, -408, -486, 813, -307, -799, 23, -497, 802, -146, -100, 541, 7, -493, 577,\
115750, -270, 672, 834, 111, -788, 247, 337, 628, -33, -964, -519, 683, 54, -703, 633, -127, -448, 759, -975, 696, 2, -870, -760, 67, 696, 306, 750, 615, 155, -933, -568, 399, 795, 164, -460, 205, 439, -526, -691, 35, -136, -481, -63, 73, -598, 748, 133, 874, -29, 4, -73, 472, 389, 962, 231, -328, 240, 149, 959, 46, -207, 72, -514, -608, 0, -14, 32, 374, -478, -806, 919, -729, -286, 652, 109, 509, -879, -979, -865, 584, -92, -346, -992, 781, 401, 575, 993, -746, -33, 684, -683, 750, -105,\
1158-425, -508, -627, 27, 770, -45, 338, 921, -139, -392, -933, 634, 563, 224, -780, 921, 991, 737, 22, 64, 414, -249, -687, 869, 50, 759, -97, 515, 20, -775, -332, 957, 138, -542, -835, 591, -819, 363, -715, -146, -950, -641, -35, -435, -407, -548, -984, 383, -216, -559, 853, 4, -410, -319, -831, -459, -628, -819, -324, 755, 696, -192, 238, -234, -724, -445, 915, 302, -708, 484, 224, -641, 25, -771, 528, -106, -744, -588, 913, -554, -515, -239, -843, -812, -171, 721, 543, -269, 440, 151,\
1159996, -723, -557, -522, -280, -514, -593, 208, 715, 404, 353, 270, -483, -785, 318, -313, 798, 638, 764, 748, -929, -827, -318, -56, 389, -546, -958, -398, 463, -700, 461, 311, -787, -488, 877, 456, 166, 535, -995, -189, -715, 244, 40, 484, 212, -329, -351, 638, -69, -446, -292, 801, -822, 490, -486, -185, 790, 370, -340, 401, -656, 584, 561, -749, 269, -19, -294, -111, 975, 874, -73, 851, 231, -331, -684, 460, 765, -654, -76, 10, 733, 520, 521, 416, -958, -202, -186, -167, 175, 343, -50,\
1160673, -763, -854, -977, -17, -853, -122, -25, 180, 149, 268, 874, -816, -745, 747, -303, -959, 390, 509, 18, -66, 275, -277, 9, 837, -124, 989, -542, -649, -845, 894, 926, 997, -847, -809, -579, -96, -372, 766, 238, -251, 503, 559, 276, -281, -102, -735, 815, 109, 175, -10, 128, 543, -558, -707, 949, 996, -422, -506, 252, 702, -930, 552, -961, 584, -79, -177, 341, -275, 503, -21, 677, -545, 8, -956, -795, -870, -254, 170, -502, -880, 106, 174, 459, 603, -600, -963, 164, -136, -641, -309,\
1161-380, -707, -727, -10, 727, 952, 997, -731, -133, 269, 287, 855, 716, -650, 479, 299, -839, -308, -782, 769, 545, 663, -536, -115, 904, -986, -258, -562, 582, 664, 408, -525, -889, 471, -370, -534, -220, 310, 766, 931, -193, -897, -192, -74, -365, -256, -359, -328, 658, -691, -431, 406, 699, 425, 713, -584, -45, -588, 289, 658, -290, -880, -987, -444, 371, 904, -155, 81, -278, -708, -189, -78, 655, 342, -998, -647, -734, -218, 726, 619, 663, 744, 518, 60, -409, 561, -727, -961, -306,\
1162-147, -550, 240, -218, -393, 267, 724, 791, -548, 480, 180, -631, 825, -170, 107, 227, -691, 905, -909, 359, 227, 287, 909, 632, -89, -522, 80, -429, 37, 561, -732, -474, 565, -798, -460, 188, 507, -511, -654, 212, -314, -376, -997, -114, -708, 512, -848, 781, 126, -956, -298, 354, -400, -121, 510, 445, 926, 27, -708, 676, 248, 834, 542, 236, -105, -153, 102, 128, 96, -348, -626, 598, 8, 978, -589, -461, -38, 381, -232, -817, 467, 356, -151, -460, 429, -408, 425, 618, -611, -247, 819,\
1163963, -160, 1000, 141, -647, -875, 108, 790, -127, 463, -37, -195, -542, 12, 845, -384, 770, -129, 315, 826, -942, 430, 146, -170, -583, -903, -489, 497, -559, -401, -29, -129, -411, 166, 942, -646, -862, -404, 785, 777, -111, -481, -738, 490, 741, -398, 846, -178, -509, -661, 748, 297, -658, -567, 531, 427, -201, -41, -808, -668, 782, -860, -324, 249, 835, -234, 116, 542, -201, 328, 675, 480, -906, 188, 445, 63, -525, 811, 277, 133, 779, -680, 950, -477, -306, -64, 552, -890, -956, 169,\
1164442, 44, -169, -243, -242, 423, -884, -757, -403, 739, -350, 383, 429, 153, -702, -725, 51, 310, 857, -56, 538, 46, -311, 132, -620, -297, -124, 534, 884, -629, -117, 506, -837, -100, -27, -381, -735, 262, 843, 703, 260, -457, 834, 469, 9, 950, 59, 127, -820, 518, 64, -783, 659, -608, -676, 802, 30, 589, 246, -369, 361, 347, 534, -376, 68, 941, 709, 264, 384, 481, 628, 199, -568, -342, -337, 853, -804, -858, -169, -270, 641, -344, 112, 530, -773, -349, -135, -367, -350, -756, -911, 180,\
1165-660, 116, -478, -265, -581, 510, 520, -986, 935, 219, 522, 744, 47, -145, 917, 638, 301, 296, 858, -721, 511, -816, 328, 473, 441, 697, -260, -673, -379, 893, 458, 154, 86, 905, 590, 231, -717, -179, 79, 272, -439, -192, 178, -200, 51, 717, -256, -358, -626, -518, -314, -825, -325, 588, 675, -892, -798, 448, -518, 603, -23, 668, -655, 845, -314, 783, -347, -496, 921, 893, -163, -748, -906, 11, -143, -64, 300, 336, 882, 646, 533, 676, -98, -148, -607, -952, -481, -959, -874, 764, 537,\
1166736, -347, 646, -843, 966, -916, -718, -391, -648, 740, 755, 919, -608, 388, -655, 68, 201, 675, -855, 7, -503, 881, 760, 669, 831, 721, -564, -445, 217, 331, 970, 521, 486, -254, 25, -259, 336, -831, 252, -995, 908, -412, -240, 123, -478, 366, 264, -504, -843, 632, -288, 896, 301, 423, 185, 318, 380, 457, -450, -162, -313, 673, -963, 570, 433, -548, 107, -39, -142, -98, -884, -3, 599, -486, -926, 923, -82, 686, 290, 99, -382, -789, 16, 495, 570, 284, 474, -504, -201, -178, -1, 592, 52,\
1167827, -540, -151, -991, 130, 353, -420, -467, -661, 417, -690, 942, 936, 814, -566, -251, -298, 341, -139, 786, 129, 525, -861, 680, 955, -245, -50, 331, 412, -38, -66, 611, -558, 392, -629, -471, -68, -535, 744, 495, 87, 558, 695, 260, -308, 215, -464, 239, -50, 193, -540, 184, -8, -194, 148, 898, -557, -21, 884, 644, -785, -689, -281, -737, 267, 50, 206, 292, 265, 380, -511, 310, 53, 375, -497, -40, 312, -606, -395, 142, 422, 662, -584, 72, 144, 40, -679, -593, 581, 689, -829, 442, 822,\
1168977, -832, -134, -248, -207, 248, 29, 259, 189, 592, -834, -866, 102, 0, 340, 25, -354, -239, 420, -730, -992, -925, -314, 420, 914, 607, -296, -415, -30, 813, 866, 153, -90, 150, -81, 636, -392, -222, -835, 482, -631, -962, -413, -727, 280, 686, -382, 157, -404, -511, -432, 455, 58, 108, -408, 290, -829, -252, 113, 550, -935, 925, 422, 38, 789, 361, 487, -460, -769, -963, -285, 206, -799, -488, -233, 416, 143, -456, 753, 520, 599, 621, -168, 178, -841, 51, 952, 374, 166, -300, -576, 844,\
1169-656, 90, 780, 371, 730, -896, -895, -386, -662, 467, -61, 130, -362, -675, -113, 135, -761, -55, 408, 822, 675, -347, 725, 114, 952, -510, -972, 390, -413, -277, -52, 315, -80, 401, -712, 147, -202, 84, 214, -178, 970, -571, -210, 525, -887, -863, 504, 192, 837, -594, 203, -876, -209, 305, -826, 377, 103, -928, -803, -956, 949, -868, -547, 824, -994, 516, 93, -524, -866, -890, -988, -501, 15, -6, 413, -825, 304, -818, -223, 525, 176, 610, 828, 391, 940, 540, -831, 650, 438, 589, 941, 57,\
1170523, 126, 221, 860, -282, -262, -226, 764, 743, -640, 390, 384, -434, 608, -983, 566, -446, 618, 456, -176, -278, 215, 871, -180, 444, -931, -200, -781, 404, 881, 780, -782, 517, -739, -548, -811, 201, -95, -249, -228, 491, -299, 700, 964, -550, 108, 334, -653, 245, -293, -552, 350, -685, -415, -818, 216, -194, -255, 295, 249, 408, 351, 287, 379, 682, 231, -693, 902, -902, 574, 937, -708, -402, -460, 827, -268, 791, 343, -780, -150, -738, 920, -430, -88, -361, -588, -727, -47, -297, 662,\
1171-840, -637, -635, 916, -857, 938, 132, -553, 391, -522, 640, 626, 690, 833, 867, -555, 577, 226, 686, -44, 0, -965, 651, -1, 909, 595, -646, 740, -821, -648, -962, 927, -193, 159, 490, 594, -189, 707, -884, 759, -278, -160, -566, -340, 19, 862, -440, 445, -598, 341, 664, -311, 309, -159, 19, -672, 705, -646, 976, 247, 686, -830, -27, -667, 81, 399, -423, -567, 945, 38, 51, 740, 621, 204, -199, -908, -593, 424, 250, -561, 695, 9, 520, 878, 120, -109, 42, -375, -635, -711, -687, 383, -278,\
117236, 970, 925, 864, 836, 309, 117, 89, 654, -387, 346, -53, 617, -164, -624, 184, -45, 852, 498, -513, 794, -682, -576, 13, -147, 285, -776, -886, -96, 483, 994, -188, 346, -629, -848, 738, 51, 128, -898, -753, -906, 270, -203, -577, 48, -243, -210, 666, 353, 636, -954, 862, 560, -944, -877, -137, 440, -945, -316, 274, -211, -435, 615, -635, -468, 744, 948, -589, 525, 757, -191, -431, 42, 451, -160, -827, -991, 324, 697, 342, -610, 894, -787, -384, 872, 734, 878, 70, -260, 57, 397, -518,\
1173629, -510, -94, 207, 214, -625, 106, -882, -575, 908, -650, 723, -154, 45, 108, -69, -565, 927, -68, -351, 707, -282, 429, -889, -596, 848, 578, -492, 41, -822, -992, 168, -286, -780, 970, 597, -293, -12, 367, 708, -415, 194, -86, -390, 224, 69, -368, -674, 1000, -672, 356, -202, -169, 826, 476, -285, 29, -448, 545, 186, 319, 67, 705, 412, 225, -212, -351, -391, -783, -9, 875, -59, -159, -123, -151, -296, 871, -638, 359, 909, -945, 345, -16, -562, -363, -183, -625, -115, -571, -329, 514,\
117499, 263, 463, -39, 597, -652, -349, 246, 77, -127, -563, -879, -30, 756, 777, -865, 675, -813, -501, 871, -406, -627, 834, -609, -205, -812, 643, -204, 291, -251, -184, -584, -541, 410, -573, -600, 908, -871, -687, 296, -713, -139, -778, -790, 347, -52, -400, 407, -653, 670, 39, -856, 904, 433, 392, 590, -271, -144, -863, 443, 353, 468, -544, 486, -930, 458, -596, -890, 163, 822, 768, 980, -783, -792, 126, 386, 367, -264, 603, -61, 728, 160, -4, -837, 832, 591, 436, 518, 796, -622, -867,\
1175-669, -947, 253, 100, -792, 841, 413, 833, -249, -550, 282, -825, 936, -348, 898, -451, -283, 818, -237, 630, 216, -499, -637, -511, 767, -396, 221, 958, -586, -920, 401, -313, -580, -145, -270, 118, 497, 426, -975, 480, -445, -150, -721, -929, 439, -893, 902, 960, -525, -793, 924, 563, 683, -727, -86, 309, 432, -762, -345, 371, -617, 149, -215, -228, 505, 593, -20, -292, 704, -999, 149, -104, 819, -414, -443, 517, -599, -5, 145, -24, -993, -283, 904, 174, -112, -276, -860, 44, -257,\
1176-931, -821, -667, 540, 421, 485, 531, 407, 833, 431, -415, 878, 503, -901, 639, -608, 896, 860, 927, 424, 113, -808, -323, 729, 382, -922, 548, -791, -379, 207, 203, 559, 537, 137, 999, -913, -240, 942, 249, 616, 775, -4, 915, 855, -987, -234, -384, 948, -310, -542, 125, -289, -599, 967, -492, -349, -552, 562, -926, 632, -164, 217, -165, -496, 847, 684, -884, 457, -748, -745, -38, 93, 961, 934, 588, 366, -130, 851, -803, -811, -211, 428, 183, -469, 888, 596, -475, -899, -681, 508, 184,\
1177921, 863, -610, -416, -119, -966, -686, 210, 733, 715, -889, -925, -434, -566, -455, 596, -514, 983, 755, -194, -802, -313, 91, -541, 808, -834, 243, -377, 256, 966, -402, -773, -308, -605, 266, 866, 118, -425, -531, 498, 666, 813, -267, 830, 69, -869, -496, 735, 28, 488, -645, -493, -689, 170, -940, 532, 844, -658, -617, 408, -200, 764, -665, 568, 342, 621, 908, 471, 280, 859, 709, 898, 81, -547, 406, 514, -595, 43, -824, -696, -746, -429, -59, -263, -813, 233, 279, -125, 687, -418,\
1178-530, 409, 614, 803, -407, 78, -676, -39, -887, -141, -292, 270, -343, 400, 907, 588, 668, 899, 973, 103, -101, -11, 397, -16, 165, 705, -410, -585, 316, 391, -346, -336, 957, -118, -538, -441, -845, 121, 591, -359, -188, -362, -208, 27, -925, -157, -495, -177, -580, 9, 531, -752, 94, 107, 820, 769, -500, 852, 617, 145, 355, 34, -463, -265, -709, -111, -855, -405, 560, 470, 3, -177, -164, -249, 450, 662, 841, -689, -509, 987, -33, 769, 234, -2, 203, 780, 744, -895, 497, -432, -406, -264,\
1179-71, 124, 778, -897, 495, 127, -76, 52, -768, 205, 464, -992, 801, -83, -806, 545, -316, 146, 772, 786, 289, -936, 145, -30, -722, -455, 270, 444, 427, -482, 383, -861, 36, 630, -404, 83, 864, 743, -351, -846, 315, -837, 357, -195, 450, -715, 227, -942, 740, -519, 476, 716, 713, 169, 492, -112, -49, -931, 866, 95, -725, 198, -50, -17, -660, 356, -142, -781, 53, 431, 720, 143, -416, 446, -497, 490, -96, 157, 239, 487, -337, -224, -445, 813, 92, -22, 603, 424, 952, -632, -367, 898, -927,\
1180884, -277, -187, -777, 537, -575, -313, 347, -33, 800, 672, -919, -541, 5, -270, -94, -265, -793, -183, -761, -516, -608, -218, 57, -889, -912, 508, 93, -90, 34, 530, 201, 999, -37, -186, -62, -980, 239, 902, 983, -287, -634, 524, -772, 470, -961, 32, 162, 315, -411, 400, -235, -283, -787, -703, 869, 792, 543, -274, 239, 733, -439, 306, 349, 579, -200, -201, -824, 384, -246, 133, -508, 770, -102, 957, -825, 740, 748, -376, 183, -426, 46, 668, -886, -43, -174, 672, -419, 390, 927, 1000,\
1181318, 886, 47, 908, -540, -825, -5, 314, -999, 354, -603, 966, -633, -689, 985, 534, -290, 167, -652, -797, -612, -79, 488, 622, -464, -950, 595, 897, 704, -238, -395, 125, 831, -180, 226, -379, 310, 564, 56, -978, 895, -61, 686, -251, 434, -417, 161, -512, 752, 528, -589, -425, 66, -925, -157, 1000, 96, 256, -239, -784, -882, -464, -909, 663, -177, -678, -441, 669, -564, -201, -121, -743, 187, -107, -768, -682, 355, 161, 411, 984, -954, 166, -842, -755, 267, -709, 372, -699, -272, -850,\
1182403, -839, 949, 622, -62, 51, 917, 70, 528, -558, -632, 832, 276, 61, -445, -195, 960, 846, -474, 764, 879, -411, 948, -62, -592, -123, -96, -551, -555, -724, 849, 250, -808, -732, 797, -839, -554, 306, -919, 888, 484, -728, 152, -122, -287, 16, -345, -396, -268, -963, -500, 433, 343, 418, -480, 828, 594, 821, -9, 933, -230, 707, -847, -610, -748, -234, 688, 935, 713, 865, -743, 293, -143, -20, 928, -906, -762, 528, 722, 412, -70, 622, -245, 539, -686, 730, -866, -705, 28, -916, -623,\
1183-768, -614, -915, -123, -183, 680, -223, 515, -37, -235, -5, 260, 347, -239, -322, -861, -848, -936, 945, 721, -580, -639, 780, -153, -26, 685, 177, 587, 307, -915, 435, 658, 539, -229, -719, -171, -858, 162, 734, -539, -437, 246, 639, 765, -477, -342, -209, -284, -779, -414, -452, 914, 338, -83, 759, 567, 266, -485, 14, 225, 347, -432, -242, 997, -365, -764, 119, -641, -416, -388, -436, -388, -54, -649, -571, -920, -477, 714, -363, 836, 369, 702, 869, 503, -287, -679, 46, -666, -202,\
1184-602, 71, -259, 967, 601, -571, -830, -993, -271, 281, -494, 482, -180, 572, 587, -651, -566, -448, -228, 511, -924, 832, -52, -712, 402, -644, -533, -865, 269, 965, 56, 675, 179, -338, -272, 614, 602, -283, 303, -70, 909, -942, 117, 839, 468, 813, -765, 884, -697, -813, 352, 374, -705, -295, 633, 211, -754, 597, -941, -142, -393, -469, -653, 688, 996, 911, 214, 431, 453, -141, 874, -81, -258, -735, -3, -110, -338, -929, -182, -306, -104, -840, -588, -759, -157, -801, 848, -698, 627, 914,\
1185-33, -353, 425, 150, -798, 553, 934, -778, -196, -132, 808, 745, -894, 144, 213, 662, 273, -79, 454, -60, -467, 48, -15, -807, 69, -930, 749, 559, -867, -103, 258, -677, 750, -303, 846, -227, -936, 744, -770, 770, -434, 594, -477, 589, -612, 535, 357, -623, 683, 369, 905, 980, -410, -663, 762, -888, -563, -845, 843, 353, -491, 996, -255, -336, -132, 695, -823, 289, -143, 365, 916, 877, 245, -530, -848, -804, -118, -108, 847, 620, -355, 499, 881, 92, -640, 542, 38, 626, -260, -34, -378,\
1186598, 890, 305, -118, 711, -385, 600, -570, 27, -129, -893, 354, 459, 374, 816, 470, 356, 661, 877, 735, -286, -780, 620, 943, -169, -888, 978, 441, -667, -399, 662, 249, 137, 598, -863, -453, 722, -815, -251, -995, -294, -707, 901, 763, 977, 137, 431, -994, 905, 593, 694, 444, -626, -816, 252, 282, 616, 841, 360, -932, 817, -908, 50, 394, -120, -786, -338, 499, -982, -95, -454, 838, -312, 320, -127, -653, 53, 16, 988, -968, -151, -369, -836, 293, -271, 483, 18, 724, -204, -965, 245, 310,\
1187987, 552, -835, -912, -861, 254, 560, 124, 145, 798, 178, 476, 138, -311, 151, -907, -886, -592, 728, -43, -489, 873, -422, -439, -489, 375, -703, -459, 338, 418, -25, 332, -454, 730, -604, -800, 37, -172, -197, -568, -563, -332, 228, -182, 994, -123, 444, -567, 98, 78, 0, -504, -150, 88, -936, 199, -651, -776, 192, 46, 526, -727, -991, 534, -659, -738, 256, -894, 965, -76, 816, 435, -418, 800, 838, 67, -733, 570, 112, -514, -416\r\
1188";
1189                thread_local! {
1190                    static TEST_TERM_AND_POINT: (Term<VoidListener>, AlacPoint) =
1191                        build_test_term(&LINE, 5, 50);
1192                }
1193                TEST_TERM_AND_POINT.with(|(term, point)| {
1194                    assert_eq!(
1195                        find_from_grid_point_bench(term, *point)
1196                            .map(|(path, ..)| path)
1197                            .unwrap_or_default(),
1198                        "392",
1199                        "Hyperlink should have been found"
1200                    );
1201                });
1202            }
1203
1204            #[perf]
1205            // https://github.com/zed-industries/zed/issues/44510
1206            pub fn issue_44510_hyperlink_benchmark() {
1207                const LINE: &str = "..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................\
1208..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................\
1209..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................\
1210..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................\
1211..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................\
1212..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................\
1213..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................\
1214..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................\
1215..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................\
1216..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................\
1217..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................\
1218..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................\
1219..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................\
1220..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................\
1221...............................................E.\r\
1222";
1223                thread_local! {
1224                    static TEST_TERM_AND_POINT: (Term<VoidListener>, AlacPoint) =
1225                        build_test_term(&LINE, 5, 50);
1226                }
1227                TEST_TERM_AND_POINT.with(|(term, point)| {
1228                    assert_eq!(
1229                        find_from_grid_point_bench(term, *point)
1230                            .map(|(path, ..)| path)
1231                            .unwrap_or_default(),
1232                        LINE.trim_end_matches(['.', '\r', '\n']),
1233                        "Hyperlink should have been found"
1234                    );
1235                });
1236            }
1237
1238            pub fn find_from_grid_point_bench(
1239                term: &Term<VoidListener>,
1240                point: AlacPoint,
1241            ) -> Option<(String, bool, Match)> {
1242                const PATH_HYPERLINK_TIMEOUT_MS: u64 = 1000;
1243
1244                thread_local! {
1245                    static TEST_REGEX_SEARCHES: RefCell<RegexSearches> =
1246                        RefCell::new({
1247                            let default_settings_content: Rc<SettingsContent> =
1248                                settings::parse_json_with_comments(&settings::default_settings())
1249                                    .unwrap();
1250                            let default_terminal_settings =
1251                                TerminalSettings::from_settings(&default_settings_content);
1252
1253                            RegexSearches::new(
1254                                &default_terminal_settings.path_hyperlink_regexes,
1255                                PATH_HYPERLINK_TIMEOUT_MS
1256                            )
1257                        });
1258                }
1259
1260                TEST_REGEX_SEARCHES.with(|regex_searches| {
1261                    find_from_grid_point(
1262                        &term,
1263                        point,
1264                        &mut regex_searches.borrow_mut(),
1265                        PathStyle::local(),
1266                    )
1267                })
1268            }
1269        }
1270    }
1271
1272    mod file_iri {
1273        // File IRIs have a ton of use cases. Absolute file URIs are supported on all platforms,
1274        // including Windows drive letters (e.g., file:///C:/path) and percent-encoded characters.
1275        // Some cases like relative file IRIs are not supported.
1276        // See https://en.wikipedia.org/wiki/File_URI_scheme
1277
1278        /// [**`cโ‚€, cโ‚, โ€ฆ, cโ‚™;`**]โ‚’โ‚šโ‚œ := use specified terminal widths of `cโ‚€, cโ‚, โ€ฆ, cโ‚™` **columns**
1279        /// (defaults to `3, longest_line_cells / 2, longest_line_cells + 1;`)
1280        ///
1281        macro_rules! test_file_iri {
1282            ($file_iri:literal) => { { test_hyperlink!(concat!("โ€นยซ๐Ÿ‘‰", $file_iri, "ยปโ€บ"); FileIri) } };
1283        }
1284
1285        #[cfg(not(target_os = "windows"))]
1286        #[test]
1287        fn absolute_file_iri() {
1288            test_file_iri!("file:///test/cool/index.rs");
1289            test_file_iri!("file:///test/cool/");
1290        }
1291
1292        mod issues {
1293            #[cfg(not(target_os = "windows"))]
1294            #[test]
1295            fn issue_file_iri_with_percent_encoded_characters() {
1296                // Non-space characters
1297                // file:///test/แฟฌฯŒฮดฮฟฯ‚/
1298                test_file_iri!("file:///test/%E1%BF%AC%CF%8C%CE%B4%CE%BF%CF%82/"); // URI
1299
1300                // Spaces
1301                test_file_iri!("file:///te%20st/co%20ol/index.rs");
1302                test_file_iri!("file:///te%20st/co%20ol/");
1303            }
1304        }
1305
1306        #[cfg(target_os = "windows")]
1307        mod windows {
1308            mod issues {
1309                // The test uses Url::to_file_path(), but it seems that the Url crate doesn't
1310                // support relative file IRIs.
1311                #[test]
1312                #[should_panic(
1313                    expected = r#"Failed to interpret file IRI `file:/test/cool/index.rs` as a path"#
1314                )]
1315                fn issue_relative_file_iri() {
1316                    test_file_iri!("file:/test/cool/index.rs");
1317                    test_file_iri!("file:/test/cool/");
1318                }
1319
1320                // See https://en.wikipedia.org/wiki/File_URI_scheme
1321                // https://github.com/zed-industries/zed/issues/39189
1322                #[test]
1323                fn issue_39189() {
1324                    test_file_iri!("file:///C:/test/cool/index.rs");
1325                    test_file_iri!("file:///C:/test/cool/");
1326                }
1327
1328                #[test]
1329                fn issue_file_iri_with_percent_encoded_characters() {
1330                    // Non-space characters
1331                    // file:///test/แฟฌฯŒฮดฮฟฯ‚/
1332                    test_file_iri!("file:///C:/test/%E1%BF%AC%CF%8C%CE%B4%CE%BF%CF%82/"); // URI
1333
1334                    // Spaces
1335                    test_file_iri!("file:///C:/te%20st/co%20ol/index.rs");
1336                    test_file_iri!("file:///C:/te%20st/co%20ol/");
1337                }
1338            }
1339        }
1340    }
1341
1342    mod iri {
1343        /// [**`cโ‚€, cโ‚, โ€ฆ, cโ‚™;`**]โ‚’โ‚šโ‚œ := use specified terminal widths of `cโ‚€, cโ‚, โ€ฆ, cโ‚™` **columns**
1344        /// (defaults to `3, longest_line_cells / 2, longest_line_cells + 1;`)
1345        ///
1346        macro_rules! test_iri {
1347            ($iri:literal) => { { test_hyperlink!(concat!("โ€นยซ๐Ÿ‘‰", $iri, "ยปโ€บ"); Iri) } };
1348        }
1349
1350        #[test]
1351        fn simple() {
1352            // In the order they appear in URL_REGEX, except 'file://' which is treated as a path
1353            test_iri!("ipfs://test/cool.ipfs");
1354            test_iri!("ipns://test/cool.ipns");
1355            test_iri!("magnet://test/cool.git");
1356            test_iri!("mailto:someone@somewhere.here");
1357            test_iri!("gemini://somewhere.here");
1358            test_iri!("gopher://somewhere.here");
1359            test_iri!("http://test/cool/index.html");
1360            test_iri!("http://10.10.10.10:1111/cool.html");
1361            test_iri!("http://test/cool/index.html?amazing=1");
1362            test_iri!("http://test/cool/index.html#right%20here");
1363            test_iri!("http://test/cool/index.html?amazing=1#right%20here");
1364            test_iri!("https://test/cool/index.html");
1365            test_iri!("https://10.10.10.10:1111/cool.html");
1366            test_iri!("https://test/cool/index.html?amazing=1");
1367            test_iri!("https://test/cool/index.html#right%20here");
1368            test_iri!("https://test/cool/index.html?amazing=1#right%20here");
1369            test_iri!("news://test/cool.news");
1370            test_iri!("git://test/cool.git");
1371            test_iri!("ssh://user@somewhere.over.here:12345/test/cool.git");
1372            test_iri!("ftp://test/cool.ftp");
1373        }
1374
1375        #[test]
1376        fn wide_chars() {
1377            // In the order they appear in URL_REGEX, except 'file://' which is treated as a path
1378            test_iri!("ipfs://ไพ‹๐Ÿƒ๐Ÿฆ€/cool.ipfs");
1379            test_iri!("ipns://ไพ‹๐Ÿƒ๐Ÿฆ€/cool.ipns");
1380            test_iri!("magnet://ไพ‹๐Ÿƒ๐Ÿฆ€/cool.git");
1381            test_iri!("mailto:someone@somewhere.here");
1382            test_iri!("gemini://somewhere.here");
1383            test_iri!("gopher://somewhere.here");
1384            test_iri!("http://ไพ‹๐Ÿƒ๐Ÿฆ€/cool/index.html");
1385            test_iri!("http://10.10.10.10:1111/cool.html");
1386            test_iri!("http://ไพ‹๐Ÿƒ๐Ÿฆ€/cool/index.html?amazing=1");
1387            test_iri!("http://ไพ‹๐Ÿƒ๐Ÿฆ€/cool/index.html#right%20here");
1388            test_iri!("http://ไพ‹๐Ÿƒ๐Ÿฆ€/cool/index.html?amazing=1#right%20here");
1389            test_iri!("https://ไพ‹๐Ÿƒ๐Ÿฆ€/cool/index.html");
1390            test_iri!("https://10.10.10.10:1111/cool.html");
1391            test_iri!("https://ไพ‹๐Ÿƒ๐Ÿฆ€/cool/index.html?amazing=1");
1392            test_iri!("https://ไพ‹๐Ÿƒ๐Ÿฆ€/cool/index.html#right%20here");
1393            test_iri!("https://ไพ‹๐Ÿƒ๐Ÿฆ€/cool/index.html?amazing=1#right%20here");
1394            test_iri!("news://ไพ‹๐Ÿƒ๐Ÿฆ€/cool.news");
1395            test_iri!("git://ไพ‹/cool.git");
1396            test_iri!("ssh://user@somewhere.over.here:12345/ไพ‹๐Ÿƒ๐Ÿฆ€/cool.git");
1397            test_iri!("ftp://ไพ‹๐Ÿƒ๐Ÿฆ€/cool.ftp");
1398        }
1399
1400        // There are likely more tests needed for IRI vs URI
1401        #[test]
1402        fn iris() {
1403            // These refer to the same location, see example here:
1404            // <https://en.wikipedia.org/wiki/Internationalized_Resource_Identifier#Compatibility>
1405            test_iri!("https://en.wiktionary.org/wiki/แฟฌฯŒฮดฮฟฯ‚"); // IRI
1406            test_iri!("https://en.wiktionary.org/wiki/%E1%BF%AC%CF%8C%CE%B4%CE%BF%CF%82"); // URI
1407        }
1408
1409        #[test]
1410        #[should_panic(expected = "Expected a path, but was a iri")]
1411        fn file_is_a_path() {
1412            test_iri!("file://test/cool/index.rs");
1413        }
1414    }
1415
1416    #[derive(Debug, PartialEq)]
1417    enum HyperlinkKind {
1418        FileIri,
1419        Iri,
1420        Path,
1421    }
1422
1423    struct ExpectedHyperlink {
1424        hovered_grid_point: AlacPoint,
1425        hovered_char: char,
1426        hyperlink_kind: HyperlinkKind,
1427        iri_or_path: String,
1428        row: Option<u32>,
1429        column: Option<u32>,
1430        hyperlink_match: RangeInclusive<AlacPoint>,
1431    }
1432
1433    /// Converts to Windows style paths on Windows, like path!(), but at runtime for improved test
1434    /// readability.
1435    fn build_term_from_test_lines<'a>(
1436        hyperlink_kind: HyperlinkKind,
1437        term_size: TermSize,
1438        test_lines: impl Iterator<Item = &'a str>,
1439    ) -> (Term<VoidListener>, ExpectedHyperlink) {
1440        #[derive(Default, Eq, PartialEq)]
1441        enum HoveredState {
1442            #[default]
1443            HoveredScan,
1444            HoveredNextChar,
1445            Done,
1446        }
1447
1448        #[derive(Default, Eq, PartialEq)]
1449        enum MatchState {
1450            #[default]
1451            MatchScan,
1452            MatchNextChar,
1453            Match(AlacPoint),
1454            Done,
1455        }
1456
1457        #[derive(Default, Eq, PartialEq)]
1458        enum CapturesState {
1459            #[default]
1460            PathScan,
1461            PathNextChar,
1462            Path(AlacPoint),
1463            RowScan,
1464            Row(String),
1465            ColumnScan,
1466            Column(String),
1467            Done,
1468        }
1469
1470        fn prev_input_point_from_term(term: &Term<VoidListener>) -> AlacPoint {
1471            let grid = term.grid();
1472            let cursor = &grid.cursor;
1473            let mut point = cursor.point;
1474
1475            if !cursor.input_needs_wrap {
1476                point = point.sub(term, Boundary::Grid, 1);
1477            }
1478
1479            if grid.index(point).flags.contains(Flags::WIDE_CHAR_SPACER) {
1480                point.column -= 1;
1481            }
1482
1483            point
1484        }
1485
1486        fn end_point_from_prev_input_point(
1487            term: &Term<VoidListener>,
1488            prev_input_point: AlacPoint,
1489        ) -> AlacPoint {
1490            if term
1491                .grid()
1492                .index(prev_input_point)
1493                .flags
1494                .contains(Flags::WIDE_CHAR)
1495            {
1496                prev_input_point.add(term, Boundary::Grid, 1)
1497            } else {
1498                prev_input_point
1499            }
1500        }
1501
1502        fn process_input(term: &mut Term<VoidListener>, c: char) {
1503            match c {
1504                '\t' => term.put_tab(1),
1505                c @ _ => term.input(c),
1506            }
1507        }
1508
1509        let mut hovered_grid_point: Option<AlacPoint> = None;
1510        let mut hyperlink_match = AlacPoint::default()..=AlacPoint::default();
1511        let mut iri_or_path = String::default();
1512        let mut row = None;
1513        let mut column = None;
1514        let mut prev_input_point = AlacPoint::default();
1515        let mut hovered_state = HoveredState::default();
1516        let mut match_state = MatchState::default();
1517        let mut captures_state = CapturesState::default();
1518        let mut term = Term::new(Config::default(), &term_size, VoidListener);
1519
1520        for text in test_lines {
1521            let chars: Box<dyn Iterator<Item = char>> =
1522                if cfg!(windows) && hyperlink_kind == HyperlinkKind::Path {
1523                    Box::new(text.chars().map(|c| if c == '/' { '\\' } else { c })) as _
1524                } else {
1525                    Box::new(text.chars()) as _
1526                };
1527            let mut chars = chars.peekable();
1528            while let Some(c) = chars.next() {
1529                match c {
1530                    '๐Ÿ‘‰' => {
1531                        hovered_state = HoveredState::HoveredNextChar;
1532                    }
1533                    '๐Ÿ‘ˆ' => {
1534                        hovered_grid_point = Some(prev_input_point.add(&term, Boundary::Grid, 1));
1535                    }
1536                    'ยซ' | 'ยป' => {
1537                        captures_state = match captures_state {
1538                            CapturesState::PathScan => CapturesState::PathNextChar,
1539                            CapturesState::PathNextChar => {
1540                                panic!("Should have been handled by char input")
1541                            }
1542                            CapturesState::Path(start_point) => {
1543                                iri_or_path = term.bounds_to_string(
1544                                    start_point,
1545                                    end_point_from_prev_input_point(&term, prev_input_point),
1546                                );
1547                                CapturesState::RowScan
1548                            }
1549                            CapturesState::RowScan => CapturesState::Row(String::new()),
1550                            CapturesState::Row(number) => {
1551                                row = Some(number.parse::<u32>().unwrap());
1552                                CapturesState::ColumnScan
1553                            }
1554                            CapturesState::ColumnScan => CapturesState::Column(String::new()),
1555                            CapturesState::Column(number) => {
1556                                column = Some(number.parse::<u32>().unwrap());
1557                                CapturesState::Done
1558                            }
1559                            CapturesState::Done => {
1560                                panic!("Extra 'ยซ', 'ยป'")
1561                            }
1562                        }
1563                    }
1564                    'โ€น' | 'โ€บ' => {
1565                        match_state = match match_state {
1566                            MatchState::MatchScan => MatchState::MatchNextChar,
1567                            MatchState::MatchNextChar => {
1568                                panic!("Should have been handled by char input")
1569                            }
1570                            MatchState::Match(start_point) => {
1571                                hyperlink_match = start_point
1572                                    ..=end_point_from_prev_input_point(&term, prev_input_point);
1573                                MatchState::Done
1574                            }
1575                            MatchState::Done => {
1576                                panic!("Extra 'โ€น', 'โ€บ'")
1577                            }
1578                        }
1579                    }
1580                    _ => {
1581                        if let CapturesState::Row(number) | CapturesState::Column(number) =
1582                            &mut captures_state
1583                        {
1584                            number.push(c)
1585                        }
1586
1587                        let is_windows_abs_path_start = captures_state
1588                            == CapturesState::PathNextChar
1589                            && cfg!(windows)
1590                            && hyperlink_kind == HyperlinkKind::Path
1591                            && c == '\\'
1592                            && chars.peek().is_some_and(|c| *c != '\\');
1593
1594                        if is_windows_abs_path_start {
1595                            // Convert Unix abs path start into Windows abs path start so that the
1596                            // same test can be used for both OSes.
1597                            term.input('C');
1598                            prev_input_point = prev_input_point_from_term(&term);
1599                            term.input(':');
1600                            process_input(&mut term, c);
1601                        } else {
1602                            process_input(&mut term, c);
1603                            prev_input_point = prev_input_point_from_term(&term);
1604                        }
1605
1606                        if hovered_state == HoveredState::HoveredNextChar {
1607                            hovered_grid_point = Some(prev_input_point);
1608                            hovered_state = HoveredState::Done;
1609                        }
1610                        if captures_state == CapturesState::PathNextChar {
1611                            captures_state = CapturesState::Path(prev_input_point);
1612                        }
1613                        if match_state == MatchState::MatchNextChar {
1614                            match_state = MatchState::Match(prev_input_point);
1615                        }
1616                    }
1617                }
1618            }
1619            term.move_down_and_cr(1);
1620        }
1621
1622        if hyperlink_kind == HyperlinkKind::FileIri {
1623            let Ok(url) = Url::parse(&iri_or_path) else {
1624                panic!("Failed to parse file IRI `{iri_or_path}`");
1625            };
1626            let Ok(path) = url.to_file_path() else {
1627                panic!("Failed to interpret file IRI `{iri_or_path}` as a path");
1628            };
1629            iri_or_path = path.to_string_lossy().into_owned();
1630        }
1631
1632        let hovered_grid_point = hovered_grid_point.expect("Missing hovered point (๐Ÿ‘‰ or ๐Ÿ‘ˆ)");
1633        let hovered_char = term.grid().index(hovered_grid_point).c;
1634        (
1635            term,
1636            ExpectedHyperlink {
1637                hovered_grid_point,
1638                hovered_char,
1639                hyperlink_kind,
1640                iri_or_path,
1641                row,
1642                column,
1643                hyperlink_match,
1644            },
1645        )
1646    }
1647
1648    fn line_cells_count(line: &str) -> usize {
1649        // This avoids taking a dependency on the unicode-width crate
1650        fn width(c: char) -> usize {
1651            match c {
1652                // Fullwidth unicode characters used in tests
1653                'ไพ‹' | '๐Ÿƒ' | '๐Ÿฆ€' | '๐Ÿ”ฅ' => 2,
1654                '\t' => 8, // it's really 0-8, use the max always
1655                _ => 1,
1656            }
1657        }
1658        const CONTROL_CHARS: &str = "โ€นยซ๐Ÿ‘‰๐Ÿ‘ˆยปโ€บ";
1659        line.chars()
1660            .filter(|c| !CONTROL_CHARS.contains(*c))
1661            .map(width)
1662            .sum::<usize>()
1663    }
1664
1665    struct CheckHyperlinkMatch<'a> {
1666        term: &'a Term<VoidListener>,
1667        expected_hyperlink: &'a ExpectedHyperlink,
1668        source_location: &'a str,
1669    }
1670
1671    impl<'a> CheckHyperlinkMatch<'a> {
1672        fn new(
1673            term: &'a Term<VoidListener>,
1674            expected_hyperlink: &'a ExpectedHyperlink,
1675            source_location: &'a str,
1676        ) -> Self {
1677            Self {
1678                term,
1679                expected_hyperlink,
1680                source_location,
1681            }
1682        }
1683
1684        fn check_path_with_position_and_match(
1685            &self,
1686            path_with_position: PathWithPosition,
1687            hyperlink_match: &Match,
1688        ) {
1689            let format_path_with_position_and_match =
1690                |path_with_position: &PathWithPosition, hyperlink_match: &Match| {
1691                    let mut result =
1692                        format!("Path = ยซ{}ยป", &path_with_position.path.to_string_lossy());
1693                    if let Some(row) = path_with_position.row {
1694                        result += &format!(", line = {row}");
1695                        if let Some(column) = path_with_position.column {
1696                            result += &format!(", column = {column}");
1697                        }
1698                    }
1699
1700                    result += &format!(
1701                        ", at grid cells {}",
1702                        Self::format_hyperlink_match(hyperlink_match)
1703                    );
1704                    result
1705                };
1706
1707            assert_ne!(
1708                self.expected_hyperlink.hyperlink_kind,
1709                HyperlinkKind::Iri,
1710                "\n    at {}\nExpected a path, but was a iri:\n{}",
1711                self.source_location,
1712                self.format_renderable_content()
1713            );
1714
1715            assert_eq!(
1716                format_path_with_position_and_match(
1717                    &PathWithPosition {
1718                        path: PathBuf::from(self.expected_hyperlink.iri_or_path.clone()),
1719                        row: self.expected_hyperlink.row,
1720                        column: self.expected_hyperlink.column
1721                    },
1722                    &self.expected_hyperlink.hyperlink_match
1723                ),
1724                format_path_with_position_and_match(&path_with_position, hyperlink_match),
1725                "\n    at {}:\n{}",
1726                self.source_location,
1727                self.format_renderable_content()
1728            );
1729        }
1730
1731        fn check_iri_and_match(&self, iri: String, hyperlink_match: &Match) {
1732            let format_iri_and_match = |iri: &String, hyperlink_match: &Match| {
1733                format!(
1734                    "Url = ยซ{iri}ยป, at grid cells {}",
1735                    Self::format_hyperlink_match(hyperlink_match)
1736                )
1737            };
1738
1739            assert_eq!(
1740                self.expected_hyperlink.hyperlink_kind,
1741                HyperlinkKind::Iri,
1742                "\n    at {}\nExpected a iri, but was a path:\n{}",
1743                self.source_location,
1744                self.format_renderable_content()
1745            );
1746
1747            assert_eq!(
1748                format_iri_and_match(
1749                    &self.expected_hyperlink.iri_or_path,
1750                    &self.expected_hyperlink.hyperlink_match
1751                ),
1752                format_iri_and_match(&iri, hyperlink_match),
1753                "\n    at {}:\n{}",
1754                self.source_location,
1755                self.format_renderable_content()
1756            );
1757        }
1758
1759        fn format_hyperlink_match(hyperlink_match: &Match) -> String {
1760            format!(
1761                "({}, {})..=({}, {})",
1762                hyperlink_match.start().line.0,
1763                hyperlink_match.start().column.0,
1764                hyperlink_match.end().line.0,
1765                hyperlink_match.end().column.0
1766            )
1767        }
1768
1769        fn format_renderable_content(&self) -> String {
1770            let mut result = format!("\nHovered on '{}'\n", self.expected_hyperlink.hovered_char);
1771
1772            let mut first_header_row = String::new();
1773            let mut second_header_row = String::new();
1774            let mut marker_header_row = String::new();
1775            for index in 0..self.term.columns() {
1776                let remainder = index % 10;
1777                if index > 0 && remainder == 0 {
1778                    first_header_row.push_str(&format!("{:>10}", (index / 10)));
1779                }
1780                second_header_row += &remainder.to_string();
1781                if index == self.expected_hyperlink.hovered_grid_point.column.0 {
1782                    marker_header_row.push('โ†“');
1783                } else {
1784                    marker_header_row.push(' ');
1785                }
1786            }
1787
1788            let remainder = (self.term.columns() - 1) % 10;
1789            if remainder != 0 {
1790                first_header_row.push_str(&" ".repeat(remainder));
1791            }
1792
1793            result += &format!("\n      [ {}]\n", first_header_row);
1794            result += &format!("      [{}]\n", second_header_row);
1795            result += &format!("       {}", marker_header_row);
1796
1797            for cell in self
1798                .term
1799                .renderable_content()
1800                .display_iter
1801                .filter(|cell| !cell.flags.intersects(WIDE_CHAR_SPACERS))
1802            {
1803                if cell.point.column.0 == 0 {
1804                    let prefix =
1805                        if cell.point.line == self.expected_hyperlink.hovered_grid_point.line {
1806                            'โ†’'
1807                        } else {
1808                            ' '
1809                        };
1810                    result += &format!("\n{prefix}[{:>3}] ", cell.point.line.to_string());
1811                }
1812
1813                match cell.c {
1814                    '\t' => result.push(' '),
1815                    c @ _ => result.push(c),
1816                }
1817            }
1818
1819            result
1820        }
1821    }
1822
1823    fn test_hyperlink<'a>(
1824        columns: usize,
1825        total_cells: usize,
1826        test_lines: impl Iterator<Item = &'a str>,
1827        hyperlink_kind: HyperlinkKind,
1828        source_location: &str,
1829    ) {
1830        const CARGO_DIR_REGEX: &str =
1831            r#"\s+(Compiling|Checking|Documenting) [^(]+\((?<link>(?<path>.+))\)"#;
1832        const RUST_DIAGNOSTIC_REGEX: &str = r#"\s+(-->|:::|at) (?<link>(?<path>.+?))(:$|$)"#;
1833        const ISSUE_12338_REGEX: &str =
1834            r#"[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2} (?<link>(?<path>.+))"#;
1835        const MULTIPLE_SAME_LINE_REGEX: &str =
1836            r#"(?<link>(?<path>๐Ÿฆ€ multiple_same_line ๐Ÿฆ€) ๐Ÿšฃ(?<line>[0-9]+) ๐Ÿ›(?<column>[0-9]+)):"#;
1837        const PATH_HYPERLINK_TIMEOUT_MS: u64 = 1000;
1838
1839        thread_local! {
1840            static TEST_REGEX_SEARCHES: RefCell<RegexSearches> =
1841                RefCell::new({
1842                    let default_settings_content: Rc<SettingsContent> =
1843                        settings::parse_json_with_comments(&settings::default_settings()).unwrap();
1844                    let default_terminal_settings = TerminalSettings::from_settings(&default_settings_content);
1845
1846                    RegexSearches::new([
1847                        RUST_DIAGNOSTIC_REGEX,
1848                        CARGO_DIR_REGEX,
1849                        ISSUE_12338_REGEX,
1850                        MULTIPLE_SAME_LINE_REGEX,
1851                    ]
1852                        .into_iter()
1853                        .chain(default_terminal_settings.path_hyperlink_regexes
1854                            .iter()
1855                            .map(AsRef::as_ref)),
1856                    PATH_HYPERLINK_TIMEOUT_MS)
1857                });
1858        }
1859
1860        let term_size = TermSize::new(columns, total_cells / columns + 2);
1861        let (term, expected_hyperlink) =
1862            build_term_from_test_lines(hyperlink_kind, term_size, test_lines);
1863        let hyperlink_found = TEST_REGEX_SEARCHES.with(|regex_searches| {
1864            find_from_grid_point(
1865                &term,
1866                expected_hyperlink.hovered_grid_point,
1867                &mut regex_searches.borrow_mut(),
1868                PathStyle::local(),
1869            )
1870        });
1871        let check_hyperlink_match =
1872            CheckHyperlinkMatch::new(&term, &expected_hyperlink, source_location);
1873        match hyperlink_found {
1874            Some((hyperlink_word, false, hyperlink_match)) => {
1875                check_hyperlink_match.check_path_with_position_and_match(
1876                    PathWithPosition::parse_str(&hyperlink_word),
1877                    &hyperlink_match,
1878                );
1879            }
1880            Some((hyperlink_word, true, hyperlink_match)) => {
1881                check_hyperlink_match.check_iri_and_match(hyperlink_word, &hyperlink_match);
1882            }
1883            None => {
1884                if expected_hyperlink.hyperlink_match.start()
1885                    != expected_hyperlink.hyperlink_match.end()
1886                {
1887                    assert!(
1888                        false,
1889                        "No hyperlink found\n     at {source_location}:\n{}",
1890                        check_hyperlink_match.format_renderable_content()
1891                    )
1892                }
1893            }
1894        }
1895    }
1896}