Pansies.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
#Region '.\_init.ps1' 0
using namespace ColorMine.ColorSpaces
using namespace PoshCode.Pansies
using namespace ColorMine.Palettes
using namespace PoshCode.Pansies.Palettes
using namespace System.Collections.Generic

# On first import, if HostPreference doesn't exist, set it and strongly type it
if(!(Test-Path Variable:HostPreference) -or $HostPreference -eq $null) {
    [System.Management.Automation.ActionPreference]$global:HostPreference = "Continue"
}

Set-Variable HostPreference -Description "Dictates the action taken when a host message is delivered" -Visibility Public -Scope Global

if(-not $IsLinux -and -not $IsMacOS) {
    [PoshCode.Pansies.Console.WindowsHelper]::EnableVirtualTerminalProcessing()
}

if(Get-Command Add-MetadataConverter -ErrorAction SilentlyContinue) {
    Add-MetadataConverter @{
        RgbColor = { [PoshCode.Pansies.RgbColor]$args[0] }
        [PoshCode.Pansies.RgbColor] = { "RgbColor '$_'" }
    }
}
#EndRegion '.\_init.ps1' 23
#Region '.\Private\ConvertToCssColor.ps1' 0
function ConvertToCssColor {
    [CmdletBinding()]
    param(
        [Parameter(ParameterSetName="PListColorDictionary", Mandatory, Position = 0)]
        [Dictionary[string,object]]$colors,

        [Parameter(ParameterSetName="ColorValue", Mandatory, Position = 0)]
        [string]$color
    )
    end {
        if($PSCmdlet.ParameterSetName -eq "PListColorDictionary") {
            [int]$r = 255 * $colors["Red Component"]
            [int]$g = 255 * $colors["Green Component"]
            [int]$b = 255 * $colors["Blue Component"]
            [PoshCode.Pansies.RgbColor]::new($r, $g, $b).ToString()
        }
        if($PSCmdlet.ParameterSetName -eq "ColorValue") {
            [PoshCode.Pansies.RgbColor]::new($color).ToString()
        }
    }
}
#EndRegion '.\Private\ConvertToCssColor.ps1'
#Region '.\Private\ExportTheme.ps1' 0
function ExportTheme {
    <#
        .SYNOPSIS
            Imports themes by name
    #>

    [CmdletBinding(SupportsShouldProcess)]
    param(
        # The name of the theme
        [Parameter(Position = 0, Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string]$Name,

        [Parameter(ValueFromPipeline, Position = 1)]
        $InputObject,

        [switch]$Force,

        [switch]$Update,

        [switch]$PassThru,

        [ValidateSet("User", "Machine")]
        [string]$Scope = "User"
    )
    process {
        $NativeThemePath = Join-Path $(Get-ConfigurationPath -Scope $Scope) "$Name.theme.psd1"

        if(Test-Path -LiteralPath $NativeThemePath) {
            if($Update) {
                Write-Verbose "Updating $NativeThemePath"
                $Theme = Import-Metadata $NativeThemePath -ErrorAction Stop
                Update-Object -InputObject $Theme -UpdateObject $InputObject | Export-Metadata $NativeThemePath
            } elseif($Force -or $PSCmdlet.ShouldContinue("Overwrite $($NativeThemePath)?", "$Name Theme exists")) {
                Write-Verbose "Exporting to $NativeThemePath"
                $InputObject | Export-Metadata $NativeThemePath
            }
        } else {
            Write-Verbose "Exporting to $NativeThemePath"
            $InputObject | Export-Metadata $NativeThemePath
        }

        if($PassThru) {
            $InputObject | Add-Member NoteProperty Name $Name -Passthru |
                           Add-Member NoteProperty PSPath $NativeThemePath -Passthru
        }
    }
}
#EndRegion '.\Private\ExportTheme.ps1'
#Region '.\Private\FindVSCodeTheme.ps1' 0
function FindVsCodeTheme {
    [CmdletBinding()]
    param($Name)

    $VSCodeExtensions = @(
        # VS Code themes are in one of two places: in the app, or in your profile folder:
        Convert-Path "~\.vscode*\extensions\"
        # If `code` is in your path, we can guess where that is...
        Get-Command Code-Insiders, Code -ErrorAction Ignore |
            Split-Path | Split-Path | Join-Path -ChildPath "resources\app\extensions\"
    )
    $Warnings = @()

    $Themes = @(
        # If they passed a file path that exists, use just that one file
        if ($Specific = Test-Path -LiteralPath $Name) {
            $File = Convert-Path $Name
            $(
                if ($File.EndsWith(".json")) {
                    try {
                        # Write-Debug "Parsing json file: $File"
                        ConvertFrom-Json (Get-Content -Path $File -Raw -Encoding utf8) -ErrorAction SilentlyContinue
                    } catch {
                        Write-Error "Couldn't parse '$File'. $(
                        if($PSVersionTable.PSVersion.Major -lt 6) {
                            'You could try again with PowerShell Core, the JSON parser there works much better!'
                        })"

                    }
                } else {
                    # Write-Debug "Parsing PList file: $File"
                    Import-PList -Path $File
                }
            ) | Select-Object @{ Name = "Name"
                                 Expr = {
                                    if ($_.name) {
                                        $_.name
                                    } else {
                                        [IO.Path]::GetFileNameWithoutExtension($File)
                                    }
                                }
                           }, @{ Name = "Path"
                                 Expr = {$File}
                           }
        } else {
            $VSCodeExtensions  = $VSCodeExtensions | Join-Path -ChildPath "\*\package.json" -Resolve
            foreach ($File in $VSCodeExtensions) {
                # Write-Debug "Considering VSCode Extention $([IO.Path]::GetFileName([IO.Path]::GetDirectoryName($File)))"
                $JSON = Get-Content -Path $File -Raw -Encoding utf8
                try {
                    $Extension = ConvertFrom-Json $JSON -ErrorAction Stop
                    # if ($Extension.contributes.themes) {
                    # Write-Debug "Found $($Extension.contributes.themes.Count) themes"
                    # }
                    $Extension.contributes.themes |
                        Select-Object @{Name="Name" ; Expr={$_.label}},
                                      @{Name="Style"; Expr={$_.uiTheme}},
                                      @{Name="Path" ; Expr={Join-Path (Split-Path $File) $_.path -resolve}}
                } catch {
                    $Warning = "Couldn't parse some VSCode extensions."
                }
            }
        }
    )
    if($Themes.Count -eq 0) {
        throw "Could not find any VSCode themes. Please use a full path."
    }

    if($Specific -and $Themes.Count -eq 1) {
        $Themes
    }

    # Make sure we're comparing the name to a name
    $Name = [IO.Path]::GetFileName(($Name -replace "\.json$|\.tmtheme$"))
    Write-Verbose "Testing theme names for '$Name'"

    # increasingly fuzzy search: (eq -> like -> match)
    if(!($Theme = $Themes.Where{$_.name -eq $Name})) {
        if (!($Theme = $Themes.Where{$_.name -like $Name})) {
            if (!($Theme = $Themes.Where{$_.name -like "*$Name*"})) {
                foreach($Warning in $Warnings) {
                    Write-Warning $Warning
                }
                Write-Error "Couldn't find the theme '$Name', please try another: $(($Themes.name | Select-Object -Unique) -join ', ')"
            }
        }
    }
    if(@($Theme).Count -gt 1) {
        $Dupes = $(if(@($Theme.Name | Get-Unique).Count -gt 1) {$Theme.Name} else {$Theme.Path}) -join ", "
        Write-Warning "Found more than one theme for '$Name'. Using '$(@($Theme)[0].Path)', but you could try again for one of: $Dupes)"
    }
    @($Theme)[0]
}
#EndRegion '.\Private\FindVSCodeTheme.ps1'
#Region '.\Private\GetColorProperty.ps1' 0
function GetColorProperty{
    <#
        .SYNOPSIS
            Search the colors for a matching theme color name and returns the foreground
    #>

    param(
        # The array of colors
        [Array]$colors,

        # An array of (partial) scope names in priority order
        # The foreground color of the first matching scope in the tokens will be returned
        [string[]]$name
    )
    # Since we loaded the themes in order of prescedence, we take the first match that has a foreground color
    foreach ($pattern in $name) {
        # Normalize color
        if($foreground = @($colors.$pattern).Where{$_}[0]) {
            ConvertToCssColor $foreground
            return
        }
    }
}
#EndRegion '.\Private\GetColorProperty.ps1'
#Region '.\Private\GetColorScopeForeground.ps1' 0
function GetColorScopeForeground {
    <#
        .SYNOPSIS
            Search the tokens for a scope name with a foreground color
    #>

    param(
        # The array of tokens
        [Array]$tokens,

        # An array of (partial) scope names in priority order
        # The foreground color of the first matching scope in the tokens will be returned
        [string[]]$name
    )
    # Since we loaded the themes in order of prescedence, we take the first match that has a foreground color
    foreach ($pattern in $name) {
        foreach ($token in $tokens) {
            if (($token.scope -split "\s*,\s*" -match $pattern) -and $token.settings.foreground) {
                ConvertToCssColor $token.settings.foreground
                return
            }
        }
    }
}
#EndRegion '.\Private\GetColorScopeForeground.ps1'
#Region '.\Private\ImportJsonIncludeLast.ps1' 0
function ImportJsonIncludeLast {
    <#
        .SYNOPSIS
            Import VSCode json themes, including any included themes
    #>

    [CmdletBinding()]
    param([string[]]$Path)

    # take the first
    $themeFile, $Path = $Path
    $theme = Get-Content $themeFile | ConvertFrom-Json

    # Output all the colors or token colors
    if ($theme.colors) {
        $theme.colors
    }
    if ($theme.tokenColors) {
        $theme.tokenColors
    }

    # Recurse includes
    if ($theme.include) {
        $Path += $themeFile | Split-Path | Join-Path -Child $theme.include | convert-path
    }
    if ($Path) {
        ImportJsonIncludeLast $Path
    }
}
#EndRegion '.\Private\ImportJsonIncludeLast.ps1'
#Region '.\Private\ImportTheme.ps1' 0
function ImportTheme {
    <#
        .SYNOPSIS
            Imports themes by name
    #>

    [CmdletBinding()]
    param(
        # The name of the theme
        [Parameter(Position=0)]
        [string]$Name
    )

    $FileName = $Name -replace "((\.theme)?\.psd1)?$" -replace '$', ".theme.psd1"

    $Path = if (!(Test-Path -LiteralPath $FileName)) {
        Get-Theme $Name | Select-Object -First 1 -ExpandProperty PSPath
    } else {
        Convert-Path $FileName
    }
    if(!$Path) {
        $Themes = @(Get-Theme "$Name*")
        if($Themes.Count -gt 1) {
            Write-Warning "No exact match for $Name. Using $($Themes[0]), but also found $($Themes[1..$($Themes.Count-1)] -join ', ')"
            $Path = $Themes[0].PSPath
        } elseif($Themes) {
            Write-Warning "No exact match for $Name. Using $($Themes[0])"
            $Path = $Themes[0].PSPath
        } else {
            $Themes = @(Get-Theme "*$Name*")
            if($Themes.Count -gt 1) {
                Write-Warning "No exact match for $Name. Using $($Themes[0]), but also found $($Themes[1..$($Themes.Count-1)] -join ', ')"
                $Path = $Themes[0].PSPath
            } elseif($Themes) {
                Write-Warning "No exact match for $Name. Using $($Themes[0])"
                $Path = $Themes[0].PSPath
            }
        }
        if(!$Path) {
            Write-Error "No theme '$Name' found. Try Get-Theme to see available themes."
            return
        }
    }

    Write-Verbose "Importing $Name theme from $Path"
    $Theme = Import-Metadata $Path -ErrorAction Stop

    # Cast the ConsoleColors here
    if($Theme['ConsoleColors']) {
        $Theme['ConsoleColors'] = $Theme['ConsoleColors'].ForEach([RgbColor])
    }
    # Convert colors to escape sequences for PSReadline.Colors
    if ($Colors = $Theme.PSReadline.Colors) {
        foreach ($color in @($Colors.Keys)) {
            # If it doesn't start with ESC
            if ($Colors[$color] -notmatch "^$([char]27)") {
                try {
                    # Use the RGBColor
                    $Colors[$color] = ([RgbColor]$Colors[$color]).ToVtEscapeSequence() <# |
                        Add-Member -MemberType NoteProperty -Name Color -Value ([RgbColor]$Colors[$color]) -PassThru #>

                } catch {
                    Write-Warning "Skipped 'PSReadLine.$color', because '$($Colors[$color])' is neither a color nor an escape sequence"
                    $null = $Colors.Remove($color)
                }
            }
        }
        $Theme['PSReadline']['Colors'] = $Colors
    }

    $Theme
}
#EndRegion '.\Private\ImportTheme.ps1'
#Region '.\Private\ShowPreview.ps1' 0
function ShowPreview {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory, Position = 0)]
        $Palette,

        [Parameter(Position = 1)]
        $Syntax,

        $Name,

        [Switch]$Tiny,

        [Switch]$MoreText,

        [Switch]$NoCodeSample
    )
    if($null -eq $Syntax) {
        $Syntax  = Get-PSReadLineOption | Select-Object -Property @(
                @{Name = "ContinuationPrompt"; Expression = { $_.ContinuationPromptColor }}
                @{Name = "Parameter"; Expression = { $_.ParameterColor }}
                @{Name = "Member"; Expression = { $_.MemberColor }}
                @{Name = "Command"; Expression = { $_.CommandColor }}
                @{Name = "Operator"; Expression = { $_.OperatorColor }}
                @{Name = "Emphasis"; Expression = { $_.EmphasisColor }}
                @{Name = "Selection"; Expression = { $_.SelectionColor }}
                @{Name = "Variable"; Expression = { $_.VariableColor }}
                @{Name = "Type"; Expression = { $_.TypeColor }}
                @{Name = "Keyword"; Expression = { $_.KeywordColor }}
                @{Name = "String"; Expression = { $_.StringColor }}
                @{Name = "Error"; Expression = { $_.ErrorColor }}
                @{Name = "Number"; Expression = { $_.NumberColor }}
                @{Name = "Default"; Expression = { $_.DefaultTokenColor }}
                @{Name = "Comment"; Expression = { $_.CommentColor }}
            )
    }
    $e = [char]27

    -join $(
        "$($Name)`n"
        if($Palette) {
            if($Palette.Count -lt 16) {
                throw "Invalid theme: missing ConsoleColors (there should be 16, but are only $($Palette.Count))"
            }

            if (!$Tiny) {
                $ansi = 30
                $bold = $false
                " Black Red Green Yellow Blue Magenta Cyan White Gray Dark Gray `n"
                " 49m 40m 41m 42m 43m 44m 45m 46m 47m 100m 107m `n"
                " 39m"

                foreach($fg in @($null) + $Palette[0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]) {
                    if($fg) {
                        "$(if($bold){"1;"}else{" "})$($ansi)m"
                        $ansi += $bold
                        $bold = !$bold
                    }
                    foreach($bg in @($null) + $Palette[0, 4, 2, 6, 1, 5, 3, 15, 7, 8]) {
                        $(if($null -ne $bg) { $bg.ToVtEscapeSequence($true) })
                        $(if($null -ne $fg) { $fg.ToVtEscapeSequence() })
                        " gYw $([char]27)[0m "
                    }
                    "`n"
                }
                "`n"
            }

            0..7 | ForEach-Object {
                $Dark = $Palette[$_]
                $Lite = $Palette[($_ + 8)]

                New-Text (" $([ConsoleColor]$_)".PadRight(12) + " $Dark ") -Fore (Get-Complement $Dark -Force) -Back $Dark -LeaveColor
                New-Text (" $([ConsoleColor]$_+8)".PadRight(9) + " $Lite ") -Fore (Get-Complement $Lite -Force) -Back $Lite
                "`n"
            }
        }

        if($Syntax -and !$NoCodeSample) {
            "$e[8A$e[45G$($Syntax.Keyword)function $($Syntax.Default)Test-Syntax $($Syntax.Default){"
            "$e[B$e[45G $($Syntax.Comment)# Demo Syntax Highlighting"
            "$e[B$e[45G $($Syntax.Default)[$($Syntax.Type)CmdletBinding$($Syntax.Default)()]"
            "$e[B$e[45G $($Syntax.Keyword)param$($Syntax.Default)( [$($Syntax.Type)IO.FileInfo$($Syntax.Default)]$($Syntax.Variable)`$Path $($Syntax.Default))"
            "$e[B"
            "$e[B$e[45G $($Syntax.Command)Write-Verbose $($Syntax.String)`"Testing in $($Syntax.Variable)`$($($Syntax.Command)Split-Path $($Syntax.Variable)`$PSScriptRoot $($Syntax.Parameter)-Leaf$($Syntax.Variable))$($Syntax.String)`" $($Syntax.Parameter)-Verbose"
            "$e[B$e[45G $($Syntax.Variable)`$Env:PSModulePath $($Syntax.Operator)-split $($Syntax.String)';' $($Syntax.Operator)-notcontains $($Syntax.Variable)`$Path$($Syntax.Default).$($Syntax.Member)FullName"
            "$e[B$e[45G$($Syntax.Default)}$e[39m$e[B"
        }

        if($Palette -and $MoreText) {
            0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 | ForEach-Object {
                $Color = $Palette[$_]
                New-Text " This is a test " -Back Black -Fore $Color -LeaveColor
                New-Text " showing more " -Back DarkGray -Fore $Color -LeaveColor
                New-Text " sample text on " -Back Gray -Fore $Color -LeaveColor
                New-Text " common backgrounds: " -Back White -Fore $Color -LeaveColor
                New-Text " $Color $([ConsoleColor]$_) ".PadRight(22) -Fore $(if($_ -le 8 -and $_ -ne 7){"White"}else{"Black"}) -Back $Color
                "`n"
            }
            "`n"
        }
    )
}
#EndRegion '.\Private\ShowPreview.ps1'
#Region '.\Public\Convert-ConsolePalette.ps1' 0
function Convert-ConsolePalette {
    # .EXTERNALHELP Pansies-help.xml
    [CmdletBinding(SupportsShouldProcess, ConfirmImpact="Medium", DefaultParameterSetName = "Dark")]
    param(
        # How much to shift the dark colors. Positive values make the colors brighter, negative values make them darker
        [Parameter(Mandatory, ParameterSetName = "Dark", Position = 0)]
        [int]$DarkShift,

        # How much to shift the bright colors. Positive values make the colors brighter, negative values make them darker
        [Parameter(Mandatory, ParameterSetName = "Bright")]
        [int]$BrightShift,

        # By default, the colors are modified in-place. If copy is set:
        # - the dark colors start with the value of the bright colors
        # - the light colors start at the value of the dark colors
        [switch]$Copy
    )
    $Palette = Get-ConsolePalette
    for($i=0;$i -lt 8; $i++){
        $Dark  = $Palette[$i].ToHunterLab()
        $Light = $Palette[$i+8].ToHunterLab()

        if ($BrightShift) {
            if ($Copy) {
                $Light = $Dark.ToHunterLab()
            }
            $Light.L  += $BrightShift
        }

        if ($DarkShift) {
            if ($Copy) {
                $Dark  = $Light.ToHunterLab()
            }
            $Dark.L   += $DarkShift
        }

        $Palette[$i]   = [PoshCode.Pansies.RgbColor]$Dark.ToRgb()
        $Palette[$i+8] = [PoshCode.Pansies.RgbColor]$Light.ToRgb()
    }

    ShowPreview $Palette -Tiny

    if($PSCmdlet.ShouldProcess("Save Theme")) {
        Set-ConsolePalette $Palette
    }
}
#EndRegion '.\Public\Convert-ConsolePalette.ps1'
#Region '.\Public\ConvertFrom-iTermColors.ps1' 0
function ConvertFrom-iTermColors {
    # .EXTERNALHELP Pansies-help.xml
    [CmdletBinding(SupportsShouldProcess)]
    param(
        # The name of (or full path to) an XML PList itermcolors scheme
        # If you provide just a name, will search for an .itermcolors file in the current folder and the theme
        [Alias("PSPath", "Name")]
        [Parameter(ValueFromPipelineByPropertyName)]
        [string]$Theme,

        [switch]$Force,

        [switch]$Update,

        [switch]$Passthru,

        [ValidateSet("User", "Machine")]
        [string]$Scope = "User"
    )

    begin {
        # In Windows Color Table order
        $PListColorNames = @(
            "Ansi 0 Color"   # DARK_BLACK
            "Ansi 4 Color"   # DARK_BLUE
            "Ansi 2 Color"   # DARK_GREEN
            "Ansi 6 Color"   # DARK_CYAN
            "Ansi 1 Color"   # DARK_RED
            "Ansi 5 Color"   # DARK_MAGENTA
            "Ansi 3 Color"   # DARK_YELLOW
            "Ansi 7 Color"   # DARK_WHITE
            "Ansi 8 Color"   # BRIGHT_BLACK
            "Ansi 12 Color"  # BRIGHT_BLUE
            "Ansi 10 Color"  # BRIGHT_GREEN
            "Ansi 14 Color"  # BRIGHT_CYAN
            "Ansi 9 Color"   # BRIGHT_RED
            "Ansi 13 Color"  # BRIGHT_MAGENTA
            "Ansi 11 Color"  # BRIGHT_YELLOW
            "Ansi 15 Color"  # BRIGHT_WHITE
        )
    }

    process {
        if (!(Test-Path $Theme)) {
            throw [System.IO.FileNotFoundException]::new("Palette file not found", $Theme)
        }

        if (!($pList = Import-PList $Theme)) {
            return
        }

        $ThemeOutput = @{
            Name = [IO.Path]::GetFileNameWithoutExtension($Theme)
            ConsoleColors = @(
                foreach($color in $PListColorNames) {
                    if(!$pList[$color]) {
                        Wait-Debugger
                        Write-Warning "Missing color $color"
                        $null
                    } else {
                        ConvertToCssColor $pList[$color]
                    }
                }
            )
        }
        if ($pList.ContainsKey("Foreground Color") -and $pList.ContainsKey("Background Color")) {
            $ThemeOutput.ConsoleForeground = ConvertToCssColor $pList["Foreground Color"]
            $ThemeOutput.ConsoleBackground = ConvertToCssColor $pList["Background Color"]
        }
        if ($pList.ContainsKey("Bold Color")) {
            if (!$ThemeOutput['PSReadLine']) {
                $ThemeOutput['PSReadLine'] = @{}
            }
            if (!$ThemeOutput['PSReadLine']['Colors']) {
                $ThemeOutput['PSReadLine']['Colors'] = @{}
            }
            $ThemeOutput['PSReadLine']['Colors']['Emphasis'] = ConvertToCssColor $pList["Bold Color"]
        }
        if ($pList.ContainsKey("Selection Color")) {
            if (!$ThemeOutput['PSReadLine']) {
                $ThemeOutput['PSReadLine'] = @{}
            }
            if (!$ThemeOutput['PSReadLine']['Colors']) {
                $ThemeOutput['PSReadLine']['Colors'] = @{}
            }
            $ThemeOutput['PSReadLine']['Colors']['Selection'] = ConvertToCssColor $pList["Selection Color"]
        }
        if(!($Name = $pList["name"])) {
            $Name = ([IO.Path]::GetFileNameWithoutExtension($Theme))
        }

        $ThemeOutput | ExportTheme -Name $Name -Passthru:$Passthru -Scope:$Scope -Force:$Force -Update:$Update
    }
}
#EndRegion '.\Public\ConvertFrom-iTermColors.ps1'
#Region '.\Public\ConvertFrom-VSCodeTheme.ps1' 0
function ConvertFrom-VSCodeTheme {
    # .EXTERNALHELP Pansies-help.xml
    [CmdletBinding(SupportsShouldProcess)]
    param(
        # The name of (or full path to) a vscode json theme
        # E.g. 'Dark+' or 'Monokai'
        [Alias("PSPath", "Name")]
        [Parameter(ValueFromPipelineByPropertyName)]
        [string]$Theme,

        # Overwrite any existing theme
        [switch]$Force,

        [switch]$Update,

        # Output the theme after importing it
        [switch]$Passthru,

        [ValidateSet("User", "Machine")]
        [string]$Scope = "User"
    )
    $ThemeSource = FindVsCodeTheme $Theme -ErrorAction Stop

    Write-Verbose "Importing $($ThemeSource.Path)"
    if($PSCmdlet.ShouldProcess($ThemeSource.Path, "Convert to $($ThemeSource.Name).theme.psd1")) {
        # Load the theme file and split the output into colors and tokencolors
        if($ThemeSource.Path.endswith(".json")) {
            $colors, $tokens = (ImportJsonIncludeLast $ThemeSource.Path).Where( {!$_.scope}, 'Split', 2)
        } else {
            $colors, $tokens = (Import-PList $ThemeSource.Path).settings.Where( {!$_.scope}, 'Split', 2)
            $colors = $colors.settings
        }

        # these should come from the colors, rather than the token scopes
        $DefaultTokenColor = GetColorProperty $colors 'editor.foreground', 'foreground', 'terminal.foreground'
        $SelectionColor = GetColorProperty $colors 'editor.selectionBackground', 'editor.selectionHighlightBackground', 'selection'
        $ErrorColor = @(@(GetColorProperty $colors 'errorForeground', 'editorError.foreground') + @(GetColorScopeForeground $tokens 'invalid'))[0]

        # I'm going to need some help figuring out what the best mappings are
        $CommandColor = GetColorScopeForeground $tokens 'support.function'
        $CommentColor = GetColorScopeForeground $tokens 'comment'
        $ContinuationPromptColor = GetColorScopeForeground $tokens 'constant.character'
        $EmphasisColor = GetColorScopeForeground $tokens 'markup.bold','markup.italic','emphasis','strong','constant.other.color', 'markup.heading'
        $KeywordColor = GetColorScopeForeground $tokens '^keyword.control$', '^keyword$', 'keyword.control', 'keyword'
        $MemberColor = GetColorScopeForeground $tokens 'variable.other.object.property', 'member', 'type.property', 'support.function.any-method', 'entity.name.function'
        $NumberColor = GetColorScopeForeground $tokens 'constant.numeric'
        $OperatorColor = GetColorScopeForeground $tokens 'keyword.operator$', 'keyword'
        $ParameterColor = GetColorScopeForeground $tokens 'parameter'
        $StringColor = GetColorScopeForeground $tokens '^string$'
        $TypeColor = GetColorScopeForeground $tokens '^storage.type$','^support.class$', '^entity.name.type.class$', '^entity.name.type$'
        $VariableColor = GetColorScopeForeground $tokens '^variable$', '^entity.name.variable$', '^variable.other$'


        $ThemeOutput = [Ordered]@{
            Name       = $ThemeSource.Name
            PSReadLine = @{
                Colors = @{
                    Command =            $CommandColor
                    Comment =            $CommentColor
                    ContinuationPrompt = $ContinuationPromptColor
                    DefaultToken =       $DefaultTokenColor
                    Emphasis =           $EmphasisColor
                    Error =              $ErrorColor
                    Keyword =            $KeywordColor
                    Member =             $MemberColor
                    Number =             $NumberColor
                    Operator =           $OperatorColor
                    Parameter =          $ParameterColor
                    Selection =          $SelectionColor
                    String =             $StringColor
                    Type =               $TypeColor
                    Variable =           $VariableColor
                }
            }
        }

        # If the VSCode Theme has terminal colors, export those
        if ($colors.'terminal.ansiBrightYellow') {
            Write-Verbose "Exporting ConsoleColors"
            $ThemeOutput['ConsoleColors'] = @(
                    GetColorProperty $colors "terminal.ansiBlack"
                    GetColorProperty $colors "terminal.ansiRed"
                    GetColorProperty $colors "terminal.ansiGreen"
                    GetColorProperty $colors "terminal.ansiYellow"
                    GetColorProperty $colors "terminal.ansiBlue"
                    GetColorProperty $colors "terminal.ansiMagenta"
                    GetColorProperty $colors "terminal.ansiCyan"
                    GetColorProperty $colors "terminal.ansiWhite"
                    GetColorProperty $colors "terminal.ansiBrightBlack"
                    GetColorProperty $colors "terminal.ansiBrightRed"
                    GetColorProperty $colors "terminal.ansiBrightGreen"
                    GetColorProperty $colors "terminal.ansiBrightYellow"
                    GetColorProperty $colors "terminal.ansiBrightBlue"
                    GetColorProperty $colors "terminal.ansiBrightMagenta"
                    GetColorProperty $colors "terminal.ansiBrightCyan"
                    GetColorProperty $colors "terminal.ansiBrightWhite"
                )
            if ($colors."terminal.background") {
                $ThemeOutput['ConsoleBackground'] = GetColorProperty $colors "terminal.background"
            }
            if ($colors."terminal.foreground") {
                $ThemeOutput['ConsoleForeground'] = GetColorProperty $colors "terminal.foreground"
            }
        }

        if (GetColorProperty $colors 'editorWarning.foreground') {
            $ThemeOutput['Host'] = @{
                'PrivateData' = @{
                    WarningForegroundColor  = GetColorProperty $colors 'editorWarning.foreground'
                    ErrorForegroundColor = GetColorProperty $Colors 'editorError.foreground'
                    VerboseForegroundColor = GetColorProperty $Colors 'editorInfo.foreground'
                    ProgressForegroundColor = GetColorProperty $Colors 'notifications.foreground'
                    ProgressBackgroundColor = GetColorProperty $Colors 'notifications.background'
                }
            }
        }

        if ($DebugPreference -in "Continue", "Inquire") {
            $global:colors = $colors
            $global:tokens = $tokens
            $global:Theme = $ThemeOutput
            ${function:global:Get-VSColorScope} = ${function:GetColorScopeForeground}
            ${function:global:Get-VSColor} = ${function:GetColorProperty}
            Write-Debug "For debugging, `$Theme, `$Colors, `$Tokens were copied to global variables, and Get-VSColor and Get-VSColorScope exported."
        }

        if ($ThemeOutput.PSReadLine.Colors.Values -contains $null) {
            Write-Warning "Some PSReadLine color values not set in '$($ThemeSource.Path)'"
        }

        $ThemeOutput | ExportTheme -Name $ThemeSource.Name -Passthru:$Passthru -Scope:$Scope -Force:$Force -Update:$Update
    }
}
#EndRegion '.\Public\ConvertFrom-VSCodeTheme.ps1'
#Region '.\Public\Export-PList.ps1' 0
function Export-PList {
    # .EXTERNALHELP Pansies-help.xml
    [CmdletBinding(SupportsShouldProcess)]
    param(
        # The object(s) to convert
        [Parameter(Mandatory, ValueFromPipeline)]
        [Alias("io")]
        [Object[]]$InputObject,

        # The path to an XML or binary plist file (e.g. a .tmTheme file)
        [Parameter(Mandatory, ValueFromPipelineByPropertyName, Position = 0)]
        [Alias("PSPath")]
        [string]$Path,

        [switch]$Binary
    )

    begin {
        $Output = @()
    }
    process {
        $Output += $InputObject
    }
    end {
        $Parent = if($Parent = Split-Path $Path) {
            if(!(Test-Path -LiteralPath $Parent -PathType Container)) {
                New-Item -ItemType Directory -Path $Parent -Force
            }
            Convert-Path $Parent
        } else {
            Convert-Path (Get-Location -PSProvider FileSystem)
        }
        $Path = Join-Path $Parent -ChildPath (Split-Path $Path -Leaf)

        if($PSCmdlet.ShouldProcess($Path,"Export InputObject as PList $(if($Binary){'Binary'}else{'Xml'})") ) {
            if ($Binary) {
                [PoshCode.Pansies.Parsers.Plist]::WriteBinary($Output, $Path)
            } else {
                [PoshCode.Pansies.Parsers.Plist]::WriteXml($Output, $Path)
            }
        }
    }
}
#EndRegion '.\Public\Export-PList.ps1'
#Region '.\Public\Export-Theme.ps1' 0
function Export-Theme {
    # .EXTERNALHELP Pansies-help.xml
    [CmdletBinding()]
    param(
        # The name of the theme to export the current settings to
        [Parameter(Position = 0, Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string]$Name,

        [string]$Update,

        [switch]$Force,

        [switch]$Passthru,

        [ValidateSet("User", "Machine")]
        [string]$Scope = "User"
    )
    end {

        $ConsoleColors = (Get-ConsolePalette -AddScreenAndPopup)
        $Theme = [Ordered]@{
            Name = "$Name"
            # Force the colors to be saved as simple '#RRGGBB' instead of native (RgbColor '#RRGGBB')
            ConsoleForeground = $ConsoleColors[16].ToString()
            ConsoleBackground = $ConsoleColors[17].ToString()
            PopupForeground   = $ConsoleColors[18].ToString()
            PopupBackground   = $ConsoleColors[19].ToString()
            ConsoleColors     = $ConsoleColors[0..15].ForEach({$_.ToString()})
        }

        if($Host.Name -eq "ConsoleHost") {
            $Theme['Host'] = @{
                PrivateData = ConvertFrom-Metadata ($Host.PrivateData | Select-Object * | ConvertTo-Metadata -AsHashtable)
            }
        }

        if ((Get-Module PSReadLine).Version -ge "2.0.0") {
            $Theme['PSReadLine'] = @{
                # TODO: convert escape sequences to RGBColor values (e.g. 30's and 90's to colors, including 38;2;R;G;B;)
                Colors = ConvertFrom-Metadata -Ordered @(
                    Get-PSReadLineOption | Select-Object -Property @(
                        @{Name = "ContinuationPrompt"; Expression = { $_.ContinuationPromptColor }}
                        @{Name = "Parameter"; Expression = { $_.ParameterColor }}
                        @{Name = "Member"; Expression = { $_.MemberColor }}
                        @{Name = "Command"; Expression = { $_.CommandColor }}
                        @{Name = "Operator"; Expression = { $_.OperatorColor }}
                        @{Name = "Emphasis"; Expression = { $_.EmphasisColor }}
                        @{Name = "Selection"; Expression = { $_.SelectionColor }}
                        @{Name = "Variable"; Expression = { $_.VariableColor }}
                        @{Name = "Type"; Expression = { $_.TypeColor }}
                        @{Name = "Keyword"; Expression = { $_.KeywordColor }}
                        @{Name = "String"; Expression = { $_.StringColor }}
                        @{Name = "Error"; Expression = { $_.ErrorColor }}
                        @{Name = "Number"; Expression = { $_.NumberColor }}
                        @{Name = "Default"; Expression = { $_.DefaultTokenColor }}
                        @{Name = "Comment"; Expression = { $_.CommentColor }}
                    ) | ConvertTo-Metadata -AsHashtable )
            }
        }

        if($Update) {
            $Theme = ImportTheme $Name -ErrorAction SilentlyContinue | Update-Object $Theme
        }

        $Theme | ExportTheme -Name $Name -Passthru:$Passthru -Scope:$Scope -Force:$Force
    }
}
#EndRegion '.\Public\Export-Theme.ps1'
#Region '.\Public\Get-Complement.ps1' 0
function Get-Complement {
    # .EXTERNALHELP Pansies-help.xml
    [CmdletBinding()]
    [OutputType([PoshCode.Pansies.RgbColor])]
    param(
        # The source color to calculate the complement of
        [Parameter(ValueFromPipeline, Mandatory, Position = 0)]
        [PoshCode.Pansies.RgbColor]$Color,

        # Force the luminance to have "enough" contrast
        [switch]$ForceContrast,

        # Assume there are only 16 colors
        [switch]$ConsoleColor,

        # If set, output the input $Color before the complement
        [switch]$Passthru
    )
    process {
        if($ConsoleColor) {
            $Color = $Color.ConsoleColor
        }

        if($Passthru) { $Color }

        if($ConsoleColor) {
            if($Color.ToHunterLab().L -lt 50) {
                [PoshCode.Pansies.RgbColor][ConsoleColor]::White
            } else {
                [PoshCode.Pansies.RgbColor][ConsoleColor]::Black
            }
        } else {
            $Hsl = $Color.ToHsl()
            $Hsl.H = ($Hsl.H + 180) % 360

            if($ForceContrast) {
                $Lab = $Hsl.ToHunterLab()
                $Source = $Color.ToHunterLab()
                $Lab.L = ($Source.L + 50) % 100
                [PoshCode.Pansies.RgbColor]$Lab
            } else {
                [PoshCode.Pansies.RgbColor]$Hsl
            }
        }
    }
}
#EndRegion '.\Public\Get-Complement.ps1'
#Region '.\Public\Get-Gradient.ps1' 0
function Get-Gradient {
    # .EXTERNALHELP Pansies-help.xml
    [CmdletBinding()]
    [OutputType([PoshCode.Pansies.RgbColor[][]],[PoshCode.Pansies.RgbColor[]])]
    param(
        [Parameter(Mandatory, Position=0)]
        [PoshCode.Pansies.RgbColor]$StartColor,

        [Parameter(Mandatory, Position=1)]
        [PoshCode.Pansies.RgbColor]$EndColor,

        [Parameter(Position=2)]
        [Alias("Length","Count","Steps")]
        [int]$Width = $Host.UI.RawUI.WindowSize.Width,

        [Parameter(Position=3)]
        [int]$Height = 1,
        [ValidateSet("CMY","CMYK","LAB","LCH","LUV","HunterLAB","HSL","HSV","HSB","RGB","XYZ","YXY")]
        $ColorSpace = "HunterLab",

        [switch]$Reverse,

        [switch]$Flatten
    )

    $Height = [Math]::Max(1, $Height)
    $Width = [Math]::Max(1, $Width)
    $Colors = new-object PoshCode.Pansies.RgbColor[][] $Height, $Width

    # Simple pythagorean distance
    $Size = [Math]::Sqrt(($Height - 1) * ($Height - 1) + ($Width - 1) * ($Width - 1))

    $Left = $StartColor."To$ColorSpace"()
    $Right = $EndColor."To$ColorSpace"()
    $StepSize = New-Object "${ColorSpace}Color" -Property @{
        Ordinals = $(
            foreach ($i in 0..($Left.Ordinals.Count-1)) {
                ($Right.Ordinals[$i] - $Left.Ordinals[$i]) / $Size
            }
        )
    }
    Write-Verbose "Size: $('{0:N2}' -f $Size) ($Width x $Height) ($($Colors.Length) x $($Colors[0].Length))"
    Write-Verbose "Diff: {$StepSize}"
    Write-Verbose "From: {$Left} $($StartColor.Ordinals)"
    Write-Verbose "To: {$Right} $($EndColor.Ordinals)"
    # For colors based on hue rotation, the math is slightly more complex:
    [bool]$RotatingColor = $StepSize | Get-Member H

    if($RotatingColor) {
        [Bool]$Change = [Math]::Abs($StepSize.H) -ge 180 / $Size
        if ($Reverse) { $Change = !$Change }
        if ($Change) {
            $StepSize.H = if ($StepSize.H -gt 0) {
                $StepSize.H - 360 / $Size
            } else {
                $StepSize.H + 360 / $Size
            }
        }
        $Ceiling = 360
    }

    for ($Line = 1; $Line -le $Height; $Line++) {
        for ($Column = 1; $Column -le $Width; $Column++) {
            $D = [Math]::Sqrt(($Line - 1) * ($Line - 1) + ($Column - 1) * ($Column - 1))

            $StepColor = New-Object "${ColorSpace}Color" -Property @{
                Ordinals = $(
                    foreach ($i in 0..$Left.Ordinals.Count) {
                        $Left.Ordinals[$i] + $StepSize.Ordinals[$i] * $D
                    }
                )
            }

            # For colors based on hue rotation, the math is slightly more complex:
            if($RotatingColor) {
                if($StepColor.H -lt 0) {
                    $StepColor.H += 360
                }
                $StepColor.H %= $Ceiling
            }
            $Ordinals1 = $StepColor.Ordinals

            $Colors[$Line - 1][$Column - 1] = $StepColor.ToRgb()
            $Ordinals2 = $Colors[$Line - 1][$Column - 1].Ordinals
            Write-Debug ("Step ${Line},${Column}: {0:N2}, {1:N2}, {2:N2} => {3:N2}, {4:N2}, {5:N2}" -f $Ordinals1[0], $Ordinals1[1], $Ordinals1[2], $Ordinals2[0], $Ordinals2[1], $Ordinals2[2] )
        }
    }

    if ($Flatten) {
        $Colors.GetEnumerator().GetEnumerator()
    } else {
        ,$Colors
    }

}
#EndRegion '.\Public\Get-Gradient.ps1'
#Region '.\Public\Get-Theme.ps1' 0
function Get-Theme {
    # .EXTERNALHELP Pansies-help.xml
    [CmdletBinding()]
    param(
        # The name of the theme(s) to show. Supports wildcards, and defaults to * everything.
        [string]$Name = "*",

        # If set, only returns themes that include ConsoleColor
        [switch]$ConsoleColors,

        # If set, only returns themes that include PSReadline Colors
        [switch]$PSReadline
    )

    $Name = $Name -replace "((\.theme)?\.psd1)?$" -replace '$', ".theme.psd1"

    foreach($Theme in Join-Path $(
            Get-ConfigurationPath -Scope User -SkipCreatingFolder
            Get-ConfigurationPath -Scope Machine -SkipCreatingFolder
            Join-Path $PSScriptRoot Themes
        ) -ChildPath $Name -Resolve -ErrorAction Ignore ) {
            if ($ConsoleColors -or $PSReadline) {
                $ThemeData = Import-Metadata -Path $Theme
                if($ConsoleColors -and !$ThemeData.ConsoleColors) {
                    continue
                }
                if($PSReadline -and !$ThemeData.PSReadline) {
                    continue
                }
            }
            $Name = if($ThemeData.Name) {
                $ThemeData.Name
            } else {
                [IO.Path]::GetFileName($Theme) -replace "\.theme\.psd1$"
            }
            $Name | Add-Member NoteProperty PSPath $Theme -PassThru |
                    Add-Member NoteProperty Name $Name -PassThru
    }
}
#EndRegion '.\Public\Get-Theme.ps1'
#Region '.\Public\Import-PList.ps1' 0
function Import-PList {
    # .EXTERNALHELP Pansies-help.xml
    [CmdletBinding()]
    param(
        # The path to an XML or binary plist file (e.g. a .tmTheme file)
        [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName, Position = 0)]
        [Alias("PSPath")]
        [string]$Path
    )

    process {
        $Path = Convert-Path $Path

        [PoshCode.Pansies.Parsers.Plist]::ReadPlist($Path)
    }
}
#EndRegion '.\Public\Import-PList.ps1'
#Region '.\Public\Import-Theme.ps1' 0
function Import-Theme {
    # .EXTERNALHELP Pansies-help.xml
    [CmdletBinding()]
    param(
        # A theme to import (can be the name of an installed PANSIES theme, or the full path to a psd1 file)
        [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
        [string]$Name,

        # By default, imported themes will update the default console colors (if they define console colors)
        # If SkipDefault is set, Import-Theme will leave the default Console Colors alone
        [switch]$SkipDefault
    )
    $Theme = ImportTheme $Name

    if ($ConsoleColors = $Theme.ConsoleColors) {
        Write-Verbose "Setting the console palette"

        # Handle setting the default foreground and background
        if($Theme.ConsoleBackground) {
            if($Theme.ConsoleForeground) {
                $ConsoleColors += [RgbColor]$Theme.ConsoleForeground
            } else {
                $ConsoleColors += Get-Complement $Theme.ConsoleBackground
            }
            $ConsoleColors += [RgbColor]$Theme.ConsoleBackground
        } elseif($Theme.ConsoleForeground) {
            $ConsoleColors += [RgbColor]$Theme.ConsoleForeground
            $ConsoleColors += Get-Complement $Theme.ConsoleForeground -ConsoleColor
        } else {
            # As a fall back, always force the background to black and the foreground to white
            # Because if you're in a default PowerShell window, you're using DarkYellow on DarkMagenta, which will be awful
            $ConsoleColors += [RgbColor]"White"
            $ConsoleColors += [RgbColor]"Black"
        }

        # Handle setting the popup foreground and background
        if($Theme.PopupBackground) {
            if($Theme.PopupForeground) {
                $ConsoleColors += [RgbColor]$Theme.PopupForeground
            } else {
                $ConsoleColors += Get-Complement $Theme.PopupBackground
            }
            $ConsoleColors += [RgbColor]$Theme.PopupBackground
        } elseif($Theme.PopupForeground) {
            $ConsoleColors += [RgbColor]$Theme.PopupForeground
            $ConsoleColors += Get-Complement $Theme.PopupForeground -ConsoleColor
        }

        Set-ConsolePalette -Colors $ConsoleColors -Default:(!$SkipDefault)
    }

    if ($PSReadLine = $Theme.PSReadLine) {
        Write-Verbose "Applying PSReadLineOptions"
        Set-PSReadLineOption @PSReadLine
    }

    if ($HostSettings = $Theme.Host) {
        function Update-Host {
            param($HostObject, $Settings)
            foreach ($key in $Settings.Keys) {
                try {
                    Write-Verbose "Applying Host settings: $key"
                    if ($HostObject.$key -is [ConsoleColor]) {
                        Write-Verbose "Converting '$($Settings.$Key)' to ConsoleColor"
                        $HostObject.$key = [ConsoleColor]([RgbColor]::ConsolePalette.FindClosestColorIndex([RgbColor]::new($Settings.$Key)))
                    } elseif ($Settings.$key -is [hashtable]) {
                        Update-Host $HostObject.$key $Settings.$Key
                    } else {
                        $HostObject.$key = $Settings.$Key
                    }
                } catch {
                    Write-Warning "Failed to apply Host '$key' = '$($Settings.$Key)' (it should have been a $($HostObject.$key.GetType().FullName)"
                }
            }
        }
        Update-Host $Host $HostSettings
    }
}
#EndRegion '.\Public\Import-Theme.ps1'
#Region '.\Public\Show-Theme.ps1' 0
function Show-Theme {
    # .EXTERNALHELP Pansies-help.xml
    [OutputType([string])]
    [CmdletBinding(DefaultParameterSetName="CurrentTheme")]
    param(
        [Alias("Theme","PSPath")]
        [Parameter(ValueFromPipelineByPropertyName)]
        [string]$Name,

        [Switch]$Tiny,

        [Switch]$MoreText,

        [Switch]$NoCodeSample
    )
    process {
        if(!$Name) {
            $Palette = Get-ConsolePalette
            ShowPreview $Palette @PSBoundParameters
        } else {
            foreach($Theme in Get-Theme $Name) {
                $Theme = ImportTheme $Theme.PSPath | Add-Member -Type NoteProperty -Name Name -Value $Theme.Name -Passthru -Force
                $Palette = $Theme.ConsoleColors
                $Syntax  = [PSCustomObject]$Theme.PSReadLine.Colors

                $PSBoundParameters['Name'] = $Theme.Name
                ShowPreview $Palette $Syntax @PSBoundParameters
            }
        }
    }
}
#EndRegion '.\Public\Show-Theme.ps1'

# SIG # Begin signature block
# MIIXzgYJKoZIhvcNAQcCoIIXvzCCF7sCAQExCzAJBgU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