diff options
| author | mo8it <mo8it@proton.me> | 2025-08-21 22:43:46 +0200 |
|---|---|---|
| committer | mo8it <mo8it@proton.me> | 2025-08-21 23:15:48 +0200 |
| commit | 2d1d531550afaac36dbf4d15c383bc0e1cbf248d (patch) | |
| tree | 67f030f84414a463e2e7958b1267baa3a14487e6 /src/term.rs | |
| parent | a712e484d09ce27a622da5e61d26bbb1004f51d2 (diff) | |
Fix file links in VS Code
Diffstat (limited to 'src/term.rs')
| -rw-r--r-- | src/term.rs | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/term.rs b/src/term.rs index b7dcd9f..3d149b3 100644 --- a/src/term.rs +++ b/src/term.rs @@ -272,22 +272,18 @@ pub fn canonicalize(path: &str) -> Option<String> { }) } -pub fn terminal_file_link<'a>( - writer: &mut impl CountedWrite<'a>, - path: &str, - canonical_path: &str, +pub fn file_path<'a, W: CountedWrite<'a>>( + writer: &mut W, color: Color, + f: impl FnOnce(&mut W) -> io::Result<()>, ) -> io::Result<()> { writer .stdout() .queue(SetForegroundColor(color))? .queue(SetAttribute(Attribute::Underlined))?; - writer.stdout().write_all(b"\x1b]8;;file://")?; - writer.stdout().write_all(canonical_path.as_bytes())?; - writer.stdout().write_all(b"\x1b\\")?; - // Only this part is visible. - writer.write_str(path)?; - writer.stdout().write_all(b"\x1b]8;;\x1b\\")?; + + f(writer)?; + writer .stdout() .queue(SetForegroundColor(Color::Reset))? @@ -296,6 +292,19 @@ pub fn terminal_file_link<'a>( Ok(()) } +pub fn terminal_file_link<'a>( + writer: &mut impl CountedWrite<'a>, + path: &str, + canonical_path: &str, +) -> io::Result<()> { + writer.stdout().write_all(b"\x1b]8;;file://")?; + writer.stdout().write_all(canonical_path.as_bytes())?; + writer.stdout().write_all(b"\x1b\\")?; + // Only this part is visible. + writer.write_str(path)?; + writer.stdout().write_all(b"\x1b]8;;\x1b\\") +} + pub fn write_ansi(output: &mut Vec<u8>, command: impl Command) { struct FmtWriter<'a>(&'a mut Vec<u8>); |
