nex_squid/scripts/win-tui-run.ps1

39 lines
1.7 KiB
PowerShell
Raw Normal View History

Judge a captured frame by what is on the screen, not by what was sent `tui-frame-check.py` is the part of `win-tui-capture.sh` that decides whether a run passed, taken out of the shell script so that fixing the judgement does not require the real machine to run again — `TUI_REUSE=1` re-reads a saved byte stream, which is how both bugs in this branch were confirmed fixed against captures taken before the fix existed. `--selftest` feeds it six screens it made up — two good ones and four broken ones, including a screen where every Chinese character makes `len()` measure the frame too narrow — and fails if the judge goes quiet on a bug or shouts at a good screen. The four rules it encodes were each paid for with a false verdict: * the right border is only trusted on rows whose *first* character is a border character, because the box-drawing bar also appears in prose and in ASCII mode as `|`, and reading the last one on a row found the wrong column; * columns are counted by accumulated display width, not by `len()`, because a terminal emulator keeps one character for a glyph that occupies two cells; * only a screen that was painted at least eight rows and seen twice is judged, so a half-drawn frame cannot be mistaken for a torn one; * a row that ends in a border but starts with prose is a row sitting *on* a border — the shape the toast produced — which is how the judge caught a bug nobody had thought to look for. `win-tui-run.ps1` was missing from the repository while `win-tui-capture.sh` depended on it, so the proof the last commit described was not in fact repeatable. It exists here, and it is the reason the captures are trustworthy: `mode con cols=100 lines=30` fails silently on the ConPTY that Windows OpenSSH allocates, so every earlier "capture at 100 columns" was a 120-column frame reflowed by the emulator. It sets the size through `[Console]::WindowWidth` and reports the size it ended up with, and the emulator replays that rather than the one we asked for.
2026-10-15 13:20:58 +00:00
# 按指定尺寸开好控制台,再在里面启动 squid,给 scripts/win-tui-capture.sh 用。
#
# powershell -NoProfile -ExecutionPolicy Bypass -File win-tui-run.ps1 `
# 100 30 C:\dev\target\release\squid.exe state --lang zh
#
# 为什么不能用 mode con:在 Windows OpenSSH 给的 ConPTY 上,
# `mode con cols=100 lines=30` 会静默失败(控制台仍是 120 列),所以以前所有
# "按 100 列抓的图"其实都是 120 列画出来后又被仿真器重排的产物。
# [Console]::WindowWidth 走 SetConsoleWindowInfo,实测真的能改。
#
# 尺寸改完把真实尺寸打印出来:测试要按控制台实际给的大小仿真,而不是按我们请求的大小。
param(
[Parameter(Mandatory = $true)][int]$Columns,
[Parameter(Mandatory = $true)][int]$Rows,
[Parameter(Mandatory = $true)][string]$Bin,
[Parameter(ValueFromRemainingArguments = $true)][string[]]$Arguments
)
Say which console a frame was judged on, and stop blaming the interface for the shell Three ways this pipeline produced a verdict that was not about the TUI. The frame judge required every right border on a screen to land in the same column. That was written when the widest window anyone captured was 100 columns and the interface drew one card. At 140 columns the menu column and the panel are two frames side by side — the menu ends at column 31, the panel at 140 — and the rows where the panel has already finished genuinely do end at 31. A tidy 140-column screen was therefore garbled on every single capture, which is a mistake the judge makes rather than the console, and mistakes the judge makes should not have to be re-litigated on real hardware. The rule is now the one that survives both layouts: the border columns of the widest rows are the picture, and a row with a border column that appears nowhere in that picture means two pictures of different sizes are stacked on one screen. `side_by_side` and the narrow-card-under-wide-card case are both in `--selftest`, so whoever tightens that rule again finds out there, in a millisecond, rather than on the box. `win-tui-run.ps1` always ran `chcp 65001`, because UTF-8 comes back through the capture with no decoding guess involved. It also means the probe always measured a UTF-8 console, while the window being complained about sits on cp936 — and which code page a console is on is exactly what decides what an unasked-for character costs. `$SQUID_TUI_CP` picks the code page now, the runner reports it as `MARK_CODEPAGE`, and the judge prints it on the first line of every report, because a frame is only evidence for the console it was taken from. Both routes are green on the box with the price list as it now stands: 140x35 on 65001, 101 settled frames, none of them overflowing, box-drawing intact; 100x32 on 936, 54 frames, same. The comments that claimed the ConPTY measures one cell because UTF-8 is forgiving have been corrected too — it measures one cell on 936 as well, which is a fact about a console with no font, not about a code page. And when the runner itself fails to parse, the stream still contains a console: a PowerShell error block, and then nothing. The judge said "no settled frame with a border was ever drawn", which is true and useless, and it read like a rendering regression badly enough that drawing code got changed because of it. A `CategoryInfo` in the stream is now reported as what it is — the capture script never started the interface — and it is a selftest case, so the excuse is on record as belonging to the harness.
2026-10-15 14:28:49 +00:00
# 代码页由 SQUID_TUI_CP 决定,默认 65001。
#
# 默认 65001 是为了抓回来的字节干净:UTF-8 下 pyte 解码不需要任何猜测。
# 但用户自己那个窗口跑在 cp936 上,而程序里的探针量的正是"当前这个控制台为一个
# 字符收几格",所以想让他那台机器上的问价过程在这里重现一遍,就得让控制台真的待
# 在那个代码页上,而不是只在源码里假设它存在。
$cp = if ($env:SQUID_TUI_CP) { $env:SQUID_TUI_CP } else { 65001 }
chcp $cp > $null
Judge a captured frame by what is on the screen, not by what was sent `tui-frame-check.py` is the part of `win-tui-capture.sh` that decides whether a run passed, taken out of the shell script so that fixing the judgement does not require the real machine to run again — `TUI_REUSE=1` re-reads a saved byte stream, which is how both bugs in this branch were confirmed fixed against captures taken before the fix existed. `--selftest` feeds it six screens it made up — two good ones and four broken ones, including a screen where every Chinese character makes `len()` measure the frame too narrow — and fails if the judge goes quiet on a bug or shouts at a good screen. The four rules it encodes were each paid for with a false verdict: * the right border is only trusted on rows whose *first* character is a border character, because the box-drawing bar also appears in prose and in ASCII mode as `|`, and reading the last one on a row found the wrong column; * columns are counted by accumulated display width, not by `len()`, because a terminal emulator keeps one character for a glyph that occupies two cells; * only a screen that was painted at least eight rows and seen twice is judged, so a half-drawn frame cannot be mistaken for a torn one; * a row that ends in a border but starts with prose is a row sitting *on* a border — the shape the toast produced — which is how the judge caught a bug nobody had thought to look for. `win-tui-run.ps1` was missing from the repository while `win-tui-capture.sh` depended on it, so the proof the last commit described was not in fact repeatable. It exists here, and it is the reason the captures are trustworthy: `mode con cols=100 lines=30` fails silently on the ConPTY that Windows OpenSSH allocates, so every earlier "capture at 100 columns" was a 120-column frame reflowed by the emulator. It sets the size through `[Console]::WindowWidth` and reports the size it ended up with, and the emulator replays that rather than the one we asked for.
2026-10-15 13:20:58 +00:00
try {
[Console]::WindowWidth = $Columns
[Console]::WindowHeight = $Rows
}
catch {
"MARK_SIZE_FAILED $($_.Exception.Message)"
}
Say which console a frame was judged on, and stop blaming the interface for the shell Three ways this pipeline produced a verdict that was not about the TUI. The frame judge required every right border on a screen to land in the same column. That was written when the widest window anyone captured was 100 columns and the interface drew one card. At 140 columns the menu column and the panel are two frames side by side — the menu ends at column 31, the panel at 140 — and the rows where the panel has already finished genuinely do end at 31. A tidy 140-column screen was therefore garbled on every single capture, which is a mistake the judge makes rather than the console, and mistakes the judge makes should not have to be re-litigated on real hardware. The rule is now the one that survives both layouts: the border columns of the widest rows are the picture, and a row with a border column that appears nowhere in that picture means two pictures of different sizes are stacked on one screen. `side_by_side` and the narrow-card-under-wide-card case are both in `--selftest`, so whoever tightens that rule again finds out there, in a millisecond, rather than on the box. `win-tui-run.ps1` always ran `chcp 65001`, because UTF-8 comes back through the capture with no decoding guess involved. It also means the probe always measured a UTF-8 console, while the window being complained about sits on cp936 — and which code page a console is on is exactly what decides what an unasked-for character costs. `$SQUID_TUI_CP` picks the code page now, the runner reports it as `MARK_CODEPAGE`, and the judge prints it on the first line of every report, because a frame is only evidence for the console it was taken from. Both routes are green on the box with the price list as it now stands: 140x35 on 65001, 101 settled frames, none of them overflowing, box-drawing intact; 100x32 on 936, 54 frames, same. The comments that claimed the ConPTY measures one cell because UTF-8 is forgiving have been corrected too — it measures one cell on 936 as well, which is a fact about a console with no font, not about a code page. And when the runner itself fails to parse, the stream still contains a console: a PowerShell error block, and then nothing. The judge said "no settled frame with a border was ever drawn", which is true and useless, and it read like a rendering regression badly enough that drawing code got changed because of it. A `CategoryInfo` in the stream is now reported as what it is — the capture script never started the interface — and it is a selftest case, so the excuse is on record as belonging to the harness.
2026-10-15 14:28:49 +00:00
"MARK_CODEPAGE $cp"
Judge a captured frame by what is on the screen, not by what was sent `tui-frame-check.py` is the part of `win-tui-capture.sh` that decides whether a run passed, taken out of the shell script so that fixing the judgement does not require the real machine to run again — `TUI_REUSE=1` re-reads a saved byte stream, which is how both bugs in this branch were confirmed fixed against captures taken before the fix existed. `--selftest` feeds it six screens it made up — two good ones and four broken ones, including a screen where every Chinese character makes `len()` measure the frame too narrow — and fails if the judge goes quiet on a bug or shouts at a good screen. The four rules it encodes were each paid for with a false verdict: * the right border is only trusted on rows whose *first* character is a border character, because the box-drawing bar also appears in prose and in ASCII mode as `|`, and reading the last one on a row found the wrong column; * columns are counted by accumulated display width, not by `len()`, because a terminal emulator keeps one character for a glyph that occupies two cells; * only a screen that was painted at least eight rows and seen twice is judged, so a half-drawn frame cannot be mistaken for a torn one; * a row that ends in a border but starts with prose is a row sitting *on* a border — the shape the toast produced — which is how the judge caught a bug nobody had thought to look for. `win-tui-run.ps1` was missing from the repository while `win-tui-capture.sh` depended on it, so the proof the last commit described was not in fact repeatable. It exists here, and it is the reason the captures are trustworthy: `mode con cols=100 lines=30` fails silently on the ConPTY that Windows OpenSSH allocates, so every earlier "capture at 100 columns" was a 120-column frame reflowed by the emulator. It sets the size through `[Console]::WindowWidth` and reports the size it ended up with, and the emulator replays that rather than the one we asked for.
2026-10-15 13:20:58 +00:00
"MARK_STARTED $([Console]::WindowWidth)x$([Console]::WindowHeight)"
& $Bin @Arguments
"MARK_QUIT $LASTEXITCODE"