diff --git a/src/term.rs b/src/term.rs index 7b8642b9..6efe4d51 100644 --- a/src/term.rs +++ b/src/term.rs @@ -1,5 +1,6 @@ use std::{ - fmt, fs, + cell::Cell, + env, fmt, fs, io::{self, BufRead, StdoutLock, Write}, }; @@ -10,6 +11,10 @@ use crossterm::{ Command, QueueableCommand, }; +thread_local! { + static VS_CODE: Cell = Cell::new(env::var_os("TERM").is_some_and(|v| v == "vscode")); +} + /// Terminal progress bar to be used when not using Ratataui. pub fn progress_bar( stdout: &mut StdoutLock, @@ -73,6 +78,11 @@ pub fn press_enter_prompt(stdout: &mut StdoutLock) -> io::Result<()> { } pub fn terminal_file_link(stdout: &mut StdoutLock, path: &str, color: Color) -> io::Result<()> { + // VS Code shows its own links. This also avoids some issues, especially on Windows. + if VS_CODE.get() { + return stdout.write_all(path.as_bytes()); + } + let canonical_path = fs::canonicalize(path).ok(); let Some(canonical_path) = canonical_path.as_deref().and_then(|p| p.to_str()) else {