Last active
November 22, 2024 17:33
-
-
Save JustinGrote/50a43909f87710a97865141ec7f06544 to your computer and use it in GitHub Desktop.
Powershell Function to create ANSI HyperLinks (Usable in Windows Terminal Preview)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Write-AnsiHyperlink { | |
<# | |
.SYNOPSIS | |
Creates an ANSI Hyperlink in a supported terminal such as Windows Terminal 1.4 | |
#> | |
[CmdletBinding()] | |
param( | |
#The Uri that you wish to have as part of the hyperlink | |
[Parameter(Mandatory,ValueFromPipeline)][UriBuilder]$Uri, | |
#The label text that will actually be shown in Windows Terminal | |
[ValidateNotNullOrEmpty()][String]$Label = $Uri.uri | |
) | |
if ($PSVersionTable.PSVersion -lt '6.0.0') { | |
$e = [char]27 | |
} else { | |
$e = "`e" | |
} | |
"${e}]8;;{0}${e}`\{1}${e}]8;;${e}`\" -f $Uri.uri,$Label | |
} |
@Jaykul I could just do the old character but it was a proof of concept and also to let people know that `e is the new escape char :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why bother with the PSVersion check?