Skip to content

Commit

Permalink
Address emojis not visible even in unicode-supported terminal #46 and…
Browse files Browse the repository at this point in the history
… expose sixel support test function
  • Loading branch information
ShaunLawrie committed Nov 19, 2024
1 parent 1deea2c commit 0ada503
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 13 deletions.
3 changes: 2 additions & 1 deletion PwshSpectreConsole/PwshSpectreConsole.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @()
Expand Down
21 changes: 20 additions & 1 deletion PwshSpectreConsole/PwshSpectreConsole.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,23 @@ foreach ($directory in @('private', 'public')) {
Get-ChildItem -Path "$PSScriptRoot\$directory\*.ps1" -Recurse | ForEach-Object {
. $_.FullName
}
}
}

$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
Binary file not shown.
Binary file not shown.
10 changes: 0 additions & 10 deletions PwshSpectreConsole/private/Test-SixelCapabilities.ps1

This file was deleted.

20 changes: 20 additions & 0 deletions PwshSpectreConsole/public/config/Test-SpectreSixelSupport.ps1
Original file line number Diff line number Diff line change
@@ -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;")
}
2 changes: 1 addition & 1 deletion PwshSpectreConsole/public/images/Get-SpectreSixelImage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0ada503

Please sign in to comment.