Skip to content

Commit

Permalink
Fixes #56
Browse files Browse the repository at this point in the history
Previously fixed in this branch:
 - #54
 - #46
  • Loading branch information
ShaunLawrie committed Jan 4, 2025
1 parent 3608f66 commit bdcf584
Show file tree
Hide file tree
Showing 14 changed files with 267 additions and 329 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 9 additions & 1 deletion PwshSpectreConsole.Docs/src/powershell/Helpers.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ sidebar:
variant: caution
"@

$script:DangerTag = @"
sidebar:
badge:
text: Deprecated
variant: danger
"@

<#
.SYNOPSIS
Returns the yaml to inject for a specific tag.
Expand All @@ -66,13 +73,14 @@ sidebar:
#>
function Get-Tag {
param (
[ValidateSet("New", "Updated", "Experimental")]
[ValidateSet("New", "Updated", "Experimental", "Danger")]
[string] $Tag
)
switch ($Tag) {
"New" { return $script:NewTag }
"Updated" { return $script:UpdatedTag }
"Experimental" { return $script:ExperimentalTag }
"Deprecated" { return $script:DangerTag }
}
}

Expand Down
29 changes: 7 additions & 22 deletions PwshSpectreConsole.Docs/src/powershell/UpdateDocs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,10 @@ Import-Module "$PSScriptRoot\Helpers.psm1" -Force
Import-Module "$PSScriptRoot\Mocks.psm1" -Force

# Ignore update tags for these, remove them from the list if they are updated this just makes it easy to bypass the "updated" tag
$ignoreUpdatesFor = @(
"Format-SpectreBarChart",
"Format-SpectreBreakdownChart",
"Format-SpectrePanel",
"Format-SpectreTable",
"Get-SpectreDemoEmoji",
"Start-SpectreDemo",
"New-SpectreChartItem",
"Get-SpectreImage",
"Get-SpectreImageExperimental",
"Add-SpectreJob",
"Invoke-SpectreCommandWithProgress",
"Invoke-SpectreCommandWithStatus",
"Invoke-SpectreScriptBlockQuietly",
"Wait-SpectreJobs",
"Read-SpectrePause",
"Get-SpectreEscapedText",
"Set-SpectreColors",
"Start-SpectreRecording",
"Stop-SpectreRecording"
)
$ignoreUpdatesFor = @()

# Mark these as deprecated
$deprecated = @("Get-SpectreImageExperimental")

# Git user details for github action commits
$env:GIT_COMMITTER_NAME = 'Shaun Lawrie (via GitHub Actions)'
Expand Down Expand Up @@ -114,7 +97,9 @@ foreach ($doc in $docs) {

# Work out the tag to apply to the current help file
$tag = $null
if([string]::IsNullOrEmpty($created) -or ((Get-Date) - ([datetime]$created)).TotalDays -lt $recentThresholdDays) {
if ($deprecated -contains $commandName) {
$tag = "Deprecated"
} elseif([string]::IsNullOrEmpty($created) -or ((Get-Date) - ([datetime]$created)).TotalDays -lt $recentThresholdDays) {
$tag = "New"
} elseif ((((Get-Date) - ([datetime]$modified)).TotalDays -lt $recentThresholdDays) -and $ignoreUpdatesFor -notcontains $commandName) {
$tag = "Updated"
Expand Down
3 changes: 1 addition & 2 deletions PwshSpectreConsole/PwshSpectreConsole.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ FunctionsToExport = 'Add-SpectreJob', 'Format-SpectreBarChart',
'Format-SpectreAligned', 'Out-SpectreHost', 'Add-SpectreTableRow',
'Invoke-SpectreLive', 'Format-SpectreException',
'Get-SpectreDemoFeatures', 'Get-SpectreRenderableSize',
'Get-SpectreSixelImage', 'Read-SpectreSelectionGrouped',
'Test-SpectreSixelSupport'
'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
4 changes: 4 additions & 0 deletions PwshSpectreConsole/PwshSpectreConsole.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ if ($script:SpectreProfile.Unicode -eq $true -or $env:IgnoreSpectreConsoleEncodi
return $script:SpectreConsole
}

if ($env:IgnoreSpectreEncoding -eq $true) {
return
}

@"
[white]Your terminal host is currently using encoding '$($SpectreProfile.Encoding)' which limits Spectre Console functionality.
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Test-SpectreSixelSupport {
Write-SpectreHost "Sixel graphics are not supported :("
}
#>
[Reflection.AssemblyMetadata("title", "Set-SpectreColors")]
[Reflection.AssemblyMetadata("title", "Test-SpectreSixelSupport")]
param ()
$response = Get-ControlSequenceResponse -ControlSequence "[c"
return $response.Contains(";4;")
Expand Down
25 changes: 21 additions & 4 deletions PwshSpectreConsole/public/images/Get-SpectreImage.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
$script:CachedImages = @{}

function Get-SpectreImage {
<#
.SYNOPSIS
Displays an image in the console using CanvasImage.
Displays an image in the console using CanvasImage or SixelImage if the terminal supports Sixel.
.DESCRIPTION
Displays an image in the console using CanvasImage. The image can be resized to a maximum width if desired.
Displays an image in the console using CanvasImage or SixelImage if the terminal supports Sixel.
The image can be resized to a maximum width if desired.
See https://www.arewesixelyet.com/ for Sixel support status for your terminal.
For SixelImage, the image will be displayed in the terminal using Sixel graphics which has a much higher resolution than CanvasImage.
![Spectre Sixel Example](/sixel.png)
.PARAMETER ImagePath
The path to the image file to be displayed.
The path to the image file to be displayed, as a local path or remote path using http/https.
.PARAMETER MaxWidth
The maximum width of the image. If not specified, the image will be displayed at its original size.
Expand All @@ -23,12 +29,23 @@ function Get-SpectreImage {
[string] $ImagePath,
[int] $MaxWidth
)

if ($ImagePath.StartsWith("http://") -or $ImagePath.StartsWith("https://")) {
if (!$script:CachedImages.ContainsKey($ImagePath) -or -not (Test-Path $script:CachedImages[$ImagePath])) {
$tempFile = New-TemporaryFile
Invoke-WebRequest -Uri $ImagePath -UseBasicParsing -Outfile $tempFile -ProgressAction SilentlyContinue
$script:CachedImages[$ImagePath] = $tempFile.FullName
}
$ImagePath = $script:CachedImages[$ImagePath]
}

$imagePathResolved = Resolve-Path $ImagePath
if (-not (Test-Path $imagePathResolved)) {
throw "The specified image path '$resolvedImagePath' does not exist."
}

$image = [Spectre.Console.CanvasImage]::new($imagePathResolved)
$image = (Test-SpectreSixelSupport) ? [Spectre.Console.SixelImage]::new($imagePathResolved) : [Spectre.Console.CanvasImage]::new($imagePathResolved)

if ($MaxWidth) {
$image.MaxWidth = $MaxWidth
}
Expand Down
Loading

0 comments on commit bdcf584

Please sign in to comment.