From f91cf05bc80ae7b7fe4c2205576115d7f2f9f940 Mon Sep 17 00:00:00 2001 From: tw93 Date: Mon, 2 Feb 2026 17:47:03 +0800 Subject: [PATCH] feat: add default icons and colors fallback in logging module --- lib/core/log.ps1 | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lib/core/log.ps1 b/lib/core/log.ps1 index b1849bf..879b485 100644 --- a/lib/core/log.ps1 +++ b/lib/core/log.ps1 @@ -12,6 +12,46 @@ $script:MOLE_LOG_LOADED = $true $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] + } +} + # ============================================================================ # Log Configuration # ============================================================================