1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2024-11-30 09:06:56 +02:00

Disable terminal links in VS-Code

This commit is contained in:
mo8it 2024-08-26 02:41:22 +02:00
parent 594e212b8a
commit ee25a7d458

View File

@ -1,5 +1,6 @@
use std::{ use std::{
fmt, fs, cell::Cell,
env, fmt, fs,
io::{self, BufRead, StdoutLock, Write}, io::{self, BufRead, StdoutLock, Write},
}; };
@ -10,6 +11,10 @@ use crossterm::{
Command, QueueableCommand, 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. /// Terminal progress bar to be used when not using Ratataui.
pub fn progress_bar( pub fn progress_bar(
stdout: &mut StdoutLock, 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<()> { 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 canonical_path = fs::canonicalize(path).ok();
let Some(canonical_path) = canonical_path.as_deref().and_then(|p| p.to_str()) else { let Some(canonical_path) = canonical_path.as_deref().and_then(|p| p.to_str()) else {