par_term/url_detection/state.rs
1//! URL detection state types.
2//!
3//! Defines the core data types for representing detected URLs and file paths,
4//! along with helper functions for querying detection state.
5
6/// Type of detected clickable item
7#[derive(Debug, Clone, PartialEq)]
8pub enum DetectedItemType {
9 /// A URL (http, https, etc.)
10 Url,
11 /// A file path (optionally with line number)
12 FilePath {
13 /// Line number if specified (e.g., file.rs:42)
14 line: Option<usize>,
15 /// Column number if specified (e.g., file.rs:42:10)
16 column: Option<usize>,
17 },
18}
19
20/// Detected URL or file path with position information
21#[derive(Debug, Clone, PartialEq)]
22pub struct DetectedUrl {
23 /// The URL or file path text
24 pub url: String,
25 /// Start column position
26 pub start_col: usize,
27 /// End column position (exclusive)
28 pub end_col: usize,
29 /// Row position
30 pub row: usize,
31 /// OSC 8 hyperlink ID (if this is an OSC 8 hyperlink, None for regex-detected items)
32 pub hyperlink_id: Option<u32>,
33 /// Type of detected item (URL or FilePath)
34 pub item_type: DetectedItemType,
35}
36
37/// Check if a specific position is within a URL or file path
38pub fn find_url_at_position(urls: &[DetectedUrl], col: usize, row: usize) -> Option<&DetectedUrl> {
39 urls.iter()
40 .find(|url| url.row == row && col >= url.start_col && col < url.end_col)
41}