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,58 @@
|
||||
$outFile = $args[0]
|
||||
if (-not $outFile) { $outFile = Join-Path $env:TEMP 'noconsole-probe.txt' }
|
||||
$lines = New-Object System.Collections.Generic.List[string]
|
||||
function L($s) { $lines.Add($s); Write-Host $s }
|
||||
$src = @"
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
public static class K32b {
|
||||
[DllImport("kernel32.dll", SetLastError=true)] public static extern bool AllocConsole();
|
||||
[DllImport("kernel32.dll", SetLastError=true)] public static extern bool FreeConsole();
|
||||
[DllImport("kernel32.dll")] public static extern IntPtr GetStdHandle(int n);
|
||||
[DllImport("kernel32.dll", SetLastError=true)] public static extern bool GetConsoleMode(IntPtr h, out uint m);
|
||||
[DllImport("kernel32.dll", SetLastError=true)] public static extern bool SetConsoleMode(IntPtr h, uint m);
|
||||
[DllImport("kernel32.dll")] public static extern IntPtr GetConsoleWindow();
|
||||
[DllImport("kernel32.dll")] public static extern uint GetConsoleOutputCP();
|
||||
}
|
||||
"@
|
||||
Add-Type -TypeDefinition $src -ErrorAction Stop
|
||||
L "##### PART A: no console attached (stdout redirected) #####"
|
||||
L ("PSVersion : " + $PSVersionTable.PSVersion)
|
||||
L ("IsOutputRedirected : " + [Console]::IsOutputRedirected)
|
||||
L ("GetConsoleWindow : 0x{0:X}" -f ([K32b]::GetConsoleWindow().ToInt64()))
|
||||
L ("Host.UI.SupportsVirtualTerminal (property exists? " + [bool]($Host.UI | Get-Member -Name SupportsVirtualTerminal -ErrorAction SilentlyContinue) + ") = " + [string]$Host.UI.SupportsVirtualTerminal)
|
||||
L ("RawUI has SupportsVirtualTerminal? " + [bool]($Host.UI.RawUI | Get-Member -Name SupportsVirtualTerminal -ErrorAction SilentlyContinue))
|
||||
$m = 0; $ok = [K32b]::GetConsoleMode([K32b]::GetStdHandle(-11), [ref]$m); $err = [Runtime.InteropServices.Marshal]::GetLastWin32Error()
|
||||
L ("GetConsoleMode(STDOUT) : $ok mode=0x{0:X} lastErr=$err" -f $m)
|
||||
L ("--- try to wrap POSIX bytes (what Set-Item Function:Write-Output would do) ---")
|
||||
try { $b = [System.Text.Encoding]::UTF8.GetBytes("x")[0]; $os = [Console]::OpenStandardOutput(); $os.WriteByte(0x1B); $os.Flush(); L "OpenStandardOutput().WriteByte(0x1B): OK (wrote raw ESC into redirected stdout)" } catch { L ("OpenStandardOutput().WriteByte THREW: " + $_.Exception.Message) }
|
||||
try { [Console]::SetCursorPosition(3,3); L ("[Console]::SetCursorPosition(3,3) : OK -> " + [Console]::CursorLeft + "," + [Console]::CursorTop) } catch { L ("[Console]::SetCursorPosition(3,3) THREW: " + $_.Exception.Message) }
|
||||
try { $w = $Host.UI.RawUI.WindowSize; L ("RawUI.WindowSize : " + $w.Width + 'x' + $w.Height) } catch { L ("RawUI.WindowSize THREW: " + $_.Exception.Message) }
|
||||
try { L ("RawUI.ForegroundColor : " + [string]$Host.UI.RawUI.ForegroundColor) } catch { L ("RawUI.ForegroundColor THREW: " + $_.Exception.Message) }
|
||||
try { [Console]::ForegroundColor = 'Red'; L ("[Console]::ForegroundColor setter : OK (no throw)") } catch { L ("[Console]::ForegroundColor setter THREW: " + $_.Exception.Message) }
|
||||
try { [Console]::Title = 'probe'; L "[Console]::Title setter : OK (no throw)" } catch { L ("[Console]::Title setter THREW: " + $_.Exception.Message) }
|
||||
L ("[Console]::OutputEncoding : " + [Console]::OutputEncoding.WebName + " (CodePage " + [Console]::OutputEncoding.CodePage + ")")
|
||||
L ("`$OutputEncoding : " + $OutputEncoding.WebName)
|
||||
L ("chcp (GetConsoleOutputCP) : " + [K32b]::GetConsoleOutputCP())
|
||||
try { L ("`$TypingCompletion / TabExpansion2 n/a") } catch {}
|
||||
L ""
|
||||
L "##### PART B: AllocConsole() -- now attached to a brand new console #####"
|
||||
$alloc = [K32b]::AllocConsole()
|
||||
L ("AllocConsole() returned : " + $alloc)
|
||||
[Console]::SetOut([System.IO.StreamWriter]::new([Console]::OpenStandardOutput(), [Console]::OutputEncoding)) 2>$null
|
||||
L ("GetConsoleWindow : 0x{0:X}" -f ([K32b]::GetConsoleWindow().ToInt64()))
|
||||
$m2 = 0; $ok2 = [K32b]::GetConsoleMode([K32b]::GetStdHandle(-11), [ref]$m2)
|
||||
L ("GetConsoleMode(STDOUT) : $ok2 mode=0x{0:X}" -f $m2)
|
||||
L (" ENABLE_VIRTUAL_TERMINAL_PROCESSING (0x4) : " + (($m2 -band 4) -eq 4))
|
||||
L (" ENABLE_PROCESSED_OUTPUT (0x1) : " + (($m2 -band 1) -eq 1))
|
||||
$ok3 = [K32b]::SetConsoleMode([K32b]::GetStdHandle(-11), $m2 -band (-bnot 4))
|
||||
$m3 = 0; [void][K32b]::GetConsoleMode([K32b]::GetStdHandle(-11), [ref]$m3)
|
||||
L ("After SetConsoleMode(mode AND NOT 0x4) -> " + $ok3 + " mode=0x{0:X}" -f $m3)
|
||||
L (" VT now off? " + ((($m3 -band 4) -eq 0)))
|
||||
[void][K32b]::SetConsoleMode([K32b]::GetStdHandle(-11), $m3 -bor 4)
|
||||
$m4 = 0; [void][K32b]::GetConsoleMode([K32b]::GetStdHandle(-11), [ref]$m4)
|
||||
L ("After re-enabling 0x4 -> mode=0x{0:X}" -f $m4)
|
||||
L ("GetConsoleOutputCP now : " + [K32b]::GetConsoleOutputCP())
|
||||
try { L ("RawUI.WindowSize now : " + $Host.UI.RawUI.WindowSize.Width + 'x' + $Host.UI.RawUI.WindowSize.Height) } catch { L ("RawUI.WindowSize THREW: " + $_.Exception.Message) }
|
||||
[System.IO.File]::WriteAllLines($outFile, $lines, (New-Object System.Text.UTF8Encoding($false)))
|
||||
[void][K32b]::FreeConsole()
|
||||
Reference in new issue
Block a user