nex_squid/scripts/win-tui-capture.sh

80 lines
4.7 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# 在 Windows 真机上把 TUI 抓成一帧纯文本,验证 ConPTY 上的绘制结果。
#
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
# ./scripts/win-tui-capture.sh # 抓 state 界面
# ./scripts/win-tui-capture.sh --lang zh # 中文界面(验证 CJK 宽度)
# TUI_KEYS="5 q" ./scripts/win-tui-capture.sh # 先切面板再退出
# TUI_COLS=140 TUI_ROWS=45 ./scripts/win-tui-capture.sh
# TUI_CELLS=2 ./scripts/win-tui-capture.sh # 强制按"一列字符收两格"画(ASCII 边框)
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
# TUI_CP=936 ./scripts/win-tui-capture.sh # 用用户窗口的代码页跑(复现方块双格)
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
# TUI_REUSE=1 TUI_OUT=/tmp/x.bin ./scripts/win-tui-capture.sh # 只重算旧帧,不连真机
The command line pays for its chrome at the same counter Three rounds were spent on a TUI that drew several frames over each other on a cp936 console, and the fix worked: the interface asks the console what it charges, per character, and draws ASCII where the console charges more than the layout paid. Meanwhile `squid status`, printed in the same window on the same machine, still produced a Storage table whose rows were each a screen and a half long. Nothing in `main.rs` had ever asked what a `█` costs. It repeats that character twenty-eight times for a gauge and lets the console do the arithmetic, and the console's arithmetic is different. `priced` is where a line stops being text and starts being cells, and `row!` is the one door the body of every report prints through: the eleven places that draw this program's chrome — the status key/value rows, the volume gauges, the process table, the tree, the history rows, the whitelist bullets, the rule headings and their `●`, the doctor's table — all of them now go through it. It is a macro rather than a helper so the format arguments stay where they were written, and one door rather than twelve `println!`s of which eleven remember the console, because the twelfth is the bug this whole thing is about. Two refusals are the interesting part. Nobody is stopped from seeing what a report actually says. Point the output at a file or a pipe and the text comes back exactly as it was, because a file is not a console: whatever glass reads the archive tomorrow may well afford the `█`, and an archive of `#` is a worse record for the sake of a screen that was never looking. The gate is the same tty question the live progress line already asked — may this line overwrite a line — so `live_stream_is_tty` is now `human_stream_is_tty`, since the two questions have the same answer and deserve one function that says what it is asked. And `--json` prints data, never through this: rewriting a person's report to flatter their terminal is a different bug with the same fingerprint. The price is not measured, even though measuring is what the interface does, for the reason in `console::prices_unasked`: measurement spends characters, and a command line is a guest on the screen it is printed to, sitting in a pipeline or in front of a shell waiting for its next prompt. So it takes the pessimistic answer the code page implies, which costs it a plainer gauge on a console whose code page overcharges characters its font could have carried. `█` becomes `#` there. A table that fits is worth more than a prettier one that does not. `no_line_of_chrome_escapes_the_counter` reads the file, with strings, character literals and comments blanked, and demands that every `print!`, `println!` and `eprintln!` either go through `priced` or print JSON or print nothing. The scan exists because this mistake cannot be seen from the machine it was made on: `println!(" {}", plan)` standing among eleven `row!` calls is correct on every terminal that charges one cell for everything, including the one it was typed on, and arrives folded over in front of somebody else. It reads character literals as literals only when they close again promptly, because `'static` is not the start of a character literal and blanking from a lifetime to the next quote hides half a file from an audit whose entire job is to look at all of it. On the box, same pseudo-console, same 100x30 window, three reports per capture and every one of them complete to `MARK_QUIT 0`. On cp936 — the code page the user's own window is on — the decoded stream contains no `█`, no `░`, no `─`, no `·`, no `…`, no arrow: the gauge reads `[#######################.....]` and the headings are underlined with `-`. On 65001 the same report keeps 104 `█`, 120 `░`, 236 `─`, 32 `·` and both arrows. Same bytes of intent, two currencies, and the receipt is now in both. `win-tui-capture.sh` takes `TUI_ARGS=` so this evidence is repeatable rather than hand-built: the default still captures the interface and judges it frame by frame, and `TUI_ARGS="status"` captures a report, where the judge is simply how many `█` survived. The architecture document tells the story as one paragraph now, because it is one story: `console::prices` measures and hands the answers to the interface, `console::prices_unasked` guesses from the code page and hands them to the command line, and each side has a test that keeps the characters it draws and the characters it priced the same list. 178 tests here, two of them this commit's, clean under clippy for the host and for `x86_64-pc-windows-msvc`, `cargo doc -D warnings` quiet over the platform and the command line.
2026-10-16 02:32:05 +00:00
# TUI_ARGS="status" ./scripts/win-tui-capture.sh # 抓命令行的输出而不是界面(判据见下)
#
# 为什么不能用 scripts/tui_smoke.py:那个脚本自己 forkpty(),是 POSIX 专属。
# 真机上没有 pty 可以 fork,只能反过来:让 sshd 用 CreatePseudoConsole 分配一个
# ConPTY(Windows OpenSSH 在 1809+ 上对 -tt 就是这么做的),crossterm 因此走真正的
# Windows 控制台后端,而不是退化到没验证过的 ANSI 假设。原始 ANSI 落盘后拿回本地,
# 用 pyte 这个终端仿真器解码成文本 —— 看到的才是用户会看到的那一帧。
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
#
# 为什么尺寸要由远端自己报:实测 ConPTY 不理 ssh 客户端的 window-change,
# `mode con cols=X lines=Y` 也会静默失败(返回 0,什么都没改)。所以尺寸由
# scripts/win-tui-run.ps1 用 [Console]::WindowWidth 改(SetConsoleWindowInfo,真的有效),
# 再把改完的真实尺寸打印回来。pyte 按这个事实仿真,而不是按我们的请求。
set -uo pipefail
cd "$(dirname "$0")/.."
WIN_HOST="${WIN_HOST:-KANGWJ@192.168.2.92}"
WIN_KEY="${WIN_KEY:-$HOME/.ssh/id_ed25519_windows}"
BIN="${WIN_BIN:-C:\dev\target\release\squid.exe}"
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
RUNNER='C:\Users\kangwj\win-tui-run.ps1'
OUT="${TUI_OUT:-/tmp/squid-win-tui.bin}"
COLS="${TUI_COLS:-100}"
ROWS="${TUI_ROWS:-30}"
DELAY="${TUI_DELAY:-8}"
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
# TUI_CELLS=2 让程序按两格的价画(边框退成 |-+),=1 按一格。远端那台机器上的
# ConPTY 控制台对全部 60 个字符都只收一格(936 与 65001 都一样),所以想看 ASCII
# 那一版只能靠 SQUID_SYMBOL_CELLS 强制 —— 伪控制台量不到两格,不等于用户那个带
# 中文字体的窗口也量不到,这条路径正是为后者准备的。
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
CELLS="${TUI_CELLS:-}"
The command line pays for its chrome at the same counter Three rounds were spent on a TUI that drew several frames over each other on a cp936 console, and the fix worked: the interface asks the console what it charges, per character, and draws ASCII where the console charges more than the layout paid. Meanwhile `squid status`, printed in the same window on the same machine, still produced a Storage table whose rows were each a screen and a half long. Nothing in `main.rs` had ever asked what a `█` costs. It repeats that character twenty-eight times for a gauge and lets the console do the arithmetic, and the console's arithmetic is different. `priced` is where a line stops being text and starts being cells, and `row!` is the one door the body of every report prints through: the eleven places that draw this program's chrome — the status key/value rows, the volume gauges, the process table, the tree, the history rows, the whitelist bullets, the rule headings and their `●`, the doctor's table — all of them now go through it. It is a macro rather than a helper so the format arguments stay where they were written, and one door rather than twelve `println!`s of which eleven remember the console, because the twelfth is the bug this whole thing is about. Two refusals are the interesting part. Nobody is stopped from seeing what a report actually says. Point the output at a file or a pipe and the text comes back exactly as it was, because a file is not a console: whatever glass reads the archive tomorrow may well afford the `█`, and an archive of `#` is a worse record for the sake of a screen that was never looking. The gate is the same tty question the live progress line already asked — may this line overwrite a line — so `live_stream_is_tty` is now `human_stream_is_tty`, since the two questions have the same answer and deserve one function that says what it is asked. And `--json` prints data, never through this: rewriting a person's report to flatter their terminal is a different bug with the same fingerprint. The price is not measured, even though measuring is what the interface does, for the reason in `console::prices_unasked`: measurement spends characters, and a command line is a guest on the screen it is printed to, sitting in a pipeline or in front of a shell waiting for its next prompt. So it takes the pessimistic answer the code page implies, which costs it a plainer gauge on a console whose code page overcharges characters its font could have carried. `█` becomes `#` there. A table that fits is worth more than a prettier one that does not. `no_line_of_chrome_escapes_the_counter` reads the file, with strings, character literals and comments blanked, and demands that every `print!`, `println!` and `eprintln!` either go through `priced` or print JSON or print nothing. The scan exists because this mistake cannot be seen from the machine it was made on: `println!(" {}", plan)` standing among eleven `row!` calls is correct on every terminal that charges one cell for everything, including the one it was typed on, and arrives folded over in front of somebody else. It reads character literals as literals only when they close again promptly, because `'static` is not the start of a character literal and blanking from a lifetime to the next quote hides half a file from an audit whose entire job is to look at all of it. On the box, same pseudo-console, same 100x30 window, three reports per capture and every one of them complete to `MARK_QUIT 0`. On cp936 — the code page the user's own window is on — the decoded stream contains no `█`, no `░`, no `─`, no `·`, no `…`, no arrow: the gauge reads `[#######################.....]` and the headings are underlined with `-`. On 65001 the same report keeps 104 `█`, 120 `░`, 236 `─`, 32 `·` and both arrows. Same bytes of intent, two currencies, and the receipt is now in both. `win-tui-capture.sh` takes `TUI_ARGS=` so this evidence is repeatable rather than hand-built: the default still captures the interface and judges it frame by frame, and `TUI_ARGS="status"` captures a report, where the judge is simply how many `█` survived. The architecture document tells the story as one paragraph now, because it is one story: `console::prices` measures and hands the answers to the interface, `console::prices_unasked` guesses from the code page and hands them to the command line, and each side has a test that keeps the characters it draws and the characters it priced the same list. 178 tests here, two of them this commit's, clean under clippy for the host and for `x86_64-pc-windows-msvc`, `cargo doc -D warnings` quiet over the platform and the command line.
2026-10-16 02:32:05 +00:00
# 默认抓 state 界面。TUI_ARGS 换成命令行子命令就能抓 `squid status` 这类纯文本:
# 那种输出没有帧可判(帧判据会说"屏上没画框"),它的判据是剥掉 ANSI 之后还剩几
# 个 █ —— cp936 下应当一个不剩(换成 # 和 .),65001 下一个不少(控制台付得起)。
TUI_ARGS="${TUI_ARGS:-state}"
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
# TUI_CP=936 让远端控制台待在用户真正使用的那个代码页上。
# 为什么要这个:代码页决定"没被问到"的字符按几格算(936 按两格),而用户自己的
# 窗口就跑在 936 上;要让他那台机器上的问价过程在这里重现一遍,就得让控制台真的
# 待在那个代码页,而不是在源码里假设它存在。实测 ConPTY 在 936 上仍对全部字符收
# 一格 —— 伪控制台没有字体,而"模糊字符收几格"从来不是代码页一个人说了算的。
CP="${TUI_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
SETUP=""
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
if [ -n "$CELLS" ]; then SETUP="${SETUP}set SQUID_SYMBOL_CELLS=$CELLS&& "; fi
if [ -n "$CP" ]; then SETUP="${SETUP}set SQUID_TUI_CP=$CP&& "; fi
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
# TUI_REUSE=1:跳过抓帧,直接重新分析 $OUT 里已有的原始 ANSI 流。
# 改判据的时候用 —— 判据写错不该逼着真机再跑一遍。
if [ "${TUI_REUSE:-}" = 1 ]; then
[ -s "$OUT" ] || { echo "TUI_REUSE=1 但 $OUT 不存在/为空"; exit 1; }
printf '\033[1;36m==>\033[0m 复用 %s (%s 字节),不连真机\n' "$OUT" "$(wc -c < "$OUT" | tr -d ' ')"
else
printf '\033[1;36m==>\033[0m 抓取 %s (请求 %sx%s, %ss)\n' "$BIN" "$COLS" "$ROWS" "$DELAY"
scp -i "$WIN_KEY" -o BatchMode=yes -q scripts/win-tui-run.ps1 "$WIN_HOST:$RUNNER" || exit 1
# 按键序列:默认只按 q 退出。想验证"有数据时"的排版,先按键进入面板再退出 ——
# 空面板和有数据的面板排的是两种版。
TUI_KEYS="${TUI_KEYS:-q}"
TUI_HOLD="${TUI_HOLD:-6}"
{ sleep "$DELAY"; for key in $TUI_KEYS; do printf '%s' "$key"; sleep "$TUI_HOLD"; done; sleep 2; } |
ssh -tt -i "$WIN_KEY" -o BatchMode=yes "$WIN_HOST" \
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
"${SETUP}powershell" -NoProfile -ExecutionPolicy Bypass -File "$RUNNER" \
The command line pays for its chrome at the same counter Three rounds were spent on a TUI that drew several frames over each other on a cp936 console, and the fix worked: the interface asks the console what it charges, per character, and draws ASCII where the console charges more than the layout paid. Meanwhile `squid status`, printed in the same window on the same machine, still produced a Storage table whose rows were each a screen and a half long. Nothing in `main.rs` had ever asked what a `█` costs. It repeats that character twenty-eight times for a gauge and lets the console do the arithmetic, and the console's arithmetic is different. `priced` is where a line stops being text and starts being cells, and `row!` is the one door the body of every report prints through: the eleven places that draw this program's chrome — the status key/value rows, the volume gauges, the process table, the tree, the history rows, the whitelist bullets, the rule headings and their `●`, the doctor's table — all of them now go through it. It is a macro rather than a helper so the format arguments stay where they were written, and one door rather than twelve `println!`s of which eleven remember the console, because the twelfth is the bug this whole thing is about. Two refusals are the interesting part. Nobody is stopped from seeing what a report actually says. Point the output at a file or a pipe and the text comes back exactly as it was, because a file is not a console: whatever glass reads the archive tomorrow may well afford the `█`, and an archive of `#` is a worse record for the sake of a screen that was never looking. The gate is the same tty question the live progress line already asked — may this line overwrite a line — so `live_stream_is_tty` is now `human_stream_is_tty`, since the two questions have the same answer and deserve one function that says what it is asked. And `--json` prints data, never through this: rewriting a person's report to flatter their terminal is a different bug with the same fingerprint. The price is not measured, even though measuring is what the interface does, for the reason in `console::prices_unasked`: measurement spends characters, and a command line is a guest on the screen it is printed to, sitting in a pipeline or in front of a shell waiting for its next prompt. So it takes the pessimistic answer the code page implies, which costs it a plainer gauge on a console whose code page overcharges characters its font could have carried. `█` becomes `#` there. A table that fits is worth more than a prettier one that does not. `no_line_of_chrome_escapes_the_counter` reads the file, with strings, character literals and comments blanked, and demands that every `print!`, `println!` and `eprintln!` either go through `priced` or print JSON or print nothing. The scan exists because this mistake cannot be seen from the machine it was made on: `println!(" {}", plan)` standing among eleven `row!` calls is correct on every terminal that charges one cell for everything, including the one it was typed on, and arrives folded over in front of somebody else. It reads character literals as literals only when they close again promptly, because `'static` is not the start of a character literal and blanking from a lifetime to the next quote hides half a file from an audit whose entire job is to look at all of it. On the box, same pseudo-console, same 100x30 window, three reports per capture and every one of them complete to `MARK_QUIT 0`. On cp936 — the code page the user's own window is on — the decoded stream contains no `█`, no `░`, no `─`, no `·`, no `…`, no arrow: the gauge reads `[#######################.....]` and the headings are underlined with `-`. On 65001 the same report keeps 104 `█`, 120 `░`, 236 `─`, 32 `·` and both arrows. Same bytes of intent, two currencies, and the receipt is now in both. `win-tui-capture.sh` takes `TUI_ARGS=` so this evidence is repeatable rather than hand-built: the default still captures the interface and judges it frame by frame, and `TUI_ARGS="status"` captures a report, where the judge is simply how many `█` survived. The architecture document tells the story as one paragraph now, because it is one story: `console::prices` measures and hands the answers to the interface, `console::prices_unasked` guesses from the code page and hands them to the command line, and each side has a test that keeps the characters it draws and the characters it priced the same list. 178 tests here, two of them this commit's, clean under clippy for the host and for `x86_64-pc-windows-msvc`, `cargo doc -D warnings` quiet over the platform and the command line.
2026-10-16 02:32:05 +00:00
"$COLS" "$ROWS" "$BIN" $TUI_ARGS "$@" \
> "$OUT" 2>&1
rc=$?
printf '\033[1;36m==>\033[0m 原始 ANSI 已存 %s (%s 字节, ssh rc=%s)\n' "$OUT" "$(wc -c < "$OUT" | tr -d ' ')" "$rc"
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
fi
The command line pays for its chrome at the same counter Three rounds were spent on a TUI that drew several frames over each other on a cp936 console, and the fix worked: the interface asks the console what it charges, per character, and draws ASCII where the console charges more than the layout paid. Meanwhile `squid status`, printed in the same window on the same machine, still produced a Storage table whose rows were each a screen and a half long. Nothing in `main.rs` had ever asked what a `█` costs. It repeats that character twenty-eight times for a gauge and lets the console do the arithmetic, and the console's arithmetic is different. `priced` is where a line stops being text and starts being cells, and `row!` is the one door the body of every report prints through: the eleven places that draw this program's chrome — the status key/value rows, the volume gauges, the process table, the tree, the history rows, the whitelist bullets, the rule headings and their `●`, the doctor's table — all of them now go through it. It is a macro rather than a helper so the format arguments stay where they were written, and one door rather than twelve `println!`s of which eleven remember the console, because the twelfth is the bug this whole thing is about. Two refusals are the interesting part. Nobody is stopped from seeing what a report actually says. Point the output at a file or a pipe and the text comes back exactly as it was, because a file is not a console: whatever glass reads the archive tomorrow may well afford the `█`, and an archive of `#` is a worse record for the sake of a screen that was never looking. The gate is the same tty question the live progress line already asked — may this line overwrite a line — so `live_stream_is_tty` is now `human_stream_is_tty`, since the two questions have the same answer and deserve one function that says what it is asked. And `--json` prints data, never through this: rewriting a person's report to flatter their terminal is a different bug with the same fingerprint. The price is not measured, even though measuring is what the interface does, for the reason in `console::prices_unasked`: measurement spends characters, and a command line is a guest on the screen it is printed to, sitting in a pipeline or in front of a shell waiting for its next prompt. So it takes the pessimistic answer the code page implies, which costs it a plainer gauge on a console whose code page overcharges characters its font could have carried. `█` becomes `#` there. A table that fits is worth more than a prettier one that does not. `no_line_of_chrome_escapes_the_counter` reads the file, with strings, character literals and comments blanked, and demands that every `print!`, `println!` and `eprintln!` either go through `priced` or print JSON or print nothing. The scan exists because this mistake cannot be seen from the machine it was made on: `println!(" {}", plan)` standing among eleven `row!` calls is correct on every terminal that charges one cell for everything, including the one it was typed on, and arrives folded over in front of somebody else. It reads character literals as literals only when they close again promptly, because `'static` is not the start of a character literal and blanking from a lifetime to the next quote hides half a file from an audit whose entire job is to look at all of it. On the box, same pseudo-console, same 100x30 window, three reports per capture and every one of them complete to `MARK_QUIT 0`. On cp936 — the code page the user's own window is on — the decoded stream contains no `█`, no `░`, no `─`, no `·`, no `…`, no arrow: the gauge reads `[#######################.....]` and the headings are underlined with `-`. On 65001 the same report keeps 104 `█`, 120 `░`, 236 `─`, 32 `·` and both arrows. Same bytes of intent, two currencies, and the receipt is now in both. `win-tui-capture.sh` takes `TUI_ARGS=` so this evidence is repeatable rather than hand-built: the default still captures the interface and judges it frame by frame, and `TUI_ARGS="status"` captures a report, where the judge is simply how many `█` survived. The architecture document tells the story as one paragraph now, because it is one story: `console::prices` measures and hands the answers to the interface, `console::prices_unasked` guesses from the code page and hands them to the command line, and each side has a test that keeps the characters it draws and the characters it priced the same list. 178 tests here, two of them this commit's, clean under clippy for the host and for `x86_64-pc-windows-msvc`, `cargo doc -D warnings` quiet over the platform and the command line.
2026-10-16 02:32:05 +00:00
if [ "$TUI_ARGS" = state ]; then
python3 scripts/tui-frame-check.py "$OUT"
else
printf '\033[1;36m==>\033[0m 命令行输出按字符判,不按帧判(TUI_ARGS=%s)\n' "$TUI_ARGS"
fi