Skip to content

Commit

Permalink
Create ListWithStrictTypes.psm1
Browse files Browse the repository at this point in the history
  • Loading branch information
ninmonkey committed Dec 25, 2023
1 parent d642898 commit 67df036
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions Pwsh/Generics/ListWithStrictTypes.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class ColorInfo {
[RgbColor]$Fg
[RgbColor]$Bg
[string] ToString() {
return $this.Ansi(
($this | Join-String -p { $_.fg, $_.Bg, $_.X11ColorName } ) )
}
[string] Ansi( [string]$Text ) {
return New-Text -Object $Text -fg $this.fg -bg $This.bg | Join-String
}
}



function Colors.Pairs.List {
[List[ColorInfo]]$pairs = @(
[ColorInfo]@{
Fg = '#6e99aa'
Bg = '#9e3232'
}
)
return $pairs
}
function Colors.Pairs.List2 {
[List[ColorInfo]]$final = @()
[List[ColorInfo]]$pairs = @(
[ColorInfo]@{
Fg = '#6e99aa'
Bg = '#9e3232'
}
)

foreach($cur in $Pairs) {
$final.Add( $cur )

$final.AddRange([ColorInfo[]]@(
[ColorInfo]@{
Fg = $cur.Fg.GetComplement($false, $false)
Bg = $cur.Bg
}
[ColorInfo]@{
Fg = $cur.Fg
Bg = $cur.Bg.GetComplement($false, $false)
}

))
}

return $final
}

Export-ModuleMember -func @(
'*'
'list.Pairs'
)

0 comments on commit 67df036

Please sign in to comment.