summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-05-13 04:11:11 +0200
committermo8it <mo8it@proton.me>2024-05-13 04:11:11 +0200
commitf6cf6c611c8b79131e1b6eac3ece7987ba1eaaf5 (patch)
tree47fa4642542b4a18ea098cd137a64a66981396b4
parent7a74a72dc8a7bd906e7733731b427a1cdeee103a (diff)
Fix Windows terminal links
-rw-r--r--README.md4
-rw-r--r--src/terminal_link.rs21
2 files changed, 14 insertions, 11 deletions
diff --git a/README.md b/README.md
index c1ce95c..e6ea8de 100644
--- a/README.md
+++ b/README.md
@@ -35,7 +35,7 @@ The following command will download and compile Rustlings:
<!-- TODO: Remove @6.0.0-beta.x -->
```bash
-cargo install rustlings@6.0.0-beta.7
+cargo install rustlings@6.0.0-beta.8
```
<details>
@@ -44,7 +44,7 @@ cargo install rustlings@6.0.0-beta.7
<!-- TODO: Remove @6.0.0-beta.x -->
- Make sure you have the latest Rust version by running `rustup update`
-- Try adding the `--locked` flag: `cargo install rustlings@6.0.0-beta.7 --locked`
+- Try adding the `--locked` flag: `cargo install rustlings@6.0.0-beta.8 --locked`
- Otherwise, please [report the issue](https://github.com/rust-lang/rustlings/issues/new)
</details>
diff --git a/src/terminal_link.rs b/src/terminal_link.rs
index c9e6bce..9bea07d 100644
--- a/src/terminal_link.rs
+++ b/src/terminal_link.rs
@@ -7,15 +7,18 @@ pub struct TerminalFileLink<'a>(pub &'a str);
impl<'a> Display for TerminalFileLink<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
- if let Ok(Some(canonical_path)) = fs::canonicalize(self.0)
- .as_deref()
- .map(|path| path.to_str())
- {
- write!(
- f,
- "\x1b]8;;file://{}\x1b\\{}\x1b]8;;\x1b\\",
- canonical_path, self.0,
- )
+ let path = fs::canonicalize(self.0);
+
+ if let Some(path) = path.as_deref().ok().and_then(|path| path.to_str()) {
+ // Windows itself can't handle its verbatim paths.
+ #[cfg(windows)]
+ let path = if path.len() > 5 && &path[0..4] == r"\\?\" {
+ &path[4..]
+ } else {
+ path
+ };
+
+ write!(f, "\x1b]8;;file://{path}\x1b\\{}\x1b]8;;\x1b\\", self.0)
} else {
write!(f, "{}", self.0)
}