diff --git a/.earthlyignore b/.earthlyignore index fb70c40..c772d93 100644 --- a/.earthlyignore +++ b/.earthlyignore @@ -1,5 +1,6 @@ # ignore output (because we put stuff there) /output/* +/Modules/* assemblies/ # ignore binary output files and folders bin/ diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 710be69..3b02c89 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -26,7 +26,7 @@ jobs: - name: earthly +push if: github.ref == 'refs/heads/main' - run: earthly --push --secret NUGET_API_KEY= --secret PSGALLERY_API_KEY --strict +all + run: earthly --push --secret NUGET_API_KEY --secret PSGALLERY_API_KEY --strict +all env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} diff --git a/Earthfile b/Earthfile index 838bf38..be64206 100644 --- a/Earthfile +++ b/Earthfile @@ -13,8 +13,7 @@ ARG --global TEMP_ROOT=/temp # These are my common build args, used in my shared /Tasks repo ARG --global MODULE_NAME=Pansies ARG --global CONFIGURATION=Release -# ARG --global PSMODULE_PUBLISH_KEY -# ARG --global NUGET_API_KEY + worker: # Dotnet tools and scripts installed by PSGet diff --git a/Source/Pansies.psd1 b/Source/Pansies.psd1 index 1eb281b..c043657 100644 --- a/Source/Pansies.psd1 +++ b/Source/Pansies.psd1 @@ -49,7 +49,7 @@ FunctionsToExport = @() CmdletsToExport = @('New-Text', 'New-Hyperlink', 'Write-Host', 'Get-Gradient', 'Get-Complement', 'Get-ColorWheel') # Variables to export from this module -# VariablesToExport = '*' +VariablesToExport = 'RgbColorCompleter' # Aliases 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 aliases to export. AliasesToExport = 'Text', 'Url' @@ -137,5 +137,6 @@ PrivateData = @{ # Minimum version of the Windows PowerShell engine required by this module PowerShellVersion = '5.1' CompatiblePSEditions = @('Core','Desktop') + } diff --git a/Source/Private/_init.ps1 b/Source/Private/_init.ps1 index d1da7ae..f101d61 100644 --- a/Source/Private/_init.ps1 +++ b/Source/Private/_init.ps1 @@ -1,5 +1,10 @@ using namespace PoshCode.Pansies +using namespace PoshCode.Pansies.Palettes +using namespace System.Collections.Generic +using namespace System.Collections using namespace ColorMine.ColorSpaces +using namespace System.Management.Automation +using namespace System.Management.Automation.Language # On first import, if HostPreference doesn't exist, set it and strongly type it if (!(Test-Path Variable:HostPreference) -or $null -eq $HostPreference) { @@ -19,11 +24,32 @@ if(Get-Command Add-MetadataConverter -ErrorAction Ignore) { } } -$xlr8r = [psobject].assembly.gettype("System.Management.Automation.TypeAccelerators") -@{ +$Accelerators = @{ "RGBColor" = [PoshCode.Pansies.RgbColor] "Entities" = [PoshCode.Pansies.Entities] -}.GetEnumerator().ForEach({ +} + +# IArgumentCompleterFactory only available on PS7+ +if ("System.Management.Automation.IArgumentCompleterFactory" -as [type]) { + Add-Type @" +using System.Management.Automation; +using PoshCode.Pansies.Palettes; +namespace PoshCode.Pansies { + public class ColorCompleterAttribute : ArgumentCompleterAttribute, IArgumentCompleterFactory { + public ColorCompleterAttribute(){} + public IArgumentCompleter Create() { + return new X11Palette(); + } + } +} +"@ -ReferencedAssemblies ([psobject].Assembly), ([PoshCode.Pansies.RgbColor].Assembly), "netstandard" -CompilerOptions "-NoWarn:1701" + + $Accelerators["ColorCompleterAttribute"] = [PoshCode.Pansies.ColorCompleterAttribute] + +} + +$xlr8r = [psobject].assembly.gettype("System.Management.Automation.TypeAccelerators") +$Accelerators.GetEnumerator().ForEach({ $Name = $_.Key $Type = $_.Value if ($xlr8r::AddReplace) { @@ -41,4 +67,22 @@ $xlr8r = [psobject].assembly.gettype("System.Management.Automation.TypeAccelerat } throw } -}) \ No newline at end of file +}) + +$script:X11Palette = [X11Palette]::new() +$RgbColorCompleter = { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) + $script:X11Palette.CompleteArgument($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) +} + +$global:PansiesColorCompleterRegistration = Register-EngineEvent -SourceIdentifier PowerShell.OnIdle { + foreach ($command in Get-Command -ParameterType RgbColor) { + foreach ($parameter in $command.Parameters.Values.Where{ $_.ParameterType -eq [RgbColor] }) { + Register-ArgumentCompleter -CommandName $command.Name -ParameterName $parameter.Name -ScriptBlock $RgbColorCompleter + } + } + Stop-Job $global:PansiesColorCompleterRegistration # This removes the event + Remove-Variable PansiesColorCompleterRegistration -Scope global +} + +Export-ModuleMember -Variable RgbColorCompleter -Function *-* -Cmdlet * -Alias *