Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions crates/libs/rdl/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,34 @@ impl std::fmt::Display for Error {
f,
"\nerror: {}\n --> {}:{}:{}",
&self.message,
&self.file_name,
hyperlink_path(&self.file_name),
self.line,
self.column + 1
)
} else if self.file_name.is_empty() {
write!(f, "\nerror: {}", &self.message)
} else {
write!(f, "\nerror: {}\n --> {}", &self.message, &self.file_name)
write!(
f,
"\nerror: {}\n --> {}",
&self.message,
hyperlink_path(&self.file_name)
)
}
}
}

/// Wraps `path` in an OSC 8 hyperlink escape sequence when stderr is an
/// interactive terminal, making the path clickable in supporting terminals.
/// Falls back to returning the path unchanged for non-TTY output so that
/// redirected output (log files, CI runners, etc.) is not polluted with
/// escape codes.
fn hyperlink_path(path: &str) -> String {
use std::io::IsTerminal as _;
if path.is_empty() || !std::io::stderr().is_terminal() {
return path.to_string();
}
// OSC 8 format: ESC ] 8 ; params ; uri ST link-text ESC ] 8 ; ; ST
// where ST (String Terminator) is ESC \.
format!("\x1b]8;;{path}\x1b\\{path}\x1b]8;;\x1b\\")
}
Loading