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 两版仍绿。
This commit is contained in:
1 parent
187549e2af
commit
60f2ae3e0f
25 files changed
+1708
No files matched your search
@@ -0,0 +1,60 @@
|
||||
param([Parameter(Mandatory=$true)][string]$HostLabel, [Parameter(Mandatory=$true)][string]$OutFile, [int]$WatchSeconds = 2)
|
||||
$lines = New-Object System.Collections.Generic.List[string]
|
||||
function L($s) { $lines.Add($s) }
|
||||
$zh = [string]::Concat([char]0x4E2D, [char]0x6587)
|
||||
$zh2 = [string]::Concat([char]0x4E2D, [char]0x6587, [char]0x5907, [char]0x4EFD)
|
||||
$ascii8 = '12345678'
|
||||
$emoji = [string]::Concat([char]::ConvertFromUtf32(0x1F600))
|
||||
$box = [string]::Concat([char]0x250C, [char]0x2500, [char]0x2510)
|
||||
$boxOdd = [string]::Concat([char]0x250C, [char]0x2502, [char]0x2510)
|
||||
L "===== Chinese / fullwidth width measurement [$HostLabel] ====="
|
||||
L ("PSVersion : " + $PSVersionTable.PSVersion)
|
||||
L ("Console.WindowWidth : " + [Console]::WindowWidth)
|
||||
L ("Console.BufferWidth : " + [Console]::BufferWidth)
|
||||
try { L ("RawUI.WindowSize : " + $Host.UI.RawUI.WindowSize.Width + 'x' + $Host.UI.RawUI.WindowSize.Height) } catch { L ("RawUI.WindowSize THREW: " + $_.Exception.Message) }
|
||||
L ("Console.OutputEncoding : " + [Console]::OutputEncoding.WebName)
|
||||
L ("IsOutputRedirected : " + [Console]::IsOutputRedirected)
|
||||
L ""
|
||||
L ".Length (CHARACTER COUNT) vs REAL COLUMNS:"
|
||||
foreach ($item in @(@('ascii 8 chars ', $ascii8), @('Chinese 2 chars', $zh), @('Chinese 4 chars', $zh2), @('box-drawing 3 ', $box), @('emoji 1 ', $emoji))) {
|
||||
$name = $item[0]; $s = $item[1]
|
||||
$chars = $s.ToCharArray()
|
||||
$codes = ($chars | ForEach-Object { 'U+{0:X4}' -f [int]$_ }) -join ' '
|
||||
$surr = if ($s.Length -gt 0) { ($s.ToCharArray() | Where-Object { [int]$_ -ge 0xD800 -and [int]$_ -le 0xDFFF }).Count } else { 0 }
|
||||
L (" $name : .Length=$($s.Length) UTF16-surrogates=$surr Measure-Object -Character=$(($s | Measure-Object -Character).Characters) codeunits=$codes")
|
||||
}
|
||||
$ms = [string]::Concat($zh, ':', [System.IO.File]::ReadAllText((Join-Path $env:TEMP 'nowhere.txt')) ) 2>$null
|
||||
L ""
|
||||
L "WHICH BUILT-IN CAN MEASURE DISPLAY WIDTH? (probe of plausible names)"
|
||||
$candidates = @('Get-DisplayWidth','Get-StringWidth','Measure-String','Get-VisualLength','Get-ConsoleStringWidth','Format-WideString','Get-WCWidth','Get-CharWidth','Get-TextWidth','Measure-Text','Get-EastAsianWidth')
|
||||
foreach ($c in $candidates) {
|
||||
$cmd = Get-Command $c -ErrorAction SilentlyContinue
|
||||
L (" Get-Command $c -> " + $(if ($cmd) { $cmd.CommandType.ToString() + ' ' + $cmd.Source } else { 'NOT FOUND' }))
|
||||
}
|
||||
L (" [System.Globalization.StringInfo]::ParseCombiningCharacters('$zh').Count = " + [System.Globalization.StringInfo]::ParseCombiningCharacters($zh).Count + " (text-element count, NOT width)")
|
||||
L (" TextInfo: CurrentCulture = " + [System.Globalization.CultureInfo]::CurrentCulture.Name)
|
||||
L (" IsInputRedirected/IsOutputRedirected : " + [Console]::IsInputRedirected + '/' + [Console]::IsOutputRedirected)
|
||||
L ""
|
||||
L "CURSOR POSITION TEST (needs a real console; skipped if redirected)"
|
||||
$skip = $false
|
||||
try { if ([Console]::IsOutputRedirected) { L " SKIPPED: stdout is redirected, [Console]::SetCursorPosition would throw 'The handle is invalid'"; $skip = $true } } catch { $skip = $true }
|
||||
if (-not $skip) {
|
||||
try {
|
||||
[Console]::CursorVisible = $false
|
||||
foreach ($pair in @(@('8 ASCII chars ', $ascii8), @('2 CJK chars ', $zh), @('4 CJK chars ', $zh2), @('3 box-drawing ', $box), @('1 emoji ', $emoji))) {
|
||||
$name = $pair[0]; $s = $pair[1]
|
||||
[Console]::BufferWidth = [Console]::BufferWidth
|
||||
[Console]::SetCursorPosition(0, 10)
|
||||
[Console]::Write($s)
|
||||
$after = [Console]::CursorLeft
|
||||
L (" write '$name' from column 0 -> CursorLeft = $after (implied display columns = $after)")
|
||||
}
|
||||
[Console]::SetCursorPosition(0, 10); [Console]::Write('.' * 40)
|
||||
[Console]::SetCursorPosition(0, 10); [Console]::Write($zh); [Console]::Write('X')
|
||||
L " visual check: expect 'ZhongWenX' where X starts at column 4 (2 CJK = 4 columns)"
|
||||
[Console]::CursorVisible = $true
|
||||
} catch { L (" CURSOR TEST THREW: " + $_.Exception.Message) }
|
||||
}
|
||||
[System.IO.File]::WriteAllLines($OutFile, $lines, (New-Object System.Text.UTF8Encoding($false)))
|
||||
Write-Host ("[width-probe {0}] done, wrote {1}" -f $HostLabel, $OutFile) -ForegroundColor Yellow
|
||||
if ($WatchSeconds -gt 0) { Start-Sleep -Seconds $WatchSeconds }
|
||||
Reference in new issue
Block a user