Skip to content

Commit 5afeec0

Browse files
committed
Support EZTheme
+semver:feature
1 parent 325ed9e commit 5afeec0

8 files changed

+125
-45
lines changed

Source/PowerLine.format.ps1xml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Configuration>
2+
<ViewDefinitions>
3+
<View>
4+
<Name>PowerLine-Preview</Name>
5+
<ViewSelectedBy>
6+
<TypeName>PowerLine.Theme</TypeName>
7+
</ViewSelectedBy>
8+
<CustomControl>
9+
<CustomEntries>
10+
<CustomEntry>
11+
<CustomItem>
12+
<ExpressionBinding>
13+
<ScriptBlock>
14+
$CurrentTheme = Get-PowerLineTheme
15+
$_ | Set-PowerLineTheme
16+
$( Write-PowerLinePrompt )
17+
$CurrentTheme | Set-PowerLineTheme
18+
</ScriptBlock>
19+
</ExpressionBinding>
20+
</CustomItem>
21+
</CustomEntry>
22+
</CustomEntries>
23+
</CustomControl>
24+
</View>
25+
</ViewDefinitions>
26+
</Configuration>

Source/PowerLine.psd1

+10-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
RootModule = 'PowerLine.psm1'
55

66
# Version number of this module.
7-
ModuleVersion = '3.1.2'
7+
ModuleVersion = '3.2.0'
88

99
# Supported PSEditions
1010
# CompatiblePSEditions = @()
@@ -34,7 +34,7 @@ PowerShellVersion = '5.0.0'
3434
# TypesToProcess = @("PowerLine.types.ps1xml")
3535

3636
# Format files (.ps1xml) to be loaded when importing this module
37-
# FormatsToProcess = @()
37+
FormatsToProcess = @("PowerLine.format.ps1xml")
3838

3939
RequiredModules = @(
4040
@{ModuleName="Configuration"; ModuleVersion="1.1.0"}
@@ -43,7 +43,7 @@ RequiredModules = @(
4343
# RequiredAssemblies = "lib\PowerLine.dll"
4444

4545
# Functions 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 functions to export.
46-
FunctionsToExport = 'Set-PowerLinePrompt', 'Write-PowerlinePrompt', 'Export-PowerLinePrompt', 'Add-PowerLineBlock', 'Remove-PowerLineBlock', 'New-PromptText', 'Get-Elapsed', 'Get-ErrorCount', 'Get-SegmentedPath', 'Get-ShortenedPath', 'Test-Success', 'Test-Elevation'
46+
FunctionsToExport = 'Set-PowerLinePrompt', 'Write-PowerlinePrompt', 'Export-PowerLinePrompt', 'Get-PowerLineTheme', 'Add-PowerLineBlock', 'Remove-PowerLineBlock', 'New-PromptText', 'Get-Elapsed', 'Get-ErrorCount', 'Get-SegmentedPath', 'Get-ShortenedPath', 'Test-Success', 'Test-Elevation'
4747

4848
# Cmdlets 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 cmdlets to export.
4949
CmdletsToExport = @()
@@ -52,7 +52,7 @@ CmdletsToExport = @()
5252
VariablesToExport = @()
5353

5454
# 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.
55-
AliasesToExport = 'New-PowerLineBlock'
55+
AliasesToExport = 'New-PowerLineBlock', 'Set-PowerLineTheme'
5656

5757
# List of all files packaged with this module
5858
# FileList = @()
@@ -61,7 +61,7 @@ AliasesToExport = 'New-PowerLineBlock'
6161
PrivateData = @{
6262
PSData = @{
6363
# Tags applied to this module. These help with module discovery in online galleries.
64-
Tags = @("Prompt","ANSI","VirtualTerminal")
64+
Tags = @("Prompt", "ANSI", "VirtualTerminal", "EzTheme")
6565

6666
# A URL to the license for this module.
6767
LicenseUri = 'https://github.com/Jaykul/PowerLine/blob/master/LICENSE'
@@ -74,6 +74,7 @@ PrivateData = @{
7474

7575
# ReleaseNotes of this module
7676
ReleaseNotes = '
77+
3.2.0: Add support for EzTheme
7778
3.1.2: Fix the -HideError switch being backwards
7879
Log non-terminating errors
7980
3.1.1: Fix default insertion point when -Timeline or -Newline are used
@@ -83,6 +84,10 @@ PrivateData = @{
8384
Fixes longstanding bug where right-aligned columns would sometimes leak background color
8485
'
8586
} # End of PSData hashtable
87+
"EzTheme" = @{
88+
Get = 'Get-PowerLineTheme'
89+
Set = 'Set-PowerLineTheme'
90+
}
8691
} # End of PrivateData hashtable
8792

8893
# HelpInfo URI of this module

Source/Public/Export-PowerLinePrompt.ps1

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ function Export-PowerLinePrompt {
55
$Local:Configuration = $Script:PowerLineConfig
66
$Configuration.Prompt = [ScriptBlock[]]$global:Prompt
77
$Configuration.Colors = [PoshCode.Pansies.RgbColor[]]$global:Prompt.Colors
8-
9-
108
@{
119
ExtendedCharacters = [PoshCode.Pansies.Entities]::ExtendedCharacters
1210
EscapeSequences = [PoshCode.Pansies.Entities]::EscapeSequences
1311
PowerLineConfig = $Script:PowerLineConfig
1412
} | Export-Configuration -AsHashtable
1513

16-
}
14+
}

Source/Public/Get-PowerLineTheme.ps1

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function Get-PowerLineTheme {
2+
<#
3+
.SYNOPSIS
4+
Get the themeable PowerLine settings
5+
#>
6+
[CmdletBinding()]
7+
param()
8+
9+
$Local:Configuration = $Script:PowerLineConfig
10+
$Configuration.Prompt = [ScriptBlock[]]$global:Prompt
11+
$Configuration.Colors = [PoshCode.Pansies.RgbColor[]]$global:Prompt.Colors
12+
13+
$null = $Configuration.Remove("DefaultAddIndex")
14+
15+
$Configuration.PowerLineCharacters = @{
16+
'ColorSeparator' = [PoshCode.Pansies.Entities]::ExtendedCharacters['ColorSeparator']
17+
'ReverseColorSeparator' = [PoshCode.Pansies.Entities]::ExtendedCharacters['ReverseColorSeparator']
18+
'Separator' = [PoshCode.Pansies.Entities]::ExtendedCharacters['Separator']
19+
'ReverseSeparator' = [PoshCode.Pansies.Entities]::ExtendedCharacters['ReverseSeparator']
20+
}
21+
22+
$Result = New-Object PSObject -Property $Configuration
23+
$Result.PSTypeNames.Insert(0, "PowerLine.Theme")
24+
$Result
25+
}

Source/Public/Set-PowerLinePrompt.ps1

+31-6
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,68 @@ function Set-PowerLinePrompt {
2020
# Set-PowerLinePrompt -FullColor
2121
#
2222
# Sets the powerline prompt and forces the assumption of full RGB color support instead of 16 color
23+
[Alias("Set-PowerLineTheme")]
2324
[CmdletBinding(DefaultParameterSetName = "PowerLine")]
2425
param(
2526
# A script which outputs a string used to update the Window Title each time the prompt is run
27+
[Parameter(ValueFromPipelineByPropertyName)]
2628
[scriptblock]$Title,
2729

2830
# Keep the .Net Current Directory in sync with PowerShell's
31+
[Parameter(ValueFromPipelineByPropertyName)]
2932
[Alias("CurrentDirectory")]
3033
[switch]$SetCurrentDirectory,
3134

3235
# If true, set the [PowerLine.Prompt] static members to extended characters from PowerLine fonts
33-
[Parameter(ParameterSetName = "PowerLine")]
36+
[Parameter(ParameterSetName = "PowerLine", ValueFromPipelineByPropertyName)]
3437
[switch]$PowerLineFont,
3538

3639
# If true, set the [PowerLine.Prompt] static members to characters available in Consolas and Courier New
3740
[Parameter(ParameterSetName = "Reset")]
3841
[switch]$ResetSeparators,
3942

4043
# If true, assume full color support, otherwise normalize to 16 ConsoleColor
41-
[Parameter()]
44+
[Parameter(ValueFromPipelineByPropertyName)]
4245
[switch]$FullColor,
4346

4447
# If true, adds ENABLE_VIRTUAL_TERMINAL_PROCESSING to the console output mode. Useful on PowerShell versions that don't restore the console
45-
[Parameter()]
48+
[Parameter(ValueFromPipelineByPropertyName)]
4649
[switch]$RestoreVirtualTerminal,
4750

4851
# Add a "I ♥ PS" on a line by itself to it's prompt (using ConsoleColors, to keep it safe from PSReadLine)
52+
[Parameter(ValueFromPipelineByPropertyName)]
4953
[switch]$Newline,
5054

5155
# Add a right-aligned timestamp before the newline (implies Newline)
56+
[Parameter(ValueFromPipelineByPropertyName)]
5257
[switch]$Timestamp,
5358

59+
# Prevent errors in the prompt from being shown (like the normal PowerShell behavior)
60+
[Parameter(ValueFromPipelineByPropertyName)]
5461
[switch]$HideErrors,
5562

5663
# One or more scriptblocks you want to use as your new prompt
64+
[Parameter(ValueFromPipelineByPropertyName)]
5765
[System.Collections.Generic.List[ScriptBlock]]$Prompt,
5866

5967
# One or more colors you want to use as the prompt background
68+
[Parameter(ValueFromPipelineByPropertyName)]
6069
[System.Collections.Generic.List[PoshCode.Pansies.RgbColor]]$Colors,
6170

6271
# If set, calls Export-PowerLinePrompt
63-
[Switch]$Save
64-
72+
[Parameter()]
73+
[Switch]$Save,
74+
75+
# A hashtable of extended characters you can use in PowerLine output (or any PANSIES output) with HTML entity syntax like "&hearts;". By default you have the HTML named entities plus the Branch (), Lock (), Gear (⛯) and Power (⚡) icons. You can add any characters you wish, but to change the Powerline theme, you need to specify these four keys using matching pairs:
76+
#
77+
# @{
78+
# "ColorSeparator" = ""
79+
# "ReverseColorSeparator" = ""
80+
# "Separator" = ""
81+
# "ReverseSeparator" = ""
82+
# }
83+
[Parameter(ValueFromPipelineByPropertyName)]
84+
[hashtable]$PowerLineCharacters
6585
)
6686
if ($null -eq $script:OldPrompt) {
6787
$script:OldPrompt = $function:global:prompt
@@ -95,7 +115,7 @@ function Set-PowerLinePrompt {
95115
}
96116
}
97117

98-
if ($PowerLineConfig.FullColor -eq $Null -and $Host.UI.SupportsVirtualTerminal) {
118+
if ($Null -eq $PowerLineConfig.FullColor -and $Host.UI.SupportsVirtualTerminal) {
99119
$PowerLineConfig.FullColor = (Get-Process -Id $global:Pid).MainWindowHandle -ne 0
100120
}
101121

@@ -141,6 +161,11 @@ function Set-PowerLinePrompt {
141161
[PoshCode.Pansies.Entities]::ExtendedCharacters['Branch'] = [char]0xE0A0
142162
[PoshCode.Pansies.Entities]::ExtendedCharacters['Gear'] = [char]0x26EF
143163
}
164+
if ($PowerLineCharacters) {
165+
foreach ($key in $PowerLineCharacters.Keys) {
166+
[PoshCode.Pansies.Entities]::ExtendedCharacters["$key"] = $PowerLineCharacters[$key].ToString()
167+
}
168+
}
144169

145170
if($null -eq $PowerLineConfig.DefaultAddIndex) {
146171
$PowerLineConfig.DefaultAddIndex = -1

Source/postfix.ps1

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if (Get-Module EzTheme -ErrorAction SilentlyContinue) {
2+
Get-ModuleTheme | Set-PowerLineTheme
3+
}

build.ps1

+20-31
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,26 @@
1-
[CmdletBinding()]
1+
#requires -Module ModuleBuilder
2+
[CmdletBinding(SupportsShouldProcess)]
23
param(
3-
[ValidateSet("Release","Debug")]
4-
$Configuration = "Release"
5-
)
6-
7-
Push-Location $PSScriptRoot
8-
try {
9-
$BuildTimer = New-Object System.Diagnostics.Stopwatch
10-
$BuildTimer.Start()
4+
# A specific folder to build into
5+
$OutputDirectory,
116

12-
$ModuleName = Split-Path $PSScriptRoot -Leaf
13-
$ErrorActionPreference = "Stop"
14-
$version = Get-Metadata ".\Source\${ModuleName}.psd1"
15-
$folder = mkdir $version -Force
7+
# The version of the output module
8+
[Alias("ModuleVersion")]
9+
[string]$SemVer
10+
)
1611

17-
Get-ChildItem Source -filter "${ModuleName}.*" |
18-
Copy-Item -Dest $folder.FullName -PassThru |
19-
ForEach {
20-
Write-Host " $($_.Name) -> $($_.FullName)"
21-
}
12+
# Sanitize parameters to pass to Build-Module
13+
$ErrorActionPreference = "Stop"
14+
Push-Location $PSScriptRoot -StackName BuildModuleScript
2215

23-
Get-ChildItem Source\Private, Source\Public -Filter *.ps1 -Recurse |
24-
Sort-Object Directory, Name |
25-
Get-Content |
26-
Set-Content "$($folder.FullName)\${ModuleName}.psm1"
27-
Write-Host " PowerLine -> $($folder.FullName)\${ModuleName}.psm1"
16+
if (-not $Semver -and (Get-Command gitversion -ErrorAction Ignore)) {
17+
if ($semver = gitversion -showvariable SemVer) {
18+
$null = $PSBoundParameters.Add("SemVer", $SemVer)
19+
}
20+
}
2821

29-
Write-Host
30-
Write-Host "Module build finished." -ForegroundColor Green
31-
$BuildTimer.Stop()
32-
Write-Host "Total Elapsed $($BuildTimer.Elapsed.ToString("hh\:mm\:ss\.ff"))"
33-
} catch {
34-
throw $_
22+
try {
23+
Build-Module @PSBoundParameters -Target CleanBuild
3524
} finally {
36-
Pop-Location
37-
}
25+
Pop-Location -StackName BuildModuleScript
26+
}

build.psd1

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Use this file to override the default parameter values used by the `Build-Module`
2+
# command when building the module (see `Get-Help Build-Module -Full` for details).
3+
@{
4+
ModuleManifest = "Source/PowerLine.psd1"
5+
OutputDirectory = "../"
6+
VersionedOutputDirectory = $true
7+
CopyDirectories = @('Examples','PowerLine.format.ps1xml','Configuration.psd1')
8+
Postfix = "postfix.ps1"
9+
}

0 commit comments

Comments
 (0)