Deliver the keys that are not characters
An arrow key has never reached this machine. Voyager threw it away for want of anywhere to put it, and a terminal sent ESC [ A, which arrived in the middle of whatever was being read and made it unrecognisable - typing Up at the CosmOS prompt put three bytes in the command line and got "I do not know". So the console names them: one byte each, 0x80 upward, above ASCII so nothing written before them can collide. Up, Down, Left, Right, Home, End and forward Delete, with room above for the paging and function keys. The console normalises, which is what it already does. Behind a window it turns the key somebody pressed into a byte; on a terminal it turns the sequence into the same byte. That is the act it has always performed on Return and Backspace, one layer further along, and it is why a program need not know which of the two it is talking to. What a key MEANS is not the console's business - that belongs to whoever is reading, the same way what is on a disk belongs to the system and what a drive is belongs to the machine. Translated only when standard input really is a terminal. Nothing else sends these sequences, a pipe holds exactly the bytes somebody put in it, and it keeps the Escape-or-Up timing problem out of every test here: a test writes the key values themselves. Line mode drops them, in both front ends, because line mode delivers characters and a line somebody else has finished editing cannot be moved about in. Press.sbx says what it was handed, in hexadecimal and by name, and reads a line before it reads keys so both halves of that rule are checked. Two recordings, one fed as standard input and one as a keyboard, agreeing byte for byte; each break fails exactly one of them. Three checks in terminal.sh type real escape sequences at a pseudo-terminal, which is the only place they are ever read as sequences: that they arrive as keys, that Escape alone is still Escape, and that a character typed straight after an escape is held rather than swallowed. Five recordings re-blessed for Press.sbx appearing on the shared disk, and the whole of that diff is the file's own line and the counts above it. 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
2a29cebc6b
commit
b3726c950a
@@ -122,6 +122,19 @@ static void drainKeyboard(void) {
|
||||
case KEY_BACKSPACE: keyPush(0x08); break;
|
||||
case KEY_TAB: keyPush('\t'); break;
|
||||
case KEY_ESCAPE: keyPush(0x1B); break;
|
||||
// ---- And the keys that are not characters at all ----
|
||||
//
|
||||
// These used to fall through the default below and vanish, because there was no
|
||||
// byte to turn them into. There is now, and it is the console's rather than
|
||||
// this window's - a terminal reaches the same values by a different road, and a
|
||||
// program is entitled not to know which of the two it is talking to.
|
||||
case KEY_UP: keyPush(CONSOLE_KEY_UP); break;
|
||||
case KEY_DOWN: keyPush(CONSOLE_KEY_DOWN); break;
|
||||
case KEY_LEFT: keyPush(CONSOLE_KEY_LEFT); break;
|
||||
case KEY_RIGHT: keyPush(CONSOLE_KEY_RIGHT); break;
|
||||
case KEY_HOME: keyPush(CONSOLE_KEY_HOME); break;
|
||||
case KEY_END: keyPush(CONSOLE_KEY_END); break;
|
||||
case KEY_DELETE: keyPush(CONSOLE_KEY_DELETE); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user