Skip to content

Commit

Permalink
Load theme files on first usage of Format-TerminalIcons
Browse files Browse the repository at this point in the history
  • Loading branch information
devblackops committed Nov 17, 2023
1 parent df4c96c commit 118a7b5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
13 changes: 13 additions & 0 deletions Terminal-Icons/Private/Import-XmlThemes.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function Import-XmlThemes {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '')]
param()

$script:iconThemes = Import-Clixml -Path $script:moduleRoot/Data/iconThemes.xml
$script:colorThemes = Import-Clixml -Path $script:moduleRoot/Data/colorThemes.xml
$script:colorSequences = Import-Clixml -Path $script:moduleRoot/Data/colorSequences.xml
$script:glyphs = Import-Clixml -Path $script:moduleRoot/Data/glyphs.xml
$script:current.Themes = @{
Color = $script:colorThemes
Icon = $script:iconThemes
}
}
8 changes: 8 additions & 0 deletions Terminal-Icons/Public/Format-TerminalIcons.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ function Format-TerminalIcons {
[hashtable]$CurrentSettings = $script:current
)

begin {
# Load the theme files on first invocation
if (-not $script:themeFilesLoaded) {
Import-XmlThemes
$script:themeFilesLoaded = $true
}
}

process {
$displayInfo = Resolve-Icon $FileInfo
if ($displayInfo.Icon) {
Expand Down
17 changes: 7 additions & 10 deletions Terminal-Icons/Terminal-Icons.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,15 @@ $userThemePath = Get-ThemeStoragePath
# Load or create default preferences
$prefs = Import-Preferences

# Load builtin theme data
$iconThemes = Import-Clixml -Path $moduleRoot/Data/iconThemes.xml
$colorThemes = Import-Clixml -Path $moduleRoot/Data/colorThemes.xml
$colorSequences = Import-Clixml -Path $moduleRoot/Data/colorSequences.xml
$glyphs = Import-Clixml -Path $moduleRoot/Data/glyphs.xml
# To speed up module load times, the theme files are not imported on module load
# Instead, the they are loaded on the first invocation of `Format-TerminalIcons`
$themeFilesLoaded = $false
$iconThemes = @{}
$colorThemes = @{}
$colorSequences = @{}
$glyphs = @{}

# Set current settings
$current = Get-CurrentSettings
$current.Themes = @{
Color = $colorThemes
Icon = $iconThemes
}

# As of 0.12.0, we no longer save the builtin theme files in the user theme folder
('devblackops_color.xml', 'devblackops_light_color.xml', 'devblackops_icon.xml').ForEach({
Expand Down

0 comments on commit 118a7b5

Please sign in to comment.