fix(control): handle all keys of one input in interactive mode

- The REPL polled the stdin fd, then read one key with std::cin; the
  other keys of the same read stayed in the std::cin buffer, and
  poll() did not report them again
- Read one key with read(2), so poll() reports each key that is not
  handled yet; skip whitespace, as operator>> did
- Stop reading at end of input: before, a closed stdin (e.g.
  < /dev/null) made the loop print the help without a pause
- Enable ControlPlugin.SeveralKeysInOneInput
- Update the documentation pages that described the defect, and
  the source line links into the changed files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-11-04 20:31:47 +00:00
committed by Dennis Klein
parent 9b6662f6a9
commit 47784207d6
9 changed files with 33 additions and 29 deletions

View File

@@ -73,7 +73,7 @@ auto operator<<(std::ostream& os, KeyParam const& param) -> std::ostream&
class InteractiveKey : public testing::TestWithParam<KeyParam>
{};
// One key, then SIGINT ends the device (see the defect below).
// One key, then SIGINT ends the device.
TEST_P(InteractiveKey, PrintsItsAction)
{
RunOptions options;
@@ -92,11 +92,8 @@ INSTANTIATE_TEST_SUITE_P(, InteractiveKey,
KeyParam{'z', "Invalid input: [z]"}),
[](testing::TestParamInfo<KeyParam> const& p) { return string(1, p.param.key); });
// Known defect: the control plugin polls the stdin file descriptor before it
// reads the next key from std::cin. Keys that arrive in one read (e.g. "cq"
// from a pipe) stay in the std::cin buffer, and the plugin never handles them.
// Enable this test with the fix.
TEST(ControlPlugin, DISABLED_SeveralKeysInOneInput)
// Keys that arrive in one read (e.g. "cq" from a pipe) are all handled.
TEST(ControlPlugin, SeveralKeysInOneInput)
{
RunOptions options;
options.control = "interactive";