refactor(windows scripts): remove BOM and improve UTF-8 handling
This commit is contained in:
+19
-18
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
LXS - Common library (Windows)
|
||||
|
||||
Sourced by windows\lxs.ps1 and every sub-script. Mirrors linux/lib/common.sh:
|
||||
@@ -11,7 +11,7 @@
|
||||
#>
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# Console setup — UTF-8 output (box drawing chars) and VT sequences (colors).
|
||||
# Console setup - UTF-8 output (box drawing chars) and VT sequences (colors).
|
||||
# Both are best-effort: a console that refuses either falls back to plain text.
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@@ -26,7 +26,7 @@ function Initialize-LxsConsole {
|
||||
[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding $false
|
||||
$script:LxsUnicodeEnabled = $true
|
||||
} catch {
|
||||
# Redirected output or a locked-down host — fall back to ASCII rules.
|
||||
# Redirected output or a locked-down host - fall back to ASCII rules.
|
||||
$script:LxsUnicodeEnabled = $false
|
||||
}
|
||||
|
||||
@@ -77,14 +77,14 @@ public static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);
|
||||
Initialize-LxsConsole
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# UI helpers — title + horizontal rule, no closed box. Mirrors common.sh.
|
||||
# UI helpers - title + horizontal rule, no closed box. Mirrors common.sh.
|
||||
#
|
||||
# Show-LxsBoxTop "TITLE" "RIGHT" → TITLE [ RIGHT ]
|
||||
# ──────────────────────────────────
|
||||
# Show-LxsBoxMid "SECTION" → ─ SECTION ────────────────────────
|
||||
# Show-LxsBoxBottom → ──────────────────────────────────
|
||||
# Show-LxsMenuItem "01" "LABEL" "desc" → [01] LABEL // desc
|
||||
# Show-LxsPrompt → >
|
||||
# Show-LxsBoxTop "TITLE" "RIGHT" -> TITLE [ RIGHT ]
|
||||
# ----------------------------------
|
||||
# Show-LxsBoxMid "SECTION" -> - SECTION ------------------------
|
||||
# Show-LxsBoxBottom -> ----------------------------------
|
||||
# Show-LxsMenuItem "01" "LABEL" "desc" -> [01] LABEL // desc
|
||||
# Show-LxsPrompt -> >
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
function Get-LxsTermWidth {
|
||||
@@ -193,7 +193,7 @@ function Write-LxsErr { param([string]$Message) Write-Host "$($script:Red)[KO]$
|
||||
# Sub-scripts read $args by hand, exactly like the bash `for arg in "$@"` loop.
|
||||
# A param([switch]) block cannot be used: LXS invokes sub-scripts with a
|
||||
# splatted string[] (& $script @Arguments), and PowerShell binds every element
|
||||
# of a splatted array positionally — '-Yes' would land in $args as a value and
|
||||
# of a splatted array positionally - '-Yes' would land in $args as a value and
|
||||
# the switch would silently stay $false.
|
||||
#
|
||||
# $opts = Read-LxsFlags -Arguments $args -Known @('-Yes', '-y', '-Help')
|
||||
@@ -255,9 +255,9 @@ function Confirm-LxsAction {
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# Progress helpers
|
||||
#
|
||||
# Invoke-LxsSpinner — external command, output captured to a log file,
|
||||
# Invoke-LxsSpinner - external command, output captured to a log file,
|
||||
# animated spinner (mirrors run_spinner in common.sh).
|
||||
# Invoke-LxsStep — inline PowerShell work; prints [..] then [OK]/[KO].
|
||||
# Invoke-LxsStep - inline PowerShell work; prints [..] then [OK]/[KO].
|
||||
#
|
||||
# Both return $true on success. Log file: $env:LXS_LOG_FILE or %TEMP%\lxs.log
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
@@ -419,7 +419,7 @@ function Assert-LxsWindows {
|
||||
Write-LxsWarn "Windows build $build is older than the supported floor ($MinimumBuild). Some tools may fail."
|
||||
}
|
||||
} catch {
|
||||
# Not fatal — CIM can be unavailable in stripped-down images.
|
||||
# Not fatal - CIM can be unavailable in stripped-down images.
|
||||
}
|
||||
return $true
|
||||
}
|
||||
@@ -435,7 +435,8 @@ function Test-LxsDiskSpace {
|
||||
$seen = @{}
|
||||
foreach ($path in $Paths) {
|
||||
if ([string]::IsNullOrWhiteSpace($path)) { continue }
|
||||
$root = try { [System.IO.Path]::GetPathRoot((Resolve-Path $path -ErrorAction Stop).Path) } catch { $null }
|
||||
$root = $null
|
||||
try { $root = [System.IO.Path]::GetPathRoot((Resolve-Path $path -ErrorAction Stop).Path) } catch { $root = $null }
|
||||
if (-not $root) { $root = [System.IO.Path]::GetPathRoot($path) }
|
||||
if (-not $root) {
|
||||
Write-LxsErr "Cannot read disk usage for $path"
|
||||
@@ -478,7 +479,7 @@ function Assert-LxsWinget {
|
||||
}
|
||||
|
||||
# `winget list` is slow (a second or more per call), and a package menu asks
|
||||
# about a dozen ids at once — so the full listing is fetched once and reused.
|
||||
# about a dozen ids at once - so the full listing is fetched once and reused.
|
||||
$script:LxsWingetListCache = $null
|
||||
|
||||
function Get-LxsWingetListText {
|
||||
@@ -535,7 +536,7 @@ function Install-LxsWingetPackage {
|
||||
Clear-LxsWingetListCache
|
||||
|
||||
if (-not $installed) {
|
||||
Write-Host "$($script:Gray) Package id: $Id — check it with: winget search --id $Id$($script:NC)"
|
||||
Write-Host "$($script:Gray) Package id: $Id - check it with: winget search --id $Id$($script:NC)"
|
||||
}
|
||||
return $installed
|
||||
}
|
||||
@@ -717,7 +718,7 @@ function Add-LxsUserPath {
|
||||
$current = [Environment]::GetEnvironmentVariable('Path', 'User')
|
||||
if ($null -eq $current) { $current = '' }
|
||||
# Windows paths are case-insensitive and a trailing backslash is
|
||||
# meaningless, so compare normalized — otherwise every run appends a
|
||||
# meaningless, so compare normalized - otherwise every run appends a
|
||||
# near-duplicate entry.
|
||||
$normalized = $Directory.TrimEnd('\')
|
||||
foreach ($entry in ($current -split ';')) {
|
||||
|
||||
Reference in New Issue
Block a user