summaryrefslogtreecommitdiff
path: root/src/term.rs
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-08-26 02:41:22 +0200
committermo8it <mo8it@proton.me>2024-08-26 02:41:22 +0200
commitee25a7d45805def5cb6516dec6c9edf54fad5e48 (patch)
treef5fb66d2747b1116eb85e063a521d7ad6e5188b8 /src/term.rs
parent594e212b8a49cae001c0a45818debaceeda3b9a3 (diff)
Disable terminal links in VS-Code
Diffstat (limited to 'src/term.rs')
-rw-r--r--src/term.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/term.rs b/src/term.rs
index 7b8642b..6efe4d5 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<bool> = 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 {