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 两版仍绿。
67 lines
4.6 KiB
PowerShell
67 lines
4.6 KiB
PowerShell
param([Parameter(Mandatory=$true)][string]$HostLabel, [Parameter(Mandatory=$true)][string]$OutFile)
|
|
$o = New-Object System.Collections.Specialized.OrderedDictionary
|
|
$src = @"
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
public static class K32 {
|
|
[DllImport("kernel32.dll", SetLastError=true)] 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")] public static extern IntPtr GetConsoleWindow();
|
|
[DllImport("kernel32.dll")] public static extern uint GetConsoleOutputCP();
|
|
[DllImport("kernel32.dll")] public static extern uint GetACP();
|
|
}
|
|
"@
|
|
Add-Type -TypeDefinition $src -ErrorAction Stop
|
|
$hOut = [K32]::GetStdHandle(-11); $hIn = [K32]::GetStdHandle(-10)
|
|
$mOut = 0; $mIn = 0
|
|
$okOut = [K32]::GetConsoleMode($hOut, [ref]$mOut)
|
|
$okIn = [K32]::GetConsoleMode($hIn, [ref]$mIn)
|
|
$o['HostLabel'] = $HostLabel
|
|
$o['PSVersion'] = $PSVersionTable.PSVersion.ToString()
|
|
$o['CLR'] = [System.Environment]::Version.ToString()
|
|
$o['IsOutputRedirected'] = [Console]::IsOutputRedirected
|
|
$o['IsInputRedirected'] = [Console]::IsInputRedirected
|
|
$o['IsErrorRedirected'] = [Console]::IsErrorRedirected
|
|
$o['GetConsoleWindow'] = ('0x{0:X}' -f ([K32]::GetConsoleWindow().ToInt64()))
|
|
$o['GetConsoleOutputCP'] = [K32]::GetConsoleOutputCP()
|
|
$o['GetACP'] = [K32]::GetACP()
|
|
$o['OutputEncoding'] = [Console]::OutputEncoding.WebName
|
|
$o['GetConsoleMode_STDOUT_ok'] = $okOut
|
|
$o['STDOUT_mode_hex'] = ('0x{0:X}' -f $mOut)
|
|
$o['STDOUT_VT_PROCESSING_0x4'] = (($mOut -band 4) -eq 4)
|
|
$o['STDOUT_PROCESSED_OUTPUT_0x1'] = (($mOut -band 1) -eq 1)
|
|
$o['STDOUT_WRAP_EOL_0x2'] = (($mOut -band 2) -eq 2)
|
|
$o['STDIN_GetConsoleMode_ok'] = $okIn
|
|
$o['STDIN_mode_hex'] = ('0x{0:X}' -f $mIn)
|
|
$o['STDIN_VT_INPUT_0x200'] = (($mIn -band 0x200) -eq 0x200)
|
|
$raw = $Host.UI.RawUI
|
|
$o['RawUI_TypeName'] = $raw.GetType().FullName
|
|
$o['RawUI_members'] = (($raw | Get-Member -MemberType Property | Select-Object -ExpandProperty Name) -join ',')
|
|
$uiProp = $Host.UI | Get-Member -Name SupportsVirtualTerminal -MemberType Property -ErrorAction SilentlyContinue
|
|
$o['HostUI_has_SupportsVirtualTerminal_member'] = [bool]$uiProp
|
|
$o['Value_Host_UI_SupportsVirtualTerminal'] = [string]$Host.UI.SupportsVirtualTerminal
|
|
$o['RawUI_has_SupportsVirtualTerminal'] = [bool]($raw | Get-Member -Name SupportsVirtualTerminal -ErrorAction SilentlyContinue)
|
|
try { $o['Value_RawUI_SupportsVirtualTerminal'] = [string]$raw.SupportsVirtualTerminal } catch { $o['Value_RawUI_SupportsVirtualTerminal'] = 'THREW: ' + $_.Exception.Message }
|
|
try { $w = $raw.WindowSize; $o['RawUI_WindowSize'] = "$($w.Width)x$($w.Height)" } catch { $o['RawUI_WindowSize'] = 'THREW: ' + $_.Exception.Message }
|
|
try { $b = $raw.BufferSize; $o['RawUI_BufferSize'] = "$($b.Width)x$($b.Height)" } catch { $o['RawUI_BufferSize'] = 'THREW: ' + $_.Exception.Message }
|
|
try { $o['RawUI_MaxPhysicalWindowSize'] = (($raw.MaxPhysicalWindowSize).Width.ToString() + 'x' + ($raw.MaxPhysicalWindowSize).Height.ToString()) } catch { $o['RawUI_MaxPhysicalWindowSize'] = 'THREW: ' + $_.Exception.Message }
|
|
try { $raw.CursorPosition = (New-Object System.Management.Automation.Host.Coordinates 3,3); $o['SetCursorPosition_ok'] = $true; $o['CursorPosition_readback'] = "$($raw.CursorPosition.X),$($raw.CursorPosition.Y)" } catch { $o['SetCursorPosition_ok'] = 'THREW: ' + $_.Exception.Message }
|
|
try { $o['KeyAvailable_read_ok'] = 'ok: ' + $raw.KeyAvailable } catch { $o['KeyAvailable_read_ok'] = 'THREW: ' + $_.Exception.Message }
|
|
# Chinese width probe, ASCII-source via code points
|
|
$zh = [string]::Concat([char]0x4E2D, [char]0x6587) # Zhong Wen
|
|
$ascii = 'AB'
|
|
$o['zh_string'] = $zh
|
|
$o['zh_Length'] = $zh.Length
|
|
$o['ascii_Length'] = $ascii.Length
|
|
$o['GetConsoleWindowTitle'] = [Console]::Title
|
|
$json = $o | ConvertTo-Json -Compress
|
|
[System.IO.File]::WriteAllText($OutFile, $json, (New-Object System.Text.UTF8Encoding($false)))
|
|
$raw.CursorPosition = (New-Object System.Management.Automation.Host.Coordinates 0,0)
|
|
Write-Host ''
|
|
Write-Host ("--- console probe [{0}] PS {1} VT={2} mode={3} ---" -f $HostLabel, $PSVersionTable.PSVersion, $Host.UI.SupportsVirtualTerminal, ('0x{0:X}' -f $mOut)) -ForegroundColor Yellow
|
|
Write-Host ("ANSI test: " + [char]27 + "[31mRED-ANSI" + [char]27 + "[0m " + [char]27 + "[42mBG-GREEN" + [char]27 + "[0m " + [char]27 + "[1;36mBOLD-CYAN" + [char]27 + "[0m")
|
|
Write-Host ("Unicode box: " + [char]0x250C + [char]0x2500 + [char]0x2510)
|
|
Write-Host ("Chinese: " + $zh + " Length=" + $zh.Length)
|
|
Write-Host '--- end ---'
|
|
Start-Sleep -Seconds 4
|