ai_agent/utils/hyperlink.rs
1// Source: /data/home/swei/claudecode/openclaudecode/src/utils/hyperlink.ts
2//! Hyperlink utilities
3//!
4//! Create clickable hyperlinks using OSC 8 escape sequences.
5
6/// OSC 8 hyperlink escape sequence start
7pub const OSC8_START: &str = "\x1b]8;;";
8/// OSC 8 hyperlink escape sequence end (using BEL as terminator)
9pub const OSC8_END: &str = "\x07";
10
11/// Create a clickable hyperlink using OSC 8 escape sequences.
12/// Falls back to plain text if the terminal doesn't support hyperlinks.
13///
14/// # Arguments
15/// * `url` - The URL to link to
16/// * `content` - Optional content to display as the link text
17/// * `supports_hyperlinks` - Optional override for testing
18///
19/// # Returns
20/// The hyperlink string or plain URL if hyperlinks not supported
21pub fn create_hyperlink(
22 url: &str,
23 content: Option<&str>,
24 supports_hyperlinks: Option<bool>,
25) -> String {
26 // For now, just return the URL without hyperlinks (simpler implementation)
27 // In production, you'd check terminal capabilities via terminfo or environment
28 let _ = supports_hyperlinks;
29
30 let display_text = content.unwrap_or(url);
31
32 // Apply basic ANSI blue color using ANSI escape codes
33 let colored_text = format!("\x1b[34m{}\x1b[0m", display_text);
34
35 // Simple version without OSC 8 to avoid compatibility issues
36 colored_text
37}