diff --git a/PwshSpectreConsole/PwshSpectreConsole.psd1 b/PwshSpectreConsole/PwshSpectreConsole.psd1 index 136d0e4..ae363e9 100644 --- a/PwshSpectreConsole/PwshSpectreConsole.psd1 +++ b/PwshSpectreConsole/PwshSpectreConsole.psd1 @@ -92,7 +92,8 @@ FunctionsToExport = 'Add-SpectreJob', 'Format-SpectreBarChart', 'Format-SpectreAligned', 'Out-SpectreHost', 'Add-SpectreTableRow', 'Invoke-SpectreLive', 'Format-SpectreException', 'Get-SpectreDemoFeatures', 'Get-SpectreRenderableSize', - 'Get-SpectreSixelImage', 'Read-SpectreSelectionGrouped' + 'Get-SpectreSixelImage', 'Read-SpectreSelectionGrouped', + 'Test-SpectreSixelSupport' # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = @() diff --git a/PwshSpectreConsole/PwshSpectreConsole.psm1 b/PwshSpectreConsole/PwshSpectreConsole.psm1 index c756664..0429fe8 100644 --- a/PwshSpectreConsole/PwshSpectreConsole.psm1 +++ b/PwshSpectreConsole/PwshSpectreConsole.psm1 @@ -21,4 +21,23 @@ foreach ($directory in @('private', 'public')) { Get-ChildItem -Path "$PSScriptRoot\$directory\*.ps1" -Recurse | ForEach-Object { . $_.FullName } -} \ No newline at end of file +} + +$script:SpectreProfile = Get-SpectreProfile +if ($script:SpectreProfile.Unicode -eq $true -or $env:IgnoreSpectreConsoleEncoding) { + return $script:SpectreConsole +} + +@" +[white]Your terminal host is currently using encoding '$($SpectreProfile.Encoding)' which limits Spectre Console functionality. + +To enable UTF-8 output in your terminal, add the following line at the top of your PowerShell `$PROFILE file and restart the terminal: +[Orange1 on Grey15]$('$OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = [System.Text.UTF8Encoding]::new()' | Get-SpectreEscapedText)[/] + +If you don't want to enable UTF-8, you can suppress this warning with the environment variable [Orange1 on Grey15]`$env:IgnoreSpectreEncoding = `$true[/] instead. + +For more details see: + - https://github.com/ShaunLawrie/PwshSpectreConsole/issues/46 + - https://spectreconsole.net/best-practices#configuring-the-windows-terminal-for-unicode-and-emoji-support + - https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles[/] +"@ | Format-SpectrePanel -Title "[Orange1] PwshSpectreConsole Warning [/]" -Color OrangeRed1 -Expand | Out-Host \ No newline at end of file diff --git a/PwshSpectreConsole/overrides/Spectre.Console.ImageSharp/lib/net6.0/Spectre.Console.ImageSharp.dll b/PwshSpectreConsole/overrides/Spectre.Console.ImageSharp/lib/net6.0/Spectre.Console.ImageSharp.dll index 45cd1f5..1a0b3ae 100644 Binary files a/PwshSpectreConsole/overrides/Spectre.Console.ImageSharp/lib/net6.0/Spectre.Console.ImageSharp.dll and b/PwshSpectreConsole/overrides/Spectre.Console.ImageSharp/lib/net6.0/Spectre.Console.ImageSharp.dll differ diff --git a/PwshSpectreConsole/overrides/Spectre.Console/lib/net6.0/Spectre.Console.dll b/PwshSpectreConsole/overrides/Spectre.Console/lib/net6.0/Spectre.Console.dll index 40cf655..d4fd963 100644 Binary files a/PwshSpectreConsole/overrides/Spectre.Console/lib/net6.0/Spectre.Console.dll and b/PwshSpectreConsole/overrides/Spectre.Console/lib/net6.0/Spectre.Console.dll differ diff --git a/PwshSpectreConsole/private/Test-SixelCapabilities.ps1 b/PwshSpectreConsole/private/Test-SixelCapabilities.ps1 deleted file mode 100644 index 66256f6..0000000 --- a/PwshSpectreConsole/private/Test-SixelCapabilities.ps1 +++ /dev/null @@ -1,10 +0,0 @@ -<# -.SYNOPSIS - Tests if the terminal supports Sixel graphics. -.DESCRIPTION - Tests if the terminal supports Sixel graphics. -#> -function Test-SixelCapabilities { - $response = Get-ControlSequenceResponse -ControlSequence "[c" - return $response.Contains(";4;") -} \ No newline at end of file diff --git a/PwshSpectreConsole/public/config/Test-SpectreSixelSupport.ps1 b/PwshSpectreConsole/public/config/Test-SpectreSixelSupport.ps1 new file mode 100644 index 0000000..5b06514 --- /dev/null +++ b/PwshSpectreConsole/public/config/Test-SpectreSixelSupport.ps1 @@ -0,0 +1,20 @@ +function Test-SpectreSixelSupport { + <# + .SYNOPSIS + Tests if the terminal supports Sixel graphics. + .DESCRIPTION + Tests if the terminal supports Sixel graphics. Sixel allows the terminal to display images. + Windows Terminal Preview and other terminals support sixel, see https://www.arewesixelyet.com/ for more. + Returns $true if the terminal supports Sixel graphics, otherwise $false. + .EXAMPLE + if (Test-SpectreSixelSupport) { + Write-SpectreHost "Sixel graphics are supported :)" + } else { + Write-SpectreHost "Sixel graphics are not supported :(" + } + #> + [Reflection.AssemblyMetadata("title", "Set-SpectreColors")] + param () + $response = Get-ControlSequenceResponse -ControlSequence "[c" + return $response.Contains(";4;") +} \ No newline at end of file diff --git a/PwshSpectreConsole/public/images/Get-SpectreSixelImage.ps1 b/PwshSpectreConsole/public/images/Get-SpectreSixelImage.ps1 index bc76186..e719718 100644 --- a/PwshSpectreConsole/public/images/Get-SpectreSixelImage.ps1 +++ b/PwshSpectreConsole/public/images/Get-SpectreSixelImage.ps1 @@ -28,7 +28,7 @@ function Get-SpectreSixelImage { [int] $MaxWidth = (Get-HostWidth) ) - if (!(Test-SixelCapabilities)) { + if (!(Test-SpectreSixelSupport)) { # check if it's windows terminal or not if ($env:WT_SESSION) { Write-SpectreHost "[yellow]WARNING: Sixel graphics are only supported in Windows Terminal Preview[/]" -PassThru