Skip to content

Commit

Permalink
Merge color completion from joel/dev
Browse files Browse the repository at this point in the history
And update the actions/upload-artifact
  • Loading branch information
Jaykul committed Sep 10, 2024
2 parents 744f6ef + 4484546 commit db4b142
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 11 deletions.
1 change: 1 addition & 0 deletions .earthlyignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ignore output (because we put stuff there)
/output/*
/Modules/*
assemblies/
# ignore binary output files and folders
bin/
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ 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 }}
PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }}

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: Pansies
path: Modules/Pansies

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: TestResults
path: Modules/Pansies-TestResults

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: Packages
path: Modules/Pansies-Packages
3 changes: 1 addition & 2 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Source/Pansies.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -137,5 +137,6 @@ PrivateData = @{
# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '5.1'
CompatiblePSEditions = @('Core','Desktop')

}

52 changes: 48 additions & 4 deletions Source/Private/_init.ps1
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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) {
Expand All @@ -41,4 +67,22 @@ $xlr8r = [psobject].assembly.gettype("System.Management.Automation.TypeAccelerat
}
throw
}
})
})

$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 *

0 comments on commit db4b142

Please sign in to comment.