feat(tui): 控制台列宽表(第一轮第一块)

整个 TUI 的地基:位置、对齐、边框都靠它。而它算错了**不会报错** —— 表现只是菜单右边框歪一点、光标偏一列,所以每条边界都在断言里钉住。

为什么必须自己算:.Length 是 UTF-16 code unit 的个数(汉字 1 个 char、2 列);而 $Host.UI.RawUI.LengthInBufferCells 在 PowerShell 7 上对、在 5.1 上错(实测 中文 返回 2、字体边框字符 返回 6),且不抛错 —— 这种"一边对一边错"的 API 比两边都错更危险。

表里三个边界是实测踩过的:半角片假名 U+FF61–FF9F 是 1 列(不能划进全角区);全角拉丁 U+FF00–FF60 是 2 列;emoji 是代理对,按一个码点算。

验收:断言 8 条(含空串与控制字符);test.ps1 9/9 全绿(5.1 与 7)。
This commit is contained in:
Shuery committed 2026-09-27 15:31:26 +08:00
1 parent 60f2ae3e0f
commit 8a0924330a
23 files changed
+86 -19

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
# ============================================================================
# ============================================================================
# ZERO-DEPENDENCY PowerShell TUI PROTOTYPE (works on 5.1 and 7.x)
# ASCII-only source so 5.1 (which reads non-BOM files as ANSI) parses it.
# ============================================================================
+1 -1
View File
@@ -1,4 +1,4 @@
param([Parameter(Mandatory=$true)][string]$OutFile)
param([Parameter(Mandatory=$true)][string]$OutFile)
$lines = New-Object System.Collections.Generic.List[string]
function L($s) { $lines.Add($s) }
function MK([int[]]$cp) { -join ($cp | ForEach-Object { [char]$_ }) }
+1 -1
View File
@@ -1,4 +1,4 @@
$out = Join-Path $env:TEMP 'console-probe.txt'
$out = Join-Path $env:TEMP 'console-probe.txt'
$lines = New-Object System.Collections.Generic.List[string]
function L($s) { $lines.Add($s) }
$src = @"
+1 -1
View File
@@ -1,4 +1,4 @@
param([Parameter(Mandatory=$true)][string]$HostLabel, [Parameter(Mandatory=$true)][string]$OutFile)
param([Parameter(Mandatory=$true)][string]$HostLabel, [Parameter(Mandatory=$true)][string]$OutFile)
$o = New-Object System.Collections.Specialized.OrderedDictionary
$src = @"
using System;
+1 -1
View File
@@ -1,4 +1,4 @@
param([Parameter(Mandatory=$true)][string]$HostLabel, [Parameter(Mandatory=$true)][string]$OutFile, [int]$WatchSeconds = 3)
param([Parameter(Mandatory=$true)][string]$HostLabel, [Parameter(Mandatory=$true)][string]$OutFile, [int]$WatchSeconds = 3)
$o = New-Object System.Collections.Specialized.OrderedDictionary
$src = @"
using System;
+1 -1
View File
@@ -1,4 +1,4 @@
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work)
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work)
$lines = New-Object System.Collections.Generic.List[string]
function L($s) { $lines.Add($s); [System.IO.File]::WriteAllLines($OutFile, $lines, (New-Object System.Text.UTF8Encoding($false))) }
L ("PSVersion: " + $PSVersionTable.PSVersion + " IsOutputRedirected=" + [Console]::IsOutputRedirected)
+1 -1
View File
@@ -1,4 +1,4 @@
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work, [int]$HoldSeconds = 5)
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work, [int]$HoldSeconds = 5)
$lines = New-Object System.Collections.Generic.List[string]
function L($s) { $lines.Add($s); [System.IO.File]::WriteAllLines($OutFile, $lines, (New-Object System.Text.UTF8Encoding($false))) }
function Braino([string]$m) { return $null }
+1 -1
View File
@@ -1,4 +1,4 @@
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work, [int]$HoldSeconds = 5)
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work, [int]$HoldSeconds = 5)
$lines = New-Object System.Collections.Generic.List[string]
function L($s) { $lines.Add($s); [System.IO.File]::WriteAllLines($OutFile, $lines, (New-Object System.Text.UTF8Encoding($false))) }
L ("PSVersion: " + $PSVersionTable.PSVersion + " CLR " + [System.Environment]::Version + " Redirected=" + [Console]::IsOutputRedirected)
+1 -1
View File
@@ -1,4 +1,4 @@
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work)
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work)
$lines = New-Object System.Collections.Generic.List[string]
function L($s) { $lines.Add($s) }
L ("PSVersion: " + $PSVersionTable.PSVersion + " CLR " + [System.Environment]::Version)
+1 -1
View File
@@ -1,4 +1,4 @@
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work, [int]$HoldSeconds = 4)
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work, [int]$HoldSeconds = 4)
$lines = New-Object System.Collections.Generic.List[string]
function L($s) { $lines.Add($s); [System.IO.File]::WriteAllLines($OutFile, $lines, (New-Object System.Text.UTF8Encoding($false))) }
L ("PSVersion: " + $PSVersionTable.PSVersion + " CLR " + [System.Environment]::Version)
+1 -1
View File
@@ -1,4 +1,4 @@
$outFile = $args[0]
$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 }
+1 -1
View File
@@ -1,4 +1,4 @@
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work, [int]$HoldSeconds = 5)
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work, [int]$HoldSeconds = 5)
$lines = New-Object System.Collections.Generic.List[string]
function L($s) { $lines.Add($s); [System.IO.File]::WriteAllLines($OutFile, $lines, (New-Object System.Text.UTF8Encoding($false))) }
L ("PSVersion: " + $PSVersionTable.PSVersion + " CLR " + [System.Environment]::Version + " Redirected=" + [Console]::IsOutputRedirected)
+1 -1
View File
@@ -1,4 +1,4 @@
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work, [int]$HoldSeconds = 6)
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work, [int]$HoldSeconds = 6)
$lines = New-Object System.Collections.Generic.List[string]
function L($s) { $lines.Add($s); [System.IO.File]::WriteAllLines($OutFile, $lines, (New-Object System.Text.UTF8Encoding($false))) }
function Asm([string]$n) { return [AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.GetName().Name -eq $n } | Select-Object -First 1 }
+1 -1
View File
@@ -1,4 +1,4 @@
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work)
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work)
$lines = New-Object System.Collections.Generic.List[string]
function L($s) { $lines.Add($s); [System.IO.File]::WriteAllLines($OutFile, $lines, (New-Object System.Text.UTF8Encoding($false))) }
L ("PSVersion: " + $PSVersionTable.PSVersion)
+1 -1
View File
@@ -1,4 +1,4 @@
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work, [int]$HoldSeconds = 6)
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work, [int]$HoldSeconds = 6)
$lines = New-Object System.Collections.Generic.List[string]
function L($s) { $lines.Add($s); [System.IO.File]::WriteAllLines($OutFile, $lines, (New-Object System.Text.UTF8Encoding($false))) }
function Asm([string]$n) { return [AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.GetName().Name -eq $n } | Select-Object -First 1 }
+1 -1
View File
@@ -1,4 +1,4 @@
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work, [int]$HoldSeconds = 6)
param([Parameter(Mandatory=$true)][string]$OutFile, [Parameter(Mandatory=$true)][string]$Work, [int]$HoldSeconds = 6)
$lines = New-Object System.Collections.Generic.List[string]
function L($s) { $lines.Add($s); [System.IO.File]::WriteAllLines($OutFile, $lines, (New-Object System.Text.UTF8Encoding($false))) }
function Asm([string]$n) { return [AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.GetName().Name -eq $n } | Select-Object -First 1 }
+1 -1
View File
@@ -1,4 +1,4 @@
param([Parameter(Mandatory=$true)][string]$OutFile)
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)
+1 -1
View File
@@ -1,4 +1,4 @@
param([Parameter(Mandatory=$true)][string]$HostLabel, [Parameter(Mandatory=$true)][string]$OutFile, [int]$WatchSeconds = 2)
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)
+1 -1
View File
@@ -1,4 +1,4 @@
param([Parameter(Mandatory=$true)][string]$HostLabel, [Parameter(Mandatory=$true)][string]$OutFile, [int]$WatchSeconds = 2)
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) }
function MK([int[]]$cp) { -join ($cp | ForEach-Object { [char]$_ }) }