Teach the console the sequences the corpus already speaks, and let the status port see the window
Three things Snake found the moment somebody ran it in a window, and all three are the same kind of mistake: the console grew a screen and kept asking the terminal. IT COULD NOT CLEAR THE SCREEN. Every program here that moves a cursor does it with ANSI escapes, because until there was a screen the thing on the other end was somebody's terminal. The controller drew "[2J" as three letters and left the board underneath. It now parses them, which is what a video terminal did - a VT100 is exactly this. The whole corpus uses two, ESC[2J and ESC[H, and the general shape is recognised so anything else is swallowed rather than drawn: a sequence nobody implemented should leave no marks. Cursor positioning is in too, since it is the same parse and one line more. IT DID NOT SEE KEYS FROM THE WINDOW, but did when the terminal behind it was focused, which is the whole diagnosis in one sentence. Snake polls the READY bit and never blocks, and consoleFetch - what the status port asks - was polling standard input regardless of whether a front end had installed a hook. So a window's keys were invisible to every program that looks before it reads, and a keystroke aimed at the terminal would be picked up instead. The hook now takes a question. Zero is the status port looking, and must not present or sleep: a program polling in a loop would otherwise be charged a frame for every glance. One is the data port blocking, where presenting is exactly right, because a machine waiting for a key is still a machine somebody is looking at. One value for both would have made either polling ruinous or waiting dead. AND IT RAN SLOWLY, which was the same bug wearing a hat: a game that never receives a steering key is a game that only ever goes one way. Six more checks in Tests/video.sh, to 32: that ESC[2J clears, that ESC[H goes to the corner without disturbing what is drawn, that ESC[3;5H counts rows and columns from one, and that an unknown sequence is swallowed and leaves nothing behind. The hook itself is still the one thing here the suite cannot reach - it exists only when there is a window, and this host has no display. It was found by a person playing Snake, which is where the Test Manual says these go on being found. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
This commit is contained in:
co-authored by
Claude Opus 5
parent
6f8ad42277
commit
556a14b288
@@ -347,6 +347,43 @@ papered scrolled 2 1 \
|
||||
&& result ok "the row that came into view is clear" "not what was there a ring ago" \
|
||||
|| result no "the row that came into view is clear" "something at 2,1"
|
||||
|
||||
# ---- The sequences the corpus already speaks ----
|
||||
#
|
||||
# Every program here that moves a cursor does it with ANSI escapes, because until there was
|
||||
# a screen the thing on the other end was somebody's terminal. A controller that did not
|
||||
# understand them drew "[2J" on the screen and left the board underneath, which is what Snake
|
||||
# did the first time it was run in a window.
|
||||
|
||||
{ printf '#Program\nstart:\n'; say "A"; emit 27; say "[2J"; epilogue; } | run clearscreen || exit 1
|
||||
papered clearscreen 2 1 \
|
||||
&& result ok "ESC[2J clears the screen" "the letter is gone" \
|
||||
|| result no "ESC[2J clears the screen" "still inked at 2,1"
|
||||
|
||||
{ printf '#Program\nstart:\n'; emit 10; emit 10; say "A"; emit 27; say "[H"; say "A"
|
||||
epilogue
|
||||
} | run home || exit 1
|
||||
inked home 2 1 \
|
||||
&& result ok "ESC[H goes back to the corner" "the second letter is at row 0" \
|
||||
|| result no "ESC[H goes back to the corner" "nothing at 2,1"
|
||||
inked home 2 17 \
|
||||
&& result ok "and leaves what was drawn alone" "the first is still on row 2" \
|
||||
|| result no "and leaves what was drawn alone" "nothing at 2,17"
|
||||
|
||||
{ printf '#Program\nstart:\n'; emit 27; say "[3;5H"; say "A"; epilogue; } | run position || exit 1
|
||||
inked position 34 17 \
|
||||
&& result ok "ESC[3;5H puts the cursor there" "row 3, column 5, counting from one" \
|
||||
|| result no "ESC[3;5H puts the cursor there" "nothing at 34,17"
|
||||
|
||||
# A sequence nobody implemented should leave no marks, which is what a real terminal does
|
||||
# with one it does not know. Drawing it would be worse than ignoring it.
|
||||
{ printf '#Program\nstart:\n'; emit 27; say "[9m"; say "A"; epilogue; } | run unknownseq || exit 1
|
||||
inked unknownseq 2 1 \
|
||||
&& result ok "an unknown sequence is swallowed" "the letter after it is at cell 0" \
|
||||
|| result no "an unknown sequence is swallowed" "nothing at 2,1"
|
||||
papered unknownseq 10 1 \
|
||||
&& result ok "and leaves nothing behind" "cell 1 is untouched" \
|
||||
|| result no "and leaves nothing behind" "something at 10,1"
|
||||
|
||||
# And what scrolled off the top is still in the map, which is scrollback nothing had to keep.
|
||||
{ printf '#Program\nstart:\n'
|
||||
say "A"
|
||||
|
||||
Reference in New Issue
Block a user