From 67df036be775388659245d84c6ded49a9cdc9fac Mon Sep 17 00:00:00 2001 From: Jake Bolton Date: Mon, 25 Dec 2023 09:23:10 -0600 Subject: [PATCH] Create ListWithStrictTypes.psm1 --- Pwsh/Generics/ListWithStrictTypes.psm1 | 55 ++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Pwsh/Generics/ListWithStrictTypes.psm1 diff --git a/Pwsh/Generics/ListWithStrictTypes.psm1 b/Pwsh/Generics/ListWithStrictTypes.psm1 new file mode 100644 index 0000000..4be8e3a --- /dev/null +++ b/Pwsh/Generics/ListWithStrictTypes.psm1 @@ -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' +)