From ee25a7d45805def5cb6516dec6c9edf54fad5e48 Mon Sep 17 00:00:00 2001 From: mo8it Date: Mon, 26 Aug 2024 02:41:22 +0200 Subject: [PATCH] Disable terminal links in VS-Code --- src/term.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 {