1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-23 14:10:07 +00:00

fix(windows): restore complete visual defaults

This commit is contained in:
Tw93
2026-03-23 17:10:16 +08:00
parent f50d1227ee
commit ca186bfa84
4 changed files with 58 additions and 42 deletions

View File

@@ -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
# ============================================================================

View File

@@ -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

View File

@@ -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

View File

@@ -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
}
}