Files
BakNRet/.scratch/_probe/vt-probe.ps1
T
Shuery 60f2ae3e0f docs: TUI 与入口重组的设计记录(4 条 ADR + 验收锚点)
grilling 三轮把设计树走完了,这里把它落成文件,避免决策只活在对话里。

ADR-0010 零依赖自研 TUI:三个候选库全部实测排除 —— ConsoleGuiTools 的 PSGallery 元数据声明最低 7.2(5.1 装不上);Spectre.Console 0.49.1 能在 5.1 加载但要塞 4 个第三方 DLL 且不支持鼠标;Terminal.Gui 1.15.0 能反射接线到真的渲染出窗口,但 Application.Shutdown() 在两端都抛 NRE。同时记下两条实测坑:无控制台时 $Host.UI.SupportsVirtualTerminal 会撒谎返回 True(第一道闸门必须是 [Console]::IsOutputRedirected),以及 5.1 的 RawUI.LengthInBufferCells 对中文返回 2、对边框字符返回 6(都不能用来排版)。

ADR-0011 进度回调这个例外:它是注入点不是状态,无头路径为 $null 时行为与今天完全一致。

ADR-0012 入口改名与垫片:这次留垫片而 Common.psm1 直接删,是因为前者是外部接口(断了是静默没用)后者是内部实现(断了当场报错)。并纠正了自己的一个伪前提 —— 本机实测没有注册任何 BakNRet 计划任务。

ADR-0013 TUI 写配置:外科式改写 + 校验通过才原子替换。硬事实是 SoftwareCatalog.psd1 根本不能被 Import-PowerShellDataFile 读入(动态表达式),任何"解析成对象再序列化"的方案都会毁掉表达式与注释。

.scratch/tui/spec.md 是这次改造的验收锚点:9 条已定决策 + 三轮的判据 + 风险表。

验收:Parse 两版仍绿。
2026-09-27 15:27:01 +08:00

38 lines
3.5 KiB
PowerShell

param([Parameter(Mandatory=$true)][string]$OutFile)
$lines = New-Object System.Collections.Generic.List[string]
function L($s) { $lines.Add($s) }
L ("PSVersion: " + $PSVersionTable.PSVersion + " PSEdition: " + $PSVersionTable.PSEdition)
L ""
L "### (1) can the host be asked whether it wants VT? ###"
$p = $Host.UI | Get-Member -Name SupportsVirtualTerminal -MemberType Property -ErrorAction SilentlyContinue
L (" [bool](`$Host.UI | Get-Member -Name SupportsVirtualTerminal) = " + [bool]$p + " (a REAL property, not a stub)")
$rw = $Host.UI.RawUI | Get-Member -Name SupportsVirtualTerminal -MemberType Property -ErrorAction SilentlyContinue
L (" [bool](`$Host.UI.RawUI | Get-Member -Name SupportsVirtualTerminal) = " + [bool]$rw + " (does NOT exist on RawUI)")
L (" value of `$Host.UI.SupportsVirtualTerminal = " + [string]$Host.UI.SupportsVirtualTerminal)
L (" property TypeName: " + $(if ($p) { $p.Definition } else { 'n/a' }))
L ""
L "### (2) is it WRITABLE? (the documented way to turn VT off: `$Host.UI.SupportsVirtualTerminal = `$false) ###"
$before = [string]$Host.UI.SupportsVirtualTerminal
try { $Host.UI.SupportsVirtualTerminal = $false; $setOk = $true } catch { $setOk = $false; L (" setter THREW: " + $_.Exception.Message) }
if ($setOk) { L (" set `$false -> value is now [" + [string]$Host.UI.SupportsVirtualTerminal + "] (before [$before])") }
try { $Host.UI.SupportsVirtualTerminal = $true } catch {}
L (" restored -> value is now [" + [string]$Host.UI.SupportsVirtualTerminal + "]")
L ""
L "### (3) WIDTH / HEIGHT REPORTING WHEN THERE IS NO CONSOLE (scheduled-task-like) ###"
L (" [Console]::IsOutputRedirected = " + [Console]::IsOutputRedirected)
try { L (" [Console]::WindowWidth = " + [Console]::WindowWidth) } catch { L (" [Console]::WindowWidth THREW: " + $_.Exception.Message) }
try { L (" [Console]::BufferWidth = " + [Console]::BufferWidth) } catch { L (" [Console]::BufferWidth THREW: " + $_.Exception.Message) }
try { L (" `$Host.UI.RawUI.WindowSize = " + $Host.UI.RawUI.WindowSize.Width + 'x' + $Host.UI.RawUI.WindowSize.Height + " <-- WRONG/hidden console, does not throw") } catch { L (" RawUI.WindowSize THREW: " + $_.Exception.Message) }
try { [Console]::SetCursorPosition(2, 2); L " [Console]::SetCursorPosition = OK" } catch { L (" [Console]::SetCursorPosition THREW: " + $_.Exception.Message) }
try { $c = New-Object System.Management.Automation.Host.Coordinates 2, 2; $Host.UI.RawUI.CursorPosition = $c; L (" `$Host.UI.RawUI.CursorPosition = OK -> " + $Host.UI.RawUI.CursorPosition.X + ',' + $Host.UI.RawUI.CursorPosition.Y) } catch { L (" RawUI.CursorPosition setter THREW: " + $_.Exception.Message) }
L ""
L "### (4) EXIT CODE PATH (the two entry scripts end with exit <code>) ###"
L (" `$LASTEXITCODE before = " + $LASTEXITCODE)
L " (run: powershell -File x.ps1 ; echo %ERRORLEVEL%)"
L "### (5) [Console]::ReadKey / RawUI.ReadKey availability ###"
try { L (" `$Host.UI.RawUI.KeyAvailable = " + $Host.UI.RawUI.KeyAvailable) } catch { L (" RawUI.KeyAvailable THREW: " + $_.Exception.Message) }
try { L (" [Console]::KeyAvailable = " + [Console]::KeyAvailable) } catch { L (" [Console]::KeyAvailable THREW: " + $_.Exception.Message) }
L (" RawUI members: " + (($Host.UI.RawUI | Get-Member -MemberType Property,Method | Select-Object -ExpandProperty Name) -join ','))
[System.IO.File]::WriteAllLines($OutFile, $lines, (New-Object System.Text.UTF8Encoding($false)))
Write-Host ("[vt-probe {0}] wrote {1}" -f $PSVersionTable.PSVersion, $OutFile) -ForegroundColor Yellow