Commit Graph

7 Commits (dev)

Author SHA1 Message Date
mula.liu b2460d506f The system panel may stop a process, once it has asked who is sitting at that number
The system panel has listed processes for a while, and a list of what is running
gets one question asked of it more than any other: this one is wedged, make it
stop. A panel that can name the hung app and then shrugs is scenery, so the
answer here is yes — spent through the machinery the interface already has for
irreversible things, a dialog that names what it is about to do and a log line
afterwards that says what it did.

The *how* is two lines and not very interesting: `kill(2)` with `SIGKILL`, or
`OpenProcess(PROCESS_TERMINATE)` followed by `TerminateProcess`. Both are the
same promise, which is why `squid_platform::process::force_stop` is called a
forced stop on every platform and the dialog says 强制结束 rather than anything
about saving. There is no TERM-then-KILL handshake in here, because there is no
polite promise to keep: the second line of the dialog is 它不会有机会保存任何内容.

`squid_stats::Sampler::stop` does not use `sysinfo`'s own `Process::kill`, and
the reason is the shape of its answer. It returns `false` for every way a stop
can fail, and two of those ways want opposite things from the reader. `ESRCH`
means the process left on its own and nothing is owed but a redraw; `EPERM`
means it is alive and the reader should go find an elevated terminal. Windows
serves the same pair up as `ERROR_INVALID_PARAMETER` and `ERROR_ACCESS_DENIED`.
A bool cannot carry that difference, so squid makes the call itself and keeps
the words the OS gave, quoted inside a sentence this program owns — the OS's
sentence arrives in the language of the OS, and translates no further than its
own frame.

The *whether* is where the damage is, so it is answered twice. First by rule, in
`squid-platform`: never this squid, never the first process of the machine, and
on Windows never one of the six names a boot rests on. Those rules exist because
the operating system does not enforce all of them. An unelevated squid on macOS
cannot reach `WindowServer` whatever it tries; an elevated squid on Windows
*can* open `csrss.exe` for termination, and the reward for one misplaced Enter
is a machine that reboots without asking. Six names is the whole cost of that
guard. `svchost` is deliberately absent from it, because it hosts services a
user may genuinely need to restart and the machine survives losing one — which
is the test a name has to pass before it belongs on that list.

Then by the operating system, whose answer is the only one with any authority
over this user, this token, this moment. Between the two sits the question the
platform module cannot answer, because it is a question about a sample rather
than about a pid: is the process holding this number still the process whose
name the user read? Pids are seat numbers, handed out again, and a process table
is drawn the moment the panel opens and read from seconds later. So
`squid_stats::Sampler::stop` reads the pid again through the new `sample_of`,
applies the rules to the process that is really there, and calls a name that no
longer matches *gone* — the thing that was pointed at really is gone, whichever
direction the pid moved. `shown_name` is why that comparison means anything:
macOS hands over a path and Windows a bare name, and the process table had been
trimming with `split('/')`, which does nothing at all to a Windows path. Nothing
was wrong on screen, because the name was already short there; it became
evidence, and evidence has to be spelled one way.

`x` is the same verb it has always been. On the three file panels it makes the
row under the cursor go away; the system panel has nothing to delete and does
have a process, so the same finger reaches the same meaning, and
`x_is_still_the_delete_key_on_a_list_of_files` pins the old meaning down so that
this one cannot push it aside. `d` still deletes everywhere. The rules are
applied in `ask_stop_process` *before* the dialog rather than after the answer:
a dialog that can only be answered "no" teaches the user that the dialog is
theatre, and the toast that names the rule says the same thing in less time.

Three crates now each hold a `sleeper()`, which is a duplication worth keeping
on purpose. The thing under test has to be a process — `sleep 60`, or
`ping -n 60 127.0.0.1` where `sleep` is not — and a kill feature tested against
a struct is a kill feature that has never killed anything. Twelve tests come
with this: five in the platform module, including the boot list and a vacant pid
reporting itself as gone; three in the sampler, one of which hands a pid to
`stop` under the wrong name and then checks that the innocent process is still
running; four in the interface, walking `x`, `y`, and a refusal from the key
press to the corpse being reaped. 190 tests green across the workspace, with
`cargo fmt --check` and `cargo clippy --workspace --all-targets` clean for the
host and for `x86_64-pc-windows-msvc` — the target where the boot list,
`TerminateProcess` and the parameter-is-incorrect mapping compile at all, which
is also where `the_processes_a_boot_rests_on_are_named_not_guessed` exists.

The Windows 10/11 box carries the part a mac can only compile. `squid.exe`
there builds with `Win32_System_Threading`, clippy clean under `-D warnings`,
185 tests green; and the dialog was read off the screen rather than off the
buffer — `TUI_COLS=140 TUI_ROWS=35 TUI_CP=936`, 2604 samples of the raw ConPTY
stream, 291 settled frames, 0 of them failing the layout judge, including the
confirm itself: `╭ 结束 iNodeCmn.exe? ╮` / `pid 9080 · 1.2% · 15.4 MB` /
`它不会有机会保存任何内容` / `回车 / y 确认 · n / esc 取消`, and 「已取消」 after `n`.
`docs/ARCHITECTURE.md` gains the module and the key, and one of its diagrams
finally admits that `squid-stats` has depended on `squid-platform` for weeks.
2026-10-16 11:49:10 +08:00
mula.liu f9f86f6103 The app list counted its own header as a row, and the cursor paid for it
Uninstall came back from the Windows box saying the thing it had already said
on macOS: once there are more apps than a page, paging down leaves the list
with no highlight anywhere. Two consoles that have spent this branch being
taught what a `█` costs agree with each other about nothing, so a complaint
that survives both of them is not standing in the console. It was standing in
`draw_uninstall`, and it had been there since the panel was written.

The panel pushes its column header — `size name version source`, plus a filter
chip while a filter is standing — into the same `List` widget that holds the
apps, and paints the highlight by asking whether `row == cursor`, where `row`
counts the apps that `visible()` returned. `ListState::selected` is handed that
same `app.uninstall.cursor`: a number in the space of visible apps, in a widget
whose rows are that space plus one, plus two with the chip. ratatui spends
`selected` on exactly one thing in this configuration, because `highlight_style`
is empty on purpose — the row paints its own highlight so that a cursor survives
a terminal with no colour at all — so the disagreement cannot mispaint a row.
What it can do is decide which rows exist on screen: the scroll window is
positioned around the row one above the cursor. While the list fits in the card,
or while the cursor is high enough in a list that does not, the cursor is inside
the window either way and the header costs nothing. That is why this needed a
machine with more installed apps than a fixture has, and why the same binary
lied the same way on both platforms.

`ScanPanel::lines` has never shown the symptom, and the reason is worth naming
rather than admiring: it holds entries and nothing else, because the heading of
that card lives on the `Block`. One widget, one index space, nothing to drift.
The uninstall *plan* was taught the same lesson from the other direction — it
used to swap item zero for a bundle heading, which held only while the `.app`
was the largest thing in the plan, until a container outgrew it and every row
under the heading sat one line away from its cursor. The app list was the third
place a header had been allowed to spend a row, and the only one nobody had
asked about.

The fix declines to count anything. `chrome` and the entries are two constraints
of one vertical `Layout`: the `Paragraph` takes the first rectangle, the `List`
gets a rectangle holding entries only, and `selected` and `band()` are back to
describing the same rows. Nowhere in the file is `cursor + header_lines` written
down, because an offset is the thing that just went wrong, and the next line of
chrome added to this header would need one of its own.

`the_app_under_the_cursor_is_the_row_that_is_on_screen` is the regression test,
and it loops over every cursor position rather than picking a deep one, because
whether one deep cursor fails depends on how tall the card happens to be where
the test is running — which is a measurement of a machine, not an invariant. For
each position it draws 140x34 and asks the buffer two questions: is the app under
the cursor on the screen at all, and is the cell it landed on wearing the accent
background and the bold that a highlight paints. The series runs twice, once with
the filter chip on screen, because the chip is the second row of the two index
spaces that were drifting apart. Before the fix it stops at cursor 25 with "the
app under the cursor is off screen". Nothing on the screen had been drawn
wrongly, which is the shape of this bug: every row was correct, and the only
thing missing was the cursor.

68 tests in the interface crate, one of them this one, green; `cargo fmt
--check` and `cargo clippy --workspace --all-targets` clean for the host.
2026-10-16 11:17:18 +08:00
mula.liu bf04f2c105 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 10:32:05 +08:00
mula.liu cc678dee21 Put the price list beside the console, since both programs pay it there
The exchange that stops the TUI overflowing lived in `squid-tui`, next to
the renderer, because that is where the bug was found: several copies of one
frame left on a cp936 console, because `─│█░·…↑↓✓` cost two cells there and
one cell in the layout. But the thing that was wrong was never specific to a
renderer. It is a fact about a console — what this glass charges for a
character whose price Unicode left unsettled — and a fact about a console is
worth exactly as much to the next program that draws on it. `squid status`
draws a volume gauge by repeating `█` twenty-eight times and rules a heading
with `─`. Same price. The difference is that the command line had nobody
asking it.

So `currency` now lives in `squid-platform`, beside `console`, and says in
its own documentation why it is there rather than beside the interface: the
command line and the interface buy the same screen at the same counter.
`Exchange` is the table — indexed by code point, holding the replacement
rather than a bit saying *this one is wrong* because the character is what
the caller needs, and built only when this console actually overcharges,
which is what makes `afford` free on the terminals where there is nothing to
repair. `disputed` says which characters are worth asking about, `cheaper`
what each is worth in characters the console accepts, `witnesses` turns
pieces of chrome into the list of questions to ask. `squid_tui::glyphs`
keeps the half that cannot travel: the walk over a finished ratatui
`Buffer`, which is a question about somebody else's library, now a `Carry`
trait implemented for `Exchange` so that the table and its spending still
read as one motion.

The tests went with their subject rather than staying where the code used to
be: what a shading block costs, and what it is worth in `.`, is a question
about prices, so those seven are in `currency` now, and what is left here is
about frames — three that draw a `Buffer` and check where the borders land,
one that reproduces the original overflow, and the two that hold the
invariant worth defending, that the glyphs this interface draws and the
glyphs it asks the price of are one list. A glyph drawn but never priced
looks correct on every terminal that charges one cell for everything,
including the one it was typed on.

176 tests here — the same number as before the move, which is what a move
ought to leave behind — clean under clippy for the host and for
`x86_64-pc-windows-msvc`, and `cargo doc -D warnings` quiet over both crates.
On the box, with only this commit applied: `RESULT: OK`, and the interface
regression at 140x35 on the code page the complaint came from — 890 samples,
90 settled frames, every one measured and none rejected, box-drawing intact.

One drive-by: `Prices::implied` documented itself by linking to a private
function, which `cargo doc -D warnings` refuses, so the link names the
function instead of promising a URL to something nobody outside the module
can reach.
2026-10-16 10:31:42 +08:00
mula.liu d2e28d8ab2 Say what the console probe measures, and stop overstating the TUI claim
The roadmap row claimed the TUI renders correctly "under the real console". It
was verified under the ConPTY that sshd allocates, which is a real console but
not the one being complained about: that one charges two cells per box-drawing
bar and the capture pipeline could not see it. The claim now names the
instrument instead of the impression, because there is one — a frame is judged
by which column its right borders land in, and the judge tests itself.

`docs/ARCHITECTURE.md` still introduced `squid-platform` as a placeholder for
Windows and counted 86 tests, both of which stopped being true a while ago.
2026-10-15 21:23:38 +08:00
mula.liu 4f1022f213 修改了README.md 2026-10-15 10:05:34 +08:00
mula.liu 54585ffc40 squid 0.1.0: macOS 磁盘清理(CLI + TUI) 2026-10-13 17:00:50 +08:00