From ca186bfa8414a5f2538dc9649fc74dc1aacc13a4 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Mon, 23 Mar 2026 17:10:16 +0800 Subject: [PATCH] fix(windows): restore complete visual defaults --- lib/core/base.ps1 | 28 +++++++++++++++++++++++++-- lib/core/log.ps1 | 41 +--------------------------------------- tests/Commands.Tests.ps1 | 28 +++++++++++++++++++++++++++ tests/Core.Tests.ps1 | 3 +++ 4 files changed, 58 insertions(+), 42 deletions(-) diff --git a/lib/core/base.ps1 b/lib/core/base.ps1 index 9f6b777..a0a2dc9 100644 --- a/lib/core/base.ps1 +++ b/lib/core/base.ps1 @@ -13,7 +13,7 @@ $script:MOLE_BASE_LOADED = $true # Color Definitions (ANSI escape codes for modern terminals) # ============================================================================ $script:ESC = [char]27 -$script:Colors = @{ +$script:DefaultColors = @{ Green = "$ESC[0;32m" Blue = "$ESC[0;34m" Cyan = "$ESC[0;36m" @@ -29,7 +29,7 @@ $script:Colors = @{ # ============================================================================ # Icon Definitions # ============================================================================ -$script:Icons = @{ +$script:DefaultIcons = @{ Confirm = [char]0x25CE # ◎ Admin = [char]0x2699 # ⚙ Success = [char]0x2713 # ✓ @@ -47,6 +47,30 @@ $script:Icons = @{ Trash = [char]0x2718 # ✘ (trash substitute) } +function Initialize-MoleVisualDefaults { + if (-not ($script:Colors -is [hashtable])) { + $script:Colors = @{} + } + + foreach ($entry in $script:DefaultColors.GetEnumerator()) { + if (-not $script:Colors.ContainsKey($entry.Key)) { + $script:Colors[$entry.Key] = $entry.Value + } + } + + if (-not ($script:Icons -is [hashtable])) { + $script:Icons = @{} + } + + foreach ($entry in $script:DefaultIcons.GetEnumerator()) { + if (-not $script:Icons.ContainsKey($entry.Key)) { + $script:Icons[$entry.Key] = $entry.Value + } + } +} + +Initialize-MoleVisualDefaults + # ============================================================================ # Global Configuration Constants # ============================================================================ diff --git a/lib/core/log.ps1 b/lib/core/log.ps1 index 879b485..dc291fb 100644 --- a/lib/core/log.ps1 +++ b/lib/core/log.ps1 @@ -11,46 +11,7 @@ $script:MOLE_LOG_LOADED = $true # Import base module $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path . "$scriptDir\base.ps1" - -# Fallbacks in case base.ps1 did not initialize icons/colors in this scope -if (-not ($script:Icons -is [hashtable])) { - $script:Icons = @{} -} - -$iconDefaults = @{ - List = "*" - Success = "+" - Warning = "!" - Error = "x" - DryRun = ">" - Arrow = ">" -} - -foreach ($key in $iconDefaults.Keys) { - if (-not $script:Icons.ContainsKey($key)) { - $script:Icons[$key] = $iconDefaults[$key] - } -} - -if (-not ($script:Colors -is [hashtable])) { - $script:Colors = @{} -} - -$colorDefaults = @{ - Cyan = "" - Green = "" - Yellow = "" - Red = "" - Gray = "" - PurpleBold = "" - NC = "" -} - -foreach ($key in $colorDefaults.Keys) { - if (-not $script:Colors.ContainsKey($key)) { - $script:Colors[$key] = $colorDefaults[$key] - } -} +Initialize-MoleVisualDefaults # ============================================================================ # Log Configuration diff --git a/tests/Commands.Tests.ps1 b/tests/Commands.Tests.ps1 index 618aa3b..ac1be19 100644 --- a/tests/Commands.Tests.ps1 +++ b/tests/Commands.Tests.ps1 @@ -37,6 +37,20 @@ Describe "Clean Command" { # If we got here without exception, test passes $true | Should -Be $true } + + It "Should not throw missing Solid property errors during dry-run startup" { + $job = Start-Job -ScriptBlock { + param($binDir) + & powershell -ExecutionPolicy Bypass -File "$binDir\clean.ps1" -DryRun 2>&1 + } -ArgumentList $script:BinDir + + Start-Sleep -Seconds 3 + $output = (Receive-Job $job -Keep 2>&1 | Out-String) + Stop-Job $job -ErrorAction SilentlyContinue + Remove-Job $job -Force -ErrorAction SilentlyContinue + + $output | Should -Not -Match "property 'Solid' cannot be found|找不到属性.?Solid" + } } } @@ -163,6 +177,20 @@ Describe "Main Entry Point" { $result | Should -Not -BeNullOrEmpty $result -join "`n" | Should -Match "Mole|v\d+\.\d+" } + + It "Should not throw missing Solid property errors during menu startup" { + $job = Start-Job -ScriptBlock { + param($molePath) + & powershell -ExecutionPolicy Bypass -File $molePath 2>&1 + } -ArgumentList $script:MolePath + + Start-Sleep -Seconds 3 + $output = (Receive-Job $job -Keep 2>&1 | Out-String) + Stop-Job $job -ErrorAction SilentlyContinue + Remove-Job $job -Force -ErrorAction SilentlyContinue + + $output | Should -Not -Match "property 'Solid' cannot be found|找不到属性.?Solid" + } It "Should list available commands in help" { $result = & powershell -ExecutionPolicy Bypass -File $script:MolePath -ShowHelp 2>&1 diff --git a/tests/Core.Tests.ps1 b/tests/Core.Tests.ps1 index 937b6f3..1423b69 100644 --- a/tests/Core.Tests.ps1 +++ b/tests/Core.Tests.ps1 @@ -31,6 +31,9 @@ Describe "Base Module" { $script:Icons.Success | Should -Not -BeNullOrEmpty $script:Icons.Error | Should -Not -BeNullOrEmpty $script:Icons.Warning | Should -Not -BeNullOrEmpty + $script:Icons.Solid | Should -Not -BeNullOrEmpty + $script:Icons.Admin | Should -Not -BeNullOrEmpty + $script:Icons.Trash | Should -Not -BeNullOrEmpty } }